bhadresh-savani commited on
Commit
e06d14d
1 Parent(s): 2ed7dd9

added models

Browse files
README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - squad_v2
4
+ license: cc-by-4.0
5
+
6
+ ---
7
+
8
+ # electra-base for QA
9
+
10
+ ## Overview
11
+ **Language model:** electra-base
12
+ **Language:** English
13
+ **Downstream-task:** Extractive QA
14
+ **Training data:** SQuAD 2.0
15
+ **Eval data:** SQuAD 2.0
16
+ **Code:** See [example](https://github.com/deepset-ai/FARM/blob/master/examples/question_answering.py) in [FARM](https://github.com/deepset-ai/FARM/blob/master/examples/question_answering.py)
17
+ **Infrastructure**: 1x Tesla v100
18
+
19
+ ## Hyperparameters
20
+
21
+ ```
22
+ seed=42
23
+ batch_size = 32
24
+ n_epochs = 5
25
+ base_LM_model = "google/electra-base-discriminator"
26
+ max_seq_len = 384
27
+ learning_rate = 1e-4
28
+ lr_schedule = LinearWarmup
29
+ warmup_proportion = 0.1
30
+ doc_stride=128
31
+ max_query_length=64
32
+ ```
33
+
34
+ ## Performance
35
+ Evaluated on the SQuAD 2.0 dev set with the [official eval script](https://worksheets.codalab.org/rest/bundles/0x6b567e1cf2e041ec80d7098f031c5c9e/contents/blob/).
36
+ ```
37
+ "exact": 77.30144024256717,
38
+ "f1": 81.35438272008543,
39
+ "total": 11873,
40
+ "HasAns_exact": 74.34210526315789,
41
+ "HasAns_f1": 82.45961302894314,
42
+ "HasAns_total": 5928,
43
+ "NoAns_exact": 80.25231286795626,
44
+ "NoAns_f1": 80.25231286795626,
45
+ "NoAns_total": 5945
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### In Transformers
51
+ ```python
52
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
53
+
54
+ model_name = "deepset/electra-base-squad2"
55
+
56
+ # a) Get predictions
57
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
58
+ QA_input = {
59
+ 'question': 'Why is model conversion important?',
60
+ 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.'
61
+ }
62
+ res = nlp(QA_input)
63
+
64
+ # b) Load model & tokenizer
65
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
66
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
67
+ ```
68
+
69
+ ### In FARM
70
+
71
+ ```python
72
+ from farm.modeling.adaptive_model import AdaptiveModel
73
+ from farm.modeling.tokenization import Tokenizer
74
+ from farm.infer import Inferencer
75
+
76
+ model_name = "deepset/electra-base-squad2"
77
+
78
+ # a) Get predictions
79
+ nlp = Inferencer.load(model_name, task_type="question_answering")
80
+ QA_input = [{"questions": ["Why is model conversion important?"],
81
+ "text": "The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks."}]
82
+ res = nlp.inference_from_dicts(dicts=QA_input)
83
+
84
+ # b) Load model & tokenizer
85
+ model = AdaptiveModel.convert_from_transformers(model_name, device="cpu", task_type="question_answering")
86
+ tokenizer = Tokenizer.load(model_name)
87
+ ```
88
+
89
+ ### In haystack
90
+ For doing QA at scale (i.e. many docs instead of single paragraph), you can load the model also in [haystack](https://github.com/deepset-ai/haystack/):
91
+ ```python
92
+ reader = FARMReader(model_name_or_path="deepset/electra-base-squad2")
93
+ # or
94
+ reader = TransformersReader(model="deepset/electra-base-squad2",tokenizer="deepset/electra-base-squad2")
95
+ ```
96
+
97
+
98
+ ## Authors
99
+ Vaishali Pal `vaishali.pal [at] deepset.ai`
100
+ Branden Chan: `branden.chan [at] deepset.ai`
101
+ Timo Möller: `timo.moeller [at] deepset.ai`
102
+ Malte Pietsch: `malte.pietsch [at] deepset.ai`
103
+ Tanay Soni: `tanay.soni [at] deepset.ai`
104
+
105
+ Note:
106
+ Borrowed this model from Haystack model repo for adding tensorflow model.
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ElectraForQuestionAnswering"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "embedding_size": 768,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "language": "english",
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "electra",
17
+ "name": "Electra",
18
+ "num_attention_heads": 12,
19
+ "num_hidden_layers": 12,
20
+ "pad_token_id": 0,
21
+ "position_embedding_type": "absolute",
22
+ "summary_activation": "gelu",
23
+ "summary_last_dropout": 0,
24
+ "summary_type": "first",
25
+ "summary_use_proj": true,
26
+ "transformers_version": "4.19.0.dev0",
27
+ "type_vocab_size": 2,
28
+ "use_cache": true,
29
+ "vocab_size": 30522
30
+ }
convert_pytorch_to_flax.py ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ from transformers import FlaxAutoModelForQuestionAnswering
2
+ model = FlaxAutoModelForQuestionAnswering.from_pretrained("./", from_pt=True)
3
+ model.save_pretrained("./")
convert_pytorch_to_tensorflow.py ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ from transformers import TFAutoModelForQuestionAnswering
2
+ model = TFAutoModelForQuestionAnswering.from_pretrained("./", from_pt=True)
3
+ model.save_pretrained("./")
flax_model.msgpack ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ff9a83a3413c0d57da7be38f7a498a5bd998f4ff8c397a9651110ba1250b94e
3
+ size 435579889
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33abdbab680c8bae8707320df17c5d4fba5969adb465e81029905fa0284d3d3e
3
+ size 435618605
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tf_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6323b685ea8c02486fc1a7f0df7875bd8ee320407853674bc1c1abb739d00d88
3
+ size 435858448
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
1
+ {"do_lower_case": true, "model_max_length": 512, "special_tokens_map_file": "/home/vaishali/Documents/deepset/electra-english-qa-tutorial_epochs5/special_tokens_map.json", "full_tokenizer_file": null}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff