{"id":13482886,"url":"https://github.com/isnowfy/snownlp","last_synced_at":"2025-05-13T20:16:53.386Z","repository":{"id":12124864,"uuid":"14715502","full_name":"isnowfy/snownlp","owner":"isnowfy","description":"Python library for processing Chinese text","archived":false,"fork":false,"pushed_at":"2020-01-19T02:39:05.000Z","size":97321,"stargazers_count":6542,"open_issues_count":44,"forks_count":1369,"subscribers_count":349,"default_branch":"master","last_synced_at":"2025-04-28T11:52:40.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ModelN/sDashboard","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isnowfy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-26T11:46:56.000Z","updated_at":"2025-04-28T10:19:58.000Z","dependencies_parsed_at":"2022-07-12T15:04:35.943Z","dependency_job_id":null,"html_url":"https://github.com/isnowfy/snownlp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isnowfy%2Fsnownlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isnowfy%2Fsnownlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isnowfy%2Fsnownlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isnowfy%2Fsnownlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isnowfy","download_url":"https://codeload.github.com/isnowfy/snownlp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020652,"owners_count":22000756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:06.432Z","updated_at":"2025-05-13T20:16:48.378Z","avatar_url":"https://github.com/isnowfy.png","language":"Python","funding_links":[],"categories":["Natural Language Processing","资源列表","Python","Papers","自然语言处理","中文自然语言处理","Packages","自然語言處理-中文","Chinese NLP Toolkits 中文NLP工具","Awesome Python","Uncategorized"],"sub_categories":["自然语言处理","Single-Document-Summarization (as references)","General Purpose NLP","General-Purpose Machine Learning","Libraries","函式庫","Toolkits 综合NLP工具包","Natural Language Processing","Uncategorized"],"readme":"# SnowNLP: Simplified Chinese Text Processing\n\nSnowNLP是一个python写的类库，可以方便的处理中文文本内容，是受到了[TextBlob](https://github.com/sloria/TextBlob)的启发而写的，由于现在大部分的自然语言处理库基本都是针对英文的，于是写了一个方便处理中文的类库，并且和TextBlob不同的是，这里没有用NLTK，所有的算法都是自己实现的，并且自带了一些训练好的字典。注意本程序都是处理的unicode编码，所以使用时请自行decode成unicode。\n\n~~~~{python}\nfrom snownlp import SnowNLP\n\ns = SnowNLP(u'这个东西真心很赞')\n\ns.words         # [u'这个', u'东西', u'真心',\n                #  u'很', u'赞']\n\ns.tags          # [(u'这个', u'r'), (u'东西', u'n'),\n                #  (u'真心', u'd'), (u'很', u'd'),\n                #  (u'赞', u'Vg')]\n\ns.sentiments    # 0.9769663402895832 positive的概率\n\ns.pinyin        # [u'zhe', u'ge', u'dong', u'xi',\n                #  u'zhen', u'xin', u'hen', u'zan']\n\ns = SnowNLP(u'「繁體字」「繁體中文」的叫法在臺灣亦很常見。')\n\ns.han           # u'「繁体字」「繁体中文」的叫法\n                # 在台湾亦很常见。'\n\ntext = u'''\n自然语言处理是计算机科学领域与人工智能领域中的一个重要方向。\n它研究能实现人与计算机之间用自然语言进行有效通信的各种理论和方法。\n自然语言处理是一门融语言学、计算机科学、数学于一体的科学。\n因此，这一领域的研究将涉及自然语言，即人们日常使用的语言，\n所以它与语言学的研究有着密切的联系，但又有重要的区别。\n自然语言处理并不是一般地研究自然语言，\n而在于研制能有效地实现自然语言通信的计算机系统，\n特别是其中的软件系统。因而它是计算机科学的一部分。\n'''\n\ns = SnowNLP(text)\n\ns.keywords(3)\t# [u'语言', u'自然', u'计算机']\n\ns.summary(3)\t# [u'因而它是计算机科学的一部分',\n                #  u'自然语言处理是一门融语言学、计算机科学、\n\t\t\t\t#\t 数学于一体的科学',\n\t\t\t\t#  u'自然语言处理是计算机科学领域与人工智能\n\t\t\t\t#\t 领域中的一个重要方向']\ns.sentences\n\ns = SnowNLP([[u'这篇', u'文章'],\n             [u'那篇', u'论文'],\n             [u'这个']])\ns.tf\ns.idf\ns.sim([u'文章'])# [0.3756070762985226, 0, 0]\n~~~~\n\n## Features\n\n* 中文分词（[Character-Based Generative Model](http://aclweb.org/anthology//Y/Y09/Y09-2047.pdf)）\n* 词性标注（[TnT](http://aclweb.org/anthology//A/A00/A00-1031.pdf) 3-gram 隐马）\n* 情感分析（现在训练数据主要是买卖东西时的评价，所以对其他的一些可能效果不是很好，待解决）\n* 文本分类（Naive Bayes）\n* 转换成拼音（Trie树实现的最大匹配）\n* 繁体转简体（Trie树实现的最大匹配）\n* 提取文本关键词（[TextRank](https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf)算法）\n* 提取文本摘要（[TextRank](https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf)算法）\n* tf，idf\n* Tokenization（分割成句子）\n* 文本相似（[BM25](http://en.wikipedia.org/wiki/Okapi_BM25)）\n* 支持python3（感谢[erning](https://github.com/erning)）\n\n## Get It now\n\n~~~~\n$ pip install snownlp\n~~~~\n\n## 关于训练\n\n现在提供训练的包括分词，词性标注，情感分析，而且都提供了我用来训练的原始文件\n以分词为例\n分词在`snownlp/seg`目录下\n~~~~{python}\nfrom snownlp import seg\nseg.train('data.txt')\nseg.save('seg.marshal')\n# from snownlp import tag\n# tag.train('199801.txt')\n# tag.save('tag.marshal')\n# from snownlp import sentiment\n# sentiment.train('neg.txt', 'pos.txt')\n# sentiment.save('sentiment.marshal')\n~~~~\n这样训练好的文件就存储为`seg.marshal`了，之后修改`snownlp/seg/__init__.py`里的`data_path`指向刚训练好的文件即可\n\n## License\n\nMIT licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisnowfy%2Fsnownlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisnowfy%2Fsnownlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisnowfy%2Fsnownlp/lists"}