hajime9652 commited on
Commit
3e8e153
1 Parent(s): 63c49f3
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +10 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoTokenizer, RobertaForQuestionAnswering
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("tsmatz/roberta_qa_japanese")
6
+ model = RobertaForQuestionAnswering.from_pretrained("tsmatz/roberta_qa_japanese")
7
+
8
+ def answer(text, question):
9
+ inputs = tokenizer(question, text, add_special_tokens=True, return_tensors="pt")
10
+ input_ids = inputs["input_ids"].tolist()[0]
11
+
12
+ outputs = model(**inputs)
13
+ answer_start_scores = outputs.start_logits
14
+ answer_end_scores = outputs.end_logits
15
+
16
+ answer_start = torch.argmax(answer_start_scores)
17
+ answer_end = torch.argmax(answer_end_scores) + 1
18
+
19
+ answer = tokenizer.convert_tokens_to_string(
20
+ tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end])
21
+ )
22
+
23
+ return answer
24
+
25
+ gr.Interface(
26
+ answer,
27
+ [
28
+ gr.Textbox(label="Text:", placeholder="Text...", lines=5),
29
+ gr.Textbox(label="Question:", placeholder="Question...", lines=1)
30
+ ],
31
+ "text",
32
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ datasets
3
+ evaluate
4
+ transformers[sentencepiece]
5
+ transformers
6
+ sentencepiece
7
+ fugashi
8
+ fugashi[unidic]
9
+ fugashi[unidic-lite]
10
+ ipadic