我正在尝试将情感分析应用到一条带有推特的熊猫数据中。我会发现错误的
IndexError: index out of range in self.
样本数据集:https://drive.google.com/file/d/14GuN3krdNhGDQCLShn3I6FJG-b5Zt02Z/view?usp=sharing
我如何尝试:
import pandas as pd
from tqdm import tqdm
from transformers import pipeline
tqdm.pandas()
sample = pd.read_csv('sample.csv')
model_name = 'finiteautomata/bertweet-base-sentiment-analysis'
classifier = pipeline('sentiment-analysis', model=model_name)
def sentiment_analysis(row):
r = classifier(row.text)[0]
return [r['label'], r['score']]
df_sample.progress_apply(sentiment_analysis, axis=1)一些推文返回错误:IndexError: index out of range in self。我不太确定为什么。

这一次发生在推特78上。
发布于 2022-03-02 11:27:23
你需要用truncating = True把句子截短
def sentiment_analysis(row):
r = classifier(row.text,truncation=True)[0]
return [r['label'], r['score']]https://stackoverflow.com/questions/71316348
复制相似问题