ELECTRA Embeddings(ELECTRA Small)

Description

ELECTRA is a BERT-like model that is pre-trained as a discriminator in a set-up resembling a generative adversarial network (GAN). It was originally published by: Kevin Clark and Minh-Thang Luong and Quoc V. Le and Christopher D. Manning: ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators, ICLR 2020.

Download Copy S3 URI

How to use

...
embeddings = BertEmbeddings.pretrained("electra_small_uncased", "en") \
.setInputCols("sentence", "token") \
.setOutputCol("embeddings")
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, embeddings])
pipeline_model = nlp_pipeline.fit(spark.createDataFrame([[""]]).toDF("text"))
result = pipeline_model.transform(spark.createDataFrame([['I love NLP']], ["text"]))
...
val embeddings = BertEmbeddings.pretrained("electra_small_uncased", "en")
.setInputCols("sentence", "token")
.setOutputCol("embeddings")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, embeddings))
val data = Seq("I love NLP").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["I love NLP"]
embeddings_df = nlu.load('en.embed.electra.small_uncased').predict(text, output_level='token')
embeddings_df

Results

	en_embed_electra_small_uncased_embeddings	            token
		
	[0.7677724361419678, -0.621893048286438, -0.93... 	I
[1.1656712293624878, -0.04712940752506256, 0.1... 	love
[1.0845087766647339, -0.00533430278301239, -0.... 	NLP

Model Information

Model Name: electra_small_uncased
Type: embeddings
Compatibility: Spark NLP 2.6.0+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [word_embeddings]
Language: [en]
Dimension: 256
Case sensitive: false

Data Source

The model is imported from https://tfhub.dev/google/electra_small/2