Update codeforces_question_solution_label.py
Browse files
codeforces_question_solution_label.py
CHANGED
|
@@ -1,57 +1,171 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
| 6 |
"""Codeforces Question Solution Label Dataset."""
|
| 7 |
|
| 8 |
-
# Define supported configurations (language subsets)
|
| 9 |
BUILDER_CONFIGS = [
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
]
|
| 14 |
|
| 15 |
def _info(self):
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
return datasets.DatasetInfo(
|
| 18 |
-
description=
|
| 19 |
-
features=datasets.Features(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
"statement": datasets.Value("string"),
|
| 23 |
-
"tags": datasets.Sequence(datasets.Value("string")),
|
| 24 |
-
"code": datasets.Value("string"),
|
| 25 |
-
"language": datasets.Value("string"),
|
| 26 |
-
}),
|
| 27 |
-
homepage="https://codeforces.com/",
|
| 28 |
-
citation="Data collected from Codeforces API",
|
| 29 |
)
|
| 30 |
|
| 31 |
def _split_generators(self, dl_manager):
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
return [
|
| 38 |
datasets.SplitGenerator(
|
| 39 |
-
name=
|
| 40 |
-
gen_kwargs={"filepath":
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
name=datasets.Split.VALIDATION,
|
| 44 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "validation.jsonl")},
|
| 45 |
-
),
|
| 46 |
-
datasets.SplitGenerator(
|
| 47 |
-
name=datasets.Split.TEST,
|
| 48 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "test.jsonl")},
|
| 49 |
-
),
|
| 50 |
]
|
| 51 |
|
| 52 |
def _generate_examples(self, filepath):
|
| 53 |
-
|
| 54 |
with open(filepath, encoding="utf-8") as f:
|
| 55 |
-
for
|
| 56 |
data = json.loads(row)
|
| 57 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2023 The HuggingFace Datasets Authors.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
# Lint as: python3
|
| 17 |
+
"""Codeforces Question Solution Label Dataset."""
|
| 18 |
+
|
| 19 |
import json
|
| 20 |
+
import os
|
| 21 |
+
import textwrap
|
| 22 |
+
|
| 23 |
+
import datasets
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class CodeforcesConfig(datasets.BuilderConfig):
|
| 27 |
+
"""BuilderConfig for Codeforces Question Solution Label."""
|
| 28 |
+
|
| 29 |
+
def __init__(self, homepage: str = None, citation: str = None, base_path: str = None, paths: dict = None, **kwargs):
|
| 30 |
+
"""BuilderConfig for Codeforces Question Solution Label.
|
| 31 |
+
Args:
|
| 32 |
+
homepage (`str`): Homepage.
|
| 33 |
+
citation (`str`): Citation reference.
|
| 34 |
+
base_path (`str`): Base path for data files.
|
| 35 |
+
paths (`dict`): Data file paths relative to base_path.
|
| 36 |
+
**kwargs: keyword arguments forwarded to super.
|
| 37 |
+
"""
|
| 38 |
+
super().__init__(**kwargs)
|
| 39 |
+
self.homepage = homepage
|
| 40 |
+
self.citation = citation
|
| 41 |
+
self.base_path = base_path
|
| 42 |
+
self.paths = paths
|
| 43 |
+
|
| 44 |
|
| 45 |
class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
| 46 |
"""Codeforces Question Solution Label Dataset."""
|
| 47 |
|
|
|
|
| 48 |
BUILDER_CONFIGS = [
|
| 49 |
+
CodeforcesConfig(
|
| 50 |
+
name="cpp",
|
| 51 |
+
version=datasets.Version("1.0.0"),
|
| 52 |
+
description=textwrap.dedent(
|
| 53 |
+
"Codeforces Question Solution Label Dataset (C++):\n"
|
| 54 |
+
"A dataset containing solutions to Codeforces problems written in C++. Each entry includes the contest ID, "
|
| 55 |
+
"problem ID, problem statement, tags, solution code, and programming language."
|
| 56 |
+
),
|
| 57 |
+
homepage="https://codeforces.com/",
|
| 58 |
+
citation=textwrap.dedent(
|
| 59 |
+
"""\
|
| 60 |
+
@misc{codeforces_solutions,
|
| 61 |
+
author = {AlbertHatsuki},
|
| 62 |
+
title = {Codeforces Question Solution Label Dataset},
|
| 63 |
+
year = {2023},
|
| 64 |
+
publisher = {Hugging Face},
|
| 65 |
+
howpublished = {\\url{https://huggingface.co/datasets/AlbertHatsuki/codeforces-question-solution-label}}
|
| 66 |
+
}"""
|
| 67 |
+
),
|
| 68 |
+
base_path="data/cpp",
|
| 69 |
+
paths={
|
| 70 |
+
datasets.Split.TRAIN: "train.jsonl",
|
| 71 |
+
datasets.Split.VALIDATION: "validation.jsonl",
|
| 72 |
+
datasets.Split.TEST: "test.jsonl",
|
| 73 |
+
},
|
| 74 |
+
),
|
| 75 |
+
CodeforcesConfig(
|
| 76 |
+
name="py",
|
| 77 |
+
version=datasets.Version("1.0.0"),
|
| 78 |
+
description=textwrap.dedent(
|
| 79 |
+
"Codeforces Question Solution Label Dataset (Python):\n"
|
| 80 |
+
"A dataset containing solutions to Codeforces problems written in Python. Each entry includes the contest ID, "
|
| 81 |
+
"problem ID, problem statement, tags, solution code, and programming language."
|
| 82 |
+
),
|
| 83 |
+
homepage="https://codeforces.com/",
|
| 84 |
+
citation=textwrap.dedent(
|
| 85 |
+
"""\
|
| 86 |
+
@misc{codeforces_solutions,
|
| 87 |
+
author = {AlbertHatsuki},
|
| 88 |
+
title = {Codeforces Question Solution Label Dataset},
|
| 89 |
+
year = {2023},
|
| 90 |
+
publisher = {Hugging Face},
|
| 91 |
+
howpublished = {\\url{https://huggingface.co/datasets/AlbertHatsuki/codeforces-question-solution-label}}
|
| 92 |
+
}"""
|
| 93 |
+
),
|
| 94 |
+
base_path="data/py",
|
| 95 |
+
paths={
|
| 96 |
+
datasets.Split.TRAIN: "train.jsonl",
|
| 97 |
+
datasets.Split.VALIDATION: "validation.jsonl",
|
| 98 |
+
datasets.Split.TEST: "test.jsonl",
|
| 99 |
+
},
|
| 100 |
+
),
|
| 101 |
+
CodeforcesConfig(
|
| 102 |
+
name="java",
|
| 103 |
+
version=datasets.Version("1.0.0"),
|
| 104 |
+
description=textwrap.dedent(
|
| 105 |
+
"Codeforces Question Solution Label Dataset (Java):\n"
|
| 106 |
+
"A dataset containing solutions to Codeforces problems written in Java. Each entry includes the contest ID, "
|
| 107 |
+
"problem ID, problem statement, tags, solution code, and programming language."
|
| 108 |
+
),
|
| 109 |
+
homepage="https://codeforces.com/",
|
| 110 |
+
citation=textwrap.dedent(
|
| 111 |
+
"""\
|
| 112 |
+
@misc{codeforces_solutions,
|
| 113 |
+
author = {AlbertHatsuki},
|
| 114 |
+
title = {Codeforces Question Solution Label Dataset},
|
| 115 |
+
year = {2023},
|
| 116 |
+
publisher = {Hugging Face},
|
| 117 |
+
howpublished = {\\url{https://huggingface.co/datasets/AlbertHatsuki/codeforces-question-solution-label}}
|
| 118 |
+
}"""
|
| 119 |
+
),
|
| 120 |
+
base_path="data/java",
|
| 121 |
+
paths={
|
| 122 |
+
datasets.Split.TRAIN: "train.jsonl",
|
| 123 |
+
datasets.Split.VALIDATION: "validation.jsonl",
|
| 124 |
+
datasets.Split.TEST: "test.jsonl",
|
| 125 |
+
},
|
| 126 |
+
),
|
| 127 |
]
|
| 128 |
|
| 129 |
def _info(self):
|
| 130 |
+
features = {
|
| 131 |
+
"contest_id": datasets.Value("string"),
|
| 132 |
+
"problem_id": datasets.Value("string"),
|
| 133 |
+
"statement": datasets.Value("string"),
|
| 134 |
+
"tags": datasets.Sequence(datasets.Value("string")),
|
| 135 |
+
"code": datasets.Value("string"),
|
| 136 |
+
"language": datasets.Value("string"),
|
| 137 |
+
}
|
| 138 |
return datasets.DatasetInfo(
|
| 139 |
+
description=self.config.description,
|
| 140 |
+
features=datasets.Features(features),
|
| 141 |
+
homepage=self.config.homepage,
|
| 142 |
+
citation=self.config.citation,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
def _split_generators(self, dl_manager):
|
| 146 |
+
"""Returns SplitGenerators."""
|
| 147 |
+
dl_paths = {
|
| 148 |
+
split: os.path.join(self.config.base_path, path)
|
| 149 |
+
for split, path in self.config.paths.items()
|
| 150 |
+
}
|
| 151 |
return [
|
| 152 |
datasets.SplitGenerator(
|
| 153 |
+
name=split,
|
| 154 |
+
gen_kwargs={"filepath": dl_paths[split]},
|
| 155 |
+
)
|
| 156 |
+
for split in dl_paths.keys()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
]
|
| 158 |
|
| 159 |
def _generate_examples(self, filepath):
|
| 160 |
+
"""Yields examples."""
|
| 161 |
with open(filepath, encoding="utf-8") as f:
|
| 162 |
+
for row_id, row in enumerate(f):
|
| 163 |
data = json.loads(row)
|
| 164 |
+
yield row_id, {
|
| 165 |
+
"contest_id": data["contest_id"],
|
| 166 |
+
"problem_id": data["problem_id"],
|
| 167 |
+
"statement": data["statement"],
|
| 168 |
+
"tags": data["tags"],
|
| 169 |
+
"code": data["code"],
|
| 170 |
+
"language": data["language"],
|
| 171 |
+
}
|