让我们从一个简单的问题开始吧.假设我有一个350字母的句子,并希望将句子分成"好心情"桶或"坏心情"桶.
什么是设计算法来解决句子的最佳方法?
我想将qdap的polarity函数应用于文档向量,每个文档可以包含多个句子,并为每个文档获取相应的极性。例如:
library(qdap)
polarity(DATA$state)$all$polarity
# Results:
[1] -0.8165 -0.4082 0.0000 -0.8944 0.0000 0.0000 0.0000 -0.5774 0.0000
[10] 0.4082 0.0000
Warning message:
In polarity(DATA$state) :
Some rows contain double punctuation. Suggested use of `sentSplit` function.
Run Code Online (Sandbox Code Playgroud)
这个警告不能忽略,因为它似乎添加了文档中每个句子的极性分数。这可能导致文档级极性分数超出 [-1, 1] 范围。
我知道首先运行sentSplit然后在句子中求平均值的选项,可能按字数加权极性,但这是 (1) 低效的(大约是在带有警告的完整文档上运行的时间的 4 倍),并且( 2)不清楚如何给句子加权。这个选项看起来像这样:
DATA$id <- seq(nrow(DATA)) # For identifying and aggregating documents
sentences <- sentSplit(DATA, "state")
library(data.table) # For aggregation
pol.dt <- data.table(polarity(sentences$state)$all)
pol.dt[, id := sentences$id]
document.polarity <- pol.dt[, sum(polarity * wc) / …Run Code Online (Sandbox Code Playgroud) 我想分析用德语写的文本的情绪。我找到了很多关于如何用英语做到这一点的教程,但我没有找到关于如何将它应用于不同语言的教程。
我有一个想法是使用TextBlobPython 库先将句子翻译成英文,然后再进行情感分析,但我不确定这是否是解决此任务的最佳方法。
或者还有其他可能的方法来解决这个任务吗?
目标:将每条推文分类为正面或负面,并将其写入输出文件,其中包含用户名、原始推文和推文的情绪。
代码:
import re,math
input_file="raw_data.csv"
fileout=open("Output.txt","w")
wordFile=open("words.txt","w")
expression=r"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"
fileAFINN = 'AFINN-111.txt'
afinn = dict(map(lambda (w, s): (w, int(s)), [ws.strip().split('\t') for ws in open(fileAFINN)]))
pattern=re.compile(r'\w+')
pattern_split = re.compile(r"\W+")
words = pattern_split.split(input_file.lower())
print "File processing started"
with open(input_file,'r') as myfile:
for line in myfile:
line = line.lower()
line=re.sub(expression," ",line)
words = pattern_split.split(line.lower())
sentiments = map(lambda word: afinn.get(word, 0), words)
#print sentiments
# How should you weight the individual word sentiments?
# You could do N, sqrt(N) or 1 for example. Here …Run Code Online (Sandbox Code Playgroud) 这里已经提出了类似的问题,但没有发布相关代码。
我正在尝试创建一个基于 Scikit-learn VotingClassifier 的 VotingClassifier。仅供参考,SGD、Bernoulli 和 MaxEnt 分类器是 SKLearn 分类器,它们是使用 Scikit 的 GridSearchCV 在相同的训练和测试数据上创建的。
但是,在尝试安装分类器时,我遇到了运行时错误。
这是主程序脚本,我得到的错误位于帖子的底部。
以下是lexicon_transformer和neg_transformer的 github 要点。
我的目录结构是这样的:
回溯(最近一次调用最后一次):文件“main_combination.py”,第 183 行,在 eclf.fit(X_train,y_train) 中
文件“C:\Users\x\python_projects\tsa\classifiers\ensemble_classifier.py”,第 147 行,适合 self.clfs_ = [clone(clf) for clf in self.clfs]
文件“C:\Users\x\Anaconda2\lib\site-packages\sklearn\base.py”,第 51 行,克隆 new_object_params[name] = clone(param, safe=False)
文件“C:\Users\x\Anaconda2\lib\site-packages\sklearn\base.py”,第 39 行,克隆 return estimator_type([clone(e, safe=safe) for e in estimator])
文件“C:\Users\x\Anaconda2\lib\site-packages\sklearn\base.py”,第 39 行,克隆 return estimator_type([clone(e, safe=safe) for e in estimator])
文件“C:\Users\x\Anaconda2\lib\site-packages\sklearn\base.py”,第 51 …
python classification machine-learning sentiment-analysis scikit-learn
我正在使用 google-cloud/language api 进行 #annotate 调用,并从我从各种在线资源中获取的评论 csv 中分析实体和情绪。
\n\n首先,我尝试分析的字符串包含 commentId,因此我重新格式化:
\n\nyoutubez22htrtb1ymtdlka404t1aokg2kirffb53u3pya0,i just bot a Nostromo... ( ._.)\xef\xbb\xbf\nyoutubez22oet0bruejcdf0gacdp431wxg3vb2zxoiov1da,Good Job Baby! MSI Propeller Blade Technology!\xef\xbb\xbf\nyoutubez22ri11akra4tfku3acdp432h1qyzap3yy4ziifc,"exactly, i have to deal with that damned brick, and the power supply can't be upgraded because of it, because as far as power supply goes, i have never seen an external one on newegg that has more power then the x51's\xef\xbb\xbf"\nyoutubez23ttpsyolztc1ep004t1aokg5zuyqxfqykgyjqs,"I like how people are liking your comment about liking the fact that Sky DID …Run Code Online (Sandbox Code Playgroud) javascript string offset google-language-api sentiment-analysis
我正在从 Twitter 上进行情绪分析,但我的推文是西班牙语,所以我无法使用 tidytext 对单词进行分类。有谁知道是否有类似的西班牙语套餐?
是否有任何 NLP python 库可以拆分句子或将单词连接成相关的单词对?例如:
那不是坏例子->“那个”“是”“不错”“例子”
“不错”的意思是一样的好,所以在机器学习中把它当作“不”和“坏”来处理是没有用的。我什至不知道如何称呼这些相关的词对。(术语提取?阶段提取?)或者甚至更好地拆分为带名词的形容词,例如:
与减税有关的不诚实媒体 -> “不诚实媒体”、“相关”、“关于”、“减税”
我找到了 toopia.termextract 但它不适用于 python3。
我有一个文本 blob,其中如果极性 > 0,我将文本分类为正,如果 = 0,则为中性,如果 < 0,则为负。我如何根据将其分类为正、负或中性来获得单词?
python machine-learning python-3.x sentiment-analysis textblob
我是 python 的初学者,正在尝试应用 Gcloud 情绪分析来分析一些句子。python代码由官方提供:https : //cloud.google.com/natural-language/docs/analyzing-sentiment
错误如下:
RetryError: 调用 functools.partial(.error_remapped_callable at 0x0000020081C0EB70>, document { type: PLAIN_TEXT content: "yes i do!" } , metadata=[('x-goog-api-client', 'gl -python/3.6.5 grpc/1.17.1 gax/1.7.0 gapic/1.1.1')]),最后一个异常:503 通道处于状态 TRANSIENT_FAILURE
我尝试了很多方法(例如禁用防火墙,切换到其他笔记本电脑/wifi)来解决但都失败了。我确定环境变量是使用应用程序默认凭据设置的,并且 API 已通过身份验证。
你有什么想法吗?非常感谢!
编码环境:
蟒蛇 3.6
赢10
来自 CMD pip 列表的 python 包——
gcloud (0.18.3),
谷歌 API 核心(1.7.0),
谷歌云语言 (1.1.1)
from google.cloud import language_v1
from google.cloud.language_v1 import enums
import six
def sample_analyze_sentiment(content):
client = language_v1.LanguageServiceClient()
# content = 'Your text to analyze, e.g. Hello, world!'
if isinstance(content, …Run Code Online (Sandbox Code Playgroud) python ×6
nlp ×5
python-3.x ×2
r ×2
textblob ×2
algorithm ×1
gcloud ×1
javascript ×1
nltk ×1
offset ×1
python-2.7 ×1
qdap ×1
scikit-learn ×1
string ×1
tidytext ×1
twitter ×1