词语分词模型
项目描述
wordseg
wordseg
是一个Python分词模型包。
目录
安装
wordseg
可以通过pip获取
pip install wordseg
从GitHub源安装wordseg
git clone https://github.com/jacksonllee/wordseg.git
cd wordseg
pip install -e ".[dev]"
用法
wordseg
实现了一个作为Python类的分词模型。实例化的模型类对象有以下方法(模仿scikit-learn风格的机器学习API)
fit
:用分词句子训练模型。predict
:从未分词句子预测分词句子。
实现的模型类如下
RandomSegmenter
:在每个潜在的词边界独立地以给定的概率随机预测分割。不需要训练。LongestStringMatching
:该模型通过从左到右沿着未分割的句子移动,并在最大词长参数约束下找到最长匹配词来构建预测词。
示例代码片段
from src.wordseg import LongestStringMatching
# Initialize a model.
model = LongestStringMatching(max_word_length=4)
# Train the model.
# `fit` takes an iterable of segmented sentences (a tuple or list of strings).
model.fit(
[
("this", "is", "a", "sentence"),
("that", "is", "not", "a", "sentence"),
]
)
# Make some predictions; `predict` gives a generator, which is materialized by list() here.
list(model.predict(["thatisadog", "thisisnotacat"]))
# [['that', 'is', 'a', 'd', 'o', 'g'], ['this', 'is', 'not', 'a', 'c', 'a', 't']]
# We can't get 'dog' and 'cat' because they aren't in the training data.
许可证
MIT许可证。请参阅LICENSE.txt
。
变更日志
请参阅CHANGELOG.md
。
贡献
请参阅CONTRIBUTING.md
。
引用
Lee, Jackson L. 2023. wordseg:Python中的词分割模型。https://doi.org/10.5281/zenodo.4077433
@software{leengrams,
author = {Jackson L. Lee},
title = {wordseg: Word segmentation models in Python},
year = 2023,
doi = {10.5281/zenodo.4077433},
url = {https://doi.org/10.5281/zenodo.4077433}
}
项目详情
下载文件
下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
wordseg-0.0.5.tar.gz (6.2 kB 查看哈希值)
构建分布
wordseg-0.0.5-py3-none-any.whl (6.2 kB 查看哈希值)
关闭
wordseg-0.0.5.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0ba2b87bcfa801508e8dbeb71c62d3056fc462b2610fd5d883680f636204700c |
|
MD5 | 4fd9b2abf4721d0a47a56b1d2d6c42d1 |
|
BLAKE2b-256 | 52f8fdf2a02790257d75017a36018ea7ce7f8530beaecec6dc97ba7c46769dc5 |
关闭
wordseg-0.0.5-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7c607f58e040c19d187e2886b093b06470ba016454377e19f63e1b866774b3d6 |
|
MD5 | 0a7301c64a87fa9a5c5fde842661ba36 |
|
BLAKE2b-256 | 5ef436a9e82678df2f11fdb5803c7463854b63b4151fff729aba807e4d7f665c |