For example in the sentence: "Earth revolves around the sun and rotate around its own axis", I want to embed it with BERT word embeddings and find the embedding for "rotate" in this particular sentence. How to do it?
For example in the sentence: "Earth revolves around the sun and rotate around its own axis", I want to embed it with BERT word embeddings and find the embedding for "rotate" in this particular sentence. How to do it?
flair has made this quite easy. First install the library using
!pip install flair
then using the below code you can get the embedding for every token in a sentence AKA context:
from flair.data import Sentence
s = Sentence('the dummy sentence to be embedded')
from flair.embeddings import BertEmbeddings
bert_embedding = BertEmbeddings()
bert_embedding.embed(s)
for token in s:
print(token.embedding)