Smaller BERT Embeddings (L-6_H-256_A-4)


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("small_bert_L6_256", "en") \
      .setInputCols("sentence", "token") \
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, embeddings])
pipeline_model =[[""]]).toDF("text"))
result = pipeline_model.transform(spark.createDataFrame(pd.DataFrame({"text": ["I love NLP"]})))
val embeddings = BertEmbeddings.pretrained("small_bert_L6_256", "en")
      .setInputCols("sentence", "token")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, embeddings))
val result =["I love NLP"].toDS.toDF("text")).transform(data)
import nlu

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


	token	en_embed_bert_small_L6_256_embeddings
	I	[0.782717764377594, 0.3001103401184082, 1.5869...
	love	[1.3923038244247437, -0.4370909631252289, 2.15...
	NLP	[1.5447113513946533, 0.4231811761856079, 0.277...

Model Information

Model Name: small_bert_L6_256
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