sjrhuschlee commited on
Commit
103e5be
1 Parent(s): bc0854e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -1
README.md CHANGED
@@ -62,7 +62,12 @@ This is the [deberta-v3-base](https://huggingface.co/microsoft/deberta-v3-base)
62
 
63
  ## Model Usage
64
  ```python
65
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
 
 
 
 
 
66
  model_name = "sjrhuschlee/deberta-v3-base-squad2"
67
 
68
  # a) Using pipelines
@@ -72,10 +77,25 @@ qa_input = {
72
  'context': 'My name is Sarah and I live in London'
73
  }
74
  res = nlp(qa_input)
 
75
 
76
  # b) Load model & tokenizer
77
  model = AutoModelForQuestionAnswering.from_pretrained(model_name)
78
  tokenizer = AutoTokenizer.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  ```
80
 
81
  ## Metrics
 
62
 
63
  ## Model Usage
64
  ```python
65
+ import torch
66
+ from transformers import(
67
+ AutoModelForQuestionAnswering,
68
+ AutoTokenizer,
69
+ pipeline
70
+ )
71
  model_name = "sjrhuschlee/deberta-v3-base-squad2"
72
 
73
  # a) Using pipelines
 
77
  'context': 'My name is Sarah and I live in London'
78
  }
79
  res = nlp(qa_input)
80
+ # {'score': 0.984, 'start': 30, 'end': 37, 'answer': ' London'}
81
 
82
  # b) Load model & tokenizer
83
  model = AutoModelForQuestionAnswering.from_pretrained(model_name)
84
  tokenizer = AutoTokenizer.from_pretrained(model_name)
85
+
86
+ question = 'Where do I live?'
87
+ context = 'My name is Sarah and I live in London'
88
+ encoding = tokenizer(question, context, return_tensors="pt")
89
+ start_scores, end_scores = model(
90
+ encoding["input_ids"],
91
+ attention_mask=encoding["attention_mask"],
92
+ return_dict=False
93
+ )
94
+
95
+ all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0].tolist())
96
+ answer_tokens = all_tokens[torch.argmax(start_scores):torch.argmax(end_scores) + 1]
97
+ answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
98
+ # 'London'
99
  ```
100
 
101
  ## Metrics