Skip to main content

A python package for HMM model with fast train and decoding implementation

Project description

中文版本的 README

FastHMM

A python package for HMM (Hidden Markov Model) model with fast train and decoding implementation

Python version

test by using Python3

Install

pip

pip install FastHMM

source

pip install git+https://github.com/312shan/FastHMM.git

Usage

from FastHMM.hmm import HMMModel

# test model training and predict
hmm_model = HMMModel()
hmm_model.train_one_line([("我", "r"), ("爱", "v"), ("北京", "ns"), ("天安门", "ns")])
hmm_model.train_one_line([("你", "r"), ("去", "v"), ("深圳", "ns")])
result = hmm_model.predict(["俺", "爱", "广州"])
print(result)

# test save and load model
hmm_model.save_model()
hmm_model = HMMModel().load_model()
result = hmm_model.predict(["我们", "爱", "深圳"])
print(result)

Output:

[('俺', 'r'), ('爱', 'v'), ('广州', 'ns')]
[('我们', 'r'), ('爱', 'v'), ('深圳', 'ns')]

Performance:

test on dataset 人民日报

python .test/test_postagging.py

Output:

train size 18484 ,test_size 1000
finish training
eval result: 
predict 57929 tags, 54228 correct,  accuracy 0.9361114467710473
runtime : 370.1029086 seconds

Most of time the consuming is on the decoding stage, I tried many ways to implement viterbi algorithm, The implementation I currently use is the fastest If you have suggestions for improving this decoding algorithm, please let me know, thank you very much.

Reference

MicroHMM
Hidden Markov model
Viterbi algorithm

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

FastHMM-0.1.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

FastHMM-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file FastHMM-0.1.2.tar.gz.

File metadata

  • Download URL: FastHMM-0.1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for FastHMM-0.1.2.tar.gz
Algorithm Hash digest
SHA256 157856e9e7505a2a9f7e1d1ea59cb6ed8696be25d7160e3a8abf9cdc512c0353
MD5 7a090d48d8d66fe4be582e3c48e758fc
BLAKE2b-256 fc7ba179d1aed2d46c24a727909ad3f05651d2732de5487986979fdcce5ee1ea

See more details on using hashes here.

File details

Details for the file FastHMM-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: FastHMM-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for FastHMM-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 360c01d063f0340b7cb56df7f0cc3a91a17017913c445a6207d8d670ae15b361
MD5 4b61a5650d34db3fd7caa320a3cec873
BLAKE2b-256 972cdcb2b902cb4e3856416aa2a841a7ba7e01148edd9978b9447b40c2dacb5f

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