misyaz narutoelbruto commited on
Commit
be9db2a
·
0 Parent(s):

Duplicate from CAMeL-Lab/bert-base-arabic-camelbert-mix

Browse files

Co-authored-by: naruto bruto <narutoelbruto@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.arrow filter=lfs diff=lfs merge=lfs -text
10
+ *.ftz filter=lfs diff=lfs merge=lfs -text
11
+ *.joblib filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.pb filter=lfs diff=lfs merge=lfs -text
15
+ *.pt filter=lfs diff=lfs merge=lfs -text
16
+ *.pth filter=lfs diff=lfs merge=lfs -text
17
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ar
4
+ license: apache-2.0
5
+ tags:
6
+ - Arabic
7
+ - Dialect
8
+ - Egyptian
9
+ - Gulf
10
+ - Levantine
11
+ - Classical Arabic
12
+ - MSA
13
+ - Modern Standard Arabic
14
+
15
+ widget:
16
+ - text: "الهدف من الحياة هو [MASK] ."
17
+ ---
18
+
19
+ # CAMeLBERT: A collection of pre-trained models for Arabic NLP tasks
20
+
21
+ ## Model description
22
+
23
+ **CAMeLBERT** is a collection of BERT models pre-trained on Arabic texts with different sizes and variants.
24
+ We release pre-trained language models for Modern Standard Arabic (MSA), dialectal Arabic (DA), and classical Arabic (CA), in addition to a model pre-trained on a mix of the three.
25
+ We also provide additional models that are pre-trained on a scaled-down set of the MSA variant (half, quarter, eighth, and sixteenth).
26
+ The details are described in the paper *"[The Interplay of Variant, Size, and Task Type in Arabic Pre-trained Language Models](https://arxiv.org/abs/2103.06678)."*
27
+
28
+ This model card describes **CAMeLBERT-Mix** (`bert-base-arabic-camelbert-mix`), a model pre-trained on a mixture of these variants: MSA, DA, and CA.
29
+
30
+ ||Model|Variant|Size|#Word|
31
+ |-|-|:-:|-:|-:|
32
+ |✔|`bert-base-arabic-camelbert-mix`|CA,DA,MSA|167GB|17.3B|
33
+ ||`bert-base-arabic-camelbert-ca`|CA|6GB|847M|
34
+ ||`bert-base-arabic-camelbert-da`|DA|54GB|5.8B|
35
+ ||`bert-base-arabic-camelbert-msa`|MSA|107GB|12.6B|
36
+ ||`bert-base-arabic-camelbert-msa-half`|MSA|53GB|6.3B|
37
+ ||`bert-base-arabic-camelbert-msa-quarter`|MSA|27GB|3.1B|
38
+ ||`bert-base-arabic-camelbert-msa-eighth`|MSA|14GB|1.6B|
39
+ ||`bert-base-arabic-camelbert-msa-sixteenth`|MSA|6GB|746M|
40
+
41
+ ## Intended uses
42
+ You can use the released model for either masked language modeling or next sentence prediction.
43
+ However, it is mostly intended to be fine-tuned on an NLP task, such as NER, POS tagging, sentiment analysis, dialect identification, and poetry classification.
44
+ We release our fine-tuninig code [here](https://github.com/CAMeL-Lab/CAMeLBERT).
45
+
46
+ #### How to use
47
+ You can use this model directly with a pipeline for masked language modeling:
48
+ ```python
49
+ >>> from transformers import pipeline
50
+ >>> unmasker = pipeline('fill-mask', model='CAMeL-Lab/bert-base-arabic-camelbert-mix')
51
+ >>> unmasker("الهدف من الحياة هو [MASK] .")
52
+ [{'sequence': '[CLS] الهدف من الحياة هو النجاح. [SEP]',
53
+ 'score': 0.10861027985811234,
54
+ 'token': 6232,
55
+ 'token_str': 'النجاح'},
56
+ {'sequence': '[CLS] الهدف من الحياة هو.. [SEP]',
57
+ 'score': 0.07626965641975403,
58
+ 'token': 18,
59
+ 'token_str': '.'},
60
+ {'sequence': '[CLS] الهدف من الحياة هو الحياة. [SEP]',
61
+ 'score': 0.05131986364722252,
62
+ 'token': 3696,
63
+ 'token_str': 'الحياة'},
64
+ {'sequence': '[CLS] الهدف من الحياة هو الموت. [SEP]',
65
+ 'score': 0.03734956309199333,
66
+ 'token': 4295,
67
+ 'token_str': 'الموت'},
68
+ {'sequence': '[CLS] الهدف من الحياة هو العمل. [SEP]',
69
+ 'score': 0.027189988642930984,
70
+ 'token': 2854,
71
+ 'token_str': 'العمل'}]
72
+ ```
73
+
74
+ *Note*: to download our models, you would need `transformers>=3.5.0`. Otherwise, you could download the models manually.
75
+
76
+ Here is how to use this model to get the features of a given text in PyTorch:
77
+ ```python
78
+ from transformers import AutoTokenizer, AutoModel
79
+ tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-mix')
80
+ model = AutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-mix')
81
+ text = "مرحبا يا عالم."
82
+ encoded_input = tokenizer(text, return_tensors='pt')
83
+ output = model(**encoded_input)
84
+ ```
85
+
86
+ and in TensorFlow:
87
+ ```python
88
+ from transformers import AutoTokenizer, TFAutoModel
89
+ tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-mix')
90
+ model = TFAutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-mix')
91
+ text = "مرحبا يا عالم."
92
+ encoded_input = tokenizer(text, return_tensors='tf')
93
+ output = model(encoded_input)
94
+ ```
95
+
96
+ ## Training data
97
+ - MSA (Modern Standard Arabic)
98
+ - [The Arabic Gigaword Fifth Edition](https://catalog.ldc.upenn.edu/LDC2011T11)
99
+ - [Abu El-Khair Corpus](http://www.abuelkhair.net/index.php/en/arabic/abu-el-khair-corpus)
100
+ - [OSIAN corpus](https://vlo.clarin.eu/search;jsessionid=31066390B2C9E8C6304845BA79869AC1?1&q=osian)
101
+ - [Arabic Wikipedia](https://archive.org/details/arwiki-20190201)
102
+ - The unshuffled version of the Arabic [OSCAR corpus](https://oscar-corpus.com/)
103
+ - DA (dialectal Arabic)
104
+ - A collection of dialectal Arabic data described in [our paper](https://arxiv.org/abs/2103.06678).
105
+ - CA (classical Arabic)
106
+ - [OpenITI (Version 2020.1.2)](https://zenodo.org/record/3891466#.YEX4-F0zbzc)
107
+
108
+ ## Training procedure
109
+ We use [the original implementation](https://github.com/google-research/bert) released by Google for pre-training.
110
+ We follow the original English BERT model's hyperparameters for pre-training, unless otherwise specified.
111
+
112
+ ### Preprocessing
113
+ - After extracting the raw text from each corpus, we apply the following pre-processing.
114
+ - We first remove invalid characters and normalize white spaces using the utilities provided by [the original BERT implementation](https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/tokenization.py#L286-L297).
115
+ - We also remove lines without any Arabic characters.
116
+ - We then remove diacritics and kashida using [CAMeL Tools](https://github.com/CAMeL-Lab/camel_tools).
117
+ - Finally, we split each line into sentences with a heuristics-based sentence segmenter.
118
+ - We train a WordPiece tokenizer on the entire dataset (167 GB text) with a vocabulary size of 30,000 using [HuggingFace's tokenizers](https://github.com/huggingface/tokenizers).
119
+ - We do not lowercase letters nor strip accents.
120
+
121
+ ### Pre-training
122
+ - The model was trained on a single cloud TPU (`v3-8`) for one million steps in total.
123
+ - The first 90,000 steps were trained with a batch size of 1,024 and the rest was trained with a batch size of 256.
124
+ - The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%.
125
+ - We use whole word masking and a duplicate factor of 10.
126
+ - We set max predictions per sequence to 20 for the dataset with max sequence length of 128 tokens and 80 for the dataset with max sequence length of 512 tokens.
127
+ - We use a random seed of 12345, masked language model probability of 0.15, and short sequence probability of 0.1.
128
+ - The optimizer used is Adam with a learning rate of 1e-4, \\(\beta_{1} = 0.9\\) and \\(\beta_{2} = 0.999\\), a weight decay of 0.01, learning rate warmup for 10,000 steps and linear decay of the learning rate after.
129
+
130
+ ## Evaluation results
131
+ - We evaluate our pre-trained language models on five NLP tasks: NER, POS tagging, sentiment analysis, dialect identification, and poetry classification.
132
+ - We fine-tune and evaluate the models using 12 dataset.
133
+ - We used Hugging Face's transformers to fine-tune our CAMeLBERT models.
134
+ - We used transformers `v3.1.0` along with PyTorch `v1.5.1`.
135
+ - The fine-tuning was done by adding a fully connected linear layer to the last hidden state.
136
+ - We use \\(F_{1}\\) score as a metric for all tasks.
137
+ - Code used for fine-tuning is available [here](https://github.com/CAMeL-Lab/CAMeLBERT).
138
+
139
+ ### Results
140
+
141
+ | Task | Dataset | Variant | Mix | CA | DA | MSA | MSA-1/2 | MSA-1/4 | MSA-1/8 | MSA-1/16 |
142
+ | -------------------- | --------------- | ------- | ----- | ----- | ----- | ----- | ------- | ------- | ------- | -------- |
143
+ | NER | ANERcorp | MSA | 80.8% | 67.9% | 74.1% | 82.4% | 82.0% | 82.1% | 82.6% | 80.8% |
144
+ | POS | PATB (MSA) | MSA | 98.1% | 97.8% | 97.7% | 98.3% | 98.2% | 98.3% | 98.2% | 98.2% |
145
+ | | ARZTB (EGY) | DA | 93.6% | 92.3% | 92.7% | 93.6% | 93.6% | 93.7% | 93.6% | 93.6% |
146
+ | | Gumar (GLF) | DA | 97.3% | 97.7% | 97.9% | 97.9% | 97.9% | 97.9% | 97.9% | 97.9% |
147
+ | SA | ASTD | MSA | 76.3% | 69.4% | 74.6% | 76.9% | 76.0% | 76.8% | 76.7% | 75.3% |
148
+ | | ArSAS | MSA | 92.7% | 89.4% | 91.8% | 93.0% | 92.6% | 92.5% | 92.5% | 92.3% |
149
+ | | SemEval | MSA | 69.0% | 58.5% | 68.4% | 72.1% | 70.7% | 72.8% | 71.6% | 71.2% |
150
+ | DID | MADAR-26 | DA | 62.9% | 61.9% | 61.8% | 62.6% | 62.0% | 62.8% | 62.0% | 62.2% |
151
+ | | MADAR-6 | DA | 92.5% | 91.5% | 92.2% | 91.9% | 91.8% | 92.2% | 92.1% | 92.0% |
152
+ | | MADAR-Twitter-5 | MSA | 75.7% | 71.4% | 74.2% | 77.6% | 78.5% | 77.3% | 77.7% | 76.2% |
153
+ | | NADI | DA | 24.7% | 17.3% | 20.1% | 24.9% | 24.6% | 24.6% | 24.9% | 23.8% |
154
+ | Poetry | APCD | CA | 79.8% | 80.9% | 79.6% | 79.7% | 79.9% | 80.0% | 79.7% | 79.8% |
155
+
156
+ ### Results (Average)
157
+ | | Variant | Mix | CA | DA | MSA | MSA-1/2 | MSA-1/4 | MSA-1/8 | MSA-1/16 |
158
+ | -------------------- | ------- | ----- | ----- | ----- | ----- | ------- | ------- | ------- | -------- |
159
+ | Variant-wise-average<sup>[[1]](#footnote-1)</sup> | MSA | 82.1% | 75.7% | 80.1% | 83.4% | 83.0% | 83.3% | 83.2% | 82.3% |
160
+ | | DA | 74.4% | 72.1% | 72.9% | 74.2% | 74.0% | 74.3% | 74.1% | 73.9% |
161
+ | | CA | 79.8% | 80.9% | 79.6% | 79.7% | 79.9% | 80.0% | 79.7% | 79.8% |
162
+ | Macro-Average | ALL | 78.7% | 74.7% | 77.1% | 79.2% | 79.0% | 79.2% | 79.1% | 78.6% |
163
+
164
+ <a name="footnote-1">[1]</a>: Variant-wise-average refers to average over a group of tasks in the same language variant.
165
+
166
+ ## Acknowledgements
167
+ This research was supported with Cloud TPUs from Google’s TensorFlow Research Cloud (TFRC).
168
+
169
+ ## Citation
170
+
171
+ ```bibtex
172
+ @inproceedings{inoue-etal-2021-interplay,
173
+ title = "The Interplay of Variant, Size, and Task Type in {A}rabic Pre-trained Language Models",
174
+ author = "Inoue, Go and
175
+ Alhafni, Bashar and
176
+ Baimukan, Nurpeiis and
177
+ Bouamor, Houda and
178
+ Habash, Nizar",
179
+ booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
180
+ month = apr,
181
+ year = "2021",
182
+ address = "Kyiv, Ukraine (Online)",
183
+ publisher = "Association for Computational Linguistics",
184
+ abstract = "In this paper, we explore the effects of language variants, data sizes, and fine-tuning task types in Arabic pre-trained language models. To do so, we build three pre-trained language models across three variants of Arabic: Modern Standard Arabic (MSA), dialectal Arabic, and classical Arabic, in addition to a fourth language model which is pre-trained on a mix of the three. We also examine the importance of pre-training data size by building additional models that are pre-trained on a scaled-down set of the MSA variant. We compare our different models to each other, as well as to eight publicly available models by fine-tuning them on five NLP tasks spanning 12 datasets. Our results suggest that the variant proximity of pre-training data to fine-tuning data is more important than the pre-training data size. We exploit this insight in defining an optimized system selection model for the studied tasks.",
185
+ }
186
+ ```
config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForMaskedLM"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "gradient_checkpointing": false,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 3072,
12
+ "layer_norm_eps": 1e-12,
13
+ "max_position_embeddings": 512,
14
+ "model_type": "bert",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 12,
17
+ "pad_token_id": 0,
18
+ "type_vocab_size": 2,
19
+ "vocab_size": 30000
20
+ }
flax_model.msgpack ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1c7ec33d731f6ab5309c80fa26a8afe17d7c665874d2c191f27fc9974573d37
3
+ size 436458787
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d234e4fe0193e74036b1db72ba9b41a2e4921d8cf0c3c421d1f6a6d8816af729
3
+ size 438873130
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tf_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e5b788e88bb1646ae054c868067e52b301331fbab6f8a6deff7119bf76a9224
3
+ size 436587688
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": false, "special_tokens_map_file": null, "full_tokenizer_file": null}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff