标签: sentiment-analysis

在DB中保存100万个句子 - 删除不相关的英语单词

我正在尝试训练朴素贝叶斯分类器,从情绪中提取正/负词.例:

我喜欢这部电影 :))

我讨厌下雨的时候:(

我的想法是根据所使用的emoctions提取正面或负面的句子,但是为了训练分类器并将其持久化到数据库中.

问题是我有超过100万个这样的句子,所以如果我逐字训练,数据库就会折腾.我想删除所有不相关的单词示例'I','this','when','it',以便我必须进行数据库查询的次数较少.

请帮我解决这个问题,向我建议更好的方法

谢谢

database hadoop nlp classification sentiment-analysis

6
推荐指数
2
解决办法
889
查看次数

使用 R 的 qdap 包估计文档极性而不使用 sentSplit

我想将qdappolarity函数应用于文档向量,每个文档可以包含多个句子,并为每个文档获取相应的极性。例如:

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)

nlp r sentiment-analysis qdap

5
推荐指数
1
解决办法
3751
查看次数

非英语文本的情感分析

我想分析用德语写的文本的情绪。我找到了很多关于如何用英语做到这一点的教程,但我没有找到关于如何将它应用于不同语言的教程。

我有一个想法是使用TextBlobPython 库先将句子翻译成英文,然后再进行情感分析,但我不确定这是否是解决此任务的最佳方法。

或者还有其他可能的方法来解决这个任务吗?

python nlp machine-learning sentiment-analysis textblob

5
推荐指数
1
解决办法
5511
查看次数

为什么谷歌自然语言为分析的字符串返回错误的 beginOffset?

我正在使用 google-cloud/language api 进行 #annotate 调用,并从我从各种在线资源中获取的评论 csv 中分析实体和情绪。

\n\n

首先,我尝试分析的字符串包含 commentId,因此我重新格式化:

\n\n
youtubez22htrtb1ymtdlka404t1aokg2kirffb53u3pya0,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&#39;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&#39;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

5
推荐指数
1
解决办法
347
查看次数

如何将句子拆分为相关词(术语提取)?

是否有任何 NLP python 库可以拆分句子或将单词连接成相关的单词对?例如:

那不是坏例子->“那个”“是”“不错”“例子”

“不错”的意思是一样的好,所以在机器学习中把它当作“不”和“坏”来处理是没有用的。我什至不知道如何称呼这些相关的词对。(术语提取?阶段提取?)或者甚至更好地拆分为带名词的形容词,例如:

与减税有关的不诚实媒体 -> “不诚实媒体”、“相关”、“关于”、“减税”

我找到了 toopia.termextract 但它不适用于 python3。

python nlp text-extraction nltk sentiment-analysis

5
推荐指数
1
解决办法
942
查看次数

参数的列数不匹配

我使用这个例子对R中的txt文档集合进行情感分析。代码是:

library(tm)
library(tidyverse)
library(tidytext)
library(glue)
library(stringr)
library(dplyr)
library(wordcloud)
require(reshape2)

files <- list.files(inputdir,pattern="*.txt")

GetNrcSentiment <- function(file){

    fileName <- glue(inputdir, file, sep = "")
    fileName <- trimws(fileName)
    fileText <- glue(read_file(fileName))
    fileText <- gsub("\\$", "", fileText) 

    tokens <- data_frame(text = fileText) %>% unnest_tokens(word, text)

    # get the sentiment from the first text: 
    sentiment <- tokens %>%
        inner_join(get_sentiments("nrc")) %>% # pull out only sentiment words
        count(sentiment) %>% # count the # of positive & negative words
        spread(sentiment, n, fill = 0) %>% …
Run Code Online (Sandbox Code Playgroud)

r sentiment-analysis tidyverse tidytext

5
推荐指数
1
解决办法
1万
查看次数

在 nltk for python 中编辑 Vader_lexicon.txt 以添加与我的域相关的单词

我正在使用vaderinnltk来查找文件中每一行的情绪。我有两个问题:

  1. 我需要添加单词,vader_lexicon.txt但其语法如下:

攻击 -2.5 0.92195 [-1, -3, -3, -3, -4, -3, -1, -2, -2, -3]

-2.5和代表什么0.92195 [-1, -3, -3, -3, -4, -3, -1, -2, -2, -3]

我应该如何为新单词编码?假设我必须添加类似'100%',的内容'A1'

  1. 我还可以在文件夹中看到积极和消极的单词txt nltk_data\corpora\opinion_lexicon。这些如何被利用?我也可以在这些 txt 文件中添加我的话吗?

python nlp nltk python-3.x sentiment-analysis

5
推荐指数
1
解决办法
3316
查看次数

RetryError: 使用 Gcloud 调用 functools.partial 时超出了 600.0s 的截止日期

我是 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 python-3.x sentiment-analysis gcloud

5
推荐指数
0
解决办法
743
查看次数

如何从 Bloomberg API 获取有关特定证券(股票)和日期范围的新闻提要?

我正在开发一个项目,该项目要求我从 Bloomberg API 获取有关特定日期范围内特定证券(例如 Netflix)的新闻文章。我想在 Python 中执行此操作并获取结构 (JSON/XML) 格式的新闻文章。我相信这可以通过使用 Bloomberg Terminal 使用 EDTF(事件驱动交易源)来完成,但我想使用 Bloomberg API 来完成此操作。

我需要这些新闻文章来对文章进行情感分析。

我读了这个问题的答案:Scrape News feed from Bloomberg Terminal

我知道我确实可以访问 EDTF feed,但不知道如何在 Python 中以编程方式获取 feed,因为围绕它的文档实际上很少甚至没有。如果我可以使用 PDBLP(https://matthewgilbert.github.io/pdblp/api.html),那就更好了!

请链接一些文档、代码示例来了解如何解决此问题。如果您在 Bloomberg 上从事过类似的项目,那么如果您能分享一些代码示例,那就太好了。谢谢你!

python nlp bloomberg python-3.x sentiment-analysis

5
推荐指数
0
解决办法
3208
查看次数

带有 tfidf 和计数向量化器的 gridsearchcv

我想使用 GridSearchCV 进行参数调整。是否还可以使用 GridSearchCV 检查 CountVectorizer 还是 TfidfVectorizer 效果最好?我的想法:

pipeline = Pipeline([
           ('vect', TfidfVectorizer()),
           ('clf', SGDClassifier()),
])
parameters = {
'vect__max_df': (0.5, 0.75, 1.0),
'vect__max_features': (None, 5000, 10000, 50000),
'vect__ngram_range': ((1, 1), (1, 2), (1,3),  
'tfidf__use_idf': (True, False),
'tfidf__norm': ('l1', 'l2', None),
'clf__max_iter': (20,),
'clf__alpha': (0.00001, 0.000001),
'clf__penalty': ('l2', 'elasticnet'),
'clf__max_iter': (10, 50, 80),
}

grid_search = GridSearchCV(pipeline, parameters, n_jobs=-1, verbose=1, cv=5)
Run Code Online (Sandbox Code Playgroud)

我的想法:CountVectorizer 与 TfidfVectorizer 相同,其中 use_idf=False 且 normalize=None。如果 GridSearchCV 给出这些参数的最佳结果,那么 CountVectorizer 是最佳选择。那是对的吗?

先感谢您 :)

python machine-learning sentiment-analysis scikit-learn gridsearchcv

5
推荐指数
1
解决办法
5900
查看次数