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+ 环境测试过,其他环境不做兼容性保障。

# 安装
## pip
```bash
pip install MicroTokenizer
```

## source
```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.1.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.1-py2.py3-none-any.whl (4.0 MB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for MicroTokenizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 74e5b065c1345c2535f61e8c36208f7228c052112c177e15120bbb2adacc9829
MD5 f2c8079740fb47a9814adc6fd469dd8b
BLAKE2b-256 19ee7596d7ad84f289b841642217d5ddf5e8a0233310f1fe1128c3dea1bcc6db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MicroTokenizer-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bbc2c6725635a904c2bdfa57aa668e4c8d74facaf93306f9b326ba914c2922b9
MD5 b826ff7c304f97a2d82ac091e72373d5
BLAKE2b-256 1cd72fdd26b9ab04e4f2d4366d993e45ece3995a4e21619c60cb56cfe01630d7

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