gpt4 book ai didi

python - 从 Huggingface 模型中提取中性情绪

转载 作者:行者123 更新时间:2023-12-01 23:12:08 31 4
gpt4 key购买 nike

我正在使用 Hugging-face pipeline 进行情绪分析任务,它会给出正面/负面情绪以及置信度分数。就我而言,我需要三个输出(正面/中性/负面)。问题是即使是中性句子(例如:“他有她有”),拥抱脸也给我很高的信心分数?有什么建议吗?

from transformers import pipeline
model = pipeline(task = 'sentiment-analysis')
sentence = 'some text to evaluate'
predicted = model(sentence)
print(predicted)

以下是一些输出示例:

----------------------------------------------
sentence = 'I love you'
predicted = model(sentence)
predicted
[{'label': 'POSITIVE', 'score': 0.9998656511306763}]
----------------------------------------------
sentence = 'I hate you'
predicted = model(sentence)
predicted
[{'label': 'NEGATIVE', 'score': 0.9991129040718079}]
----------------------------------------------
sentence = 'I have she had'
predicted = model(sentence)
predicted
[{'label': 'POSITIVE', 'score': 0.9821817874908447}]
----------------------------------------------
sentence = 'I go to work'
predicted = model(sentence)
predicted
[{'label': 'POSITIVE', 'score': 0.9457777738571167}]
----------------------------------------------
sentence = 'This movie was actually neither that funny, nor super witty.'
predicted = model(sentence)
predicted
[{'label': 'NEGATIVE', 'score': 0.9997298121452332}]

最佳答案

您可以使用 model确实包含一个 neutral 标签,this模型例如:

model = pipeline('sentiment-analysis', model="finiteautomata/bertweet-base-sentiment-analysis")`

关于python - 从 Huggingface 模型中提取中性情绪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69726643/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com