Skip to main content

A micro tokenizer for Chinese

Project description

# 微型中文分词器

一个微型的中文分词器,能够按照词语的频率(概率)来利用构建 DAG(有向无环图)来分词。

# 特点 / 特色

* 微型:主要代码只有一个文件,不足 200 行
* 面向教育:可以导出 `graphml` 格式的图结构文件,辅助学习者理解算法过程
* 良好的分词性能:由于使用类似 `结巴分词` 的算法,具有良好的分词性能
* 具有良好的扩展性:使用和 `结巴分词` 一样的字典文件,可以轻松添加自定义字典

# 演示

## 在线演示
在线的 Jupyter Notebook 在 [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/howl-anderson/MicroTokenizer/master?filepath=.notebooks%2FMicroTokenizer.ipynb)

## 离线演示
### 分词
代码:
```python
import MicroTokenizer

tokens = MicroTokenizer.cut("知识就是力量")
print(tokens)
```
输出:
```python
['知识', '就是', '力量']
```
### 有向无环图效果演示
![DAG of 'knowledge is power'](.images/DAG_of_knowledge_is_power.png)

#### 备注
* `<s>` 和 `</s>` 是图的起始和结束节点,不是实际要分词的文本
* 图中 Edge 上标注的是 `log(下一个节点的概率的倒数)`
* 最短路径已经用 `深绿色` 作了标记

### 更多演示
#### "王小明在北京的清华大学读书"
![DAG of xiaomin](.images/DAG_of_xiaomin.png)


# 依赖
只在 python 3.5+ 环境测试过,其他环境不做兼容性保障。

# 安装
```console
pip install git+https://github.com/howl-anderson/MicroTokenizer.git
```

# 如何使用
## 分词
见上文

## 导出 GraphML 文件
```python
from MicroTokenizer.MicroTokenizer import MicroTokenizer

micro_tokenizer = MicroTokenizer()
micro_tokenizer.build_graph("知识就是力量")
micro_tokenizer.write_graphml("output.graphml")
```

# Roadmap
* 融合 HMM 模型 以处理 OOV 以及提高 Performance
* 和主流分词模型做一个分词能力的测试

# Credits


=======
History
=======

0.1.0 (2018-06-12)
------------------

* First release on PyPI.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MicroTokenizer-0.1.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

MicroTokenizer-0.1.0-py2.py3-none-any.whl (4.0 MB view details)

Uploaded Python 2Python 3

File details

Details for the file MicroTokenizer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for MicroTokenizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35ce945d897758f69bbf7ebd6c4cf2bba2c98993f9f783db15ad152333d088be
MD5 b77a956398cf7845b8246a2ce4feff7f
BLAKE2b-256 78a7658fea9402faad02abba42e4c626cba2716e32eea90a00efd93f411f4c69

See more details on using hashes here.

File details

Details for the file MicroTokenizer-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for MicroTokenizer-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 acad8eff59536e5a5d6654b73040b8350f4ca58f9890ff95dac7c69f8e6bee49
MD5 6777c12a12d0cb9ebcc5ab15a745bb35
BLAKE2b-256 2197918a67c5e774d4cae888ae9b342cc37bafd3a1730d00db98e1ee21ef8f23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page