Smaller BERT Sentence Embeddings (L-8_H-128_A-2)


This is one of the smaller BERT models referenced in Well-Read Students Learn Better: On the Importance of Pre-training Compact Models. The smaller BERT models are intended for environments with restricted computational resources. They can be fine-tuned in the same manner as the original BERT models. However, they are most effective in the context of knowledge distillation, where the fine-tuning labels are produced by a larger and more accurate teacher.


How to use

embeddings = BertEmbeddings.pretrained("sent_small_bert_L8_128", "en") \
      .setInputCols("sentence") \
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, embeddings])
pipeline_model =[[""]]).toDF("text"))
result = pipeline_model.transform(spark.createDataFrame(pd.DataFrame({"text": ["I hate cancer, "Antibiotics aren't painkiller"]})))
val embeddings = BertEmbeddings.pretrained("sent_small_bert_L8_128", "en")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, embeddings))
val result =["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.small_bert_L8_128').predict(text, output_level='sentence')


	en_embed_sentence_small_bert_L8_128_embeddings	      sentence
 	[1.3234734535217285, -0.39469125866889954, 0.0... 	I hate cancer
 	[1.8613495826721191, -0.7580474019050598, -0.6... 	Antibiotics aren't painkiller

Model Information

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

Data Source

The model is imported from