codeforces-question-solution-label / codeforces_question_solution_label.py
AlbertHatsuki's picture
Upload codeforces_question_solution_label.py
43a35eb verified
raw
history blame
1.71 kB
import datasets
import os
import json
class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="cpp", description="C++ Solutions"),
datasets.BuilderConfig(name="py", description="Python Solutions"),
datasets.BuilderConfig(name="java", description="Java Solultions"),
]
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features({
"contest_id": datasets.Value("string"),
"problem_id": datasets.Value("string"),
"statement": datasets.Value("string"),
"tags": datasets.Sequence(datasets.Value("string")),
"code": datasets.Value("string"),
"language": datasets.Value("string"),
}),
)
def _split_generators(self, dl_manager):
config = self.config.name
data_dir = f"{config}/"
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": os.path.join(data_dir, "train.jsonl")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": os.path.join(data_dir, "validation.jsonl")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": os.path.join(data_dir, "test.jsonl")},
),
]
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as f:
for key, row in enumerate(f):
data = json.loads(row)
yield key, data