2020-02-25 20:39:08 +03:00
|
|
|
// Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
|
|
|
|
// Copyright 2019 Guillaume Becquin
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-08-12 14:39:04 +03:00
|
|
|
extern crate anyhow;
|
2020-02-24 18:23:44 +03:00
|
|
|
|
2020-06-23 17:54:46 +03:00
|
|
|
use rust_bert::pipelines::question_answering::{QaInput, QuestionAnsweringModel};
|
2020-02-24 18:23:44 +03:00
|
|
|
|
2020-08-12 14:39:04 +03:00
|
|
|
fn main() -> anyhow::Result<()> {
|
2020-06-23 17:54:46 +03:00
|
|
|
// Set-up Question Answering model
|
2020-04-26 10:08:04 +03:00
|
|
|
let qa_model = QuestionAnsweringModel::new(Default::default())?;
|
2020-02-25 13:27:59 +03:00
|
|
|
|
2020-06-23 17:54:46 +03:00
|
|
|
// Define input
|
2020-03-06 23:40:32 +03:00
|
|
|
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.");
|
2020-06-23 17:54:46 +03:00
|
|
|
let qa_input_1 = QaInput {
|
|
|
|
question: question_1,
|
|
|
|
context: context_1,
|
|
|
|
};
|
|
|
|
let qa_input_2 = QaInput {
|
|
|
|
question: question_2,
|
|
|
|
context: context_2,
|
|
|
|
};
|
2020-02-24 18:23:44 +03:00
|
|
|
|
2020-06-23 17:54:46 +03:00
|
|
|
// Get answer
|
2020-09-13 13:25:22 +03:00
|
|
|
let answers = qa_model.predict(&[qa_input_1, qa_input_2], 1, 32);
|
2020-02-25 20:32:26 +03:00
|
|
|
println!("{:?}", answers);
|
2020-02-24 18:23:44 +03:00
|
|
|
Ok(())
|
2020-06-23 17:54:46 +03:00
|
|
|
}
|