Skip to main content

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 = 5                        # number of tags is 5
>>> 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)

# Computing log likelihood
>>> tags = torch.tensor([[2, 3], [1, 0], [3, 4]], dtype=torch.long)  # (seq_length, batch_size)
>>> model(emissions, tags)

# Decoding
>>> model.decode(emissions)             # decoding the best path
>>> model.decode(emissions, nbest=3)    # decoding the top 3 paths

Metadata

Release files for pytorchcrf 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorchcrf 1.2.0
File Size Uploaded
pytorchcrf-1.2.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytorchcrf 1.2.0
File Interpreter ABI Platform
pytorchcrf-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / pytorchcrf-1.2.0.tar.gz

Download URL pytorchcrf-1.2.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5ee4e0c0aa0be49c0b5816513e2c40b91d293e36dc76bb3216bd26bd67d7e16a
BLAKE2b-256 checksum
How to use checksums
0227ac052d7dd1e1c249ee4603903cf33b0b72417cd4c728c5e02b644dbf41b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release files / pytorchcrf-1.2.0-py3-none-any.whl

Download URL pytorchcrf-1.2.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fad8a8dba816a9a76a74c6cfc535aab226666893797e2842f2d978562064124
BLAKE2b-256 checksum
How to use checksums
b33a85ae7d34b43d833c7d1a17200a15afa4d506b5995b93604f425250ae9d06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page