Giter Site home page Giter Site logo

snownlp's People

Contributors

bryant1410 avatar duanguoxue avatar erning avatar henrychanhy avatar isnowfy avatar mozillazg avatar weilu avatar zengliangju avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snownlp's Issues

想知道情感分析的背後的詳細原理

您好
1.
根據您的程式碼,關於情感分析的部分,沒理解錯誤的話,其背後的演算法是基於Bayes的相關模型?
去看過TextBlob的實作後,發現他也是應用Bayes相關的模型(https://textblob.readthedocs.io/en/dev/advanced_usage.html#sentiment-analyzers)

看了你們的東西,但我對於其背後的原理沒有很懂,想知道你們是怎麼用Bayes相關的模型,來進行情感分析的?
想請問您有沒有相關的文獻,或是網站可以參考呢?

TextBlob有做polarity,subjective/objective的分析,不過您的範例只有positive value
那個value值,是否代表越接近1,代表情緒越正向;越接近0,代表情緒越負向呢?

因為TextBlob,在針對英文上面,情緒分析做得很完善
只是中文分析上面,好像還沒有一個針對「極性、正負向」的情緒分析,一個全面且很有效的套件?
目前貌似只有您踏出第一步(而且相當大的一步,感謝),所以想先充分理解您的東西,未來看有沒有機會來完善中文文字探勘這一塊的缺漏

sentiment训练后结果不变?

用自己的训练集训练:

def train():
    from snownlp import sentiment
    sentiment.train('filter_neg.txt', 'filter_pos.txt')
    sentiment.save('sentiment.marshal')

然后调用marshal进行情感分析结果输出:

from snownlp import sentiment
    sentiment.data_path = 'sentiment.marshal'

    with open('test.txt') as f:
        data = f.xreadlines()
        for line in data:
            line = line.decode('utf-8').replace('\r', ' ').replace('\n', ' ').replace('\t', ' ')
            snlp = SnowNLP(line)
            print snlp.sentiments

可是得到的结果和没有调用新的marshal一样,请问是哪里写得有问题吗?

Interspersed English words

Ni Hao, I would like to be able to parse News Articles, some of which contain English words mixed within the chinese sentence.

Eg

s = SnowNLP(u'这个东西真心很cool赞')

print s.pinyin

This results in..

[u'zhe', u'ge', u'dong', u'xi', u'zhen', u'xin', u'hen', u'c', u'o', u'o', u'l', u'zan']

:(

商品评论数据

你好,我是一名学生,正在看你的代码,不知道怎么去找开源的商品评论数据集呢,想用你的做一些分析看看。。。。谢谢

sentiments能说明一下吗

s.sentiments 返回值为 5.4515365364e-05 这是不正常的吧
这个值正常来说应该是小于1的是吧

断句有点问题

楼主你好,我用snowlp做断句处理(s.sentence)时,发现只能对中文格式标点进行断句,若句子中有英文标点则这一句就没有实现断句。比如微博上的评论不一定都是使用中文标点,有很多使用中英文夹杂的标点,这时断句就不够准确了。

小白问题:now初始化位置

我想问下就是词性标注跟分词训练的时候初始化now的时候只在最开始初始化now = ['BOS', 'BOS']么,不是应该在data里每个sentence初始化now = ['BOS', 'BOS']么

Thanks

Thank you for your work.It help me deal with a lot of problems.

需要对结果进行子串归并

对于一个语料

腾讯体育讯 “绿树带风翻翠浪,红花冒雨透芳心”,对于英超的众多荷尔蒙分泌过剩的球星们而言,如果有一位面若桃花的女学生主动投怀送抱,想必很少有人能把持的住,不过有一个人却对此说了“不”,这就是曼联 新C罗 贾努扎伊,根据英国大报《太阳报》的爆料,一位来自利物浦的女大学生曾同他有过一次约会,虽然女方非常的主动,甚至自掏腰包,可是贾努扎伊在女色面前硬是上演了“活该屌丝”的一幕。
提起贾努扎伊,这位叫做梅丽莎的女士非常无奈,她的第一反应是,“我从来没见过贾努扎伊这么吝啬的男人。”这位长相靓丽、气质不俗的女大学生对《太阳报》讲述了她同曼联红星的交往经历,“我们两个是在社交网络上认识的,对于第一次约会,我感到非常兴奋,并且好好的装扮了一下,这可是花了我30英镑。原本,我想他会开着豪车来接我,可是到最后,反而是我开车去接他,到了地方,我还亲自支付停车费。接下来,他居然带我去一家不起眼的快餐店吃饭,这太让我惊讶了,我没有想到堂堂曼联球星在约会时还会吃这玩意。”按照梅丽莎的说法,贾努扎伊请她吃饭仅仅花费了18英镑,而这次晚餐,她还自掏了5英镑停车费。
吃完晚餐,两个人“言归正传”, 贾努扎伊和梅丽莎去了一家宾馆过夜,让这位大学生吃惊的是,虽然曼联天才的周薪足足有3万英镑,但是他找了一家条件很差的三星级宾馆,房费区区60英镑。当然更让梅丽莎瞠目结舌的还在后面,正所谓“花心柔软春含露,柳骨藏蕤夜宿莺”,孤男寡女、同处一室,该干点啥干点啥呗,贾努扎伊偏偏不走寻常路。梅丽莎透露,在这家宾馆里,贾努扎伊做了两件事,第一件事情是看片,据称是一部叫做《X元素》的电视剧,第二件事情是聊天,曼联天才讲述了自己爱用发胶的偏好,还聊到了他的母亲经常帮自己修理眉毛。至于男女床笫那点事,贾努扎伊是只字不提,更没有实际行动。在晚上9点多的时候,两个人实在没有啥事可干了,最终梅丽莎开车把贾努扎伊送回了家。
从两人吃饭到开房,贾努扎伊一共花费了78英镑,如此的吝啬让梅丽莎伤透了心。让她哭笑不得的是,在两人分别一个小时后,曼联天才给梅丽莎发了短信,内容是“我爱你”。此后,梅丽莎和贾努扎伊又保持了一段时间的电话和短信联系,她甚至还特地打车去曼彻斯特同其再度见面,然而这一次她又失望了,曼联天才连区区40英镑打车费都不愿意给她支付。目前,梅丽莎有了新的男朋友,回忆这段往事的时候,她辛酸的表示,“我认为一个拿普通工资的男人都会比他对我好。”看起来,曼联天才伤透了这位女大学生的心。

使用 keywords(3) 的输出为:

扎伊

而这实际是个人名“贾努扎伊”,这种通过子串归并是很容易得出这个人名并且具有更高的分值的。
建议考虑。

textrank算法的困惑,请解惑,非常感谢!

您好,关于textrank算法中,感觉有点问题,以keywordTextRank为例,
当计算节点k的rank值时,您的代码是
for k, v in self.words.items():
m[k] = 1-self.d
for j in v:
if k == j or len(self.words[j]) == 0:
continue
m[k] += (self.d/len(self.words[j])*self.vertex[j])
if abs(m[k] - self.vertex[k]) > max_diff:
max_diff = abs(m[k] - self.vertex[k])
根据k,v的关系,v中包含的是指向节点k的所有节点集合,如果这样,在内循环中的len(self.words[j]这里算的是节点j的入度,即指向节点j的数量。但实际的textrank算法中,这里应该是节点j的出度,即节点j外链接的数量。请问作者,这里的代码是否有问题?感谢!

snownlp doesn't work under python 2.6

When importing snownlp, the following exception is thrown:

Traceback (most recent call last):
File "./1.py", line 4, in
from snownlp import SnowNLP
File "/usr/local/lib/python2.6/dist-packages/snownlp/init.py", line 5, in
from . import seg
File "/usr/local/lib/python2.6/dist-packages/snownlp/seg/init.py", line 12, in
segger.load(data_path, True)
File "/usr/local/lib/python2.6/dist-packages/snownlp/seg/seg.py", line 23, in load
self.segger.load(fname, iszip)
File "/usr/local/lib/python2.6/dist-packages/snownlp/seg/y09_2047.py", line 40, in load
if sys.version_info.major == 3:
AttributeError: 'tuple' object has no attribute 'major'

This is because sys.version_info is a tuple in python 2.6 and only can be accessed by name, such as sys.version_info.major since python 2.7

开放更多接口

你好!

一直用python,不过在分词领域只是刚刚接触。
我现在做的一个设想是希望读取一份很大(大概60页左右)的文件,然后根据文件内容,为用户提供一些输入建议,比如读取了“一枝红杏出墙来”,那在用户输入“一枝红”后自动提示“杏出墙来”。
想通过这个库来实现,不过似乎需要用到其中的trie或其他的数据结构。
由于对分词算法太不熟悉,所以暂时无法快速理解整个库的内部逻辑,所以希望作者能给出一点提示和建议。
感谢!

Python 3.5 SnowNLP关键词分析每次运行结果不同

比如我在一段文本里面选择10个关键词
content=...#内容
r=SnowNLP(content)
result=r.keywords(10, False)
第一次运行结果:
['執', '這', '壺', '年', '版', '星期日', '下午', '收', '也出', '土']
第二次:
['出', '年', '版', '星期日', '下午', '執壺', '種', '級', '低', '岛']
第三次:
['壺', '種', '年', '星期日', '下午', '岛', '也出', '也收藏', '物館', '明這']

我怀疑原因和python版本有关,见jieba分词的类似问题
fxsjy/jieba#228

加载太慢,可否考虑优化一下

看了一下,语料库的大小也就几M,但是执行 from snownlp import SnowNLP 需要花费快10秒钟,感觉可能程序有些地方有问题?可否考虑优化一下?

数字计算出bug了

Traceback (most recent call last):
File "./test.py", line 30, in
print s.sentiments
File "/usr/local/lib/python2.7/dist-packages/snownlp/init.py", line 37, in sentiments
return sentiment.classify(self.doc)
File "/usr/local/lib/python2.7/dist-packages/snownlp/sentiment/init.py", line 67, in classify
return classifier.classify(sent)
File "/usr/local/lib/python2.7/dist-packages/snownlp/sentiment/init.py", line 40, in classify
ret, prob = self.classifier.classify(self.handle(sent))
File "/usr/local/lib/python2.7/dist-packages/snownlp/classification/bayes.py", line 71, in classify
now += exp(tmp[otherk]-tmp[k])
OverflowError: math range error

我认为这里可以抓住这个exp的异常然后假设这个数字是sys.maxint

hi boy

你的bm25算法,计算idf的时候用的是math.log(self.D-v+0.5)-math.log(v+0.5),但是我看了一些文章,计算方式确实log(self.D)-log(v+1),请问这2个计算有什么区别,还是可以替换的呢???

可以提供文本训练的接口么?

首先非常感谢你的工作,这个工具太棒了。能不能提供一下训练的接口,这样可以根据不同的应用场景使用语料自己训练

如何自定义情感词典

hi,首先感谢作者做出这样一个实用的库出来,我想问如果我手上有情感词汇词典文本文件,如果和本库结合使用?thanks

情感计算

你好 我想问下你们关于情感的功能用的是什么算法呢

文章切成句子有问题

normal/init.py get_sentences函数,当文本中包含全角空格(\xe3\x80\x80)的时候,文本不能处理 需将全角空格先替换成半角空格或者直接删除

可以加载json文件吗?

本人最近想用snownlp对中文文本(微博数据)进行情感分析,用的是json文件,自己试了一下没成功,动手能力不是很好,请问大家有没有做过这方面的工作了?

python3下的问题

通过pip安装后

import snownlp

报错,提示seg.marshal文件有问题

具体错误信息如下:
/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/snownlp/init.py in ()
3
4 from . import normal
----> 5 from . import seg
6 from . import tag
7 from . import sentiment

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/snownlp/seg/init.py in ()
10 'seg.marshal')
11 segger = TnTseg.Seg()
---> 12 segger.load(data_path, True)
13
14

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/snownlp/seg/seg.py in load(self, fname, iszip)
21
22 def load(self, fname, iszip=True):
---> 23 self.segger.load(fname, iszip)
24
25 def train(self, fname):

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/snownlp/seg/y09_2047.py in load(self, fname, iszip)
45 try:
46 f = gzip.open(fname, 'rb')
---> 47 d = marshal.loads(f.read())
48 except IOError:
49 f = open(fname, 'rb')

ValueError: bad marshal data (unknown type code)

如何产生更好的summary

不好意思,这个其实不是什么issue,我只是想请教一下,如何产生更好的summary?需要在现有的算法上做什么改进吗?

classification

不知道楼主可否给一个 classification example, source code看不太明白。

然后,不知道会希望加入SVM之类的方法吗?

在向服务器部署时,进程意外终止

在向服务器部署时,进程意外终止

感谢您的分享,很实用的库,学习中
不过在部署服务器的时候,出现了一点问题

场景复现

服务器环境:centos,内存2G,CPU Intel(R) Xeon(R) E5-2420 1.9GHz

在执行模块导入时

from snownlp import SnowNLP

进程be killed
使用top命令查看CPU占用超过100%,Memory 27%
而在更低配置的个人电脑上就没有问题,一直没有分析出原因,不知您有可行的建议么

关于分词模块的数据平滑

CharacterBasedGenerativeModel统计时默认用的是NormalProb做的数据平滑,我在训练时试图换成frequency.py中的加一平滑或古德图灵平滑,结果分词结果却出奇的差,请问是怎么回事呢?

使用 cPickle 代替 marshal ?

marshal 的 文档 上有这么一句:

it may change between Python versions (although it rarely does)

不过 marshal 的速度比 cPickle 要快很多。

MemoryError

 * Running on http://127.0.0.1:8001/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "weibo_sentiment/main.py", line 24, in <module>
    from weibo_sentiment import (
  File "/home/www/weibo_sentiment/weibo_sentiment/weibo_model.py", line 10, in <module>
    from snownlp import SnowNLP
  File "/usr/local/lib/python2.7/dist-packages/snownlp/__init__.py", line 5, in <module>
    from . import seg
  File "/usr/local/lib/python2.7/dist-packages/snownlp/seg/__init__.py", line 12, in <module>
    segger.load(data_path, True)
  File "/usr/local/lib/python2.7/dist-packages/snownlp/seg/seg.py", line 23, in load
    self.segger.load(fname, iszip)
  File "/usr/local/lib/python2.7/dist-packages/snownlp/seg/y09_2047.py", line 51, in load
    data = f.read()
  File "/usr/lib/python2.7/gzip.py", line 254, in read
    self._read(readsize)
  File "/usr/lib/python2.7/gzip.py", line 313, in _read
    self._add_read_data( uncompress )
  File "/usr/lib/python2.7/gzip.py", line 331, in _add_read_data
    self.extrabuf = self.extrabuf[offset:] + data
MemoryError

It is running on Aliyun ECS 1GB RAM.

File "/usr/local/lib/python2.7/dist-packages/snownlp/seg/y09_2047.py", line 51, in load
    data = f.read()

Change to readlines ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.