首页 > 解决方案 > 如何加快情绪分析?

问题描述

我正在对几种语言进行情绪分析。我的代码运行成功,但速度极慢(1000 万条记录仅用于 11K 条记录)。这是我的代码:

# Spanish Classifier - from https://github.com/aylliote/senti-py
clf = SentimentClassifier()

# Italian Classifier - Also for Russian
from polyglot.text import Text as T

# Germany Classifier
from textblob_de import TextBlobDE as TextBlob_d

# English
from textblob import TextBlob

# French
from textblob_fr import PatternTagger, PatternAnalyzer

def Flag(row):
    try:
        if row['lang'] == 'es':
            txt=clf.predict(row['rev'])
            return txt
        elif row['lang'] == 'it':
            txt=T(row['rev'])
            return txt.polarity
        elif row['lang'] == 'de':
            txt=TextBlob_d(row['rev'])
            return txt.sentiment
        elif row['lang'] == 'en':
            txt=TextBlob(row['rev'])
            return txt.sentiment.polarity
        elif row['lang'] == 'fr':
            txt=TextBlob(row['rev'], pos_tagger=PatternTagger(), 
            analyzer=PatternAnalyzer())
            return txt.sentiment[0]
        elif row['lang'] == 'ru':
            txt=T(row['rev'])
            return txt.polarity
        else:
            return ""
    except:
        return ""

df['sent']=df.apply(Flag,axis=1)

我检查了其他关于 textblob.sentiments import NaiveBayesAnalyzer 非常慢的帖子,但我认为这与我在这里面临的情况不同?

谢谢

标签: pythonnlpclassificationsentiment-analysistextblob

解决方案


推荐阅读