No project description provided
Project description
sequence-classifier
sequence-classifier
is an open-source library designed for sequence classification in PyTorch. It provides utilities for sequence classifiers, particularly Conditional random fields (CRFs), and it can calculate the log likelihood of tag sequences and retrieve the best label sequences. sequence-classifier
also offers the capability to compute the marginal log likelihood and the marginal probability. These features are handy when working with partially annotated datasets.
If you are searching for libraries to handle sequence labeling tasks such as named-entity recognition or part-of-speech tagging combined with the use of foundation models like BERT, RoBERTa, or DeBERTa, you will find sequence-classifier
to be helpful.
Prerequisites
- Python 3.8+
Installation
You can install sequence-classifier via pip:
pip install sequence-classifier
Basic Usage
import torch
from sequence_classifier.crf import Crf
batch_size = 3
sequence_length = 15
num_tags = 6
logits = torch.randn(batch_size, sequence_length, num_tags)
tag_indices = torch.randint(0, num_tags, (batch_size, sequence_length))
model = Crf(num_tags)
dist = model(logits)
nll_loss = dist.log_likelihood(tag_indices).sum().neg()
best_sequence = dist.argmax
References
- Alexander Rush. 2020. Torch-Struct: Deep Structured Prediction Library. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics: System Demonstrations, pages 335–342, Online. Association for Computational Linguistics.
- Yuta Tsuboi, Hisashi Kashima, Shinsuke Mori, Hiroki Oda, and Yuji Matsumoto. 2008. Training Conditional Random Fields Using Incomplete Annotations. In Proceedings of the 22nd International Conference on Computational Linguistics (Coling 2008), pages 897–904, Manchester, UK. Coling 2008 Organizing Committee.
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
Built Distribution
Hashes for sequence_classifier-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb8cc48a43c46a48814b771b1a004e3fb119cfac17b502903f98229b563ecb02 |
|
MD5 | bdd9e62619fb23cb675c1fa694ea0c39 |
|
BLAKE2b-256 | fe4b835296a4445b02b9f24e63cde5c22a97abee85ee0fc270a03a821c32fc4e |
Hashes for sequence_classifier-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 173521d28e7fbe0ad2eccb79fbabe6cdb745cd56f0d57b1bc558c8f0f7da1fdf |
|
MD5 | 4a534a5748fb816beba21b7719781b1c |
|
BLAKE2b-256 | b16300ea27b7b1044a748696dfafe2cd91684366179070287a9aeced68d8a76a |