一个微型的基于 Python 的 HMM (隐马尔可夫模型) 包.
只在 Python 3 下进行过测试
pip install MicroHMM
pip install git https://github.com/howl-anderson/MicroHMM.git
from MicroHMM.hmm import HMMModel
hmm_model = HMMModel()
# train model line by line
# input format: list of (observation, hidden_state) pair
hmm_model.train_one_line([("我", "人称"), ("是", "动词"), ("中国人", "名词")])
hmm_model.train_one_line([("你", "人称"), ("去", "动词"), ("上海", "名词")])
# predict by line
# input format: list of observation
result = hmm_model.predict(["你", "是", "中国人"])
print(result)
输出:
[('你', '人称'), ('是', '动词'), ('中国人', '名词')]
- [TODO] 使用预先
math.log
的处理方式,加速运行速度 - [TODO] 解决
math.log
在偶然情况写下会出现的math domain error