I have dataframe with 1000 text rows.
I did word2vec .
Now I want to create a new field which give me the distance from each sentence to the word that i want, lets say the word “king”.
I thought about taking in each sentence the 4 closet words to the word king and make average of them.
maybe by using model.wv.similarity
.
the avg of each sentnce will be in the field df[‘king’]
I will glad to know how to do that or to hear about another method.
example data:
data = {
'text': [
"The king sat on the throne with wisdom.",
"A queen ruled the kingdom alongside the king.",
"Knights were loyal to their king.",
"The empire prospered under the rule of a wise monarch."
]
}
df = pd.DataFrame(data)
df['text']=df['text'].str.split()
model = Word2Vec(df['text'], vector_size=100, window=2, min_count=1 )
model.wv.similarity('Knights','king')