gpt4 book ai didi

python - 有没有办法提高 nltk.sentiment.vader 情感分析的性能?

转载 作者:行者123 更新时间:2023-11-28 18:20:43 25 4
gpt4 key购买 nike

我的文字来源于一个社交网络,所以你可以想象它的本质,我认为文字是我想象中的干净和最小的;执行以下 sanitizer 后:

  • 没有网址,没有用户名
  • 没有标点符号,没有重音符号
  • 没有数字
  • 没有停用词(我想 vader 还是这样做了)

我认为运行时是线性的,我不打算进行任何并行化,因为更改可用代码需要付出大量努力,例如,对于大约 1000 条从 ~50 kb 到 ~150 kb 字节的文本,它需要大约

在我的机器上运行时间约为 10 分钟。

是否有更好的方法来提供算法以加快 cooking 时间?代码与 SentimentIntensityAnalyzer 旨在工作的一样简单,这里是主要部分

sid = SentimentIntensityAnalyzer()

c.execute("select body, creation_date, group_id from posts where (substring(lower(body) from (%s))=(%s)) and language=\'en\' order by creation _ date DESC (s,s,)")
conn.commit()
if(c.rowcount>0):
dump_fetched = c.fetchall()

textsSql=pd.DataFrame(dump_fetched,columns=['body','created_at', 'group_id'])
del dump_fetched
gc.collect()
texts = textsSql['body'].values
# here, some data manipulation: steps listed above
polarity_ = [sid.polarity_scores(s)['compound'] for s in texts]

最佳答案

/1。您不需要删除停用词,nltk+vader 已经这样做了。

/2。您无需删除标点符号,因为除了处理开销外,这也会影响 vader 的极性计算。所以,继续使用标点符号吧。

    >>> txt = "this is superb!"
>>> s.polarity_scores(txt)
{'neg': 0.0, 'neu': 0.313, 'pos': 0.687, 'compound': 0.6588}
>>> txt = "this is superb"
>>> s.polarity_scores(txt)
{'neg': 0.0, 'neu': 0.328, 'pos': 0.672, 'compound': 0.6249}

/3.你也应该引入句子标记化,因为它会提高准确性,然后根据句子计算一个段落的平均极性。这里的例子:https://github.com/cjhutto/vaderSentiment/blob/master/vaderSentiment/vaderSentiment.py#L517

/4。极性计算彼此完全独立,可以使用 multiprocessing pool对于小尺寸,比如 10,可以很好地提高速度。

polarity_ = [sid.polarity_scores(s)['compound'] for s in texts]

关于python - 有没有办法提高 nltk.sentiment.vader 情感分析的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45296897/

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