Views
No views yet
| Public leaderboard | Private leaderboard |
|---|---|
![]() | ![]() |
1from transformers import pipeline
2# model_checkpoint = "nguyenvulebinh/vi-mrc-large"
3model_checkpoint = "nguyenvulebinh/vi-mrc-base"
4nlp = pipeline('question-answering', model=model_checkpoint,
5 tokenizer=model_checkpoint)
6QA_input = {
7 'question': "Bình là chuyên gia về gì ?",
8 'context': "Bình Nguyễn là một người đam mê với lĩnh vực xử lý ngôn ngữ tự nhiên . Anh nhận chứng chỉ Google Developer Expert năm 2020"
9}
10res = nlp(QA_input)
11print('pipeline: {}'.format(res))
12#{'score': 0.5782045125961304, 'start': 45, 'end': 68, 'answer': 'xử lý ngôn ngữ tự nhiên'}1from infer import tokenize_function, data_collator, extract_answer
2from model.mrc_model import MRCQuestionAnswering
3from transformers import AutoTokenizer
4
5model_checkpoint = "nguyenvulebinh/vi-mrc-large"
6#model_checkpoint = "nguyenvulebinh/vi-mrc-base"
7tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
8model = MRCQuestionAnswering.from_pretrained(model_checkpoint)
9
10QA_input = {
11 'question': "Bình được công nhận với danh hiệu gì ?",
12 'context': "Bình Nguyễn là một người đam mê với lĩnh vực xử lý ngôn ngữ tự nhiên . Anh nhận chứng chỉ Google Developer Expert năm 2020"
13}
14
15inputs = [tokenize_function(*QA_input)]
16inputs_ids = data_collator(inputs)
17outputs = model(**inputs_ids)
18answer = extract_answer(inputs, outputs, tokenizer)
19
20print(answer)
21# answer: Google Developer Expert. Score start: 0.9926977753639221, Score end: 0.9909810423851013