aubmindlab commited on
Commit
e3ede7a
1 Parent(s): dafe995

Added model files

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