nbnn_language_detection / nbnn_language_detection.py
pere's picture
debug
320f200
raw
history blame
1.76 kB
from datasets import DatasetBuilder, DatasetInfo, SplitGenerator
from datasets.features import Features, Value
import json
class NbnnLanguageDetection(DatasetBuilder):
VERSION = "0.1.0"
def _info(self):
print("DEBUG: Inside _info method")
return DatasetInfo(
features=Features({
'text': Value('string'),
'language': Value('string'),
}),
supervised_keys=('text', 'language')
)
def _split_generators(self, dl_manager):
print("DEBUG: Inside _split_generators method")
urls = {
'train': 'https://huggingface.co/datasets/NbAiLab/nbnn_language_detection/resolve/main/train.jsonl',
'dev': 'https://huggingface.co/datasets/NbAiLab/nbnn_language_detection/resolve/main/dev.jsonl',
'test': 'https://huggingface.co/datasets/NbAiLab/nbnn_language_detection/resolve/main/test.jsonl',
}
downloaded_files = dl_manager.download(urls)
print(f"DEBUG: Downloaded files: {downloaded_files}")
return [
SplitGenerator(name=split, gen_kwargs={'filepath': downloaded_files[split]})
for split in urls.keys()
]
def _generate_examples(self, filepath):
print(f"DEBUG: Inside _generate_examples method with filepath: {filepath}")
with open(filepath, 'r') as f:
for id, line in enumerate(f):
print(f"DEBUG: Processing line {id}")
data = json.loads(line)
print(f"DEBUG: Yielding id: {id}, text: {data['text']}, language: {data['language']}")
yield id, {
'text': data['text'],
'language': data['language']
}