python - 如何加快情绪分析?
问题描述
我正在对几种语言进行情绪分析。我的代码运行成功,但速度极慢(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 非常慢的帖子,但我认为这与我在这里面临的情况不同?
谢谢
解决方案
推荐阅读
- flutter - 是否可以在 Flutter 中创建声音编辑器?
- c# - 使用 process.start 从 .netcore 运行 docker 会引发错误
- html - 用于修改加载网页图像的 Chrome 扩展程序
- python - 类型错误:* 之后的 add() 参数必须是可迭代的,而不是设置
- macos - Ace 编辑器行相互重叠
- python - 从列中提取子字符串
- php - 带有现成物品和发票的 PayPal 订阅 API
- security - Google 安全命令中心 - 资产安全标记与 FINDINGS 安全标记之间的关系
- ruby - 如何在 ruby 中为 rspec 加载和读取 yml 夹具文件
- android - 使用 Firestore 和 Google Speech to Text 时出现重复的类错误