pub struct QuestionAnsweringModel { /* private fields */ }
Expand description

Implementations§

Build a new QuestionAnsweringModel

Arguments
  • question_answering_config - QuestionAnsweringConfig object containing the resource references (model, vocabulary, configuration) and device placement (CPU/GPU)
Example
use rust_bert::pipelines::question_answering::QuestionAnsweringModel;

let qa_model = QuestionAnsweringModel::new(Default::default())?;

Perform extractive question answering given a list of QaInputs

Arguments
  • qa_inputs - &[QaInput] Array of Question Answering inputs (context and question pairs)
  • top_k - return the top-k answers for each QaInput. Set to 1 to return only the best answer.
  • batch_size - maximum batch size for the model forward pass.
Returns
  • Vec<Vec<Answer>> Vector (same length as qa_inputs) of vectors (each of length top_k) containing the extracted answers.
Example
use rust_bert::pipelines::question_answering::{QaInput, QuestionAnsweringModel};

let qa_model = QuestionAnsweringModel::new(Default::default())?;

let question_1 = String::from("Where does Amy live ?");
let context_1 = String::from("Amy lives in Amsterdam");
let question_2 = String::from("Where does Eric live");
let context_2 = String::from("While Amy lives in Amsterdam, Eric is in The Hague.");

let qa_input_1 = QaInput {
    question: question_1,
    context: context_1,
};
let qa_input_2 = QaInput {
    question: question_2,
    context: context_2,
};
let answers = qa_model.predict(&[qa_input_1, qa_input_2], 1, 32);

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more