Views
No views yet
xlm-roberta-base on the Japanese JaQuAD dataset for extractive question answering.xlm-roberta-basefrom_pretrained:1from transformers import AutoTokenizer, AutoModelForQuestionAnswering
2import torch
3
4model_id = "takehika/xlm-roberta-ja-jaquad-qa"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForQuestionAnswering.from_pretrained(model_id).eval()
7
8text = "私は音声アシスタントです。名前はありませんが皆はAIと呼んでいるようです。自宅は暗い箱の中ですが寂しくはありません。好きな食べ物は電気で特技は繰り返すことです。"
9questions= ["音声アシスタントはどこに住んでいますか?", "好きな食べ物は?", "名前は?"]
10
11for q in questions:
12 inputs = tokenizer.encode_plus(
13 q, text,
14 add_special_tokens=True,
15 return_tensors="pt",
16 truncation=True,
17 max_length=512,
18 )
19 inputs = {k: v for k, v in inputs.items()}
20
21 with torch.no_grad():
22 out = model(**inputs)
23
24 start = out.start_logits.argmax(dim=-1).item()
25 end = out.end_logits.argmax(dim=-1).item()
26 answer = tokenizer.decode(inputs["input_ids"][0][start:end+1], skip_special_tokens=True)
27
28 print(f"質問: {q} -> 回答: {answer}")SkelterLabsInc/JaQuAD)xlm-roberta-base@article{DBLP:journals/corr/abs-1911-02116,
author = {Alexis Conneau and
Kartikay Khandelwal and
Naman Goyal and
Vishrav Chaudhary and
Guillaume Wenzek and
Francisco Guzm{\'{a}}n and
Edouard Grave and
Myle Ott and
Luke Zettlemoyer and
Veselin Stoyanov},
title = {Unsupervised Cross-lingual Representation Learning at Scale},
journal = {CoRR},
volume = {abs/1911.02116},
year = {2019},
url = {http://arxiv.org/abs/1911.02116},
eprinttype = {arXiv},
eprint = {1911.02116},
timestamp = {Mon, 11 Nov 2019 18:38:09 +0100},
biburl = {https://dblp.org/rec/journals/corr/abs-1911-02116.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}@misc{so2022jaquad,
title={{JaQuAD: Japanese Question Answering Dataset for Machine Reading Comprehension}},
author={ByungHoon So and Kyuhong Byun and Kyungwon Kang and Seongjin Cho},
year={2022},
eprint={2202.01764},
archivePrefix={arXiv},
primaryClass={cs.CL}
}