ELECTRA Sentence Embeddings(ELECTRA Large)

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

How to use

...
embeddings = BertEmbeddings.pretrained("sent_electra_large_uncased", "en") \
      .setInputCols("sentence") \
      .setOutputCol("sentence_embeddings")
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, embeddings])
pipeline_model = nlp_pipeline.fit(spark.createDataFrame([[""]]).toDF("text"))
result = pipeline_model.transform(spark.createDataFrame(pd.DataFrame({"text": ["I hate cancer, "Antibiotics aren't painkiller"]})))
...
val embeddings = BertEmbeddings.pretrained("sent_electra_large_uncased", "en")
      .setInputCols("sentence")
      .setOutputCol("sentence_embeddings")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, embeddings))
val result = pipeline.fit(Seq.empty["I hate cancer, "Antibiotics aren't painkiller"].toDS.toDF("text")).transform(data)
import nlu

text = ["I hate cancer", "Antibiotics aren't painkiller"]
embeddings_df = nlu.load('en.embed_sentence.electra_large_uncased').predict(text, output_level='sentence')
embeddings_df

Results

	sentence	                        en_embed_sentence_electra_large_uncased_embeddings
		
      I hate cancer 	                  [-0.5168956518173218, -0.4284093976020813, -0....
      Antibiotics aren't painkiller 	[0.03924501687288284, 0.28086787462234497, 0.3...

Model Information

Model Name: sent_electra_large_uncased
Type: embeddings
Compatibility: Spark NLP 2.6.0+
License: Open Source
Edition: Official
Input Labels: [sentence]
Output Labels: [sentence_embeddings]
Language: [en]
Dimension: 1024
Case sensitive: false

Data Source

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