I am trying to get the bert embeddings for all the values present in dataframe.
My code looks like:
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
import pandas as pd
sentences =[ ["I'm happy", "I'm full of happiness"], ["I am sam", "I am good"]]
df = pd.DataFrame(sentences)
encoded_df = df.applymap(model.encode(convert_to_tensor=True))
Facing the below error:
encode() missing 1 required positional argument: 'sentences'
Is there any method to achieve this?
CodePudding user response:
You can use
encoded_df = df.applymap(lambda x: model.encode(x, convert_to_tensor=True))