julien-c HF staff commited on
Commit
f08f52d
1 Parent(s): 156076f

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/valhalla/longformer-base-4096-finetuned-squadv1/README.md

Files changed (1) hide show
  1. README.md +54 -0
README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LONGFORMER-BASE-4096 fine-tuned on SQuAD v1
2
+ This is longformer-base-4096 model fine-tuned on SQuAD v1 dataset for question answering task.
3
+
4
+ [Longformer](https://arxiv.org/abs/2004.05150) model created by Iz Beltagy, Matthew E. Peters, Arman Coha from AllenAI. As the paper explains it
5
+
6
+ > `Longformer` is a BERT-like model for long documents.
7
+
8
+ The pre-trained model can handle sequences with upto 4096 tokens.
9
+
10
+
11
+ ## Model Training
12
+ This model was trained on google colab v100 GPU. You can find the fine-tuning colab here [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zEl5D-DdkBKva-DdreVOmN0hrAfzKG1o?usp=sharing).
13
+
14
+ Few things to keep in mind while training longformer for QA task,
15
+ by default longformer uses sliding-window local attention on all tokens. But For QA, all question tokens should have global attention. For more details on this please refer the paper. The `LongformerForQuestionAnswering` model automatically does that for you. To allow it to do that
16
+ 1. The input sequence must have three sep tokens, i.e the sequence should be encoded like this
17
+ ` <s> question</s></s> context</s>`. If you encode the question and answer as a input pair, then the tokenizer already takes care of that, you shouldn't worry about it.
18
+ 2. `input_ids` should always be a batch of examples.
19
+
20
+ ## Results
21
+ |Metric | # Value |
22
+ |-------------|---------|
23
+ | Exact Match | 85.1466 |
24
+ | F1 | 91.5415 |
25
+
26
+ ## Model in Action 🚀
27
+ ```python
28
+ import torch
29
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering,
30
+
31
+ tokenizer = AutoTokenizer.from_pretrained("valhalla/longformer-base-4096-finetuned-squadv1")
32
+ model = AutoModelForQuestionAnswering.from_pretrained("valhalla/longformer-base-4096-finetuned-squadv1")
33
+
34
+ text = "Huggingface has democratized NLP. Huge thanks to Huggingface for this."
35
+ question = "What has Huggingface done ?"
36
+ encoding = tokenizer(question, text, return_tensors="pt")
37
+ input_ids = encoding["input_ids"]
38
+
39
+ # default is local attention everywhere
40
+ # the forward method will automatically set global attention on question tokens
41
+ attention_mask = encoding["attention_mask"]
42
+
43
+ start_scores, end_scores = model(input_ids, attention_mask=attention_mask)
44
+ all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0].tolist())
45
+
46
+ answer_tokens = all_tokens[torch.argmax(start_scores) :torch.argmax(end_scores)+1]
47
+ answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
48
+ # output => democratized NLP
49
+ ```
50
+
51
+ The `LongformerForQuestionAnswering` isn't yet supported in `pipeline` . I'll update this card once the support has been added.
52
+
53
+ > Created with ❤️ by Suraj Patil [![Github icon](https://cdn0.iconfinder.com/data/icons/octicons/1024/mark-github-32.png)](https://github.com/patil-suraj/)
54
+ [![Twitter icon](https://cdn0.iconfinder.com/data/icons/shift-logotypes/32/Twitter-32.png)](https://twitter.com/psuraj28)