isco_esco_occupations_taxonomy / isco_esco_occupations_taxonomy.py
Daniel Duckworth
checkpoint
d2c5b2b
from typing import List
from datasets.tasks import QuestionAnsweringExtractive, LanguageModeling, MaskedLM, MultipleChoice, TextClassification, TextToTextGeneration
import pandas as pd
import datasets
import os
logger = datasets.logging.get_logger(__name__)
CITATION = """TBA"""
_DESCRIPTION = """\
ISCO ESCO Occupations Taxonomy Dataset (IEOTD) is a hierarhical \
taxonomy dataset, consisting of occupation groups from ISCO, \
occupations from ESCO and definitions.
"""
# TODO: Update license based on ILO and ESCO
LICENSE = """\
By accessing ISCO ESCO Occupations Taxonomy Dataset, you indicate that you agree to the terms and conditions associated with their use. Please read the IEA Disclaimer and License Agreement for full details. [Disclaimer_and_License_Agreement.pdf (iea.nl)](https://www.iea.nl/sites/default/files/data-repository/Disclaimer_and_License_Agreement.pdf)
"""
HOMEPAGE_URL = "https://iea.nl"
_URL = "/"
_URLS = {
"full": _URL + "data/data.parquet",
}
class IscoEscoTaxonomyConfig(datasets.BuilderConfig):
"""BuilderConfig for ISCO ESCO Taxonomy."""
def __init__(self, **kwargs):
"""BuilderConfig for SQUAD.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(IscoEscoTaxonomyConfig, self).__init__(**kwargs)
class IscoEscoTaxonomy(datasets.GeneratorBasedBuilder):
"""The ISCO ESCO Occupations Taxonomy Dataset v1.0.0"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="isco_1-2",
version=datasets.Version("1.0.0", ""),
description="ISCO hierarchy levels 1-2",
),
]
BUILDER_CONFIG_CLASS = IscoEscoTaxonomyConfig
DEFAULT_CONFIG_NAME = "default"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"entailment": datasets.features.Sequence(
{
"ISCO_DEFINITION_1": datasets.Value("string"),
"ISCO_CODE_1": datasets.ClassLabel(names_file="labels/isco_code_1.txt"),
"ISCO_LABEL_1": datasets.Value("string"),
"ESCO_DESCRIPTION": datasets.Value("string"),
}
),
}
),
)
def _info(self):
cwd=os.getcwd()
script_dir = os.path.join(cwd)
return datasets.DatasetInfo(
description="The ISCO ESCO Occupations Taxonomy Dataset",
citation=CITATION,
homepage=HOMEPAGE_URL,
license=LICENSE,
builder_name="isco_esco_occupations",
supervised_keys=None,
task_templates=[
TextClassification(task="text-classification", text_column="ESCO_DESCRIPTION", label_column="ESCO_OCCUPATION"),
# TaskTemplate("text-to-text", text_column="ESCO_DESCRIPTION", summary_column="ESCO_OCCUPATION"),
],
features=Features({
"ISCO_CODE_1": ClassLabel(names_file=os.path.join(cwd, "../", "isco_esco_occupations_taxonomy", "labels", "isco_code_1.txt")),
# "ISCO_CODE_1": ClassLabel(names_file=os.path.join(script_dir, "../", "isco_esco_occupations_taxonomy", "labels", "isco_code_1.txt")),
"ISCO_LABEL_1": ClassLabel(names_file="labels/isco_label_1.txt"),
"ISCO_DEFINITION_1": Value("string"),
"ISCO_CODE_2": ClassLabel(names_file="labels/isco_code_2.txt"),
"ISCO_LABEL_2": ClassLabel(names_file="labels/isco_label_2.txt"),
"ISCO_DEFINITION_2": Value("string"),
"ISCO_CODE_3": ClassLabel(names_file="labels/isco_code_3.txt"),
"ISCO_LABEL_3": ClassLabel(names_file="labels/isco_label_3.txt"),
"ISCO_DEFINITION_3": Value("string"),
"ISCO_CODE_4": ClassLabel(names_file="labels/isco_code_4.txt"),
"ISCO_LABEL_4": ClassLabel(names_file="labels/isco_label_4.txt"),
"ISCO_DEFINITION_4": Value("string"),
"ISCO_CODES": ClassLabel(names_file="labels/isco_codes.txt"),
"ISCO_LABELS": ClassLabel(names_file="labels/isco_labels.txt"),
"ESCO_CODE": ClassLabel(names_file="labels/esco_code.txt"),
"ESCO_LABELS": ClassLabel(names_file="labels/esco_labels.txt"),
"ESCO_OCCUPATION": ClassLabel(names_file="labels/esco_occupation.txt"),
"ESCO_DESCRIPTION": Value("string"),
"LANGUAGE": ClassLabel(names_file="labels/language.txt"),
'isco1': Sequence(
feature={
'ISCO_DEFINITION_1': Value(dtype='large_string'),
'ISCO_CODE_1': ClassLabel(names_file="labels/isco_code_1.txt"),
'ISCO_LABEL_1': ClassLabel(names_file="labels/isco_label_1.txt")
}
)
}))
def _split_generators(self, dl_manager: DownloadManager) -> List[SplitGenerator]:
isco_esco_all = dl_manager.download_and_extract(DOWNLOAD_URL)
return [
SplitGenerator(name=datasets.Split.ALL, gen_kwargs={"filepaths": isco_esco_all}),
]
def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
logger.info("generating examples from = %s", filepath)
df = pd.read_parquet(filepath)
for i, row in df.iterrows():
yield i, row.to_dict()