Skip to main content

Linear-chain conditional random fields for natural language processing

Project description

Chaine

Linear-chain conditional random fields for natural language processing.

Chaine is a modern Python library without third-party dependencies and a backend written in C. You can train conditional random fields for natural language processing tasks like named entity recognition.

  • Lightweight: No use of bloated third-party libraries.
  • Fast: Performance critical parts are written in C and thus blazingly fast.
  • Easy to use: Designed with special focus on usability and a beautiful high-level API.

You can install the latest stable version from PyPI:

$ pip install chaine

Please refer to the introducing paper by Lafferty et al. for the theoretical concepts behind conditional random fields.

Minimal working example

>>> import chaine
>>> tokens = [["John", "Lennon", "was", "born", "in", "Liverpool"]]
>>> labels = [["B-PER", "I-PER", "O", "O", "O", "B-LOC"]]
>>> model = chaine.train(tokens, labels, max_iterations=5)
>>> model.predict(tokens)
[['B-PER', 'I-PER', 'O', 'O', 'O', 'B-LOC']]

Check out the examples for a more real-world use case.

Development

If you have modified chaine/crf.pyx, you have to compile Cython to C++ first (which will update chainie/crf.cpp) and then build the extension:

$ python cythonize && poetry install

Credits

This project makes use of and is partially based on:

Project details


Download files

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

Files for chaine, version 1.4.0
Filename, size File type Python version Upload date Hashes
Filename, size chaine-1.4.0-cp39-cp39-win_amd64.whl (625.6 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size chaine-1.4.0-cp39-cp39-win32.whl (600.7 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size chaine-1.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (889.3 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size chaine-1.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (856.8 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size chaine-1.4.0-cp39-cp39-macosx_10_15_x86_64.whl (395.9 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size chaine-1.4.0-cp38-cp38-win_amd64.whl (625.8 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size chaine-1.4.0-cp38-cp38-win32.whl (601.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size chaine-1.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (899.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size chaine-1.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (864.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size chaine-1.4.0-cp38-cp38-macosx_10_15_x86_64.whl (395.1 kB) File type Wheel Python version cp38 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page