Alexander Slessor commited on
Commit
468b2e1
1 Parent(s): a77ffa1

refactor readme and test_endpoint

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. README.md +13 -5
  3. test_endpoint.py +38 -0
.gitignore CHANGED
@@ -2,9 +2,10 @@ __pycache__
2
  *.ipynb
3
  *.pdf
4
 
5
- test_endpoint.py
6
  test_handler_local.py
7
 
8
  setup
9
  upload_to_hf
10
  requirements.txt
 
 
 
2
  *.ipynb
3
  *.pdf
4
 
 
5
  test_handler_local.py
6
 
7
  setup
8
  upload_to_hf
9
  requirements.txt
10
+ hf_token.py
11
+
README.md CHANGED
@@ -4,8 +4,17 @@ license: apache-2.0
4
  datasets:
5
  - bookcorpus
6
  - wikipedia
 
 
 
 
 
 
 
7
  ---
8
 
 
 
9
  # BERT large model (uncased) whole word masking finetuned on SQuAD
10
 
11
  Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
@@ -137,15 +146,14 @@ exact_match = 86.91
137
 
138
 
139
 
140
- # HF endpoint deployment errors
141
 
142
- 1
143
- ```
144
  {'error': 'Body needs to provide a inputs key, recieved: b\'{"question":"What is my name?","context":"My name is Clara and I live in Berkeley."}\''}
145
  ```
146
 
147
- 2
148
- ```
149
  {'error': 'Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper__index_select)'}
150
  ```
151
 
 
4
  datasets:
5
  - bookcorpus
6
  - wikipedia
7
+ tags:
8
+ - endpoints-template
9
+ library_name: generic
10
+ model-index:
11
+ - name: bert-large-uncased-whole-word-masking-finetuned-squad
12
+ results: []
13
+ pipeline_tag: other
14
  ---
15
 
16
+ # DEPLOYED @: https://ciy95hpzki22rqvf.us-east-1.aws.endpoints.huggingface.cloud
17
+
18
  # BERT large model (uncased) whole word masking finetuned on SQuAD
19
 
20
  Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
 
146
 
147
 
148
 
149
+ # Error Log
150
 
151
+ ```json
 
152
  {'error': 'Body needs to provide a inputs key, recieved: b\'{"question":"What is my name?","context":"My name is Clara and I live in Berkeley."}\''}
153
  ```
154
 
155
+
156
+ ```json
157
  {'error': 'Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper__index_select)'}
158
  ```
159
 
test_endpoint.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from hf_token import HF_TOKEN
3
+
4
+ def query(token: str, url: str, payload: dict):
5
+ '''
6
+ returns:: (dict) ::
7
+ {
8
+ "score": 0.9873963594436646,
9
+ "start": 34,
10
+ "end": 40,
11
+ "answer": "Berlin"
12
+ }
13
+ '''
14
+ headers = {
15
+ "Authorization": f"Bearer {token}",
16
+ "Content-Type": "application/json"
17
+ }
18
+ response = requests.post(url, headers=headers, json=payload)
19
+ return response.json()
20
+
21
+
22
+ if __name__ == "__main__":
23
+ url = 'https://ciy95hpzki22rqvf.us-east-1.aws.endpoints.huggingface.cloud'
24
+ context_bert_abstract = "We introduce a new language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers. Unlike recent language representation models (Peters et al., 2018a; Radford et al., 2018), BERT is designed to pretrain deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers. As a result, the pre-trained BERT model can be finetuned with just one additional output layer to create state-of-the-art models for a wide range of tasks, such as question answering and language inference, without substantial taskspecific architecture modifications. BERT is conceptually simple and empirically powerful. It obtains new state-of-the-art results on eleven natural language processing tasks, including pushing the GLUE score to 80.5% (7.7% point absolute improvement), MultiNLI accuracy to 86.7% (4.6% absolute improvement), SQuAD v1.1 question answering Test F1 to 93.2 (1.5 point absolute improvement) and SQuAD v2.0 Test F1 to 83.1 (5.1 point absolute improvement)."
25
+ input_ = {
26
+ "inputs": {
27
+ "question": "What does the 'B' in BERT stand for?",
28
+ "context": context_bert_abstract
29
+ }
30
+ }
31
+ output = query(
32
+ HF_TOKEN,
33
+ url,
34
+ input_
35
+ )
36
+ print(output)
37
+
38
+