copious / run_test.py
amsa02's picture
Upload 2 files
1f4dedc verified
raw
history blame
1.52 kB
"""
Test script to load and verify the converted JSONL dataset.
Author: Amir Safari
Date: 17.10.2025
This script loads the converted JSONL files (train.jsonl, dev.jsonl, test.jsonl)
and verifies they can be properly loaded with the HuggingFace datasets library.
"""
from datasets import load_dataset, Features, Value, Sequence, ClassLabel
print("Attempting to load the converted JSONL dataset...")
# Define all possible NER tags for the dataset
NER_TAGS = [
"O", "B-Taxon", "I-Taxon", "B-Geographical_Location", "I-Geographical_Location",
"B-Habitat", "I-Habitat", "B-Temporal_Expression", "I-Temporal_Expression",
"B-Person", "I-Person",
]
# Manually define the features object for robustness
features = Features({
'id': Value('string'),
'tokens': Sequence(Value('string')),
'ner_tags': Sequence(ClassLabel(names=NER_TAGS))
})
try:
# Load the JSON files directly using the manually defined features
dataset = load_dataset("json", data_files={
"train": "train.jsonl",
"validation": "dev.jsonl",
"test": "test.jsonl"
}, features=features)
print("\n✅ Success! The dataset was loaded correctly.")
print("Here is the loaded dataset info:")
print(dataset)
print("\nHere's the first training example:")
print(dataset["train"][0])
except Exception as e:
print(f"\n❌ An error occurred: {e}")
print("Please make sure the 'train.jsonl', 'dev.jsonl', and 'test.jsonl' files exist.")