https://github.com/rikeda71/torchcrf
An Inplementation of CRF (Conditional Random Fields) in PyTorch 1.0
https://github.com/rikeda71/torchcrf
conditional-random-fields crf named-entity-recognition ner pytorch
Last synced: 5 months ago
JSON representation
An Inplementation of CRF (Conditional Random Fields) in PyTorch 1.0
- Host: GitHub
- URL: https://github.com/rikeda71/torchcrf
- Owner: rikeda71
- License: mit
- Created: 2018-11-07T08:03:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-01T09:26:36.000Z (over 4 years ago)
- Last Synced: 2024-12-01T14:46:31.786Z (5 months ago)
- Topics: conditional-random-fields, crf, named-entity-recognition, ner, pytorch
- Language: Python
- Homepage:
- Size: 63.5 KB
- Stars: 136
- Watchers: 4
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.ja.md
- License: LICENSE
Awesome Lists containing this project
README
# Torch CRF
[](https://circleci.com/gh/s14t284/TorchCRF)
[](https://coveralls.io/github/s14t284/TorchCRF)
[](LICENSE)[](https://pypi.org/project/TorchCRF/)
[](https://badge.fury.io/py/TorchCRF)PyTorch 1.0 による条件付き確率場 (CRF) の実装
## 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)
```### 推論
```python
>>> crf.forward(hidden, labels, mask)
tensor([-7.6204, -3.6124], grad_fn=)
```### 系列ラベルの予測
```python
>>> crf.viterbi_decode(hidden, mask)
[[0, 2, 2], [4, 0]]
```## License
MIT
## References
- [threelittlemonkeys/lstm-crf-pytorch](https://github.com/threelittlemonkeys/lstm-crf-pytorch)
- [kmkurn/pytorch-crf](https://github.com/kmkurn/pytorch-crf)