Smaller BERT Embeddings (L-10_H-768_A-12)

Description

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.

Download Copy S3 URI

How to use

...
embeddings = BertEmbeddings.pretrained("small_bert_L10_768", "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("small_bert_L10_768", "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.bert.small_L10_768').predict(text, output_level='token')
embeddings_df

Results

	token	en_embed_bert_small_L10_768_embeddings
		
I 	[-0.48520517349243164, -0.4840145409107208, 0....
love 	[-0.5073645114898682, -0.1760852038860321, -0....
NLP 	[0.20363765954971313, 0.5075660347938538, 0.25...

Model Information

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

Data Source

The model is imported from https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-768_A-12/1