Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

python - Problem on "df['text'].progress_apply(lambda x: bex.extract(x))"

The following is my program code. However, I received an error message as "Error Message". Could you show me how to solve this problem?

bex = BertExtractor()
df["text_feature"] = df["text"].progress_apply(lambda x: bex.extract(x)) 
sim = cos_sim_matrix(np.stack(df.text_feature))

Error Message

 AttributeError: 'str' object has no attribute 'detach'

Explanation of Error Message

 AttributeError                            Traceback (most recent call last)
 <ipython-input-69-dff606d12a1d> in <module>()
      17 
      18 bex = BertExtractor()
 ---> 19 df["text_feature"] = df["text"].progress_apply(lambda x: bex.extract(x)) 
      20 sim = cos_sim_matrix(np.stack(df.text_feature))
      21 

pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-60-f7c4eb8ea2b1> in extract(self, sentence)
     24             return seq_out[0][0].cpu().detach().numpy() 
     25         else:
---> 26             return seq_out[0][0].detach().numpy()
     27 
question from:https://stackoverflow.com/questions/65661238/problem-on-dftext-progress-applylambda-x-bex-extractx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...