litNlp 简介
litNlp 是基于 Tensorflow 2.0 实现的一个轻量级的深度情感极性推理模型,使用字符级代替词语级进一步提升训练和推理速度,可以实现细粒度的多级别情感极性训练和预测。
TF2 下 GPU 和 CPU 平台都能直接安装运行,是搭建 NLP 分类模型类 baseline 的快速方案。
1. 内置情感分析模型-利用深度模型优化语义建模,使用字符级减少 tokenizer 的大小。
2. 直接提供模型训练,默认 Text-CNN 字符级卷积网络作为 baseline ,自带早停操作,使用少的参数即可开始训练多分类模型。
直接使用 emample/sa_ui.py 进行前端 ui 展示效果
# 安装 streamlit 之后直接运行脚本
streamlit run sa_ui.py
使用方法
- pip install litNlp
- 模型需要先通过训练,保存在 sa_model 里面,然后就可以批预测,具体的使用见 example 文件内容
from litNlp.predict import SA_Model_Predict
# 批处理文本
predict_text = ['这个我不喜欢', '这个我喜欢不']
# 初始化并加载模型
tokenizer_path = 'sa_model/tokenizer.pickle'
sa_model_path = 'sa_model/c_cnn_m.h5'
model = SA_Model_Predict(tokenizer_path,sa_model_path_m=sa_model_path)
sa_score = model.predict(predict_text)
print([i[1] for i in sa_score])
参数解释
# 最大句子长度
maxlen = 100
# 最大的tokenizer字典长度
max_words = 1000
# 设置embedding大小
embedding_dim = 300
# 模型的保存位置,后续用于推理
sa_model_path_m = 'sa_model/c_cnn_m.h5'
# 离线保存tokenizer
tokenize_path ='sa_model/tokenizer.pickle'
# 分类的类别数
num_classes = 2
# train_method : 模型训练方式,默认textcnn,可选:bilstm, gru
train_method = 'textcnn'
2 个 epoch 的二分类性能
jupyter 加载
情感分析,优化语义的情感推理
pipy code
Metadata
Release files for litNlp 0.8.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| litNlp-0.8.5.tar.gz | 5.8 kB | Without provenance | Details for litNlp-0.8.5.tar.gz |
Release files / litNlp-0.8.5.tar.gz
| Download URL | litNlp-0.8.5.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad1f01879db5aebb9dae2de59e25adf911dd4778cf679fdff1e0e138ee7b1a90
|
|
BLAKE2b-256 checksum How to use checksums |
5d812a083cee608fd9b0c05f6b72a3b19f995539861a2258be645f9718c9cf19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.5
|
Security for litNlp 0.8.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.