|
|
import csv |
|
|
|
|
|
import datasets |
|
|
|
|
|
_DESCRIPTION = "Swedish school lunches." |
|
|
|
|
|
_TRAIN_DOWNLOAD_URL = "./meals.csv" |
|
|
|
|
|
labels = ["FOOD", "NO", "ANY", "SIDE", "MESSAGE", "GENERIC"] |
|
|
|
|
|
|
|
|
class Skolmat(datasets.GeneratorBasedBuilder): |
|
|
def _info(self): |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=datasets.Features( |
|
|
{ |
|
|
"meal": datasets.Value("string"), |
|
|
"label": datasets.features.ClassLabel(names=labels), |
|
|
} |
|
|
), |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL) |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path} |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
|
with open(filepath, encoding="utf8") as csv_file: |
|
|
reader = csv.reader(csv_file) |
|
|
next(reader, None) |
|
|
for i, row in enumerate(reader): |
|
|
(meal, label) = row |
|
|
yield i, { |
|
|
"meal": meal, |
|
|
"label": labels.index(label), |
|
|
} |
|
|
|