All Projects → kajyuuen → pytorch-partial-crf

kajyuuen / pytorch-partial-crf

Licence: MIT License
CRF, Partial CRF and Marginal CRF in PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytorch-partial-crf

StatNLP-Framework
C++ based implementation of StatNLP framework
Stars: ✭ 17 (-26.09%)
Mutual labels:  crf, conditional-random-fields
Sequence tagging
Named Entity Recognition (LSTM + CRF) - Tensorflow
Stars: ✭ 1,889 (+8113.04%)
Mutual labels:  crf, conditional-random-fields
NLP-paper
🎨 🎨NLP 自然语言处理教程 🎨🎨 https://dataxujing.github.io/NLP-paper/
Stars: ✭ 23 (+0%)
Mutual labels:  crf
giantgo-render
基于vue3 element plus的快速表单生成器
Stars: ✭ 28 (+21.74%)
Mutual labels:  crf
jcrfsuite
Java interface for CRFsuite: http://www.chokkan.org/software/crfsuite/
Stars: ✭ 44 (+91.3%)
Mutual labels:  crf
Hierarchical-Word-Sense-Disambiguation-using-WordNet-Senses
Word Sense Disambiguation using Word Specific models, All word models and Hierarchical models in Tensorflow
Stars: ✭ 33 (+43.48%)
Mutual labels:  crf
Legal-Entity-Recognition
A Dataset of German Legal Documents for Named Entity Recognition
Stars: ✭ 98 (+326.09%)
Mutual labels:  crf
BiLSTM-CRF-NER-PyTorch
This repo contains a PyTorch implementation of a BiLSTM-CRF model for named entity recognition task.
Stars: ✭ 109 (+373.91%)
Mutual labels:  crf
grobid-ner
A Named-Entity Recogniser based on Grobid.
Stars: ✭ 38 (+65.22%)
Mutual labels:  crf
crf4j
a complete Java port of crfpp(crf++)
Stars: ✭ 30 (+30.43%)
Mutual labels:  crf
Computer-Vision
implemented some computer vision problems
Stars: ✭ 25 (+8.7%)
Mutual labels:  crf
crf-seg
crf-seg:用于生产环境的中文分词处理工具,可自定义语料、可自定义模型、架构清晰,分词效果好。java编写。
Stars: ✭ 13 (-43.48%)
Mutual labels:  crf
tutorial-UGM-hyperspectral
A Tutorial on Modeling and Inference in Undirected Graphical Models for Hyperspectral Image Analysis
Stars: ✭ 21 (-8.7%)
Mutual labels:  conditional-random-fields
crfs-rs
Pure Rust port of CRFsuite: a fast implementation of Conditional Random Fields (CRFs)
Stars: ✭ 22 (-4.35%)
Mutual labels:  crf
korean ner tagging challenge
KU_NERDY 이동엽, 임희석 (2017 국어 정보 처리 시스템경진대회 금상) - 한글 및 한국어 정보처리 학술대회
Stars: ✭ 30 (+30.43%)
Mutual labels:  crf
lstm-crf-tagging
No description or website provided.
Stars: ✭ 13 (-43.48%)
Mutual labels:  crf
deepseg
Chinese word segmentation in tensorflow 2.x
Stars: ✭ 23 (+0%)
Mutual labels:  crf
CIP
Basic exercises of chinese information processing
Stars: ✭ 32 (+39.13%)
Mutual labels:  crf
entity recognition
Entity recognition codes for "2019 Datagrand Cup: Text Information Extraction Challenge"
Stars: ✭ 26 (+13.04%)
Mutual labels:  crf
grobid-quantities
GROBID extension for identifying and normalizing physical quantities.
Stars: ✭ 53 (+130.43%)
Mutual labels:  crf

pytorch-partial-crf

Partial/Fuzzy conditional random field in PyTorch.

Document: https://pytorch-partial-crf.readthedocs.io/

How to use

Install

pip install pytorch-partial-crf

Use CRF

import torch
from pytorch_partial_crf import CRF

# Create 
num_tags = 6
model = CRF(num_tags)

batch_size, sequence_length = 3, 5
emissions = torch.randn(batch_size, sequence_length, num_tags)

tags = torch.LongTensor([
    [1, 2, 3, 3, 5],
    [1, 3, 4, 2, 1],
    [1, 0, 2, 4, 4],
])

# Computing negative log likelihood
model(emissions, tags)

Use partial CRF

import torch
from pytorch_partial_crf import PartialCRF

# Create 
num_tags = 6
model = PartialCRF(num_tags)

batch_size, sequence_length = 3, 5
emissions = torch.randn(batch_size, sequence_length, num_tags)

# Set unknown tag to -1
tags = torch.LongTensor([
    [1, 2, 3, 3, 5],
    [-1, 3, 3, 2, -1],
    [-1, 0, -1, -1, 4],
])

# Computing negative log likelihood
model(emissions, tags)

Use Marginal CRF

import torch
from pytorch_partial_crf import MarginalCRF

# Create 
num_tags = 6
model = MarginalCRF(num_tags)

batch_size, sequence_length = 3, 5
emissions = torch.randn(batch_size, sequence_length, num_tags)

# Set probability tags
marginal_tags = torch.Tensor([
        [
            [0.2, 0.2, 0.2, 0.1, 0.1, 0.2],
            [0.8, 0.0, 0.0, 0.1, 0.1, 0.0],
            [0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
            [0.3, 0.0, 0.0, 0.1, 0.6, 0.0],
        ],
        [
            [0.2, 0.2, 0.2, 0.1, 0.1, 0.2],
            [0.8, 0.0, 0.0, 0.1, 0.1, 0.0],
            [0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
            [0.3, 0.0, 0.0, 0.1, 0.6, 0.0],
        ],
        [
            [0.2, 0.2, 0.2, 0.1, 0.1, 0.2],
            [0.8, 0.0, 0.0, 0.1, 0.1, 0.0],
            [0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
            [0.3, 0.0, 0.0, 0.1, 0.6, 0.0],
        ],
])
# Computing negative log likelihood
model(emissions, marginal_tags)

Decoding

Viterbi decode

model.viterbi_decode(emissions)

Restricted viterbi decode

possible_tags = torch.randn(batch_size, sequence_length, num_tags)
possible_tags[possible_tags <= 0] = 0 # `0` express that can not pass.
possible_tags[possible_tags > 0] = 1  # `1` express that can pass.
possible_tags = possible_tags.byte()
model.restricted_viterbi_decode(emissions, possible_tags)

Marginal probabilities

model.marginal_probabilities(emissions)

Contributing

We welcome contributions! Please post your requests and comments on Issue.

License

MIT

References

The implementation is based on AllenNLP CRF module and pytorch-crf.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].