BHSo commited on
Commit
5ea424d
1 Parent(s): b018f55

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -7
README.md CHANGED
@@ -43,22 +43,27 @@ from transformers import AutoModelForQuestionAnswering, AutoTokenizer
43
  question = 'アレクサンダー・グラハム・ベルは、どこで生まれたの?'
44
  context = 'アレクサンダー・グラハム・ベルは、スコットランド生まれの科学者、発明家、工学者である。世界初の>実用的電話の発明で知られている。'
45
 
46
- model = AutoModelForQuestionAnswering.from_pretrained('SkelterLabsInc/bert-base-japanese-jaquad')
47
- tokenizer = AutoTokenizer.from_pretrained('SkelterLabsInc/bert-base-japanese-jaquad')
 
 
48
 
49
- inputs = tokenizer(question, context, add_special_tokens=True, return_tensors="pt")
 
50
  input_ids = inputs["input_ids"].tolist()[0]
51
  outputs = model(**inputs)
52
  answer_start_scores = outputs.start_logits
53
  answer_end_scores = outputs.end_logits
54
 
55
- # Get the most likely beginning of answer with the argmax of the score
56
  answer_start = torch.argmax(answer_start_scores)
57
- # Get the most likely end of answer with the argmax of the score
 
58
  answer_end = torch.argmax(answer_end_scores) + 1
59
 
60
- answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))
61
- # answer: 'スコットランド'
 
62
  ```
63
 
64
  ## License
 
43
  question = 'アレクサンダー・グラハム・ベルは、どこで生まれたの?'
44
  context = 'アレクサンダー・グラハム・ベルは、スコットランド生まれの科学者、発明家、工学者である。世界初の>実用的電話の発明で知られている。'
45
 
46
+ model = AutoModelForQuestionAnswering.from_pretrained(
47
+ 'SkelterLabsInc/bert-base-japanese-jaquad')
48
+ tokenizer = AutoTokenizer.from_pretrained(
49
+ 'SkelterLabsInc/bert-base-japanese-jaquad')
50
 
51
+ inputs = tokenizer(
52
+ question, context, add_special_tokens=True, return_tensors="pt")
53
  input_ids = inputs["input_ids"].tolist()[0]
54
  outputs = model(**inputs)
55
  answer_start_scores = outputs.start_logits
56
  answer_end_scores = outputs.end_logits
57
 
58
+ # Get the most likely beginning of answer with the argmax of the score.
59
  answer_start = torch.argmax(answer_start_scores)
60
+ # Get the most likely end of answer with the argmax of the score.
61
+ # 1 is added to `answer_end` because the index pointed by score is inclusive.
62
  answer_end = torch.argmax(answer_end_scores) + 1
63
 
64
+ answer = tokenizer.convert_tokens_to_string(
65
+ tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))
66
+ # answer = 'スコットランド'
67
  ```
68
 
69
  ## License