RichardErkhov commited on
Commit
76e8ee4
1 Parent(s): 4265931

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +190 -0
README.md ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ aragpt2-large - bnb 4bits
11
+ - Model creator: https://huggingface.co/aubmindlab/
12
+ - Original model: https://huggingface.co/aubmindlab/aragpt2-large/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ language: ar
20
+ license: other
21
+ license_name: custom
22
+ license_link: https://github.com/aub-mind/arabert/blob/master/aragpt2/LICENSE
23
+ datasets:
24
+ - wikipedia
25
+ - Osian
26
+ - arabic-billion-words
27
+ - oscar
28
+ - Assafir-private
29
+ inference: false
30
+ widget:
31
+ - text: "يحكى أن مزارعا مخادعا قام ببيع بئر الماء الموجود في أرضه لجاره مقابل مبلغ كبير من المال"
32
+ - text: "القدس مدينة تاريخية، بناها الكنعانيون في"
33
+ - text: "كان يا ما كان في قديم الزمان"
34
+ ---
35
+
36
+ # Arabic GPT2
37
+
38
+ <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraGPT2.png" width="100" align="left"/>
39
+
40
+ You can find more information in our paper [AraGPT2](https://arxiv.org/abs/2012.15520)
41
+
42
+ 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.
43
+
44
+ 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.
45
+ These models were trained using the `lamb` optimizer and follow the same architecture as `gpt2` and are fully compatible with the `transformers` library.
46
+
47
+ 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`).
48
+ 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.
49
+
50
+ AraGPT2 is trained on the same large Arabic Dataset as AraBERTv2.
51
+
52
+
53
+ # NOTE: The model expects the input to be preprocessed using the `arabert` library.
54
+ if not the model won't be able to generate the correct output.
55
+
56
+ ## Testing the model using `transformers`:
57
+
58
+ The model code is now hosted on HuggingFace so you need to use the `trust_remote_code` flag, and can be used as follows:
59
+
60
+
61
+ ```python
62
+ from transformers import AutoModelForCausalLM, pipeline
63
+
64
+ from arabert.preprocess import ArabertPreprocessor
65
+
66
+ MODEL_NAME='aubmindlab/aragpt2-large'
67
+ arabert_prep = ArabertPreprocessor(model_name=MODEL_NAME)
68
+
69
+ text=""
70
+ text_clean = arabert_prep.preprocess(text)
71
+
72
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, trust_remote_code=True)
73
+ tokenizer = GPT2TokenizerFast.from_pretrained(MODEL_NAME)
74
+ generation_pipeline = pipeline(
75
+ "text-generation", model=MODEL_NAME, trust_remote_code=True
76
+ )
77
+
78
+ #feel free to try different decoding settings
79
+ generation_pipeline(text,
80
+ pad_token_id=pipeline.tokenizer.eos_token_id,
81
+ num_beams=10,
82
+ max_length=200,
83
+ top_p=0.9,
84
+ repetition_penalty = 3.0,
85
+ no_repeat_ngram_size = 3)[0]['generated_text']
86
+ >>>
87
+ ```
88
+ ## Finetunning using `transformers`:
89
+
90
+ Follow the guide linked [here](https://towardsdatascience.com/fine-tuning-gpt2-on-colab-gpu-for-free-340468c92ed)
91
+
92
+ ## Finetuning using our code with TF 1.15.4:
93
+
94
+ Create the Training TFRecords:
95
+ ```bash
96
+ python create_pretraining_data.py
97
+ --input_file=<RAW TEXT FILE with documents/article separated by an empty line>
98
+ --output_file=<OUTPUT TFRecord>
99
+ --tokenizer_dir=<Directory with the GPT2 Tokenizer files>
100
+ ```
101
+
102
+ Finetuning:
103
+ ```bash
104
+ python3 run_pretraining.py \
105
+ --input_file="gs://<GS_BUCKET>/pretraining_data/*" \
106
+ --output_dir="gs://<GS_BUCKET>/pretraining_model/" \
107
+ --config_file="config/small_hparams.json" \
108
+ --batch_size=128 \
109
+ --eval_batch_size=8 \
110
+ --num_train_steps= \
111
+ --num_warmup_steps= \
112
+ --learning_rate= \
113
+ --save_checkpoints_steps= \
114
+ --max_seq_length=1024 \
115
+ --max_eval_steps= \
116
+ --optimizer="lamb" \
117
+ --iterations_per_loop=5000 \
118
+ --keep_checkpoint_max=10 \
119
+ --use_tpu=True \
120
+ --tpu_name=<TPU NAME> \
121
+ --do_train=True \
122
+ --do_eval=False
123
+ ```
124
+ # Model Sizes
125
+
126
+ Model | Optimizer | Context size | Embedding Size | Num of heads | Num of layers | Model Size / Num of Params |
127
+ ---|:---:|:---:|:---:|:---:|:---:|:---:
128
+ AraGPT2-base | `lamb` | 1024 | 768 | 12 | 12 | 527MB/135M |
129
+ AraGPT2-medium | `lamb` | 1024 | 1024 | 16 | 24 |1.38G/370M |
130
+ AraGPT2-large | `adafactor` | 1024 | 1280 | 20 | 36 | 2.98GB/792M |
131
+ AraGPT2-mega | `adafactor` | 1024 | 1536 | 25 | 48 | 5.5GB/1.46B |
132
+
133
+ 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.
134
+
135
+ ## Compute
136
+
137
+ For Dataset Source see the [Dataset Section](#Dataset)
138
+
139
+ Model | Hardware | num of examples (seq len = 1024) | Batch Size | Num of Steps | Time (in days)
140
+ ---|:---:|:---:|:---:|:---:|:---:
141
+ AraGPT2-base | TPUv3-128 | 9.7M | 1792 | 125K | 1.5
142
+ AraGPT2-medium | TPUv3-8 | 9.7M | 1152 | 85K | 1.5
143
+ AraGPT2-large | TPUv3-128 | 9.7M | 256 | 220k | 3
144
+ AraGPT2-mega | TPUv3-128 | 9.7M | 256 | 780K | 9
145
+
146
+ # Dataset
147
+
148
+ The pretraining data used for the new AraBERT model is also used for **GPT2 and ELECTRA**.
149
+
150
+ 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)
151
+
152
+ 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:
153
+ - OSCAR unshuffled and filtered.
154
+ - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
155
+ - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
156
+ - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
157
+ - Assafir news articles. Huge thank you for Assafir for giving us the data
158
+
159
+ # Disclaimer
160
+
161
+ 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.
162
+
163
+ # If you used this model please cite us as :
164
+
165
+ ```
166
+ @inproceedings{antoun-etal-2021-aragpt2,
167
+ title = "{A}ra{GPT}2: Pre-Trained Transformer for {A}rabic Language Generation",
168
+ author = "Antoun, Wissam and
169
+ Baly, Fady and
170
+ Hajj, Hazem",
171
+ booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
172
+ month = apr,
173
+ year = "2021",
174
+ address = "Kyiv, Ukraine (Virtual)",
175
+ publisher = "Association for Computational Linguistics",
176
+ url = "https://www.aclweb.org/anthology/2021.wanlp-1.21",
177
+ pages = "196--207",
178
+ }
179
+ ```
180
+
181
+ # Acknowledgments
182
+ 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.
183
+
184
+ # Contacts
185
+ **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>
186
+
187
+ **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>
188
+
189
+
190
+