A micro python package for HMM (Hidden Markov Model).
Only test by using Python3
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)
Output:
[('你', '人称'), ('是', '动词'), ('中国人', '名词')]