|
"""TODO(social_i_qa): Add a description here.""" |
|
|
|
from __future__ import absolute_import, division, print_function |
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """ |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
We introduce Social IQa: Social Interaction QA, a new question-answering benchmark for testing social commonsense intelligence. Contrary to many prior benchmarks that focus on physical or taxonomic knowledge, Social IQa focuses on reasoning about people’s actions and their social implications. For example, given an action like "Jesse saw a concert" and a question like "Why did Jesse do this?", humans can easily infer that Jesse wanted "to see their favorite performer" or "to enjoy the music", and not "to see what's happening inside" or "to see if it works". The actions in Social IQa span a wide variety of social situations, and answer candidates contain both human-curated answers and adversarially-filtered machine-generated candidates. Social IQa contains over 37,000 QA pairs for evaluating models’ abilities to reason about the social implications of everyday events and situations. (Less) |
|
""" |
|
_URL = "https://storage.googleapis.com/ai2-mosaic/public/socialiqa/socialiqa-train-dev.zip" |
|
|
|
|
|
class SocialIQa(datasets.GeneratorBasedBuilder): |
|
"""TODO(social_i_qa): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("0.1.0") |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
|
|
"context": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"answerA": datasets.Value("string"), |
|
"answerB": datasets.Value("string"), |
|
"answerC": datasets.Value("string"), |
|
"label": datasets.Value("string"), |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://leaderboard.allenai.org/socialiqa/submissions/get-started", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
dl_dir = os.path.join(dl_dir, "socialiqa-train-dev") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(dl_dir, "train.jsonl"), |
|
"labelpath": os.path.join(dl_dir, "train-labels.lst"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(dl_dir, "dev.jsonl"), |
|
"labelpath": os.path.join(dl_dir, "dev-labels.lst"), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, labelpath): |
|
"""Yields examples.""" |
|
|
|
with open(labelpath, encoding="utf-8") as f: |
|
labels = [label.strip() for label in f] |
|
with open(filepath, encoding="utf-8") as f1: |
|
for id_, row in enumerate(f1): |
|
data = json.loads(row) |
|
label = labels[id_] |
|
context = data["context"] |
|
answerA = data["answerA"] |
|
answerB = data["answerB"] |
|
answerC = data["answerC"] |
|
question = data["question"] |
|
yield id_, { |
|
"context": context, |
|
"question": question, |
|
"answerA": answerA, |
|
"answerB": answerB, |
|
"answerC": answerC, |
|
"label": label, |
|
} |
|
|