Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions t5/data/glue_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def get_glue_postprocess_fn(builder_config):
return functools.partial(
postprocessors.string_label_to_class_id,
label_classes=builder_config.label_classes,
use_default=False,
)

GLUE_METRICS = collections.OrderedDict([
Expand Down
6 changes: 5 additions & 1 deletion t5/data/postprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ def lower_text(string, **unused_kwargs):
def string_label_to_class_id(string_label,
label_classes,
default=-1,
use_default=True,
**unused_kwargs):
"""Returns index of string_label in label_classes or default if not found."""
if string_label in label_classes:
return label_classes.index(string_label)
else:
return default
if use_default:
return default
else:
return string_label


def multirc(string_label, example=None, is_target=False):
Expand Down
2 changes: 2 additions & 0 deletions t5/data/postprocessors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def test_string_label_to_class_id(self):
self.assertEqual(postprocessors.string_label_to_class_id("two", cls), 1)
self.assertEqual(postprocessors.string_label_to_class_id("foo", cls), -1)
self.assertEqual(postprocessors.string_label_to_class_id("foo", cls, 2), 2)
self.assertEqual(postprocessors.string_label_to_class_id(
"foo", cls, use_default=False), "foo")

def test_multirc(self):
self.assertDictEqual(
Expand Down