有没有办法提高情感维德情绪分析器?

2024-10-01 13:39:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我的文本来自一个社交网络,所以你可以想象它的本质,我认为文本是干净的,我能想象到的最小;在执行以下卫生处理之后:

  • 没有网址,没有用户名
  • 没有标点,没有重音
  • 没有数字
  • 没有停止语(我想维德还是这么做的)

我认为运行时是线性的,我不打算做任何并行化,因为更改可用代码需要大量的工作, 例如,对于大约1000个从~50kb到~150kb的文本,它需要大约

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

有没有更好的方法来输入算法来加快烹饪时间? 代码很简单,就像感伤强度分析器要工作的那样,这里是主要部分

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]

Tags: 代码from文本iddate时间groupbody
1条回答
网友
1楼 · 发布于 2024-10-01 13:39:17

/1。你不需要删除停止语,nltk+vader已经这样做了。在

/2。您不需要删除标点符号,因为这会影响维德的极性计算,除了处理开销。所以,继续用标点符号。在

    >>> 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]

相关问题 更多 >