mirror of
https://github.com/guillaume-be/rust-bert.git
synced 2024-09-11 12:55:34 +03:00
Updated README, bumped version
This commit is contained in:
parent
afa606152b
commit
fe4f7c689d
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust-bert"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
authors = ["Guillaume Becquin <guillaume.becquin@gmail.com>"]
|
||||
edition = "2018"
|
||||
default-run = "rust-bert"
|
||||
|
29
README.md
29
README.md
@ -20,7 +20,28 @@ Multiple choices| |✅ |✅
|
||||
## Ready-to-use pipelines
|
||||
|
||||
Leveraging Huggingface's pipelines, ready to use end-to-end NLP pipelines are available as part of this crate. The following capabilities are currently available:
|
||||
#### 1. Sentiment analysis
|
||||
#### 1. Question Answering
|
||||
Extractive question answering from a given question and context. DistilBERT model finetuned on SQuAD (Stanford Question Answering Dataset)
|
||||
|
||||
```rust
|
||||
let device = Device::cuda_if_available();
|
||||
let qa_model = QuestionAnsweringModel::new(vocab_path,
|
||||
config_path,
|
||||
weights_path, device)?;
|
||||
|
||||
let question = "Where does Amy live ?";
|
||||
let context = "Amy lives in Amsterdam";
|
||||
|
||||
let answers = qa_model.predict(question, context, 1);
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
[Answer { score: 0.9976814985275269, start: 13, end: 21, answer: "Amsterdam" }]
|
||||
```
|
||||
|
||||
|
||||
#### 2. Sentiment analysis
|
||||
Predicts the binary sentiment for a sentence. DistilBERT model finetuned on SST-2.
|
||||
```rust
|
||||
let device = Device::cuda_if_available();
|
||||
@ -47,20 +68,20 @@ Output:
|
||||
]
|
||||
```
|
||||
|
||||
#### 2. Named Entity Recognition
|
||||
#### 3. Named Entity Recognition
|
||||
Extracts entities (Person, Location, Organization, Miscellaneous) from text. BERT cased large model finetuned on CoNNL03, contributed by the [MDZ Digital Library team at the Bavarian State Library](https://github.com/dbmdz)
|
||||
```rust
|
||||
// Set-up model
|
||||
let device = Device::cuda_if_available();
|
||||
let ner_model = NERModel::new(vocab_path,
|
||||
config_path,
|
||||
weights_path, device)?;
|
||||
|
||||
// Define input
|
||||
let input = [
|
||||
"My name is Amy. I live in Paris.",
|
||||
"Paris is a city in France."
|
||||
];
|
||||
|
||||
let output = ner_model.predict(input.to_vec());
|
||||
```
|
||||
Output:
|
||||
```
|
||||
|
@ -2,7 +2,7 @@ extern crate failure;
|
||||
extern crate dirs;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use rust_bert::pipelines::question_answering::{QuestionAnsweringModel};
|
||||
use rust_bert::pipelines::question_answering::QuestionAnsweringModel;
|
||||
use tch::Device;
|
||||
|
||||
|
||||
@ -17,7 +17,9 @@ fn main() -> failure::Fallible<()> {
|
||||
|
||||
// Set-up Question Answering model
|
||||
let device = Device::Cpu;
|
||||
let qa_model = QuestionAnsweringModel::new(vocab_path, config_path, weights_path, device)?;
|
||||
let qa_model = QuestionAnsweringModel::new(vocab_path,
|
||||
config_path,
|
||||
weights_path, device)?;
|
||||
|
||||
// Define input
|
||||
let question = "Where does Amy live ?";
|
||||
|
Loading…
Reference in New Issue
Block a user