Cemotion

Cemotion

高效中文情感分析和分词工具库

Cemotion是一个Python中文NLP库,主要用于情感分析和通用领域分词。该库采用BERT模型训练,可为中文文本提供情感倾向置信度。新增的Cegementor类使用BAStructBERT模型进行语义分词。Cemotion支持批量处理和多平台部署,可自动调用GPU加速。2.0版本在性能和准确度方面有所提升。

Cemotion中文NLP情感分析中文分词BERTGithub开源项目

中文版

Cemotion is a Chinese NLP (Natural Language Processing) library for Python that can perform sentiment analysis and general domain Chinese word segmentation.

The Cemotion 2.0 model is trained using BERT (Bidirectional Encoder Representations from Transformers), which returns a sentiment confidence score between 0 and 1 for Chinese text (sentiment polarity with 0 being negative and 1 being positive).

Additionally, the newly added Cegementor Chinese word segmentation class uses the BAStructBERT general domain Chinese word segmentation model to segment text semantically.

With Cemotion, you will be able to:

  • Analyze the sentiment of Chinese text in batches
  • Perform Chinese text segmentation in batches
  • Deploy to production environments such as Linux, macOS, Windows (supports Apple Silicon)

This module depends on the PyTorch environment (which will be installed automatically) and requires Python version 3.8 or higher. Older machines may not be able to run it.

Please note that Cemotion will automatically utilize the GPUs of NVIDIA and Apple Silicon. If there is no GPU available, it will use CPU for inference.

Installation Method

  1. Enter the command window and create a virtual environment by entering the following commands in sequence.

For Linux and macOS:

python3 -m venv venv # Create a virtual environment . venv/bin/activate # Activate the virtual environment

For Windows:

python -m venv venv # Create a virtual environment venv\Scripts\activate # Activate the virtual environment
  1. Install the Cemotion library by entering the following commands in sequence:
pip install --upgrade pip pip install cemotion

Links

Usage

Chinese Sentiment Classification

Analyze by text string

from cemotion import Cemotion str_text1 = '配置顶级,不解释,手机需要的各个方面都很完美' str_text2 = '院线看电影这么多年以来,这是我第一次看电影睡着了。简直是史上最大烂片!没有之一!侮辱智商!大家小心警惕!千万不要上当!再也不要看了!' c = Cemotion() print(f'"{str_text1}"\nPredicted value:{c.predict(str_text1)}'\n') print(f'"{str_text2}"\nPredicted value:{c.predict(str_text2)}'\n')
# Return Content (This module returns the sentiment confidence score for the sentence, with a value ranging from 0 to 1):
" 配置顶级,不解释,手机需要的各个方面都很完美 "
 预测值:0.999962 

" 院线看电影这么多年以来,这是我第一次看电影睡着了。简直是史上最大烂片!没有之一!侮辱智商!大家小心警惕!千万不要上当!再也不要看了! "
 预测值:0.000147

Using a list for batch analysis

from cemotion import Cemotion list_text = ['内饰蛮年轻的,而且看上去质感都蛮好,貌似本田所有车都有点相似,满高档的!', '总而言之,是一家不会再去的店。'] c = Cemotion() print(c.predict(list_text))
# Return Content (This module returns the sentiment confidence score for the sentence, with a value ranging from 0 to 1).:
[['内饰蛮年轻的,而且看上去质感都蛮好,貌似本田所有车都有点相似,满高档的!', 0.999962], ['总而言之,是一家不会再去的店。', 0.000194]]

Chinese text segmentation

Segmentation of a single text

from cemotion import Cegmentor text = '这辆车的内饰设计非常现代,而且用料考究,给人一种豪华的感觉。' segmenter = Cegmentor() segmentation_result = segmenter.segment(text) print(segmentation_result)
# Return content as a single sentence segmentation
['这', '辆', '车', '的', '内饰', '设计', '非常', '现代', ',', '而且', '用料', '考究', ',', '给', '人', '一', '种', '豪华', '的', '感觉', '。']

Using a list for batch Chinese text segmentation

from cemotion import Cegmentor text = '这辆车的内饰设计非常现代,而且用料考究,给人一种豪华的感觉。' list_text = [ '随着科技的发展,智能手机的功能越来越强大,给我们的生活带来了很多便利。', '他从小就对天文学充满好奇,立志要成为一名宇航员,探索宇宙的奥秘。', '这种新型的太阳能电池板转换效率高,而且环保,有望在未来得到广泛应用。' ] segmenter = Cegmentor() segmentation_result = segmenter.segment(list_text) print(segmentation_result)
# Return content as a list of segmentations
[
['随着', '科技', '的', '发展', ',', '智能', '手机', '的', '功能', '越来越', '强大', ',', '给', '我们', '的', '生活', '带来', '了', '很多', '便利', '。'],
['他', '从小', '就', '对', '天文学', '充满', '好奇', ',', '立志', '要', '成为', '一', '名', '宇航员', ',', '探索', '宇宙', '的', '奥秘', '。'],
['这种', '新型', '的', '太阳能', '电池板', '转换', '效率', '高', ',', '而且', '环保', ',', '有望', '在', '未来', '得到', '广泛', '应用', '。']
]

Main Updates in Version 2.0

  1. Replaced the dependency on TensorFlow with PyTorch.

  2. Changed the old version's BRNN + LSTM to the BERT model.

