aubmindlab
commited on
Commit
•
2a332cf
1
Parent(s):
a27f413
Added model files
Browse files- README.md +157 -0
- config.json +40 -0
- merges.txt +0 -0
- pytorch_model.bin +3 -0
- tf1_model.tar.gz +3 -0
- tokenizer.json +0 -0
- vocab.json +0 -0
README.md
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
You can find more information in our paper [AraGPT2](https://arxiv.org/abs/2012.15520)
|
18 |
+
|
19 |
+
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.
|
20 |
+
|
21 |
+
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.
|
22 |
+
These models were trained using the `lamb` optimizer and follow the same architecture as `gpt2` and are fully compatible with the `transformers` library.
|
23 |
+
|
24 |
+
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`).
|
25 |
+
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.
|
26 |
+
|
27 |
+
AraGPT2 is trained on the same large Arabic Dataset as AraBERTv2.
|
28 |
+
|
29 |
+
# Usage
|
30 |
+
|
31 |
+
## Testing the model using `transformers`:
|
32 |
+
|
33 |
+
```python
|
34 |
+
from transformers import GPT2TokenizerFast, pipeline
|
35 |
+
#for base and medium
|
36 |
+
from transformers import GPT2LMHeadModel
|
37 |
+
#for large and mega
|
38 |
+
from arabert.aragpt2.grover.modeling_gpt2 import GPT2LMHeadModel
|
39 |
+
|
40 |
+
from arabert.preprocess import ArabertPreprocessor
|
41 |
+
|
42 |
+
MODEL_NAME='aragpt2-mega'
|
43 |
+
arabert_prep = ArabertPreprocessor(model_name=MODEL_NAME, keep_emojis=True)
|
44 |
+
|
45 |
+
text=""
|
46 |
+
text_clean = arabert_prep.preprocess(text)
|
47 |
+
|
48 |
+
model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
|
49 |
+
tokenizer = GPT2TokenizerFast.from_pretrained(MODEL_NAME)
|
50 |
+
generation_pipeline = pipeline("text-generation",model=model,tokenizer=tokenizer)
|
51 |
+
|
52 |
+
#feel free to try different decodinn settings
|
53 |
+
generation_pipeline(text,
|
54 |
+
pad_token_id=tokenizer.eos_token_id,
|
55 |
+
num_beams=10,
|
56 |
+
max_length=200,
|
57 |
+
top_p=0.9,
|
58 |
+
repetition_penalty = 3.0,
|
59 |
+
no_repeat_ngram_size = 3)[0]['generated_text']
|
60 |
+
>>>
|
61 |
+
```
|
62 |
+
## Finetunning using `transformers`:
|
63 |
+
|
64 |
+
Follow the guide linked [here](https://towardsdatascience.com/fine-tuning-gpt2-on-colab-gpu-for-free-340468c92ed)
|
65 |
+
|
66 |
+
## Finetuning using our code with TF 1.15.4:
|
67 |
+
|
68 |
+
- Create the Training TFRecords:
|
69 |
+
```bash
|
70 |
+
python create_pretraining_data.py
|
71 |
+
--input_file=<RAW TEXT FILE with documents/article sperated by an empty line>
|
72 |
+
--output_file=<OUTPUT TFRecord>
|
73 |
+
--tokenizer_dir=<Directory with the GPT2 Tokenizer files>
|
74 |
+
```
|
75 |
+
|
76 |
+
- Finetuning:
|
77 |
+
```bash
|
78 |
+
python3 run_pretraining.py \
|
79 |
+
--input_file="gs://<GS_BUCKET>/pretraining_data/*" \
|
80 |
+
--output_dir="gs://<GS_BUCKET>/pretraining_model/" \
|
81 |
+
--config_file="config/small_hparams.json" \
|
82 |
+
--batch_size=128 \
|
83 |
+
--eval_batch_size=8 \
|
84 |
+
--num_train_steps= \
|
85 |
+
--num_warmup_steps= \
|
86 |
+
--learning_rate= \
|
87 |
+
--save_checkpoints_steps= \
|
88 |
+
--max_seq_length=1024 \
|
89 |
+
--max_eval_steps= \
|
90 |
+
--optimizer="lamb" \
|
91 |
+
--iterations_per_loop=5000 \
|
92 |
+
--keep_checkpoint_max=10 \
|
93 |
+
--use_tpu=True \
|
94 |
+
--tpu_name=<TPU NAME> \
|
95 |
+
--do_train=True \
|
96 |
+
--do_eval=False
|
97 |
+
```
|
98 |
+
# Model Sizes
|
99 |
+
|
100 |
+
Model | Optimizer | Context size | Embedding Size | Num of heads | Num of layers | Model Size / Num of Params |
|
101 |
+
---|:---:|:---:|:---:|:---:|:---:|:---:
|
102 |
+
AraGPT2-base | `lamb` | 1024 | 768 | 12 | 12 | 527MB/135M |
|
103 |
+
AraGPT2-medium | `lamb` | 1024 | 1024 | 16 | 24 | 1.38G/370M |
|
104 |
+
AraGPT2-large | `adafactor` | 1024 | 1280 | 20 | 36 | 2.98GB/792M |
|
105 |
+
AraGPT2-mega | `adafactor` | 1024 | 1536 | 25 | 48 | 5.5GB/1.46B |
|
106 |
+
|
107 |
+
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.
|
108 |
+
|
109 |
+
## Compute
|
110 |
+
|
111 |
+
For Dataset Source see the [Dataset Section](#Dataset)
|
112 |
+
|
113 |
+
Model | Hardware | num of examples (seq len = 1024) | Batch Size | Num of Steps | Time (in days)
|
114 |
+
---|:---:|:---:|:---:|:---:|:---:
|
115 |
+
AraGPT2-base | TPUv3-128 | 9.7M | 1792 | 125K | 1.5
|
116 |
+
AraGPT2-medium | TPUv3-8 | 9.7M | 1152 | 85K | 1.5
|
117 |
+
AraGPT2-large | TPUv3-128 | 9.7M | 256 | 220k | 3
|
118 |
+
AraGPT2-mega | TPUv3-128 | 9.7M | 256 | 780K | 9
|
119 |
+
|
120 |
+
# Dataset
|
121 |
+
|
122 |
+
The pretraining data used for the new AraBERT model is also used for **GPT2 and ELECTRA**.
|
123 |
+
|
124 |
+
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)
|
125 |
+
|
126 |
+
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:
|
127 |
+
- OSCAR unshuffled and filtered.
|
128 |
+
- [Arabic Wikipedia dump](https://archive.org/details/arwiki-20190201) from 2020/09/01
|
129 |
+
- [The 1.5B words Arabic Corpus](https://www.semanticscholar.org/paper/1.5-billion-words-Arabic-Corpus-El-Khair/f3eeef4afb81223df96575adadf808fe7fe440b4)
|
130 |
+
- [The OSIAN Corpus](https://www.aclweb.org/anthology/W19-4619)
|
131 |
+
- Assafir news articles. Huge thank you for Assafir for giving us the data
|
132 |
+
|
133 |
+
# Disclaimer
|
134 |
+
|
135 |
+
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.
|
136 |
+
|
137 |
+
# If you used this model please cite us as :
|
138 |
+
|
139 |
+
```
|
140 |
+
@misc{antoun2020aragpt2,
|
141 |
+
title={AraGPT2: Pre-Trained Transformer for Arabic Language Generation},
|
142 |
+
author={Wissam Antoun and Fady Baly and Hazem Hajj},
|
143 |
+
year={2020},
|
144 |
+
eprint={2012.15520},
|
145 |
+
archivePrefix={arXiv},
|
146 |
+
primaryClass={cs.CL}
|
147 |
+
}
|
148 |
+
```
|
149 |
+
|
150 |
+
# Acknowledgments
|
151 |
+
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.
|
152 |
+
|
153 |
+
# Contacts
|
154 |
+
**Wissam Antoun**: [Linkedin](https://www.linkedin.com/in/wissam-antoun-622142b4/) | [Twitter](https://twitter.com/wissam_antoun) | [Github](https://github.com/WissamAntoun) | <[email protected]> | <[email protected]>
|
155 |
+
|
156 |
+
**Fady Baly**: [Linkedin](https://www.linkedin.com/in/fadybaly/) | [Twitter](https://twitter.com/fadybaly) | [Github](https://github.com/fadybaly) | <[email protected]> | <[email protected]>
|
157 |
+
|
config.json
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"activation_function": "gelu_new",
|
3 |
+
"architectures": [
|
4 |
+
"GPT2LMHeadModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"attn_pdrop": 0.1,
|
8 |
+
"bos_token_id": 0,
|
9 |
+
"embd_pdrop": 0.1,
|
10 |
+
"eos_token_id": 0,
|
11 |
+
"hidden_act": "gelu",
|
12 |
+
"hidden_dropout_prob": 0.1,
|
13 |
+
"initializer_range": 0.014142135623731,
|
14 |
+
"intermediate_size": 6144,
|
15 |
+
"layer_norm_epsilon": 1e-05,
|
16 |
+
"model_type": "gpt2",
|
17 |
+
"n_ctx": 1024,
|
18 |
+
"n_embd": 1536,
|
19 |
+
"n_head": 24,
|
20 |
+
"n_inner": null,
|
21 |
+
"n_layer": 48,
|
22 |
+
"n_positions": 1024,
|
23 |
+
"resid_pdrop": 0.1,
|
24 |
+
"summary_activation": null,
|
25 |
+
"summary_first_dropout": 0.1,
|
26 |
+
"summary_proj_to_labels": true,
|
27 |
+
"summary_type": "cls_index",
|
28 |
+
"summary_use_proj": true,
|
29 |
+
"task_specific_params": {
|
30 |
+
"text-generation": {
|
31 |
+
"do_sample": true,
|
32 |
+
"max_length": 50,
|
33 |
+
"num_beams": 5,
|
34 |
+
"top_p": 0.95,
|
35 |
+
"repetition_penalty": 3.0,
|
36 |
+
"no_repeat_ngram_size": 3
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"vocab_size": 64000
|
40 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d32e8f1f64d7012df94ece21dd0e09edd366ddf3cc71e7ff0baf0669f7b9e400
|
3 |
+
size 5889735421
|
tf1_model.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:049f887a1d858ce880fc235ee53af0602f3c8140c39d8b10bb36acf44490fd0f
|
3 |
+
size 5426458682
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|