sjrhuschlee commited on
Commit
c44c487
1 Parent(s): a60a482

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -4
README.md CHANGED
@@ -78,7 +78,7 @@ qa_input = {
78
  'context': 'My name is Sarah and I live in London'
79
  }
80
  res = nlp(qa_input)
81
- # {'score': 0.9844420552253723, 'start': 30, 'end': 37, 'answer': ' London'}
82
 
83
  # b) Load model & tokenizer
84
  model = AutoModelForQuestionAnswering.from_pretrained(model_name)
@@ -87,11 +87,14 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
87
  question = 'Where do I live?'
88
  context = 'My name is Sarah and I live in London'
89
  encoding = tokenizer(question, context, return_tensors="pt")
90
-
91
- start_scores, end_scores = model(encoding["input_ids"], attention_mask=encoding["attention_mask"], return_dict=False)
 
 
 
92
 
93
  all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0].tolist())
94
- answer_tokens = all_tokens[torch.argmax(start_scores) :torch.argmax(end_scores)+1]
95
  answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
96
  # 'London'
97
  ```
 
78
  'context': 'My name is Sarah and I live in London'
79
  }
80
  res = nlp(qa_input)
81
+ # {'score': 0.984, 'start': 30, 'end': 37, 'answer': ' London'}
82
 
83
  # b) Load model & tokenizer
84
  model = AutoModelForQuestionAnswering.from_pretrained(model_name)
 
87
  question = 'Where do I live?'
88
  context = 'My name is Sarah and I live in London'
89
  encoding = tokenizer(question, context, return_tensors="pt")
90
+ start_scores, end_scores = model(
91
+ encoding["input_ids"],
92
+ attention_mask=encoding["attention_mask"],
93
+ return_dict=False
94
+ )
95
 
96
  all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0].tolist())
97
+ answer_tokens = all_tokens[torch.argmax(start_scores):torch.argmax(end_scores) + 1]
98
  answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
99
  # 'London'
100
  ```