Update README.md
Browse files
README.md
CHANGED
@@ -17,13 +17,15 @@ widget:
|
|
17 |
BERTIN is a series of BERT-based models for Spanish. The current model hub points to the best of all RoBERTa-base models trained from scratch on the Spanish portion of mC4 using [Flax](https://github.com/google/flax). All code and scripts are included.
|
18 |
|
19 |
This is part of the
|
20 |
-
[Flax/Jax Community Week](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104),
|
|
|
|
|
21 |
|
22 |
## Spanish mC4
|
23 |
|
24 |
-
mC4 is a multilingual variant of the C4, the Colossal, Cleaned version of Common Crawl's web crawl corpus. While C4 was used to train the T5 text-to-text Transformer models, mC4 comprises natural text in 101 languages drawn from the public Common Crawl web
|
25 |
|
26 |
-
The Spanish portion of mC4 (`mc4-es`) contains about 416 million samples and 235 billion words in
|
27 |
|
28 |
```bash
|
29 |
$ zcat c4/multilingual/c4-es*.tfrecord*.json.gz | wc -l
|
@@ -37,9 +39,9 @@ $ zcat c4/multilingual/c4-es*.tfrecord-*.json.gz | jq -r '.text | split(" ") | l
|
|
37 |
|
38 |
## Perplexity sampling
|
39 |
|
40 |
-
|
41 |
|
42 |
-
In order to efficiently build this subset of data, we
|
43 |
|
44 |
<figure>
|
45 |
|
@@ -48,37 +50,42 @@ In order to efficiently build this subset of data, we decied to leverage a techn
|
|
48 |
<caption>Figure 1. Perplexity distributions by percentage CCNet corpus.</caption>
|
49 |
</figure>
|
50 |
|
51 |
-
In this work, we tested the
|
52 |
|
53 |
## Methodology
|
54 |
|
55 |
-
In order to test our
|
56 |
|
57 |
<figure>
|
58 |
|
59 |
![](./images/perp-p95.png)
|
60 |
|
61 |
-
<caption>Figure 2. Perplexity distributions and
|
62 |
</figure>
|
63 |
|
64 |
-
With the extracted perplexity percentiles, we created two functions to oversample the central quartiles with the idea of
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
<figure>
|
68 |
|
69 |
![](./images/perp-resample.png)
|
70 |
|
71 |
-
<caption>Figure 3. Expected perplexity distributions of the sample `mc4-es` after applying `
|
72 |
</figure>
|
73 |
|
74 |
<figure>
|
75 |
|
76 |
![](./images/perp-resample-gaussian.png)
|
77 |
|
78 |
-
<caption>Figure 4. Expected perplexity distributions of the sample `mc4-es` after applying `
|
79 |
</figure>
|
80 |
|
81 |
-
Figure 5 shows the
|
82 |
|
83 |
```python
|
84 |
from datasets import load_dataset
|
@@ -99,19 +106,19 @@ for split in ("random", "stepwise", "gaussian"):
|
|
99 |
|
100 |
![](./images/datasets-perp.png)
|
101 |
|
102 |
-
<caption>Figure 5.
|
103 |
</figure>
|
104 |
|
105 |
-
|
106 |
|
107 |
<figure>
|
108 |
|
109 |
![](./images/datasets-random-comparison.png)
|
110 |
|
111 |
-
<caption>Figure 6.
|
112 |
</figure>
|
113 |
|
114 |
-
We then used the same setup as
|
115 |
|
116 |
Our first test, tagged `beta` in this repository, refers to an initial experiment using `stepwise` but a small factor to oversample everything.
|
117 |
|
|
|
17 |
BERTIN is a series of BERT-based models for Spanish. The current model hub points to the best of all RoBERTa-base models trained from scratch on the Spanish portion of mC4 using [Flax](https://github.com/google/flax). All code and scripts are included.
|
18 |
|
19 |
This is part of the
|
20 |
+
[Flax/Jax Community Week](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104), organized by [HuggingFace](https://huggingface.co/) and TPU usage sponsored by Google Cloud.
|
21 |
+
|
22 |
+
The aim of this project was to pre-train a RoBERTa-base model from scratch for during the Flax/JAX Community Event in which Google Cloud provided free TPUv3-8 to do the training using Huggingface's Flax implementations of their library.
|
23 |
|
24 |
## Spanish mC4
|
25 |
|
26 |
+
mC4 is a multilingual variant of the C4, the Colossal, Cleaned version of Common Crawl's web crawl corpus. While C4 was used to train the T5 text-to-text Transformer models, mC4 comprises natural text in 101 languages drawn from the public Common Crawl web-scrape and was used to train mT5, the multilingual version of T5.
|
27 |
|
28 |
+
The Spanish portion of mC4 (`mc4-es`) contains about 416 million samples and 235 billion words in approximately 1TB of uncompressed data.
|
29 |
|
30 |
```bash
|
31 |
$ zcat c4/multilingual/c4-es*.tfrecord*.json.gz | wc -l
|
|
|
39 |
|
40 |
## Perplexity sampling
|
41 |
|
42 |
+
The large amount of text in mC4-es makes training a language model within the time constraints of the Flax/JAX Community Event by HuggingFace problematic. This motivated the exploration of sampling methods, with the goal of creating a subset of the dataset that allows well-performing training with roughly one eighth of the data (~50M samples) and in approximately half the training steps.
|
43 |
|
44 |
+
In order to efficiently build this subset of data, we decided to leverage a technique we call *perplexity sampling* and whose origin can be traced to the construction of CCNet (Wenzek et al., 2020) and their work extracting high quality monolingual datasets from web-crawl data. In their work, they suggest the possibility of applying fast language-models trained on high-quality data such as Wikipedia to filter out texts that deviate too much from correct expressions of a language (see Figure 1). They also released Kneser-Ney models for 100 languages (Spanish included) as implemented in the KenLM library (Heafield, 2011) and trained on their respective Wikipedias.
|
45 |
|
46 |
<figure>
|
47 |
|
|
|
50 |
<caption>Figure 1. Perplexity distributions by percentage CCNet corpus.</caption>
|
51 |
</figure>
|
52 |
|
53 |
+
In this work, we tested the hypothesis that perplexity sampling might help reduce training-data size and training times.
|
54 |
|
55 |
## Methodology
|
56 |
|
57 |
+
In order to test our hypothesis, we first calculated the perplexity of each document in a random subset (roughly a quarter of the data) of mC4-es and extracted their distribution and quartiles (see Figure 2).
|
58 |
|
59 |
<figure>
|
60 |
|
61 |
![](./images/perp-p95.png)
|
62 |
|
63 |
+
<caption>Figure 2. Perplexity distributions and quartiles (red lines) of 100M samples of mc4-es.</caption>
|
64 |
</figure>
|
65 |
|
66 |
+
With the extracted perplexity percentiles, we created two functions to oversample the central quartiles with the idea of biasing against samples that are either too small (short, repetitive texts) or too long (potentially poor quality) (see Figure 3).
|
67 |
+
|
68 |
+
The first function is a `Stepwise` that simply oversamples the central quartiles using quartile boundaries and a factor for the desired sampling frequency for each quartile, obviously given larger frequencies for middle quartiles (oversampling Q2, Q3, subsampling Q1, Q4).
|
69 |
+
The second function was a Gaussian approximation of the `Stepwise` function to smooth out the sharp boundaries and give a better approximation of the underlying distribution (see Figure 4).
|
70 |
+
|
71 |
+
We adjusted the `factor` parameter of the `Stepwise` function, and the `factor` and `width` parameter of the `Gaussian` function to roughly be able to sample 50M samples from the 416M in `mc4-es` (see Figure 4). For comparison, we also sampled randomly `mC4-es` up to 50M samples as well. In terms of sizes, we went down from 1TB of data to ~200GB.
|
72 |
|
73 |
|
74 |
<figure>
|
75 |
|
76 |
![](./images/perp-resample.png)
|
77 |
|
78 |
+
<caption>Figure 3. Expected perplexity distributions of the sample `mc4-es` after applying the `Stepwise` function.</caption>
|
79 |
</figure>
|
80 |
|
81 |
<figure>
|
82 |
|
83 |
![](./images/perp-resample-gaussian.png)
|
84 |
|
85 |
+
<caption>Figure 4. Expected perplexity distributions of the sample `mc4-es` after applying `Gaussian` function.</caption>
|
86 |
</figure>
|
87 |
|
88 |
+
Figure 5 shows the perplexity distributions of the 50M subsets for each of the approximations. All subsets can be easily accessed for reproducibility purposes using the `bertin-project/mc4-es-sampled` dataset. Since the validation set was too small to extract a 10% (5M) of the samples using perplexity-sampling with the same `factor` and `width`, in our experiments we decided to sample from the training sets. In the `bertin-project/mc4-es-sampled` dataset, the `validation` set pulls the samples from the original `mc4`.
|
89 |
|
90 |
```python
|
91 |
from datasets import load_dataset
|
|
|
106 |
|
107 |
![](./images/datasets-perp.png)
|
108 |
|
109 |
+
<caption>Figure 5. Experimental perplexity distributions of the sampled `mc4-es` after applying `Gaussian` and `Stepwise` functions.</caption>
|
110 |
</figure>
|
111 |
|
112 |
+
`Random` sampling displayed the same perplexity distribution of the underlying true distribution, as can be seen in Figure 6.
|
113 |
|
114 |
<figure>
|
115 |
|
116 |
![](./images/datasets-random-comparison.png)
|
117 |
|
118 |
+
<caption>Figure 6. Experimental perplexity distribution of the sampled `mc4-es` after applying `Random` sampling.</caption>
|
119 |
</figure>
|
120 |
|
121 |
+
We then used the same setup as Liu et al. (2019) but trained only for half the steps (250k) on a sequence length of 128. Then, we continued training the most promising model for 25k more on sequence length 512.
|
122 |
|
123 |
Our first test, tagged `beta` in this repository, refers to an initial experiment using `stepwise` but a small factor to oversample everything.
|
124 |
|