Skip to main content

中文版

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

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 版本的接口和老版本保持相同,您可以无缝切换。

Metadata

Release files for Cemotion 2.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Cemotion 2.2.3
File Size Uploaded
cemotion-2.2.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Cemotion 2.2.3
File Interpreter ABI Platform
cemotion-2.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / cemotion-2.2.3.tar.gz

Download URL cemotion-2.2.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7a2fee00b1c22215619a81b985ebe0aeac2b67b001135b3cf4e35fdf1f274d41
BLAKE2b-256 checksum
How to use checksums
fa1bec22e4a3a7b39d58186b324503350ce64301df106419f85333f2459dd0f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / cemotion-2.2.3-py3-none-any.whl

Download URL cemotion-2.2.3-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8fd7ad0880689b429303bb58514dee58a8fb65920187410a3f10dee0b7f6c1b
BLAKE2b-256 checksum
How to use checksums
48dd00af50c9891f754e96fb6dfcd1848b1d3e6b851bcaeb83fc7d625a34c47f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

2.2.3 This release

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

1 release file

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page