Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
multi-class-classification
Size:
1M - 10M
DOI:
License:
Publish unsplit Parquet corpus
Browse files- .gitignore +2 -0
- README.md +61 -21
- data/all/part-00000.parquet +3 -0
- data/all/part-00001.parquet +3 -0
- data/all/part-00002.parquet +3 -0
- data/all/part-00003.parquet +3 -0
- data/all/part-00004.parquet +3 -0
- data/all/part-00005.parquet +3 -0
- data/all/part-00006.parquet +3 -0
- data/all/part-00007.parquet +3 -0
- data/all/part-00008.parquet +3 -0
- data/all/part-00009.parquet +3 -0
- data/all/part-00010.parquet +3 -0
- reports/all_validation.json +169 -0
- requirements.txt +2 -1
- scripts/build_all.py +206 -0
- scripts/validate_all.py +104 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/build/
|
| 2 |
+
__pycache__/
|
README.md
CHANGED
|
@@ -3,6 +3,8 @@ pretty_name: Many Emotions
|
|
| 3 |
license: other
|
| 4 |
task_categories:
|
| 5 |
- text-classification
|
|
|
|
|
|
|
| 6 |
multilinguality:
|
| 7 |
- multilingual
|
| 8 |
source_datasets:
|
|
@@ -18,8 +20,12 @@ language:
|
|
| 18 |
size_categories:
|
| 19 |
- 1M<n<10M
|
| 20 |
configs:
|
| 21 |
-
- config_name:
|
| 22 |
default: true
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
data_files:
|
| 24 |
- split: train
|
| 25 |
path: data/split_dataset_train.jsonl.gz
|
|
@@ -33,6 +39,7 @@ configs:
|
|
| 33 |
path: data/many_emotions.json.gz
|
| 34 |
tags:
|
| 35 |
- emotion
|
|
|
|
| 36 |
- multilingual
|
| 37 |
---
|
| 38 |
|
|
@@ -40,9 +47,9 @@ tags:
|
|
| 40 |
|
| 41 |
Many Emotions is a multilingual text-classification dataset for recognizing seven emotion categories. It combines examples from Emotion, DailyDialog, and GoEmotions and provides text in English, French, Italian, Spanish, and German.
|
| 42 |
|
| 43 |
-
The
|
| 44 |
|
| 45 |
-
> **
|
| 46 |
|
| 47 |
## Labels
|
| 48 |
|
|
@@ -54,7 +61,7 @@ The prepared split contains 2,710,741 rows derived from 550,123 source IDs. Ever
|
|
| 54 |
| 3 | love | 186,061 | 6.9% |
|
| 55 |
| 4 | sadness | 615,520 | 22.7% |
|
| 56 |
| 5 | surprise | 94,298 | 3.5% |
|
| 57 |
-
| 6 | neutral | 500,
|
| 58 |
|
| 59 |
## Load the dataset
|
| 60 |
|
|
@@ -64,25 +71,41 @@ Install the required library:
|
|
| 64 |
pip install datasets
|
| 65 |
```
|
| 66 |
|
| 67 |
-
Load the
|
| 68 |
|
| 69 |
```python
|
| 70 |
from datasets import load_dataset
|
| 71 |
|
| 72 |
-
dataset = load_dataset("ma2za/many_emotions",
|
| 73 |
```
|
| 74 |
|
| 75 |
-
`
|
|
|
|
|
|
|
| 76 |
|
| 77 |
```python
|
| 78 |
raw = load_dataset("ma2za/many_emotions", "raw")
|
| 79 |
```
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
## Dataset structure
|
| 84 |
|
| 85 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
| Split | Rows |
|
| 88 |
|---|---:|
|
|
@@ -91,7 +114,7 @@ Both configurations load directly from compressed JSON Lines files and do not ex
|
|
| 91 |
| test | 135,537 |
|
| 92 |
| **Total** | **2,710,741** |
|
| 93 |
|
| 94 |
-
These are row-level splits, not source-grouped splits. Removing the final language suffix from `id` gives the source ID. Its membership across the
|
| 95 |
|
| 96 |
| Source ID membership | Source IDs |
|
| 97 |
|---|---:|
|
|
@@ -105,14 +128,14 @@ These are row-level splits, not source-grouped splits. Removing the final langua
|
|
| 105 |
|
| 106 |
Pairwise, train shares 122,325 source IDs with validation and 122,579 with test. Validation and test share 23,131 source IDs.
|
| 107 |
|
| 108 |
-
The
|
| 109 |
|
| 110 |
| Language | Code | Rows |
|
| 111 |
|---|---|---:|
|
| 112 |
| English | `en` | 550,122 |
|
| 113 |
| German | `de` | 542,598 |
|
| 114 |
| Italian | `it` | 541,145 |
|
| 115 |
-
| Spanish | `es` | 538,
|
| 116 |
| French | `fr` | 538,176 |
|
| 117 |
|
| 118 |
### Data fields
|
|
@@ -120,8 +143,10 @@ The prepared files contain approximately the same number of rows for each langua
|
|
| 120 |
| Field | Type | Description |
|
| 121 |
|---|---|---|
|
| 122 |
| `id` | string | Example identifier derived from the source and language. |
|
|
|
|
| 123 |
| `text` | string | Text to classify. |
|
| 124 |
| `label` | integer | Emotion class ID from 0 through 6. |
|
|
|
|
| 125 |
| `dataset` | string | Source dataset: `emotion`, `daily_dialog`, or `go_emotions`. |
|
| 126 |
| `license` | string | License or usage designation inherited from the source row. |
|
| 127 |
| `language` | string | ISO 639-1 language code: `de`, `en`, `es`, `fr`, or `it`. |
|
|
@@ -131,8 +156,10 @@ Example:
|
|
| 131 |
```json
|
| 132 |
{
|
| 133 |
"id": "emotion_199458_en",
|
|
|
|
| 134 |
"text": "i live with a big wonderful family that wants me to feel welcomed so sitting alone in my room is not an option",
|
| 135 |
"label": 2,
|
|
|
|
| 136 |
"dataset": "emotion",
|
| 137 |
"license": "educational/research",
|
| 138 |
"language": "en"
|
|
@@ -149,29 +176,42 @@ The prepared data retains 550,123 of the raw source IDs; 48,175 raw IDs are abse
|
|
| 149 |
|
| 150 |
## Source composition
|
| 151 |
|
| 152 |
-
Counts in the
|
| 153 |
|
| 154 |
| Source | Rows | Share | License value stored in rows |
|
| 155 |
|---|---:|---:|---|
|
| 156 |
| [Emotion](https://huggingface.co/datasets/dair-ai/emotion) | 2,055,918 | 75.8% | `educational/research` |
|
| 157 |
| [DailyDialog](https://aclanthology.org/attachments/I17-1099.Datasets.zip) | 414,020 | 15.3% | `CC BY-NC-SA 4.0` |
|
| 158 |
-
| [GoEmotions](https://huggingface.co/datasets/google-research-datasets/go_emotions) | 240,
|
| 159 |
|
| 160 |
## Data quality and limitations
|
| 161 |
|
| 162 |
-
The following results come from
|
| 163 |
|
| 164 |
-
- All 2,710,
|
| 165 |
-
-
|
| 166 |
-
- There are no repeated `(language, text, label)` triples in the
|
| 167 |
- There are 159,897 exact `(language, text)` values associated with multiple labels, involving 323,049 rows. The same text can have as many as six labels.
|
| 168 |
-
-
|
| 169 |
-
-
|
| 170 |
- Labels are imbalanced and strongly associated with source. For example, 83.2% of DailyDialog rows and 64.7% of GoEmotions rows are neutral, while the Emotion contribution contains no neutral rows.
|
| 171 |
- The translation method and translation-quality evaluation are not documented in this repository. Inspect the languages relevant to your use case before training or evaluation.
|
| 172 |
- Median text length is 15 to 16 whitespace-delimited words, depending on language; the 95th percentile is 39 to 42 words.
|
| 173 |
|
| 174 |
-
Source labels are normalized to anger, fear, joy, love, sadness, surprise, and neutral. The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
## Licensing
|
| 177 |
|
|
|
|
| 3 |
license: other
|
| 4 |
task_categories:
|
| 5 |
- text-classification
|
| 6 |
+
task_ids:
|
| 7 |
+
- multi-class-classification
|
| 8 |
multilinguality:
|
| 9 |
- multilingual
|
| 10 |
source_datasets:
|
|
|
|
| 20 |
size_categories:
|
| 21 |
- 1M<n<10M
|
| 22 |
configs:
|
| 23 |
+
- config_name: all
|
| 24 |
default: true
|
| 25 |
+
data_files:
|
| 26 |
+
- split: full
|
| 27 |
+
path: data/all/*.parquet
|
| 28 |
+
- config_name: split
|
| 29 |
data_files:
|
| 30 |
- split: train
|
| 31 |
path: data/split_dataset_train.jsonl.gz
|
|
|
|
| 39 |
path: data/many_emotions.json.gz
|
| 40 |
tags:
|
| 41 |
- emotion
|
| 42 |
+
- emotion-classification
|
| 43 |
- multilingual
|
| 44 |
---
|
| 45 |
|
|
|
|
| 47 |
|
| 48 |
Many Emotions is a multilingual text-classification dataset for recognizing seven emotion categories. It combines examples from Emotion, DailyDialog, and GoEmotions and provides text in English, French, Italian, Spanish, and German.
|
| 49 |
|
| 50 |
+
The default unsplit corpus contains 2,710,740 non-empty rows derived from 550,123 source IDs. Every row records its source dataset and source-specific license.
|
| 51 |
|
| 52 |
+
> **No train/test split is implied.** The default `all` configuration intentionally exposes one `full` partition. Create splits appropriate for your task and group them by `source_id`.
|
| 53 |
|
| 54 |
## Labels
|
| 55 |
|
|
|
|
| 61 |
| 3 | love | 186,061 | 6.9% |
|
| 62 |
| 4 | sadness | 615,520 | 22.7% |
|
| 63 |
| 5 | surprise | 94,298 | 3.5% |
|
| 64 |
+
| 6 | neutral | 500,391 | 18.5% |
|
| 65 |
|
| 66 |
## Load the dataset
|
| 67 |
|
|
|
|
| 71 |
pip install datasets
|
| 72 |
```
|
| 73 |
|
| 74 |
+
Load the complete corpus as one dataset:
|
| 75 |
|
| 76 |
```python
|
| 77 |
from datasets import load_dataset
|
| 78 |
|
| 79 |
+
dataset = load_dataset("ma2za/many_emotions", split="full")
|
| 80 |
```
|
| 81 |
|
| 82 |
+
`all` is the default configuration. Calling `load_dataset("ma2za/many_emotions")` without `split="full"` returns a `DatasetDict` containing that partition.
|
| 83 |
+
|
| 84 |
+
Load the source records and their five text columns with:
|
| 85 |
|
| 86 |
```python
|
| 87 |
raw = load_dataset("ma2za/many_emotions", "raw")
|
| 88 |
```
|
| 89 |
|
| 90 |
+
The deprecated row-level splits remain available for reproducibility:
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
legacy = load_dataset("ma2za/many_emotions", "split")
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
All configurations load directly from data files and do not execute repository code.
|
| 97 |
|
| 98 |
## Dataset structure
|
| 99 |
|
| 100 |
+
### Default unsplit corpus
|
| 101 |
+
|
| 102 |
+
| Partition | Rows |
|
| 103 |
+
|---|---:|
|
| 104 |
+
| full | 2,710,740 |
|
| 105 |
+
|
| 106 |
+
The default corpus is stored in 11 Zstandard-compressed Parquet shards. It adds explicit `source_id` and `label_name` columns and omits the single empty record found in the legacy files.
|
| 107 |
+
|
| 108 |
+
### Deprecated legacy splits
|
| 109 |
|
| 110 |
| Split | Rows |
|
| 111 |
|---|---:|
|
|
|
|
| 114 |
| test | 135,537 |
|
| 115 |
| **Total** | **2,710,741** |
|
| 116 |
|
| 117 |
+
These splits are retained only for reproducibility. They are row-level splits, not source-grouped splits. Removing the final language suffix from `id` gives the source ID. Its membership across the legacy splits is:
|
| 118 |
|
| 119 |
| Source ID membership | Source IDs |
|
| 120 |
|---|---:|
|
|
|
|
| 128 |
|
| 129 |
Pairwise, train shares 122,325 source IDs with validation and 122,579 with test. Validation and test share 23,131 source IDs.
|
| 130 |
|
| 131 |
+
The default corpus contains approximately the same number of rows for each language:
|
| 132 |
|
| 133 |
| Language | Code | Rows |
|
| 134 |
|---|---|---:|
|
| 135 |
| English | `en` | 550,122 |
|
| 136 |
| German | `de` | 542,598 |
|
| 137 |
| Italian | `it` | 541,145 |
|
| 138 |
+
| Spanish | `es` | 538,699 |
|
| 139 |
| French | `fr` | 538,176 |
|
| 140 |
|
| 141 |
### Data fields
|
|
|
|
| 143 |
| Field | Type | Description |
|
| 144 |
|---|---|---|
|
| 145 |
| `id` | string | Example identifier derived from the source and language. |
|
| 146 |
+
| `source_id` | string | Shared identifier for all retained language variants of a source example. Available in `all`. |
|
| 147 |
| `text` | string | Text to classify. |
|
| 148 |
| `label` | integer | Emotion class ID from 0 through 6. |
|
| 149 |
+
| `label_name` | string | Human-readable emotion label. Available in `all`. |
|
| 150 |
| `dataset` | string | Source dataset: `emotion`, `daily_dialog`, or `go_emotions`. |
|
| 151 |
| `license` | string | License or usage designation inherited from the source row. |
|
| 152 |
| `language` | string | ISO 639-1 language code: `de`, `en`, `es`, `fr`, or `it`. |
|
|
|
|
| 156 |
```json
|
| 157 |
{
|
| 158 |
"id": "emotion_199458_en",
|
| 159 |
+
"source_id": "emotion_199458",
|
| 160 |
"text": "i live with a big wonderful family that wants me to feel welcomed so sitting alone in my room is not an option",
|
| 161 |
"label": 2,
|
| 162 |
+
"label_name": "joy",
|
| 163 |
"dataset": "emotion",
|
| 164 |
"license": "educational/research",
|
| 165 |
"language": "en"
|
|
|
|
| 176 |
|
| 177 |
## Source composition
|
| 178 |
|
| 179 |
+
Counts in the default unsplit corpus:
|
| 180 |
|
| 181 |
| Source | Rows | Share | License value stored in rows |
|
| 182 |
|---|---:|---:|---|
|
| 183 |
| [Emotion](https://huggingface.co/datasets/dair-ai/emotion) | 2,055,918 | 75.8% | `educational/research` |
|
| 184 |
| [DailyDialog](https://aclanthology.org/attachments/I17-1099.Datasets.zip) | 414,020 | 15.3% | `CC BY-NC-SA 4.0` |
|
| 185 |
+
| [GoEmotions](https://huggingface.co/datasets/google-research-datasets/go_emotions) | 240,802 | 8.9% | `apache license 2.0` |
|
| 186 |
|
| 187 |
## Data quality and limitations
|
| 188 |
|
| 189 |
+
The following results come from complete build-time and post-build scans:
|
| 190 |
|
| 191 |
+
- All 2,710,740 default rows have the documented typed schema, unique IDs, non-empty text, valid language codes, and labels between 0 and 6.
|
| 192 |
+
- The empty legacy record `go_emotions_1_48976_es` is excluded from `all`. Its corresponding Spanish field is also empty in the raw record.
|
| 193 |
+
- There are no repeated `(language, text, label)` triples in the default corpus.
|
| 194 |
- There are 159,897 exact `(language, text)` values associated with multiple labels, involving 323,049 rows. The same text can have as many as six labels.
|
| 195 |
+
- The deprecated legacy files place the same-language text across train and validation for 14,535 values, train and test for 14,660 values, and validation and test for 888 values. None has the same label on both sides of the measured pair.
|
| 196 |
+
- The deprecated legacy files also distribute translations of the same source example across splits. The default `full` partition has no split boundaries and makes no evaluation claim.
|
| 197 |
- Labels are imbalanced and strongly associated with source. For example, 83.2% of DailyDialog rows and 64.7% of GoEmotions rows are neutral, while the Emotion contribution contains no neutral rows.
|
| 198 |
- The translation method and translation-quality evaluation are not documented in this repository. Inspect the languages relevant to your use case before training or evaluation.
|
| 199 |
- Median text length is 15 to 16 whitespace-delimited words, depending on language; the 95th percentile is 39 to 42 words.
|
| 200 |
|
| 201 |
+
Source labels are normalized to anger, fear, joy, love, sadness, surprise, and neutral. The default corpus preserves the normalized labels from the legacy prepared files.
|
| 202 |
+
|
| 203 |
+
## Reproducibility
|
| 204 |
+
|
| 205 |
+
`reports/all_validation.json` records input and shard checksums, row counts, feature definitions, language counts, label counts, source counts, and license counts.
|
| 206 |
+
|
| 207 |
+
Rebuild into a separate directory:
|
| 208 |
+
|
| 209 |
+
```bash
|
| 210 |
+
python scripts/build_all.py --output-dir build/all --report build/all_validation.json
|
| 211 |
+
python scripts/validate_all.py --report build/all_validation.json
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
The builder concatenates the three legacy files into one partition, derives `source_id`, adds `label_name`, excludes empty text, and writes deterministic 250,000-row Parquet shards. It does not assign new train, validation, or test splits.
|
| 215 |
|
| 216 |
## Licensing
|
| 217 |
|
data/all/part-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4af344ca136b03b5524aba5eb42bb4ab34d8f5918ca329b59f55f08f24129749
|
| 3 |
+
size 13348676
|
data/all/part-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6428bd49dcb8087cba478000860f24a5e9910b609ea56e06d11837fba40f719f
|
| 3 |
+
size 13351647
|
data/all/part-00002.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9d7dfc4a8239cac1aff98a9b2b1acfcdd7cf92829aa968e7ef801e713005aa14
|
| 3 |
+
size 13360167
|
data/all/part-00003.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71c7aa1340780023f57bccfbd37ecb2054183c9477a318e7f1c34bb9c74589e8
|
| 3 |
+
size 13337982
|
data/all/part-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12a0457a7af6210ab84fe1812b4df598a041f6c82b43ec29f2fe312d75c16c5f
|
| 3 |
+
size 13333900
|
data/all/part-00005.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cfd0c00708b7f763247c271214448fa4da22bcf4c795ce88ffe8fcbfd75e2d33
|
| 3 |
+
size 13325351
|
data/all/part-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2ec738b8486708f14f7325492d3cb3afed3c539177c9d62352072c0b89b28271
|
| 3 |
+
size 13360140
|
data/all/part-00007.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5366a33b945df50d0fa855d435d6b2efd6dcf01a321b22962c86a948455c9f94
|
| 3 |
+
size 13334655
|
data/all/part-00008.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d22610d780922a42b910354bf0b79ffdef6748920ba2e7ee93cf5ea07bc26b8a
|
| 3 |
+
size 13356232
|
data/all/part-00009.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:837d1651bcb9abdc4769089206fdd745cabda60462a7b35b1d20c4b46ba9c59a
|
| 3 |
+
size 13351262
|
data/all/part-00010.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:09e0bfe169f287eab6ad8620a0c196816cee13f28361293c4cd427108c0670df
|
| 3 |
+
size 11262857
|
reports/all_validation.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"config": "all",
|
| 3 |
+
"counts": {
|
| 4 |
+
"dropped_empty_text": 1,
|
| 5 |
+
"input_rows": 2710741,
|
| 6 |
+
"input_unique_ids": 2710741,
|
| 7 |
+
"labels": {
|
| 8 |
+
"anger": 306529,
|
| 9 |
+
"fear": 242462,
|
| 10 |
+
"joy": 765479,
|
| 11 |
+
"love": 186061,
|
| 12 |
+
"neutral": 500391,
|
| 13 |
+
"sadness": 615520,
|
| 14 |
+
"surprise": 94298
|
| 15 |
+
},
|
| 16 |
+
"languages": {
|
| 17 |
+
"de": 542598,
|
| 18 |
+
"en": 550122,
|
| 19 |
+
"es": 538699,
|
| 20 |
+
"fr": 538176,
|
| 21 |
+
"it": 541145
|
| 22 |
+
},
|
| 23 |
+
"licenses": {
|
| 24 |
+
"CC BY-NC-SA 4.0": 414020,
|
| 25 |
+
"apache license 2.0": 240802,
|
| 26 |
+
"educational/research": 2055918
|
| 27 |
+
},
|
| 28 |
+
"output_rows": 2710740,
|
| 29 |
+
"output_unique_ids": 2710740,
|
| 30 |
+
"retained_source_ids": 550123,
|
| 31 |
+
"sources": {
|
| 32 |
+
"daily_dialog": 414020,
|
| 33 |
+
"emotion": 2055918,
|
| 34 |
+
"go_emotions": 240802
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
"features": {
|
| 38 |
+
"dataset": {
|
| 39 |
+
"_type": "Value",
|
| 40 |
+
"dtype": "string"
|
| 41 |
+
},
|
| 42 |
+
"id": {
|
| 43 |
+
"_type": "Value",
|
| 44 |
+
"dtype": "string"
|
| 45 |
+
},
|
| 46 |
+
"label": {
|
| 47 |
+
"_type": "ClassLabel",
|
| 48 |
+
"names": [
|
| 49 |
+
"anger",
|
| 50 |
+
"fear",
|
| 51 |
+
"joy",
|
| 52 |
+
"love",
|
| 53 |
+
"sadness",
|
| 54 |
+
"surprise",
|
| 55 |
+
"neutral"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
"label_name": {
|
| 59 |
+
"_type": "Value",
|
| 60 |
+
"dtype": "string"
|
| 61 |
+
},
|
| 62 |
+
"language": {
|
| 63 |
+
"_type": "Value",
|
| 64 |
+
"dtype": "string"
|
| 65 |
+
},
|
| 66 |
+
"license": {
|
| 67 |
+
"_type": "Value",
|
| 68 |
+
"dtype": "string"
|
| 69 |
+
},
|
| 70 |
+
"source_id": {
|
| 71 |
+
"_type": "Value",
|
| 72 |
+
"dtype": "string"
|
| 73 |
+
},
|
| 74 |
+
"text": {
|
| 75 |
+
"_type": "Value",
|
| 76 |
+
"dtype": "string"
|
| 77 |
+
}
|
| 78 |
+
},
|
| 79 |
+
"format_version": 1,
|
| 80 |
+
"input_files": [
|
| 81 |
+
{
|
| 82 |
+
"bytes": 143575307,
|
| 83 |
+
"path": "data/split_dataset_train.jsonl.gz",
|
| 84 |
+
"rows": 2439666,
|
| 85 |
+
"sha256": "b420aba48b9cd72b9363a9794dad3346cd572ae7418b77962b14fd44b725eeb2"
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"bytes": 7969332,
|
| 89 |
+
"path": "data/split_dataset_validation.jsonl.gz",
|
| 90 |
+
"rows": 135538,
|
| 91 |
+
"sha256": "24c46037cc2be059040caf83bfd8fb76110111517857602acdc1caa1d41848c5"
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"bytes": 7981677,
|
| 95 |
+
"path": "data/split_dataset_test.jsonl.gz",
|
| 96 |
+
"rows": 135537,
|
| 97 |
+
"sha256": "a26f085aa3157ffe3f8817d94d64040050072341d6395a12e7b6b31ad5b338f7"
|
| 98 |
+
}
|
| 99 |
+
],
|
| 100 |
+
"partition": "full",
|
| 101 |
+
"shards": [
|
| 102 |
+
{
|
| 103 |
+
"bytes": 13348676,
|
| 104 |
+
"path": "data/all/part-00000.parquet",
|
| 105 |
+
"rows": 250000,
|
| 106 |
+
"sha256": "4af344ca136b03b5524aba5eb42bb4ab34d8f5918ca329b59f55f08f24129749"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"bytes": 13351647,
|
| 110 |
+
"path": "data/all/part-00001.parquet",
|
| 111 |
+
"rows": 250000,
|
| 112 |
+
"sha256": "6428bd49dcb8087cba478000860f24a5e9910b609ea56e06d11837fba40f719f"
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"bytes": 13360167,
|
| 116 |
+
"path": "data/all/part-00002.parquet",
|
| 117 |
+
"rows": 250000,
|
| 118 |
+
"sha256": "9d7dfc4a8239cac1aff98a9b2b1acfcdd7cf92829aa968e7ef801e713005aa14"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"bytes": 13337982,
|
| 122 |
+
"path": "data/all/part-00003.parquet",
|
| 123 |
+
"rows": 250000,
|
| 124 |
+
"sha256": "71c7aa1340780023f57bccfbd37ecb2054183c9477a318e7f1c34bb9c74589e8"
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"bytes": 13333900,
|
| 128 |
+
"path": "data/all/part-00004.parquet",
|
| 129 |
+
"rows": 250000,
|
| 130 |
+
"sha256": "12a0457a7af6210ab84fe1812b4df598a041f6c82b43ec29f2fe312d75c16c5f"
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"bytes": 13325351,
|
| 134 |
+
"path": "data/all/part-00005.parquet",
|
| 135 |
+
"rows": 250000,
|
| 136 |
+
"sha256": "cfd0c00708b7f763247c271214448fa4da22bcf4c795ce88ffe8fcbfd75e2d33"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"bytes": 13360140,
|
| 140 |
+
"path": "data/all/part-00006.parquet",
|
| 141 |
+
"rows": 250000,
|
| 142 |
+
"sha256": "2ec738b8486708f14f7325492d3cb3afed3c539177c9d62352072c0b89b28271"
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"bytes": 13334655,
|
| 146 |
+
"path": "data/all/part-00007.parquet",
|
| 147 |
+
"rows": 250000,
|
| 148 |
+
"sha256": "5366a33b945df50d0fa855d435d6b2efd6dcf01a321b22962c86a948455c9f94"
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"bytes": 13356232,
|
| 152 |
+
"path": "data/all/part-00008.parquet",
|
| 153 |
+
"rows": 250000,
|
| 154 |
+
"sha256": "d22610d780922a42b910354bf0b79ffdef6748920ba2e7ee93cf5ea07bc26b8a"
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"bytes": 13351262,
|
| 158 |
+
"path": "data/all/part-00009.parquet",
|
| 159 |
+
"rows": 250000,
|
| 160 |
+
"sha256": "837d1651bcb9abdc4769089206fdd745cabda60462a7b35b1d20c4b46ba9c59a"
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"bytes": 11262857,
|
| 164 |
+
"path": "data/all/part-00010.parquet",
|
| 165 |
+
"rows": 210740,
|
| 166 |
+
"sha256": "09e0bfe169f287eab6ad8620a0c196816cee13f28361293c4cd427108c0670df"
|
| 167 |
+
}
|
| 168 |
+
]
|
| 169 |
+
}
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
datasets
|
|
|
|
|
|
| 1 |
+
datasets==5.0.0
|
| 2 |
+
pyarrow==25.0.0
|
scripts/build_all.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import collections
|
| 3 |
+
import gzip
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pyarrow as pa
|
| 9 |
+
import pyarrow.parquet as pq
|
| 10 |
+
from datasets import ClassLabel, Features, Value
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
LABELS = ["anger", "fear", "joy", "love", "sadness", "surprise", "neutral"]
|
| 14 |
+
LANGUAGES = {"de", "en", "es", "fr", "it"}
|
| 15 |
+
INPUTS = [
|
| 16 |
+
"split_dataset_train.jsonl.gz",
|
| 17 |
+
"split_dataset_validation.jsonl.gz",
|
| 18 |
+
"split_dataset_test.jsonl.gz",
|
| 19 |
+
]
|
| 20 |
+
FEATURES = Features(
|
| 21 |
+
{
|
| 22 |
+
"id": Value("string"),
|
| 23 |
+
"source_id": Value("string"),
|
| 24 |
+
"text": Value("string"),
|
| 25 |
+
"label": ClassLabel(names=LABELS),
|
| 26 |
+
"label_name": Value("string"),
|
| 27 |
+
"dataset": Value("string"),
|
| 28 |
+
"license": Value("string"),
|
| 29 |
+
"language": Value("string"),
|
| 30 |
+
}
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def file_sha256(path):
|
| 35 |
+
digest = hashlib.sha256()
|
| 36 |
+
with path.open("rb") as stream:
|
| 37 |
+
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
| 38 |
+
digest.update(chunk)
|
| 39 |
+
return digest.hexdigest()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def parse_args():
|
| 43 |
+
parser = argparse.ArgumentParser()
|
| 44 |
+
parser.add_argument("--data-dir", type=Path, default=Path("data"))
|
| 45 |
+
parser.add_argument("--output-dir", type=Path, default=Path("data/all"))
|
| 46 |
+
parser.add_argument("--report", type=Path, default=Path("reports/all_validation.json"))
|
| 47 |
+
parser.add_argument("--rows-per-shard", type=int, default=250_000)
|
| 48 |
+
parser.add_argument("--batch-size", type=int, default=25_000)
|
| 49 |
+
return parser.parse_args()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def main():
|
| 53 |
+
args = parse_args()
|
| 54 |
+
if args.output_dir.exists() and any(args.output_dir.iterdir()):
|
| 55 |
+
raise SystemExit(f"output directory is not empty: {args.output_dir}")
|
| 56 |
+
|
| 57 |
+
args.output_dir.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
args.report.parent.mkdir(parents=True, exist_ok=True)
|
| 59 |
+
|
| 60 |
+
schema = FEATURES.arrow_schema
|
| 61 |
+
required = {"id", "text", "label", "dataset", "license", "language"}
|
| 62 |
+
ids = set()
|
| 63 |
+
source_ids = set()
|
| 64 |
+
counts = collections.Counter()
|
| 65 |
+
label_counts = collections.Counter()
|
| 66 |
+
language_counts = collections.Counter()
|
| 67 |
+
source_counts = collections.Counter()
|
| 68 |
+
license_counts = collections.Counter()
|
| 69 |
+
input_files = []
|
| 70 |
+
shards = []
|
| 71 |
+
writer = None
|
| 72 |
+
shard_index = 0
|
| 73 |
+
rows_in_shard = 0
|
| 74 |
+
batch = []
|
| 75 |
+
|
| 76 |
+
def open_writer():
|
| 77 |
+
nonlocal writer, shard_index, rows_in_shard
|
| 78 |
+
path = args.output_dir / f"part-{shard_index:05d}.parquet"
|
| 79 |
+
writer = pq.ParquetWriter(
|
| 80 |
+
path,
|
| 81 |
+
schema,
|
| 82 |
+
compression="zstd",
|
| 83 |
+
compression_level=9,
|
| 84 |
+
use_dictionary=True,
|
| 85 |
+
write_statistics=True,
|
| 86 |
+
write_page_index=True,
|
| 87 |
+
)
|
| 88 |
+
shards.append(path)
|
| 89 |
+
shard_index += 1
|
| 90 |
+
rows_in_shard = 0
|
| 91 |
+
|
| 92 |
+
def write_rows(rows):
|
| 93 |
+
nonlocal writer, rows_in_shard
|
| 94 |
+
offset = 0
|
| 95 |
+
while offset < len(rows):
|
| 96 |
+
if writer is None:
|
| 97 |
+
open_writer()
|
| 98 |
+
available = args.rows_per_shard - rows_in_shard
|
| 99 |
+
chunk = rows[offset : offset + available]
|
| 100 |
+
writer.write_table(pa.Table.from_pylist(chunk, schema=schema), row_group_size=65_536)
|
| 101 |
+
rows_in_shard += len(chunk)
|
| 102 |
+
offset += len(chunk)
|
| 103 |
+
if rows_in_shard == args.rows_per_shard:
|
| 104 |
+
writer.close()
|
| 105 |
+
writer = None
|
| 106 |
+
|
| 107 |
+
for filename in INPUTS:
|
| 108 |
+
path = args.data_dir / filename
|
| 109 |
+
file_rows = 0
|
| 110 |
+
input_files.append(
|
| 111 |
+
{
|
| 112 |
+
"path": path.as_posix(),
|
| 113 |
+
"bytes": path.stat().st_size,
|
| 114 |
+
"sha256": file_sha256(path),
|
| 115 |
+
}
|
| 116 |
+
)
|
| 117 |
+
with gzip.open(path, "rt", encoding="utf-8") as stream:
|
| 118 |
+
for line_number, line in enumerate(stream, 1):
|
| 119 |
+
counts["input_rows"] += 1
|
| 120 |
+
file_rows += 1
|
| 121 |
+
row = json.loads(line)
|
| 122 |
+
missing = required - row.keys()
|
| 123 |
+
if missing:
|
| 124 |
+
raise ValueError(f"{path}:{line_number}: missing fields {sorted(missing)}")
|
| 125 |
+
if row["id"] in ids:
|
| 126 |
+
raise ValueError(f"{path}:{line_number}: duplicate id {row['id']}")
|
| 127 |
+
ids.add(row["id"])
|
| 128 |
+
if row["language"] not in LANGUAGES:
|
| 129 |
+
raise ValueError(f"{path}:{line_number}: invalid language {row['language']}")
|
| 130 |
+
if not isinstance(row["label"], int) or not 0 <= row["label"] < len(LABELS):
|
| 131 |
+
raise ValueError(f"{path}:{line_number}: invalid label {row['label']}")
|
| 132 |
+
if not isinstance(row["text"], str) or not row["text"].strip():
|
| 133 |
+
counts["dropped_empty_text"] += 1
|
| 134 |
+
continue
|
| 135 |
+
|
| 136 |
+
suffix = "_" + row["language"]
|
| 137 |
+
if not row["id"].endswith(suffix):
|
| 138 |
+
raise ValueError(f"{path}:{line_number}: id/language mismatch {row['id']}")
|
| 139 |
+
source_id = row["id"][: -len(suffix)]
|
| 140 |
+
source_ids.add(source_id)
|
| 141 |
+
output = {
|
| 142 |
+
"id": row["id"],
|
| 143 |
+
"source_id": source_id,
|
| 144 |
+
"text": row["text"],
|
| 145 |
+
"label": row["label"],
|
| 146 |
+
"label_name": LABELS[row["label"]],
|
| 147 |
+
"dataset": row["dataset"],
|
| 148 |
+
"license": row["license"],
|
| 149 |
+
"language": row["language"],
|
| 150 |
+
}
|
| 151 |
+
batch.append(output)
|
| 152 |
+
counts["output_rows"] += 1
|
| 153 |
+
label_counts[row["label"]] += 1
|
| 154 |
+
language_counts[row["language"]] += 1
|
| 155 |
+
source_counts[row["dataset"]] += 1
|
| 156 |
+
license_counts[row["license"]] += 1
|
| 157 |
+
if len(batch) == args.batch_size:
|
| 158 |
+
write_rows(batch)
|
| 159 |
+
batch.clear()
|
| 160 |
+
input_files[-1]["rows"] = file_rows
|
| 161 |
+
|
| 162 |
+
if batch:
|
| 163 |
+
write_rows(batch)
|
| 164 |
+
if writer is not None:
|
| 165 |
+
writer.close()
|
| 166 |
+
|
| 167 |
+
shard_files = []
|
| 168 |
+
shard_rows_total = 0
|
| 169 |
+
for path in shards:
|
| 170 |
+
rows = pq.ParquetFile(path).metadata.num_rows
|
| 171 |
+
shard_rows_total += rows
|
| 172 |
+
shard_files.append(
|
| 173 |
+
{
|
| 174 |
+
"path": path.as_posix(),
|
| 175 |
+
"rows": rows,
|
| 176 |
+
"bytes": path.stat().st_size,
|
| 177 |
+
"sha256": file_sha256(path),
|
| 178 |
+
}
|
| 179 |
+
)
|
| 180 |
+
if shard_rows_total != counts["output_rows"]:
|
| 181 |
+
raise ValueError(f"shard row mismatch: {shard_rows_total} != {counts['output_rows']}")
|
| 182 |
+
|
| 183 |
+
report = {
|
| 184 |
+
"format_version": 1,
|
| 185 |
+
"config": "all",
|
| 186 |
+
"partition": "full",
|
| 187 |
+
"features": FEATURES.to_dict(),
|
| 188 |
+
"input_files": input_files,
|
| 189 |
+
"shards": shard_files,
|
| 190 |
+
"counts": {
|
| 191 |
+
**dict(sorted(counts.items())),
|
| 192 |
+
"input_unique_ids": len(ids),
|
| 193 |
+
"output_unique_ids": counts["output_rows"],
|
| 194 |
+
"retained_source_ids": len(source_ids),
|
| 195 |
+
"labels": {LABELS[key]: value for key, value in sorted(label_counts.items())},
|
| 196 |
+
"languages": dict(sorted(language_counts.items())),
|
| 197 |
+
"sources": dict(sorted(source_counts.items())),
|
| 198 |
+
"licenses": dict(sorted(license_counts.items())),
|
| 199 |
+
},
|
| 200 |
+
}
|
| 201 |
+
args.report.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 202 |
+
print(json.dumps(report["counts"], indent=2, sort_keys=True))
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
if __name__ == "__main__":
|
| 206 |
+
main()
|
scripts/validate_all.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import hashlib
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import pyarrow.parquet as pq
|
| 7 |
+
from datasets import ClassLabel, Features, Value
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
LABELS = ["anger", "fear", "joy", "love", "sadness", "surprise", "neutral"]
|
| 11 |
+
LANGUAGES = {"de", "en", "es", "fr", "it"}
|
| 12 |
+
FEATURES = Features(
|
| 13 |
+
{
|
| 14 |
+
"id": Value("string"),
|
| 15 |
+
"source_id": Value("string"),
|
| 16 |
+
"text": Value("string"),
|
| 17 |
+
"label": ClassLabel(names=LABELS),
|
| 18 |
+
"label_name": Value("string"),
|
| 19 |
+
"dataset": Value("string"),
|
| 20 |
+
"license": Value("string"),
|
| 21 |
+
"language": Value("string"),
|
| 22 |
+
}
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def file_sha256(path):
|
| 27 |
+
digest = hashlib.sha256()
|
| 28 |
+
with path.open("rb") as stream:
|
| 29 |
+
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
| 30 |
+
digest.update(chunk)
|
| 31 |
+
return digest.hexdigest()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def parse_args():
|
| 35 |
+
parser = argparse.ArgumentParser()
|
| 36 |
+
parser.add_argument("--report", type=Path, default=Path("reports/all_validation.json"))
|
| 37 |
+
return parser.parse_args()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def main():
|
| 41 |
+
args = parse_args()
|
| 42 |
+
report = json.loads(args.report.read_text(encoding="utf-8"))
|
| 43 |
+
ids = set()
|
| 44 |
+
rows = 0
|
| 45 |
+
source_ids = set()
|
| 46 |
+
|
| 47 |
+
for shard in report["shards"]:
|
| 48 |
+
path = Path(shard["path"])
|
| 49 |
+
if file_sha256(path) != shard["sha256"]:
|
| 50 |
+
raise ValueError(f"checksum mismatch: {path}")
|
| 51 |
+
parquet = pq.ParquetFile(path)
|
| 52 |
+
if parquet.schema_arrow != FEATURES.arrow_schema:
|
| 53 |
+
raise ValueError(f"schema mismatch: {path}")
|
| 54 |
+
if parquet.metadata.num_rows != shard["rows"]:
|
| 55 |
+
raise ValueError(f"row count mismatch: {path}")
|
| 56 |
+
for batch in parquet.iter_batches(batch_size=65_536):
|
| 57 |
+
columns = batch.to_pydict()
|
| 58 |
+
for index, row_id in enumerate(columns["id"]):
|
| 59 |
+
language = columns["language"][index]
|
| 60 |
+
source_id = columns["source_id"][index]
|
| 61 |
+
label = columns["label"][index]
|
| 62 |
+
if row_id in ids:
|
| 63 |
+
raise ValueError(f"duplicate id: {row_id}")
|
| 64 |
+
ids.add(row_id)
|
| 65 |
+
source_ids.add(source_id)
|
| 66 |
+
if language not in LANGUAGES:
|
| 67 |
+
raise ValueError(f"invalid language: {language}")
|
| 68 |
+
if row_id != f"{source_id}_{language}":
|
| 69 |
+
raise ValueError(f"id/source mismatch: {row_id}")
|
| 70 |
+
if not columns["text"][index].strip():
|
| 71 |
+
raise ValueError(f"empty text: {row_id}")
|
| 72 |
+
if not 0 <= label < len(LABELS):
|
| 73 |
+
raise ValueError(f"invalid label: {row_id}")
|
| 74 |
+
if columns["label_name"][index] != LABELS[label]:
|
| 75 |
+
raise ValueError(f"label name mismatch: {row_id}")
|
| 76 |
+
rows += 1
|
| 77 |
+
|
| 78 |
+
expected = report["counts"]
|
| 79 |
+
if rows != expected["output_rows"]:
|
| 80 |
+
raise ValueError(f"total row mismatch: {rows} != {expected['output_rows']}")
|
| 81 |
+
if len(ids) != rows:
|
| 82 |
+
raise ValueError(f"unique id mismatch: {len(ids)} != {rows}")
|
| 83 |
+
if len(ids) != expected["output_unique_ids"]:
|
| 84 |
+
raise ValueError(f"reported unique id mismatch: {len(ids)} != {expected['output_unique_ids']}")
|
| 85 |
+
if len(source_ids) != expected["retained_source_ids"]:
|
| 86 |
+
raise ValueError(
|
| 87 |
+
f"source id mismatch: {len(source_ids)} != {expected['retained_source_ids']}"
|
| 88 |
+
)
|
| 89 |
+
print(
|
| 90 |
+
json.dumps(
|
| 91 |
+
{
|
| 92 |
+
"status": "valid",
|
| 93 |
+
"rows": rows,
|
| 94 |
+
"unique_ids": len(ids),
|
| 95 |
+
"source_ids": len(source_ids),
|
| 96 |
+
"shards": len(report["shards"]),
|
| 97 |
+
},
|
| 98 |
+
indent=2,
|
| 99 |
+
)
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
main()
|