Datasets:
Tasks:
Text Classification
Sub-tasks:
sentiment-classification
Languages:
English
Size:
1K - 10K
License:
# coding=utf-8 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# Lint as: python3 | |
"""ETPC: The Extended Typology Paraphrase Corpus""" | |
import os | |
from typing import Dict, Generator, Any, Union, Optional, List, Tuple | |
import datasets | |
from datasets.tasks import TextClassification | |
from lxml import etree | |
logger = datasets.logging.get_logger(__name__) | |
_CITATION = """\ | |
@inproceedings{kovatchev-etal-2018-etpc, | |
title = "{ETPC} - A Paraphrase Identification Corpus Annotated with Extended Paraphrase Typology and Negation", | |
author = "Kovatchev, Venelin and | |
Mart{\'\i}, M. Ant{\`o}nia and | |
Salam{\'o}, Maria", | |
booktitle = "Proceedings of the Eleventh International Conference on Language Resources and Evaluation ({LREC} 2018)", | |
month = may, | |
year = "2018", | |
address = "Miyazaki, Japan", | |
publisher = "European Language Resources Association (ELRA)", | |
url = "https://aclanthology.org/L18-1221", | |
} | |
""" | |
_DESCRIPTION = """\ | |
The EPT typology addresses several practical limitations of existing paraphrase typologies: it is the first typology that copes with the non-paraphrase pairs in the paraphrase identification corpora and distinguishes between contextual and habitual paraphrase types. ETPC is the largest corpus to date annotated with atomic paraphrase types. | |
""" | |
_HOMEPAGE = "https://github.com/venelink/ETPC" | |
_LICENSE = "Unknown" | |
_URLS = [ | |
"https://raw.githubusercontent.com/venelink/ETPC/master/Corpus/text_pairs.xml", | |
"https://raw.githubusercontent.com/venelink/ETPC/master/Corpus/textual_paraphrases.xml", | |
] | |
class Sst2(datasets.GeneratorBasedBuilder): | |
"""SST-2 dataset.""" | |
VERSION = datasets.Version("2.0.0") | |
def _info(self): | |
features = datasets.Features( | |
{ | |
"idx": datasets.Value("int32"), | |
"sentence1": datasets.Value("string"), | |
"sentence2": datasets.Value("string"), | |
"etpc_label": datasets.Value("int8"), | |
"mrpc_label": datasets.Value("int8"), | |
"negation": datasets.Value("int8"), | |
"paraphrase_types": datasets.Value("string"), | |
} | |
) | |
return datasets.DatasetInfo( | |
description=_DESCRIPTION, | |
features=features, | |
homepage=_HOMEPAGE, | |
license=_LICENSE, | |
citation=_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
dl_dir = dl_manager.download_and_extract(_URLS) | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
gen_kwargs={ | |
"file_paths": dl_manager.iter_files(dl_dir), | |
}, | |
), | |
] | |
def _generate_examples(self, file_paths): | |
file_paths = list(file_paths) | |
text_pairs_path = file_paths[0] | |
paraphrase_types_path = file_paths[1] | |
parser = etree.XMLParser(encoding="utf-8", recover=True) | |
tree_text_pairs = etree.parse(text_pairs_path, parser=parser) | |
tree_paraphrase_types = etree.parse(paraphrase_types_path, parser=parser) | |
root_text_pairs = tree_text_pairs.getroot() | |
root_paraphrase_types = tree_paraphrase_types.getroot() | |
for idx, row in enumerate(root_text_pairs): | |
children = row.getchildren() | |
current_pair_id = row.find(".//pair_id").text | |
paraphrase_types = root_paraphrase_types.xpath( | |
f".//pair_id[text()='{current_pair_id}']/parent::relation/type_name/text()" | |
) | |
str_paraphrase_types = ",".join(paraphrase_types) | |
yield idx, { | |
"idx": int(row.find(".//pair_id").text) | |
if row.find(".//pair_id") is not None | |
else int(idx), | |
"sentence1": row.find(".//sent1_raw").text, | |
"sentence2": row.find(".//sent2_raw").text, | |
"etpc_label": int(row.find(".//etpc_label").text), | |
"mrpc_label": int(row.find(".//mrpc_label").text), | |
"negation": int(row.find(".//negation").text), | |
"paraphrase_types": str_paraphrase_types, | |
} | |