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.
How to use
...
embeddings = BertSentenceEmbeddings.pretrained("sent_small_bert_L4_768", "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([['I hate cancer', "Antibiotics aren't painkiller"]], ["text"]))
...
val embeddings = BertSentenceEmbeddings.pretrained("sent_small_bert_L4_768", "en")
.setInputCols("sentence")
.setOutputCol("sentence_embeddings")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, embeddings))
val data = Seq("I hate cancer, "Antibiotics aren't painkiller").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu
text = ["I hate cancer", "Antibiotics aren't painkiller"]
embeddings_df = nlu.load('en.embed_sentence.small_bert_L4_768').predict(text, output_level='sentence')
embeddings_df
Results
en_embed_sentence_small_bert_L4_768_embeddings sentence
[0.4034431576728821, 0.08385054022073746, 0.08... I hate cancer
[-0.2262536883354187, 0.02650507353246212, -0.... Antibiotics aren't painkiller
Model Information
Model Name: | sent_small_bert_L4_768 |
Type: | embeddings |
Compatibility: | Spark NLP 2.6.0+ |
License: | Open Source |
Edition: | Official |
Input Labels: | [sentence] |
Output Labels: | [sentence_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-4_H-768_A-12/1