Additionally, the interface of version 2.0 remains the same as the old version, allowing for seamless switching.

中文版

Cemotion 是 Python 下的中文 NLP 库,可以进行中文情感倾向分析、通用领域中文分词。

Cemotion 2.0 模型使用 BERT (Bidirectional Encoder Representations from Transformers) 训练得到,会为中文文本返回 0~1 之间的情感倾向置信度 (情感极性 0 为消极,1 为积极)。

此外,新加入的 Cegementor 中文分词类采用 BAStructBERT 通用领域中文分词模型对文本按语义进行分词。

使用 Cemotion,您将能够:

  • 批量分析中文文本的情感
  • 批量进行中文文本分词
  • 部署至 Linux、macOS、Windows 等生产环境中 (支持 Apple Silicon)

该模块依赖于 PyTorch 环境(会自动安装),要求 Python 3.8 或更高版本,较老的机器可能无法运行。

注意,Cemotion 会自动调用 NVIDIA 和 Apple Silicon 的 GPU。如果没有 GPU,则使用 CPU 推理。

安装方法

1.进入命令窗口,创建虚拟环境,依次输入以下命令

Linux 和 macOS:

python3 -m venv venv #创建虚拟环境 . venv/bin/activate #激活虚拟环境

Windows:

python -m venv venv #创建虚拟环境 venv\Scripts\activate #激活虚拟环境

2.安装Cemotion库,依次输入

pip install --upgrade pip pip install cemotion

链接

使用方法

中文情感分类

单个文本进行分析

from cemotion import Cemotion str_text1 = '配置顶级,不解释,手机需要的各个方面都很完美' str_text2 = '院线看电影这么多年以来,这是我第一次看电影睡着了。简直是史上最大烂片!没有之一!侮辱智商!大家小心警惕!千万不要上当!再也不要看了!' c = Cemotion() print(f'"{str_text1}"\n预测值:{c.predict(str_text1)}\n') print(f'"{str_text2}"\n预测值:{c.predict(str_text2)}\n' )
#返回内容(该模块返回了这句话的情感置信度,值在0到1之间):
" 配置顶级,不解释,手机需要的各个方面都很完美 "
 预测值:0.999962 

" 院线看电影这么多年以来,这是我第一次看电影睡着了。简直是史上最大烂片!没有之一!侮辱智商!大家小心警惕!千万不要上当!再也不要看了! "
 预测值:0.000147

使用列表进行批量分析

from cemotion import Cemotion list_text = ['内饰蛮年轻的,而且看上去质感都蛮好,貌似本田所有车都有点相似,满高档的!', '总而言之,是一家不会再去的店。'] c = Cemotion() print(c.predict(list_text))
#返回内容(该模块返回了列表中每句话的情感置信度,值在0到1之间):
[['内饰蛮年轻的,而且看上去质感都蛮好,貌似本田所有车都有点相似,满高档的!', 0.999962], ['总而言之,是一家不会再去的店。', 0.000194]]

中文文本分词

单个文本进行分词

from cemotion import Cegmentor text = '这辆车的内饰设计非常现代,而且用料考究,给人一种豪华的感觉。' segmenter = Cegmentor() segmentation_result = segmenter.segment(text) print(segmentation_result)
#返回内容为单句分词
['这', '辆', '车', '的', '内饰', '设计', '非常', '现代', ',', '而且', '用料', '考究', ',', '给', '人', '一', '种', '豪华', '的', '感觉', '。']

使用列表进行批量中文分词

from cemotion import Cegmentor text = '这辆车的内饰设计非常现代,而且用料考究,给人一种豪华的感觉。' list_text = [ '随着科技的发展,智能手机的功能越来越强大,给我们的生活带来了很多便利。', '他从小就对天文学充满好奇,立志要成为一名宇航员,探索宇宙的奥秘。', '这种新型的太阳能电池板转换效率高,而且环保,有望在未来得到广泛应用。' ] segmenter = Cegmentor() segmentation_result = segmenter.segment(list_text) print(segmentation_result)
#返回内容为分词列表
[
['随着', '科技', '的', '发展', ',', '智能', '手机', '的', '功能', '越来越', '强大', ',', '给', '我们', '的', '生活', '带来', '了', '很多', '便利', '。'],
['他', '从小', '就', '对', '天文学', '充满', '好奇', ',', '立志', '要', '成为', '一', '名', '宇航员', ',', '探索', '宇宙', '的', '奥秘', '。'],
['这种', '新型', '的', '太阳能', '电池板', '转换', '效率', '高', ',', '而且', '环保', ',', '有望', '在', '未来', '得到', '广泛', '应用', '。']
]

2.0 版本主要更新内容

1.替换依赖 TensorFlow 为 PyTorch

2.将老版本的 BRNN + LSTM 更改为 BERT 模型

此外,2.0

编辑推荐精选

博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

热门AI工具AI办公办公工具智能排版AI生成PPT博思AIPPT海量精品模板AI创作
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

AI助手热门AI工具AI创作AI辅助写作讯飞绘文内容运营个性化文章多平台分发
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

热门AI工具生产力协作转型TraeAI IDE
商汤小浣熊

商汤小浣熊

最强AI数据分析助手

小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。

imini AI

imini AI

像人一样思考的AI智能体

imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。

下拉加载更多