跳转到主要内容

词语分词模型

项目描述

wordseg

DOI PyPI version Supported Python versions CircleCI

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 查看哈希值)

上传时间 Python 3

由以下提供支持