wissamantoun commited on
Commit
f39a1bd
1 Parent(s): d7de129

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +149 -146
README.md CHANGED
@@ -1,146 +1,149 @@
1
- ---
2
- language: ar
3
- datasets:
4
- - wikipedia
5
- - OSIAN
6
- - 1.5B Arabic Corpus
7
- - OSCAR Arabic Unshuffled
8
- inference: false
9
- widget:
10
- - text: "يحكى أن مزارعا مخادعا قام ببيع بئر الماء الموجود في أرضه لجاره مقابل مبلغ كبير من المال"
11
- - text: "القدس مدينة تاريخية، بناها الكنعانيون في"
12
- - text: "كان يا ما كان في قديم الزمان"
13
- ---
14
-
15
- # Arabic GPT2
16
-
17
- <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraGPT2.png" width="100" align="left"/>
18
-
19
- You can find more information in our paper [AraGPT2](https://arxiv.org/abs/2012.15520)
20
-
21
- The code in this repository was used to train all GPT2 variants. The code support training and fine-tuning GPT2 on GPUs and TPUs via the TPUEstimator API.
22
-
23
- GPT2-base and medium uses the code from the `gpt2` folder and can trains models from the [minimaxir/gpt-2-simple](https://github.com/minimaxir/gpt-2-simple) repository.
24
- These models were trained using the `lamb` optimizer and follow the same architecture as `gpt2` and are fully compatible with the `transformers` library.
25
-
26
- GPT2-large and GPT2-mega were trained using the [imcaspar/gpt2-ml](https://github.com/imcaspar/gpt2-ml/) library, and follow the `grover` architecture. You can use the pytorch classes found in `grover/modeling_gpt2.py` as a direct replacement for classes in the `transformers` library (it should support version `v4.x` from `transformers`).
27
- Both models are trained using the `adafactor` optimizer, since the `adam` and `lamb` optimizer use too much memory causing the model to not even fit 1 batch on a TPU core.
28
-
29
- AraGPT2 is trained on the same large Arabic Dataset as AraBERTv2.
30
-
31
- # Usage
32
-
33
- ## Testing the model using `transformers`:
34
-
35
- ```python
36
- from transformers import GPT2TokenizerFast, pipeline
37
- #for base and medium
38
- from transformers import GPT2LMHeadModel
39
- #for large and mega
40
- from arabert.aragpt2.grover.modeling_gpt2 import GPT2LMHeadModel
41
-
42
- from arabert.preprocess import ArabertPreprocessor
43
-
44
- MODEL_NAME='aubmindlab/aragpt2-mega'
45
- arabert_prep = ArabertPreprocessor(model_name=MODEL_NAME)
46
-
47
- text=""
48
- text_clean = arabert_prep.preprocess(text)
49
-
50
- model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
51
- tokenizer = GPT2TokenizerFast.from_pretrained(MODEL_NAME)
52
- generation_pipeline = pipeline("text-generation",model=model,tokenizer=tokenizer)
53
-
54
- #feel free to try different decodinn settings
55
- generation_pipeline(text,
56
- pad_token_id=tokenizer.eos_token_id,
57
- num_beams=10,
58
- max_length=200,
59
- top_p=0.9,
60
- repetition_penalty = 3.0,
61
- no_repeat_ngram_size = 3)[0]['generated_text']
62
- >>>
63
- ```
64
- ## Finetunning using `transformers`:
65
-
66
- Follow the guide linked [here](https://towardsdatascience.com/fine-tuning-gpt2-on-colab-gpu-for-free-340468c92ed)
67
-
68
- ## Finetuning using our code with TF 1.15.4:
69
-
70
- Create the Training TFRecords:
71
- ```bash
72
- python create_pretraining_data.py
73
- --input_file=<RAW TEXT FILE with documents/article sperated by an empty line>
74
- --output_file=<OUTPUT TFRecord>
75
- --tokenizer_dir=<Directory with the GPT2 Tokenizer files>
76
- ```
77
-
78
- Finetuning:
79
- ```bash
80
- python3 run_pretraining.py \\r\n --input_file="gs://<GS_BUCKET>/pretraining_data/*" \\r\n --output_dir="gs://<GS_BUCKET>/pretraining_model/" \\r\n --config_file="config/small_hparams.json" \\r\n --batch_size=128 \\r\n --eval_batch_size=8 \\r\n --num_train_steps= \\r\n --num_warmup_steps= \\r\n --learning_rate= \\r\n --save_checkpoints_steps= \\r\n --max_seq_length=1024 \\r\n --max_eval_steps= \\r\n --optimizer="lamb" \\r\n --iterations_per_loop=5000 \\r\n --keep_checkpoint_max=10 \\r\n --use_tpu=True \\r\n --tpu_name=<TPU NAME> \\r\n --do_train=True \\r\n --do_eval=False
81
- ```
82
- # Model Sizes
83
-
84
- Model | Optimizer | Context size | Embedding Size | Num of heads | Num of layers | Model Size / Num of Params |
85
- ---|:---:|:---:|:---:|:---:|:---:|:---:
86
- AraGPT2-base | `lamb` | 1024 | 768 | 12 | 12 | 527MB/135M |
87
- AraGPT2-medium | `lamb` | 1024 | 1024 | 16 | 24 | 1.38G/370M |
88
- AraGPT2-large | `adafactor` | 1024 | 1280 | 20 | 36 | 2.98GB/792M |
89
- AraGPT2-mega | `adafactor` | 1024 | 1536 | 25 | 48 | 5.5GB/1.46B |
90
-
91
- All models are available in the `HuggingFace` model page under the [aubmindlab](https://huggingface.co/aubmindlab/) name. Checkpoints are available in PyTorch, TF2 and TF1 formats.
92
-
93
- ## Compute
94
-
95
- For Dataset Source see the [Dataset Section](#Dataset)
96
-
97
- Model | Hardware | num of examples (seq len = 1024) | Batch Size | Num of Steps | Time (in days)
98
- ---|:---:|:---:|:---:|:---:|:---:
99
- AraGPT2-base | TPUv3-128 | 9.7M | 1792 | 125K | 1.5
100
- AraGPT2-medium | TPUv3-8 | 9.7M | 1152 | 85K | 1.5
101
- AraGPT2-large | TPUv3-128 | 9.7M | 256 | 220k | 3
102
- AraGPT2-mega | TPUv3-128 | 9.7M | 256 | 780K | 9
103
-
104
- # Dataset
105
-
106
- The pretraining data used for the new AraBERT model is also used for **GPT2 and ELECTRA**.
107
-
108
- 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)
109
-
110
- 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:
111
- - OSCAR unshuffled and filtered.
112
- - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
113
- - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
114
- - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
115
- - Assafir news articles. Huge thank you for Assafir for giving us the data
116
-
117
- # Disclaimer
118
-
119
- The text generated by GPT2 Arabic is automatically generated by a neural network model trained on a large amount of texts, which does not represent the authors' or their institutes' official attitudes and preferences. The text generated by GPT2 Arabic should only be used for research and scientific purposes. If it infringes on your rights and interests or violates social morality, please do not propagate it.
120
-
121
- # If you used this model please cite us as :
122
-
123
- ```
124
- @inproceedings{antoun-etal-2021-aragpt2,
125
- title = "{A}ra{GPT}2: Pre-Trained Transformer for {A}rabic Language Generation",
126
- author = "Antoun, Wissam and
127
- Baly, Fady and
128
- Hajj, Hazem",
129
- booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
130
- month = apr,
131
- year = "2021",
132
- address = "Kyiv, Ukraine (Virtual)",
133
- publisher = "Association for Computational Linguistics",
134
- url = "https://www.aclweb.org/anthology/2021.wanlp-1.21",
135
- pages = "196--207",
136
- }
137
- ```
138
-
139
- # Acknowledgments
140
- 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.
141
-
142
- # Contacts
143
- **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>
144
-
145
- **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>
146
-
 
 
 
 
1
+ ---
2
+ language: ar
3
+ datasets:
4
+ - wikipedia
5
+ - Osian
6
+ - 1.5B-Arabic-Corpus
7
+ - oscar-arabic-unshuffled
8
+ - Assafir(private)
9
+ inference: false
10
+ widget:
11
+ - text: "يحكى أن مزارعا مخادعا قام ببيع بئر الماء الموجود في أرضه لجاره مقابل مبلغ كبير من المال"
12
+ - text: "القدس مدينة تاريخية، بناها الكنعانيون في"
13
+ - text: "كان يا ما كان في قديم الزمان"
14
+ ---
15
+
16
+ # Arabic GPT2
17
+
18
+ <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraGPT2.png" width="100" align="left"/>
19
+
20
+ You can find more information in our paper [AraGPT2](https://arxiv.org/abs/2012.15520)
21
+
22
+ The code in this repository was used to train all GPT2 variants. The code support training and fine-tuning GPT2 on GPUs and TPUs via the TPUEstimator API.
23
+
24
+ GPT2-base and medium uses the code from the `gpt2` folder and can trains models from the [minimaxir/gpt-2-simple](https://github.com/minimaxir/gpt-2-simple) repository.
25
+ These models were trained using the `lamb` optimizer and follow the same architecture as `gpt2` and are fully compatible with the `transformers` library.
26
+
27
+ GPT2-large and GPT2-mega were trained using the [imcaspar/gpt2-ml](https://github.com/imcaspar/gpt2-ml/) library, and follow the `grover` architecture. You can use the pytorch classes found in `grover/modeling_gpt2.py` as a direct replacement for classes in the `transformers` library (it should support version `v4.x` from `transformers`).
28
+ Both models are trained using the `adafactor` optimizer, since the `adam` and `lamb` optimizer use too much memory causing the model to not even fit 1 batch on a TPU core.
29
+
30
+ AraGPT2 is trained on the same large Arabic Dataset as AraBERTv2.
31
+
32
+ # Usage
33
+
34
+ ## Testing the model using `transformers`:
35
+
36
+ You need to use the GPT2LMHeadModel from `arabert`: `pip install arabert`
37
+
38
+ ```python
39
+ from transformers import GPT2TokenizerFast, pipeline
40
+ #for base and medium
41
+ from transformers import GPT2LMHeadModel
42
+ #for large and mega
43
+ from arabert.aragpt2.grover.modeling_gpt2 import GPT2LMHeadModel
44
+
45
+ from arabert.preprocess import ArabertPreprocessor
46
+
47
+ MODEL_NAME='aubmindlab/aragpt2-mega'
48
+ arabert_prep = ArabertPreprocessor(model_name=MODEL_NAME)
49
+
50
+ text=""
51
+ text_clean = arabert_prep.preprocess(text)
52
+
53
+ model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
54
+ tokenizer = GPT2TokenizerFast.from_pretrained(MODEL_NAME)
55
+ generation_pipeline = pipeline("text-generation",model=model,tokenizer=tokenizer)
56
+
57
+ #feel free to try different decoding settings
58
+ generation_pipeline(text,
59
+ pad_token_id=tokenizer.eos_token_id,
60
+ num_beams=10,
61
+ max_length=200,
62
+ top_p=0.9,
63
+ repetition_penalty = 3.0,
64
+ no_repeat_ngram_size = 3)[0]['generated_text']
65
+ >>>
66
+ ```
67
+ ## Finetunning using `transformers`:
68
+
69
+ Follow the guide linked [here](https://towardsdatascience.com/fine-tuning-gpt2-on-colab-gpu-for-free-340468c92ed)
70
+
71
+ ## Finetuning using our code with TF 1.15.4:
72
+
73
+ Create the Training TFRecords:
74
+ ```bash
75
+ python create_pretraining_data.py
76
+ --input_file=<RAW TEXT FILE with documents/article separated by an empty line>
77
+ --output_file=<OUTPUT TFRecord>
78
+ --tokenizer_dir=<Directory with the GPT2 Tokenizer files>
79
+ ```
80
+
81
+ Finetuning:
82
+ ```bash
83
+ python3 run_pretraining.py \\r\n --input_file="gs://<GS_BUCKET>/pretraining_data/*" \\r\n --output_dir="gs://<GS_BUCKET>/pretraining_model/" \\r\n --config_file="config/small_hparams.json" \\r\n --batch_size=128 \\r\n --eval_batch_size=8 \\r\n --num_train_steps= \\r\n --num_warmup_steps= \\r\n --learning_rate= \\r\n --save_checkpoints_steps= \\r\n --max_seq_length=1024 \\r\n --max_eval_steps= \\r\n --optimizer="lamb" \\r\n --iterations_per_loop=5000 \\r\n --keep_checkpoint_max=10 \\r\n --use_tpu=True \\r\n --tpu_name=<TPU NAME> \\r\n --do_train=True \\r\n --do_eval=False
84
+ ```
85
+ # Model Sizes
86
+
87
+ Model | Optimizer | Context size | Embedding Size | Num of heads | Num of layers | Model Size / Num of Params |
88
+ ---|:---:|:---:|:---:|:---:|:---:|:---:
89
+ AraGPT2-base | `lamb` | 1024 | 768 | 12 | 12 | 527MB/135M |
90
+ AraGPT2-medium | `lamb` | 1024 | 1024 | 16 | 24 | 1.38G/370M |
91
+ AraGPT2-large | `adafactor` | 1024 | 1280 | 20 | 36 | 2.98GB/792M |
92
+ AraGPT2-mega | `adafactor` | 1024 | 1536 | 25 | 48 | 5.5GB/1.46B |
93
+
94
+ All models are available in the `HuggingFace` model page under the [aubmindlab](https://huggingface.co/aubmindlab/) name. Checkpoints are available in PyTorch, TF2 and TF1 formats.
95
+
96
+ ## Compute
97
+
98
+ For Dataset Source see the [Dataset Section](#Dataset)
99
+
100
+ Model | Hardware | num of examples (seq len = 1024) | Batch Size | Num of Steps | Time (in days)
101
+ ---|:---:|:---:|:---:|:---:|:---:
102
+ AraGPT2-base | TPUv3-128 | 9.7M | 1792 | 125K | 1.5
103
+ AraGPT2-medium | TPUv3-8 | 9.7M | 1152 | 85K | 1.5
104
+ AraGPT2-large | TPUv3-128 | 9.7M | 256 | 220k | 3
105
+ AraGPT2-mega | TPUv3-128 | 9.7M | 256 | 780K | 9
106
+
107
+ # Dataset
108
+
109
+ The pretraining data used for the new AraBERT model is also used for **GPT2 and ELECTRA**.
110
+
111
+ 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)
112
+
113
+ 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:
114
+ - OSCAR unshuffled and filtered.
115
+ - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
116
+ - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
117
+ - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
118
+ - Assafir news articles. Huge thank you for Assafir for giving us the data
119
+
120
+ # Disclaimer
121
+
122
+ The text generated by GPT2 Arabic is automatically generated by a neural network model trained on a large amount of texts, which does not represent the authors' or their institutes' official attitudes and preferences. The text generated by GPT2 Arabic should only be used for research and scientific purposes. If it infringes on your rights and interests or violates social morality, please do not propagate it.
123
+
124
+ # If you used this model please cite us as :
125
+
126
+ ```
127
+ @inproceedings{antoun-etal-2021-aragpt2,
128
+ title = "{A}ra{GPT}2: Pre-Trained Transformer for {A}rabic Language Generation",
129
+ author = "Antoun, Wissam and
130
+ Baly, Fady and
131
+ Hajj, Hazem",
132
+ booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
133
+ month = apr,
134
+ year = "2021",
135
+ address = "Kyiv, Ukraine (Virtual)",
136
+ publisher = "Association for Computational Linguistics",
137
+ url = "https://www.aclweb.org/anthology/2021.wanlp-1.21",
138
+ pages = "196--207",
139
+ }
140
+ ```
141
+
142
+ # Acknowledgments
143
+ 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 continuous 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.
144
+
145
+ # Contacts
146
+ **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>
147
+
148
+ **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>
149
+