<jupyter_start><jupyter_text><jupyter_code>!pip install flair
import numpy as np
from flair.embeddings import WordEmbeddings,TransformerWordEmbeddings
from flair.data import Sentence
from scipy.spatial import distance<jupyter_output><empty_output><jupyter_text>**Glove Embeding example**<jupyter_code>glove_embedding=WordEmbeddings('glove')
sentence1=Sentence('apple released iphone 12pro max in 2020')
glove_embedding.embed(sentence1)

for token in sentence1:
    print(token)
    print(token.embedding)
sentence1[0]
sentence1[0].embedding

sentence_2 = Sentence('an apple a day keeps the doctor away')
glove_embedding.embed(sentence_2)

for token in sentence_2:
    print(token)
    print(token.embedding)
    print("\n")
glove_dst = distance.euclidean(np.array(sentence1[0].embedding), 
                               np.array(sentence_2[1].embedding))
print("Distance between apple embeddings for Glove = {}".format(glove_dst))<jupyter_output>Distance between apple embeddings for Glove = 0.0<jupyter_text>**Bert Embedding**<jupyter_code>bert_embedding = TransformerWordEmbeddings('bert-base-multilingual-cased')


bert_embedding.embed(sentence1)
for token in sentence1:
    print(token)
    print(token.embedding)
bert_embedding.embed(sentence_2)

for token in sentence_2:
    print(token)
    print(token.embedding)
bert_dst = distance.euclidean(np.array(sentence1[0].embedding), 
                               np.array(sentence_2[1].embedding))

print("Distance between apple embeddings for Glove = {}".format(bert_dst))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10246679316888045, 'fraction_numerical': 0.018975332068311195, 'mean_word_length': 5.038167938931298, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '254310', 'license': 'Apache-2.0', 'n_tokens_mistral': 550, 'n_tokens_neox': 513, 'n_words': 96, 'path': 'Bert_Vs_word2vec.ipynb', 'repo_name': 'adityakumarpinjala/BERT-V-s-Word2vec', 'size': '1581'}