https://github.com/nicksenger/candle-token-classification
Token Classification for BERT-like models via Candle
https://github.com/nicksenger/candle-token-classification
candle deep-learning neural-networks nlp
Last synced: 5 months ago
JSON representation
Token Classification for BERT-like models via Candle
- Host: GitHub
- URL: https://github.com/nicksenger/candle-token-classification
- Owner: nicksenger
- Created: 2023-12-05T00:10:31.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-16T06:17:24.000Z (about 1 year ago)
- Last Synced: 2025-05-12T12:13:46.488Z (5 months ago)
- Topics: candle, deep-learning, neural-networks, nlp
- Language: Rust
- Homepage:
- Size: 32.2 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Candle Token Classification
This project provides support for using pre-trained token classification models of the BERT lineage (BERT, RoBERTa, DeBERTa, Electra, etc) via [Candle](https://github.com/huggingface/candle)
## Usage
```rust
use candle_token_classification::BertLikeTokenClassificationHead; // Import the token classifier trait from this library
use candle_token_classification::BertTokenClassificationHead; // Import the concrete classifier (BERT & ELECTRA are provided)fn main() -> Result<(), Box> {
// ... retrieve Config, VarBuilder & Tokenizer from filesystem, HF hub, etclet classifier = BertTokenClassificationHead::load(vb, &config)?;
// retrieve an ordered list of labels for the chosen classifier
let labels = config.id2label.values().cloned().collect();let output = classifier.classify( // classify some text (or use `classifier.forward` to get the output tensor)
"This is the text we'd like to classify.",
&labels,
&tokenizer,
&classifier.device
);println!("{:?}", output) // view human-readable output or send for downstream processing, etc
Ok(())
}
```## Contributing
This repo was made specifically for my use-case of UPOS tagging with pre-trained models. As such it is likely missing things required to support work outside that scope. If you need other functionality, contributions are welcome :)