Datasets:
fix/remove_empty_sample
#3
by
tomaarsen
HF staff
- opened
Hello!
Pull Request overview
- Remove empty sample at the end of the dataset.
Before:
>>> dataset = load_dataset("conll2002", "es")
DatasetDict({
train: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 8324
})
validation: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1916
})
test: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1518
})
})
>>> dataset.filter(lambda sample: not sample["tokens"])
DatasetDict({
train: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1
})
validation: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1
})
test: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1
})
})
After:
>>> dataset = load_dataset("conll2002.py", "es")
DatasetDict({
train: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 8323
})
validation: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1915
})
test: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 1517
})
})
>>> dataset.filter(lambda sample: not sample["tokens"])
Filter: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 8323/8323 [00:00<00:00, 29228.02 examples/s]
Filter: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1915/1915 [00:00<00:00, 32264.91 examples/s]
Filter: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1517/1517 [00:00<00:00, 25711.34 examples/s]
DatasetDict({
train: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 0
})
validation: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 0
})
test: Dataset({
features: ['id', 'tokens', 'pos_tags', 'ner_tags'],
num_rows: 0
})
})
See also https://huggingface.co./datasets/conll2003/blob/main/conll2003.py#L237, this patch has been applied there too.
- Tom Aarsen