julien-c HF staff commited on
Commit
7217207
1 Parent(s): ceacc9a

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/Primer/bart-squad2/README.md

Files changed (1) hide show
  1. README.md +63 -0
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: "en"
3
+ ---
4
+
5
+ # BART-Squad2
6
+
7
+ ## Model description
8
+
9
+ BART for extractive (span-based) question answering, trained on Squad 2.0.
10
+
11
+ F1 score of 87.4.
12
+
13
+ ## Intended uses & limitations
14
+
15
+ Unfortunately, the Huggingface auto-inference API won't run this model, so if you're attempting to try it through the input box above and it complains, don't be discouraged!
16
+
17
+ #### How to use
18
+
19
+ Here's a quick way to get question answering running locally:
20
+
21
+ ```python
22
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering
23
+
24
+ tokenizer = AutoTokenizer.from_pretrained("Primer/bart-squad2")
25
+ model = AutoModelForQuestionAnswering.from_pretrained("Primer/bart-squad2")
26
+ model.to('cuda'); model.eval()
27
+
28
+ def answer(question, text):
29
+ seq = '<s>' + question + ' </s> </s> ' + text + ' </s>'
30
+ tokens = tokenizer.encode_plus(seq, return_tensors='pt', padding='max_length', max_length=1024)
31
+ input_ids = tokens['input_ids'].to('cuda')
32
+ attention_mask = tokens['attention_mask'].to('cuda')
33
+ start, end, _ = model(input_ids, attention_mask=attention_mask)
34
+ start_idx = int(start.argmax().int())
35
+ end_idx = int(end.argmax().int())
36
+ print(tokenizer.decode(input_ids[0, start_idx:end_idx]).strip())
37
+ # ^^ it will be an empty string if the model decided "unanswerable"
38
+
39
+ >>> question = "Where does Tom live?"
40
+ >>> context = "Tom is an engineer in San Francisco."
41
+ >>> answer(question, context)
42
+ San Francisco
43
+ ```
44
+
45
+ (Just drop the `.to('cuda')` stuff if running on CPU).
46
+
47
+ #### Limitations and bias
48
+
49
+ Unknown, no further evaluation has been performed. In a technical sense one big limitation is that it's 1.6G 😬
50
+
51
+ ## Training procedure
52
+
53
+ `run_squad.py` with:
54
+
55
+ |param|value|
56
+ |---|---|
57
+ |batch size|8|
58
+ |max_seq_length|1024|
59
+ |learning rate|1e-5|
60
+ |epochs|2|
61
+
62
+ Modified to freeze shared parameters and encoder embeddings.
63
+