wissamantoun commited on
Commit
859faed
โ€ข
1 Parent(s): 5a6e787

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -110
README.md CHANGED
@@ -1,111 +1,115 @@
1
- ---
2
- language: ar
3
- datasets:
4
- - wikipedia
5
- - OSIAN
6
- - 1.5B Arabic Corpus
7
- - OSCAR Arabic Unshuffled
8
- ---
9
-
10
- # AraELECTRA
11
-
12
- <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraELECTRA.png" width="100" align="left"/>
13
-
14
- **ELECTRA** is a method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). AraELECTRA achieves state-of-the-art results on Arabic QA dataset.
15
-
16
- For a detailed description, please refer to the AraELECTRA paper [AraELECTRA: Pre-Training Text Discriminators for Arabic Language Understanding](https://arxiv.org/abs/2012.15516).
17
-
18
- ## How to use the discriminator in `transformers`
19
-
20
- ```python
21
- from transformers import ElectraForPreTraining, ElectraTokenizerFast
22
- import torch
23
-
24
- discriminator = ElectraForPreTraining.from_pretrained("aubmindlab/araelectra-base-discriminator")
25
- tokenizer = ElectraTokenizerFast.from_pretrained("aubmindlab/araelectra-base-discriminator")
26
-
27
- sentence = ""
28
- fake_sentence = ""
29
-
30
- fake_tokens = tokenizer.tokenize(fake_sentence)
31
- fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt")
32
- discriminator_outputs = discriminator(fake_inputs)
33
- predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2)
34
-
35
- [print("%7s" % token, end="") for token in fake_tokens]
36
-
37
- [print("%7s" % int(prediction), end="") for prediction in predictions.tolist()]
38
- ```
39
-
40
- # Model
41
-
42
- Model | HuggingFace Model Name | Size (MB/Params)|
43
- ---|:---:|:---:
44
- AraELECTRA-base-generator | [araelectra-base-generator](https://huggingface.co/aubmindlab/araelectra-base-generator) | 227MB/60M |
45
- AraELECTRA-base-discriminator | [araelectra-base-discriminator](https://huggingface.co/aubmindlab/araelectra-base-discriminator) | 516MB/135M |
46
-
47
- # Compute
48
- Model | Hardware | num of examples (seq len = 512) | Batch Size | Num of Steps | Time (in days)
49
- ---|:---:|:---:|:---:|:---:|:---:
50
- AraELECTRA-base | TPUv3-8 | - | 256 | 2M | 24
51
-
52
- # Dataset
53
-
54
- The pretraining data used for the new **AraELECTRA** model is also used for **AraGPT2 and AraBERTv2**.
55
-
56
- The dataset consists of 77GB or 200,095,961 lines or 8,655,948,860 words or 82,232,988,358 chars (before applying Farasa Segmentation)
57
-
58
- For the new dataset we added the unshuffled OSCAR corpus, after we thoroughly filter it, to the previous dataset used in AraBERTv1 but with out the websites that we previously crawled:
59
- - OSCAR unshuffled and filtered.
60
- - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
61
- - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
62
- - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
63
- - Assafir news articles. Huge thank you for Assafir for giving us the data
64
-
65
- # Preprocessing
66
-
67
- It is recommended to apply our preprocessing function before training/testing on any dataset.
68
- **Install farasapy to segment text for AraBERT v1 & v2 `pip install farasapy`**
69
-
70
- ```python
71
- from arabert.preprocess import ArabertPreprocessor
72
-
73
- model_name="araelectra-base"
74
- arabert_prep = ArabertPreprocessor(model_name=model_name)
75
-
76
- text = "ูˆู„ู† ู†ุจุงู„ุบ ุฅุฐุง ู‚ู„ู†ุง ุฅู† ู‡ุงุชู ุฃูˆ ูƒู…ุจูŠูˆุชุฑ ุงู„ู…ูƒุชุจ ููŠ ุฒู…ู†ู†ุง ู‡ุฐุง ุถุฑูˆุฑูŠ"
77
- arabert_prep.preprocess(text)
78
- ```
79
-
80
-
81
- # TensorFlow 1.x models
82
-
83
- **You can find the PyTorch, TF2 and TF1 models in HuggingFace's Transformer Library under the ```aubmindlab``` username**
84
-
85
- - `wget https://huggingface.co/aubmindlab/MODEL_NAME/resolve/main/tf1_model.tar.gz` where `MODEL_NAME` is any model under the `aubmindlab` name
86
-
87
- # If you used this model please cite us as :
88
-
89
- ```
90
- @inproceedings{antoun-etal-2021-araelectra,
91
- title = "{A}ra{ELECTRA}: Pre-Training Text Discriminators for {A}rabic Language Understanding",
92
- author = "Antoun, Wissam and
93
- Baly, Fady and
94
- Hajj, Hazem",
95
- booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
96
- month = apr,
97
- year = "2021",
98
- address = "Kyiv, Ukraine (Virtual)",
99
- publisher = "Association for Computational Linguistics",
100
- url = "https://www.aclweb.org/anthology/2021.wanlp-1.20",
101
- pages = "191--195",
102
- }
103
- ```
104
-
105
- # Acknowledgments
106
- Thanks to TensorFlow Research Cloud (TFRC) for the free access to Cloud TPUs, couldn't have done it without this program, and to the [AUB MIND Lab](https://sites.aub.edu.lb/mindlab/) Members for the continous support. Also thanks to [Yakshof](https://www.yakshof.com/#/) and Assafir for data and storage access. Another thanks for Habib Rahal (https://www.behance.net/rahalhabib), for putting a face to AraBERT.
107
-
108
- # Contacts
109
- **Wissam Antoun**: [Linkedin](https://www.linkedin.com/in/wissam-antoun-622142b4/) | [Twitter](https://twitter.com/wissam_antoun) | [Github](https://github.com/WissamAntoun) | <wfa07@mail.aub.edu> | <wissam.antoun@gmail.com>
110
-
 
 
 
 
111
  **Fady Baly**: [Linkedin](https://www.linkedin.com/in/fadybaly/) | [Twitter](https://twitter.com/fadybaly) | [Github](https://github.com/fadybaly) | <fgb06@mail.aub.edu> | <baly.fady@gmail.com>
1
+ ---
2
+ language: ar
3
+ datasets:
4
+ - wikipedia
5
+ - Osian
6
+ - 1.5B-Arabic-Corpus
7
+ - oscar-arabic-unshuffled
8
+ - Assafir(private)
9
+ ---
10
+
11
+ # AraELECTRA
12
+
13
+ <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraELECTRA.png" width="100" align="left"/>
14
+
15
+ **ELECTRA** is a method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). AraELECTRA achieves state-of-the-art results on Arabic QA dataset.
16
+
17
+ For a detailed description, please refer to the AraELECTRA paper [AraELECTRA: Pre-Training Text Discriminators for Arabic Language Understanding](https://arxiv.org/abs/2012.15516).
18
+
19
+ ## How to use the discriminator in `transformers`
20
+
21
+ ```python
22
+ from transformers import ElectraForPreTraining, ElectraTokenizerFast
23
+ import torch
24
+
25
+ discriminator = ElectraForPreTraining.from_pretrained("aubmindlab/araelectra-base-discriminator")
26
+ tokenizer = ElectraTokenizerFast.from_pretrained("aubmindlab/araelectra-base-discriminator")
27
+
28
+ sentence = ""
29
+ fake_sentence = ""
30
+
31
+ fake_tokens = tokenizer.tokenize(fake_sentence)
32
+ fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt")
33
+ discriminator_outputs = discriminator(fake_inputs)
34
+ predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2)
35
+
36
+ [print("%7s" % token, end="") for token in fake_tokens]
37
+
38
+ [print("%7s" % int(prediction), end="") for prediction in predictions.tolist()]
39
+ ```
40
+
41
+ # Model
42
+
43
+ Model | HuggingFace Model Name | Size (MB/Params)|
44
+ ---|:---:|:---:
45
+ AraELECTRA-base-generator | [araelectra-base-generator](https://huggingface.co/aubmindlab/araelectra-base-generator) | 227MB/60M |
46
+ AraELECTRA-base-discriminator | [araelectra-base-discriminator](https://huggingface.co/aubmindlab/araelectra-base-discriminator) | 516MB/135M |
47
+
48
+ # Compute
49
+ Model | Hardware | num of examples (seq len = 512) | Batch Size | Num of Steps | Time (in days)
50
+ ---|:---:|:---:|:---:|:---:|:---:
51
+ AraELECTRA-base | TPUv3-8 | - | 256 | 2M | 24
52
+
53
+ # Dataset
54
+
55
+ The pretraining data used for the new **AraELECTRA** model is also used for **AraGPT2 and AraBERTv2**.
56
+
57
+ The dataset consists of 77GB or 200,095,961 lines or 8,655,948,860 words or 82,232,988,358 chars (before applying Farasa Segmentation)
58
+
59
+ For the new dataset we added the unshuffled OSCAR corpus, after we thoroughly filter it, to the previous dataset used in AraBERTv1 but with out the websites that we previously crawled:
60
+ - OSCAR unshuffled and filtered.
61
+ - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
62
+ - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
63
+ - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
64
+ - Assafir news articles. Huge thank you for Assafir for giving us the data
65
+
66
+ # Preprocessing
67
+
68
+ It is recommended to apply our preprocessing function before training/testing on any dataset.
69
+
70
+ **Install the arabert python package to segment text for AraBERT v1 & v2 or to clean your data `pip install arabert`**
71
+
72
+ ```python
73
+ from arabert.preprocess import ArabertPreprocessor
74
+
75
+ model_name="araelectra-base"
76
+ arabert_prep = ArabertPreprocessor(model_name=model_name)
77
+
78
+ text = "ูˆู„ู† ู†ุจุงู„ุบ ุฅุฐุง ู‚ู„ู†ุง ุฅู† ู‡ุงุชู ุฃูˆ ูƒู…ุจูŠูˆุชุฑ ุงู„ู…ูƒุชุจ ููŠ ุฒู…ู†ู†ุง ู‡ุฐุง ุถุฑูˆุฑูŠ"
79
+ arabert_prep.preprocess(text)
80
+
81
+ >>> output: ูˆู„ู† ู†ุจุงู„ุบ ุฅุฐุง ู‚ู„ู†ุง : ุฅู† ู‡ุงุชู ุฃูˆ ูƒู…ุจูŠูˆุชุฑ ุงู„ู…ูƒุชุจ ููŠ ุฒู…ู†ู†ุง ู‡ุฐุง ุถุฑูˆุฑูŠ
82
+ ```
83
+
84
+
85
+ # TensorFlow 1.x models
86
+
87
+ **You can find the PyTorch, TF2 and TF1 models in HuggingFace's Transformer Library under the ```aubmindlab``` username**
88
+
89
+ - `wget https://huggingface.co/aubmindlab/MODEL_NAME/resolve/main/tf1_model.tar.gz` where `MODEL_NAME` is any model under the `aubmindlab` name
90
+
91
+ # If you used this model please cite us as :
92
+
93
+ ```
94
+ @inproceedings{antoun-etal-2021-araelectra,
95
+ title = "{A}ra{ELECTRA}: Pre-Training Text Discriminators for {A}rabic Language Understanding",
96
+ author = "Antoun, Wissam and
97
+ Baly, Fady and
98
+ Hajj, Hazem",
99
+ booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
100
+ month = apr,
101
+ year = "2021",
102
+ address = "Kyiv, Ukraine (Virtual)",
103
+ publisher = "Association for Computational Linguistics",
104
+ url = "https://www.aclweb.org/anthology/2021.wanlp-1.20",
105
+ pages = "191--195",
106
+ }
107
+ ```
108
+
109
+ # Acknowledgments
110
+ Thanks to TensorFlow Research Cloud (TFRC) for the free access to Cloud TPUs, couldn't have done it without this program, and to the [AUB MIND Lab](https://sites.aub.edu.lb/mindlab/) Members for the continous support. Also thanks to [Yakshof](https://www.yakshof.com/#/) and Assafir for data and storage access. Another thanks for Habib Rahal (https://www.behance.net/rahalhabib), for putting a face to AraBERT.
111
+
112
+ # Contacts
113
+ **Wissam Antoun**: [Linkedin](https://www.linkedin.com/in/wissam-antoun-622142b4/) | [Twitter](https://twitter.com/wissam_antoun) | [Github](https://github.com/WissamAntoun) | <wfa07@mail.aub.edu> | <wissam.antoun@gmail.com>
114
+
115
  **Fady Baly**: [Linkedin](https://www.linkedin.com/in/fadybaly/) | [Twitter](https://twitter.com/fadybaly) | [Github](https://github.com/fadybaly) | <fgb06@mail.aub.edu> | <baly.fady@gmail.com>