RichardErkhov commited on
Commit
7b7906f
1 Parent(s): 509d09a

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +188 -0
README.md ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-base - GGUF
11
+ - Model creator: https://huggingface.co/aubmindlab/
12
+ - Original model: https://huggingface.co/aubmindlab/aragpt2-base/
13
+
14
+
15
+ | Name | Quant method | Size |
16
+ | ---- | ---- | ---- |
17
+ | [aragpt2-base.Q2_K.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q2_K.gguf) | Q2_K | 0.09GB |
18
+ | [aragpt2-base.IQ3_XS.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.IQ3_XS.gguf) | IQ3_XS | 0.1GB |
19
+ | [aragpt2-base.IQ3_S.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.IQ3_S.gguf) | IQ3_S | 0.1GB |
20
+ | [aragpt2-base.Q3_K_S.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q3_K_S.gguf) | Q3_K_S | 0.1GB |
21
+ | [aragpt2-base.IQ3_M.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.IQ3_M.gguf) | IQ3_M | 0.1GB |
22
+ | [aragpt2-base.Q3_K.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q3_K.gguf) | Q3_K | 0.1GB |
23
+ | [aragpt2-base.Q3_K_M.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q3_K_M.gguf) | Q3_K_M | 0.1GB |
24
+ | [aragpt2-base.Q3_K_L.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q3_K_L.gguf) | Q3_K_L | 0.11GB |
25
+ | [aragpt2-base.IQ4_XS.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.IQ4_XS.gguf) | IQ4_XS | 0.11GB |
26
+ | [aragpt2-base.Q4_0.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q4_0.gguf) | Q4_0 | 0.11GB |
27
+ | [aragpt2-base.IQ4_NL.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.IQ4_NL.gguf) | IQ4_NL | 0.11GB |
28
+ | [aragpt2-base.Q4_K_S.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q4_K_S.gguf) | Q4_K_S | 0.11GB |
29
+ | [aragpt2-base.Q4_K.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q4_K.gguf) | Q4_K | 0.12GB |
30
+ | [aragpt2-base.Q4_K_M.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q4_K_M.gguf) | Q4_K_M | 0.12GB |
31
+ | [aragpt2-base.Q4_1.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q4_1.gguf) | Q4_1 | 0.12GB |
32
+ | [aragpt2-base.Q5_0.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q5_0.gguf) | Q5_0 | 0.13GB |
33
+ | [aragpt2-base.Q5_K_S.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q5_K_S.gguf) | Q5_K_S | 0.13GB |
34
+ | [aragpt2-base.Q5_K.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q5_K.gguf) | Q5_K | 0.13GB |
35
+ | [aragpt2-base.Q5_K_M.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q5_K_M.gguf) | Q5_K_M | 0.13GB |
36
+ | [aragpt2-base.Q5_1.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q5_1.gguf) | Q5_1 | 0.14GB |
37
+ | [aragpt2-base.Q6_K.gguf](https://huggingface.co/RichardErkhov/aubmindlab_-_aragpt2-base-gguf/blob/main/aragpt2-base.Q6_K.gguf) | Q6_K | 0.15GB |
38
+
39
+
40
+
41
+
42
+ Original model description:
43
+ ---
44
+ language: ar
45
+ datasets:
46
+ - wikipedia
47
+ - Osian
48
+ - 1.5B-Arabic-Corpus
49
+ - oscar-arabic-unshuffled
50
+ - Assafir(private)
51
+ widget:
52
+ - text: "يحكى أن مزارعا مخادعا قام ببيع بئر الماء الموجود في أرضه لجاره مقابل مبلغ كبير من المال"
53
+ - text: "القدس مدينة تاريخية، بناها الكنعانيون في"
54
+ - text: "كان يا ما كان في قديم الزمان"
55
+ ---
56
+
57
+ # Arabic GPT2
58
+
59
+ <img src="https://raw.githubusercontent.com/aub-mind/arabert/master/AraGPT2.png" width="100" align="left"/>
60
+
61
+ You can find more information in our paper [AraGPT2](https://arxiv.org/abs/2012.15520)
62
+
63
+ 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.
64
+
65
+ 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.
66
+ These models were trained using the `lamb` optimizer and follow the same architecture as `gpt2` and are fully compatible with the `transformers` library.
67
+
68
+ 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`).
69
+ 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.
70
+
71
+ AraGPT2 is trained on the same large Arabic Dataset as AraBERTv2.
72
+
73
+ # Usage
74
+
75
+ ## Testing the model using `transformers`:
76
+
77
+ ```python
78
+ from transformers import GPT2TokenizerFast, pipeline
79
+ #for base and medium
80
+ from transformers import GPT2LMHeadModel
81
+ #for large and mega
82
+ # pip install arabert
83
+ from arabert.aragpt2.grover.modeling_gpt2 import GPT2LMHeadModel
84
+
85
+ from arabert.preprocess import ArabertPreprocessor
86
+
87
+ MODEL_NAME='aubmindlab/aragpt2-base'
88
+ arabert_prep = ArabertPreprocessor(model_name=MODEL_NAME)
89
+
90
+ text=""
91
+ text_clean = arabert_prep.preprocess(text)
92
+
93
+ model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
94
+ tokenizer = GPT2TokenizerFast.from_pretrained(MODEL_NAME)
95
+ generation_pipeline = pipeline("text-generation",model=model,tokenizer=tokenizer)
96
+
97
+ #feel free to try different decoding settings
98
+ generation_pipeline(text,
99
+ pad_token_id=tokenizer.eos_token_id,
100
+ num_beams=10,
101
+ max_length=200,
102
+ top_p=0.9,
103
+ repetition_penalty = 3.0,
104
+ no_repeat_ngram_size = 3)[0]['generated_text']
105
+ ```
106
+ ## Finetunning using `transformers`:
107
+
108
+ Follow the guide linked [here](https://towardsdatascience.com/fine-tuning-gpt2-on-colab-gpu-for-free-340468c92ed)
109
+
110
+ ## Finetuning using our code with TF 1.15.4:
111
+
112
+ Create the Training TFRecords:
113
+ ```bash
114
+ python create_pretraining_data.py
115
+ --input_file=<RAW TEXT FILE with documents/article separated by an empty line>
116
+ --output_file=<OUTPUT TFRecord>
117
+ --tokenizer_dir=<Directory with the GPT2 Tokenizer files>
118
+ ```
119
+
120
+ Finetuning:
121
+ ```bash
122
+ 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
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
+ Model | Hardware | num of examples (seq len = 1024) | Batch Size | Num of Steps | Time (in days)
138
+ ---|:---:|:---:|:---:|:---:|:---:
139
+ AraGPT2-base | TPUv3-128 | 9.7M | 1792 | 125K | 1.5
140
+ AraGPT2-medium | TPUv3-8 | 9.7M | 1152 | 85K | 1.5
141
+ AraGPT2-large | TPUv3-128 | 9.7M | 256 | 220k | 3
142
+ AraGPT2-mega | TPUv3-128 | 9.7M | 256 | 780K | 9
143
+
144
+ # Dataset
145
+
146
+ The pretraining data used for the new AraGPT2 model is also used for **AraBERTv2 and AraELECTRA**.
147
+
148
+ 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)
149
+
150
+ For the new dataset we added the unshuffled OSCAR corpus after we thoroughly filter it, to the dataset used in AraBERTv1 but without the websites that we previously crawled:
151
+ - OSCAR unshuffled and filtered.
152
+ - [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
153
+ - [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
154
+ - [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
155
+ - Assafir news articles. Huge thank you for Assafir for giving us the data
156
+
157
+ # Disclaimer
158
+
159
+ The text generated by AraGPT2 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 AraGPT2 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.
160
+
161
+ # If you used this model please cite us as :
162
+
163
+ ```
164
+ @inproceedings{antoun-etal-2021-aragpt2,
165
+ title = "{A}ra{GPT}2: Pre-Trained Transformer for {A}rabic Language Generation",
166
+ author = "Antoun, Wissam and
167
+ Baly, Fady and
168
+ Hajj, Hazem",
169
+ booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
170
+ month = apr,
171
+ year = "2021",
172
+ address = "Kyiv, Ukraine (Virtual)",
173
+ publisher = "Association for Computational Linguistics",
174
+ url = "https://www.aclweb.org/anthology/2021.wanlp-1.21",
175
+ pages = "196--207",
176
+ }
177
+ ```
178
+
179
+ # Acknowledgments
180
+ 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.
181
+
182
+ # Contacts
183
+ **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>
184
+
185
+ **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>
186
+
187
+
188
+