Skip to main content

Implementation of Conditional Random Fields in pytorch

Project description

Copyright (c) 2018 Ryuya Ikeda

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Description: # Torch CRF

Implementation of CRF (Conditional Random Fields) in PyTorch 1.0

## Requirements

  • python3 (>=3.6)

  • PyTorch 1.0

## Installation

$ pip install TorchCRF

## Usage

`python >>> import torch >>> from TorchCRF import CRF >>> batch_size = 2 >>> sequence_size = 3 >>> num_labels = 5 >>> mask = torch.FloatTensor([[1, 1, 1], [1, 1, 0]]) # (batch_size. sequence_size) >>> labels = torch.LongTensor([[0, 2, 3], [1, 4, 1]]) # (batch_size, sequence_size) >>> hidden = torch.randn((batch_size, sequence_size, num_labels), requires_grad=True) >>> crf = CRF(num_labels) `

### Computing log-likelihood (used where forward)

`python >>> crf.forward(hidden, labels, mask) tensor([-7.6204, -3.6124], grad_fn=<ThSubBackward>) `

### Decoding (predict labels of sequences)

`python >>> crf.viterbi_decode(hidden, mask) [[0, 2, 2], [4, 0]] `

## License

MIT

## References

Platform: UNKNOWN Requires-Python: >=3.6 Description-Content-Type: text/markdown

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

TorchCRF-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

TorchCRF-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file TorchCRF-1.0.0.tar.gz.

File metadata

  • Download URL: TorchCRF-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for TorchCRF-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c6c44766fb55ac118b9d9c4c1e664ed570feb471c7c828cf804363ef05957c9e
MD5 65a046a2d3503df45e6cd150d6a6823f
BLAKE2b-256 bec6c710531f98898e191a7aaff8a725f3e54568deb52ec8b21ce85e644af647

See more details on using hashes here.

File details

Details for the file TorchCRF-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: TorchCRF-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for TorchCRF-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 473cce22162b5c4773b503791781831f2d19bcc2fb6abd0774fb99275565e5e1
MD5 4e76928b160e5b9cf0bed29a006e43ff
BLAKE2b-256 601a3f05758c074d7cc616e95111b33f4a74767d47866d65d26e0fcaa205d95d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page