Views
No views yet
1# Load model directly
2from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
3
4tokenizer = AutoTokenizer.from_pretrained("Tien-THM/bert-mini-fine-tuning-squad")
5model = TFAutoModelForQuestionAnswering.from_pretrained("Tien-THM/bert-mini-fine-tuning-squad")
6
7import numpy as np
8
9def Inference(context, question):
10 encoding = tokenizer(context, question, return_tensors='tf')
11 start_pos = model(encoding).start_logits
12 end_pos = model(encoding).end_logits
13 s = np.argmax(start_pos[0])
14 e = np.argmax(end_pos[0])
15 print(tokenizer.decode(encoding['input_ids'][0][s:e+1]))
16
17question = 'How many layes does BERT-large have'
18context = 'BERT-large is really big... it has 24-layers and an embedding size
19of 1,024, for a total of 340M parameters! Altogether it is 1.34GB, so
20expect it to take a couple minutes to download to your Colab instance'
21
22Inference(context, question)
23# Answer: 24 - layers and an em ##bed ##ding size of 1 , 02 ##4| Epoch | Train loss | Validation loss | Exact Match |
|---|---|---|---|
| #1 | 4.7110 | 3.6251 | 0.38 |
| #2 | 3.2650 | 3.3062 | 0.42 |
| #3 | 2.7899 | 3.2184 | 0.44 |
| #4 | 2.4633 | 3.1946 | 0.45 |