PyTorch CRF with N-best decoding
Project description
PyTorch CRF with N-best Decoding
Implementation of Conditional Random Fields (CRF) in PyTorch 1.0. It supports top-N most probable paths decoding.
The package is based on pytorch-crf with only the following differences
- Method
_viterbi_decode
that decodes the most probable path get optimized. Running time gets reduced to 50% or less with batch size 15+ and sequence length 20+ - The class now supports decoding top-N most probable paths through the implementation of the method
_viterbi_decode_nbest
Requirements
- Python 3 (>= 3.6)
- PyTorch 1.0
Installation
pip install pytorchcrf
Examples
>>> import torch
>>> from pytorchcrf import CRF
>>> num_tags = 4 # number of tags is 4
>>> model = CRF(num_tags)
>>> seq_length = 3 # maximum sequence length in a batch
>>> batch_size = 2 # number of samples in the batch
>>> emissions = torch.randn(seq_length, batch_size, num_tags)
>>> model.decode(emissions)
>>> model.decode(emissions, nbest=3)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file pytorchcrf-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pytorchcrf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0cedda07c6128c74c679db2a85720f96934e00863a0eda097aa6c071fc9a83 |
|
MD5 | dd38ad99400135c77266ee82260a5814 |
|
BLAKE2b-256 | b93e2e7cb52ca442e04fe1238c9fa2cd68950643af9fbe22b174b33c4f4eed27 |