ZeyadAhmed commited on
Commit
57d184a
1 Parent(s): 3e3e903

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -0
README.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AraElectra for Question Answering on Arabic-SQuADv2
2
+
3
+ This is the [AraElectra](https://huggingface.co/aubmindlab/araelectra-base-discriminator) model, fine-tuned using the [Arabic-SQuADv2.0](https://huggingface.co/datasets/ZeyadAhmed/Arabic-SQuADv2.0) dataset. It's been trained on question-answer pairs, including unanswerable questions, for the task of Question Answering. with help of [AraElectra Classifier](https://huggingface.co/ZeyadAhmed/AraElectra-Arabic-SQuADv2-CLS) to predicted unanswerable question.
4
+
5
+ ## Overview
6
+ **Language model:** AraElectra <br>
7
+ **Language:** Arabic <br>
8
+ **Downstream-task:** Extractive QA
9
+ **Training data:** Arabic-SQuADv2.0
10
+ **Eval data:** Arabic-SQuADv2.0 <br>
11
+ **Test data:** Arabic-SQuADv2.0 <br>
12
+ **Code:** [See More Info on Github](https://github.com/zeyadahmed10/Arabic-MRC)
13
+ **Infrastructure**: 1x Tesla K80
14
+
15
+ ## Hyperparameters
16
+
17
+ ```
18
+ batch_size = 8
19
+ n_epochs = 4
20
+ base_LM_model = "AraElectra"
21
+ learning_rate = 3e-5
22
+ optimizer = AdamW
23
+ padding = dynamic
24
+ ```
25
+
26
+ ## Online Demo on Arabic Wikipedia and User Provided Contexts
27
+ See model in action hosted on streamlit [![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://share.streamlit.io/wissamantoun/arabic-wikipedia-qa-streamlit/main)
28
+
29
+ ## Usage
30
+ For best results use the AraBert [preprocessor](https://github.com/aub-mind/arabert/blob/master/preprocess.py) by aub-mind
31
+ ```python
32
+ from transformers import ElectraForQuestionAnswering, ElectraForSequenceClassification, AutoTokenizer, pipeline
33
+ from preprocess import ArabertPreprocessor
34
+ prep_object = ArabertPreprocessor("araelectra-base-discriminator")
35
+ question = prep_object('ما هي جامعة الدول العربية ؟')
36
+ context = prep_object('''
37
+ جامعة الدول العربية هيمنظمة إقليمية تضم دولاً عربية في آسيا وأفريقيا.
38
+ ينص ميثاقها على التنسيق بين الدول الأعضاء في الشؤون الاقتصادية، ومن ضمنها العلاقات التجارية الاتصالات، العلاقات الثقافية، الجنسيات ووثائق وأذونات السفر والعلاقات الاجتماعية والصحة. المقر الدائم لجامعة الدول العربية يقع في القاهرة، عاصمة مصر (تونس من 1979 إلى 1990).
39
+ ''')
40
+ # a) Get predictions
41
+ qa_modelname = 'ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA'
42
+ cls_modelname = 'ZeyadAhmed/AraElectra-Arabic-SQuADv2-CLS'
43
+ qa_pipe = pipeline('question-answering', model=qa_modelname, tokenizer=qa_modelname)
44
+ QA_input = {
45
+ 'question': question,
46
+ 'context': context
47
+ }
48
+ CLS_input = {
49
+ 'text': question,
50
+ 'text_pair': context
51
+ }
52
+ qa_res = qa_pipe(QA_input)
53
+ cls_res = cls_pipe(CLS_iput)
54
+ threshold = 0.5 #hyperparameter can be tweaked
55
+ ## note classification results label0 probability it can be answered label1 probability can't be answered
56
+ ## if label1 probability > threshold then consider the output of qa_res is empty string else take the qa_res
57
+ # b) Load model & tokenizer
58
+ qa_model = ElectraForQuestionAnswering.from_pretrained(qa_modelname)
59
+ cls_model = ElectraForSequenceClassification.from_pretrained(cls_modelname)
60
+ tokenizer = AutoTokenizer.from_pretrained(qa_modelname)
61
+ ```
62
+
63
+ ## Performance
64
+ Evaluated on the Arabic-SQuAD 2.0 test set with the [official eval script](https://worksheets.codalab.org/rest/bundles/0x6b567e1cf2e041ec80d7098f031c5c9e/contents/blob/) except changing in the preprocessing a little to fit the arabic language [the modified eval script](https://github.com/zeyadahmed10/Arabic-MRC/blob/main/evaluatev2.py).
65
+
66
+ ```
67
+ "exact": 65.11555277951281,
68
+ "f1": 71.49042547237256,,
69
+
70
+ "total": 9606,
71
+ "HasAns_exact": 56.14535768645358,
72
+ "HasAns_f1": 67.79623803036668,
73
+ "HasAns_total": 5256,
74
+ "NoAns_exact": 75.95402298850574,
75
+ "NoAns_f1": 75.95402298850574,
76
+ "NoAns_total": 4350
77
+ ```