java-8m-methods-v2 / java-8m-methods-v2.py
anjandash's picture
added support files
8f4f4fc
raw
history blame
2.19 kB
import os
import sys
import csv
import datasets
csv.field_size_limit(sys.maxsize)
_DESCRIPTION = "Java 8M Methods :: A collection 8 million java methods (Version 2) [PROBE COMPATIBLE]"
_CITATION = "NOT AVAILABLE"
_HOMEPAGE = "NOT AVAILABLE"
_LICENSE = "MIT"
_BASE_TRAIN_FILE_URL = "https://huggingface.co/datasets/anjandash/java-8m-methods-v2/resolve/main/train.csv"
_BASE_VALID_FILE_URL = "https://huggingface.co/datasets/anjandash/java-8m-methods-v2/resolve/main/valid.csv"
_BASE_TEST_FILE_URL = "https://huggingface.co/datasets/anjandash/java-8m-methods-v2/resolve/main/test.csv"
_URLS = {
"train": _BASE_TRAIN_FILE_URL,
"valid": _BASE_VALID_FILE_URL,
"test": _BASE_TEST_FILE_URL
}
class Java8mMethodsV2(datasets.GeneratorBasedBuilder): # or datasets.DatasetBuilder
"""Java 8M Methods (Version 2) [PROBE COMPATIBLE]"""
def _info(self):
"""Returns Info"""
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
}
),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators"""
data_file = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_file["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_file["valid"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_file["test"] }),
]
def _generate_examples(self, filepath):
"""Yields Examples"""
with open(filepath, encoding="utf-8") as f:
reader = csv.reader(f)
for id_, row in enumerate(reader):
if id_ == 0:
continue
yield id_, {
"id": row[0],
"text": row[1],
}