Description
This model contains a deep bidirectional transformer trained on Wikipedia and the BookCorpus. The details are described in the paper “BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding”.
How to use
...
embeddings = BertEmbeddings.pretrained("bert_base_uncased", "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("bert_base_uncased", "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').predict(text, output_level='token')
embeddings_df
Results
token en_embed_bert_embeddings
I [0.5920650362968445, 0.18827693164348602, 0.12...
love [1.2889715433120728, 0.8475795388221741, 0.720...
NLP [0.21503107249736786, -0.9925870299339294, 1.0...
Model Information
Model Name: | bert_base_uncased |
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/google/bert_uncased_L-12_H-768_A-12/1