-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding arc_easy, arc_challenge, mutual, mutual_plus (#1206)
- Loading branch information
Showing
8 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from dataclasses import dataclass | ||
|
||
from jiant.tasks.lib.templates.shared import labels_to_bimap | ||
from jiant.tasks.lib.templates import multiple_choice as mc_template | ||
from jiant.utils.python.io import read_json_lines | ||
|
||
|
||
@dataclass | ||
class Example(mc_template.Example): | ||
@property | ||
def task(self): | ||
return ArcChallengeTask | ||
|
||
|
||
@dataclass | ||
class TokenizedExample(mc_template.TokenizedExample): | ||
pass | ||
|
||
|
||
@dataclass | ||
class DataRow(mc_template.DataRow): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Batch(mc_template.Batch): | ||
pass | ||
|
||
|
||
class ArcChallengeTask(mc_template.AbstractMultipleChoiceTask): | ||
Example = Example | ||
TokenizedExample = Example | ||
DataRow = DataRow | ||
Batch = Batch | ||
|
||
CHOICE_KEYS = ["A", "B", "C", "D", "E"] | ||
CHOICE_TO_ID, ID_TO_CHOICE = labels_to_bimap(CHOICE_KEYS) | ||
NUM_CHOICES = len(CHOICE_KEYS) | ||
|
||
def get_train_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.train_path), set_type="train") | ||
|
||
def get_val_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.val_path), set_type="val") | ||
|
||
def get_test_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.test_path), set_type="test") | ||
|
||
@classmethod | ||
def _create_examples(cls, lines, set_type): | ||
potential_label_map = { | ||
"1": "A", | ||
"2": "B", | ||
"3": "C", | ||
"4": "D", | ||
"5": "E", | ||
} | ||
NUM_CHOICES = len(potential_label_map) | ||
examples = [] | ||
for i, line in enumerate(lines): | ||
label = line["answerKey"] | ||
if label in potential_label_map: | ||
label = potential_label_map[label] | ||
choice_list = [d["text"] for d in line["question"]["choices"]] | ||
filler_choice_list = ["." for i in range(NUM_CHOICES - len(choice_list))] | ||
choice_list = choice_list + filler_choice_list | ||
assert len(choice_list) == NUM_CHOICES | ||
|
||
examples.append( | ||
Example( | ||
guid="%s-%s" % (set_type, i), | ||
prompt=line["question"]["stem"], | ||
choice_list=choice_list, | ||
label=label, | ||
) | ||
) | ||
return examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from dataclasses import dataclass | ||
|
||
from jiant.tasks.lib.templates.shared import labels_to_bimap | ||
from jiant.tasks.lib.templates import multiple_choice as mc_template | ||
from jiant.utils.python.io import read_json_lines | ||
|
||
|
||
@dataclass | ||
class Example(mc_template.Example): | ||
@property | ||
def task(self): | ||
return ArcEasyTask | ||
|
||
|
||
@dataclass | ||
class TokenizedExample(mc_template.TokenizedExample): | ||
pass | ||
|
||
|
||
@dataclass | ||
class DataRow(mc_template.DataRow): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Batch(mc_template.Batch): | ||
pass | ||
|
||
|
||
class ArcEasyTask(mc_template.AbstractMultipleChoiceTask): | ||
Example = Example | ||
TokenizedExample = Example | ||
DataRow = DataRow | ||
Batch = Batch | ||
|
||
CHOICE_KEYS = ["A", "B", "C", "D", "E"] | ||
CHOICE_TO_ID, ID_TO_CHOICE = labels_to_bimap(CHOICE_KEYS) | ||
NUM_CHOICES = len(CHOICE_KEYS) | ||
|
||
def get_train_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.train_path), set_type="train") | ||
|
||
def get_val_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.val_path), set_type="val") | ||
|
||
def get_test_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.test_path), set_type="test") | ||
|
||
@classmethod | ||
def _create_examples(cls, lines, set_type): | ||
potential_label_map = { | ||
"1": "A", | ||
"2": "B", | ||
"3": "C", | ||
"4": "D", | ||
"5": "E", | ||
} | ||
NUM_CHOICES = len(potential_label_map) | ||
examples = [] | ||
for i, line in enumerate(lines): | ||
label = line["answerKey"] | ||
if label in potential_label_map: | ||
label = potential_label_map[label] | ||
choice_list = [d["text"] for d in line["question"]["choices"]] | ||
filler_choice_list = ["." for i in range(NUM_CHOICES - len(choice_list))] | ||
choice_list = choice_list + filler_choice_list | ||
assert len(choice_list) == NUM_CHOICES | ||
|
||
examples.append( | ||
Example( | ||
guid="%s-%s" % (set_type, i), | ||
prompt=line["question"]["stem"], | ||
choice_list=choice_list, | ||
label=label, | ||
) | ||
) | ||
return examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from dataclasses import dataclass | ||
|
||
from jiant.tasks.lib.templates.shared import labels_to_bimap | ||
from jiant.tasks.lib.templates import multiple_choice as mc_template | ||
from jiant.utils.python.io import read_json_lines | ||
|
||
|
||
@dataclass | ||
class Example(mc_template.Example): | ||
@property | ||
def task(self): | ||
return MutualTask | ||
|
||
|
||
@dataclass | ||
class TokenizedExample(mc_template.TokenizedExample): | ||
pass | ||
|
||
|
||
@dataclass | ||
class DataRow(mc_template.DataRow): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Batch(mc_template.Batch): | ||
pass | ||
|
||
|
||
class MutualTask(mc_template.AbstractMultipleChoiceTask): | ||
Example = Example | ||
TokenizedExample = Example | ||
DataRow = DataRow | ||
Batch = Batch | ||
|
||
CHOICE_KEYS = ["A", "B", "C", "D"] | ||
CHOICE_TO_ID, ID_TO_CHOICE = labels_to_bimap(CHOICE_KEYS) | ||
NUM_CHOICES = len(CHOICE_KEYS) | ||
|
||
def get_train_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.train_path), set_type="train") | ||
|
||
def get_val_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.val_path), set_type="val") | ||
|
||
def get_test_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.test_path), set_type="test") | ||
|
||
@classmethod | ||
def _create_examples(cls, lines, set_type): | ||
examples = [] | ||
for i, line in enumerate(lines): | ||
examples.append( | ||
Example( | ||
guid="%s-%s" % (set_type, i), | ||
prompt=line["article"], | ||
choice_list=[d for d in line["options"]], | ||
label=line["answers"], | ||
) | ||
) | ||
return examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from dataclasses import dataclass | ||
|
||
from jiant.tasks.lib.templates.shared import labels_to_bimap | ||
from jiant.tasks.lib.templates import multiple_choice as mc_template | ||
from jiant.utils.python.io import read_json_lines | ||
|
||
|
||
@dataclass | ||
class Example(mc_template.Example): | ||
@property | ||
def task(self): | ||
return MutualPlusTask | ||
|
||
|
||
@dataclass | ||
class TokenizedExample(mc_template.TokenizedExample): | ||
pass | ||
|
||
|
||
@dataclass | ||
class DataRow(mc_template.DataRow): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Batch(mc_template.Batch): | ||
pass | ||
|
||
|
||
class MutualPlusTask(mc_template.AbstractMultipleChoiceTask): | ||
Example = Example | ||
TokenizedExample = Example | ||
DataRow = DataRow | ||
Batch = Batch | ||
|
||
CHOICE_KEYS = ["A", "B", "C", "D"] | ||
CHOICE_TO_ID, ID_TO_CHOICE = labels_to_bimap(CHOICE_KEYS) | ||
NUM_CHOICES = len(CHOICE_KEYS) | ||
|
||
def get_train_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.train_path), set_type="train") | ||
|
||
def get_val_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.val_path), set_type="val") | ||
|
||
def get_test_examples(self): | ||
return self._create_examples(lines=read_json_lines(self.test_path), set_type="test") | ||
|
||
@classmethod | ||
def _create_examples(cls, lines, set_type): | ||
examples = [] | ||
for i, line in enumerate(lines): | ||
examples.append( | ||
Example( | ||
guid="%s-%s" % (set_type, i), | ||
prompt=line["article"], | ||
choice_list=[d for d in line["options"]], | ||
label=line["answers"], | ||
) | ||
) | ||
return examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters