分词模型
wordseg的Python项目详细描述
wordseg公司
wordseg
是一个Python分词模型包。在
目录:
安装
wordseg
可通过pip获得:
pip install wordseg
要从GitHub源安装wordseg
,请执行以下操作:
使用
wordseg
将分词模型作为Python类实现。
实例化的模型类对象具有以下方法
(模拟scikit learn样式的API进行机器学习):
fit
:用分段句子训练模型。在predict
:从未切分的句子中预测分段句子。在
实现的模型类如下:
RandomSegmenter
: 在每个潜在的单词上随机预测切分 边界独立于给定概率。不需要培训。在LongestStringMatching
: 该模型通过移动来构造预测词 从左到右沿着未分段的句子和 在最大字长参数的约束下,寻找最长的匹配词。在
示例代码段:
fromwordsegimportLongestStringMatching# 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.
引文
李,杰克逊L。2020年。Python中的分词模型。https://doi.org/10.5281/zenodo.4077433
@software{leengrams,author={Jackson L. Lee},title={wordseg: Word segmentation models in Python},year=2020,doi={10.5281/zenodo.4077433},url={https://doi.org/10.5281/zenodo.4077433}}
许可证
麻省理工学院执照。请参阅^{
变更日志
请参阅^{
- 项目
标签: