Skip to content

Instantly share code, notes, and snippets.

@gaphex
Created November 17, 2019 15:21
Show Gist options
  • Select an option

  • Save gaphex/020de4d695a2b4b577290b9b95f95e79 to your computer and use it in GitHub Desktop.

Select an option

Save gaphex/020de4d695a2b4b577290b9b95f95e79 to your computer and use it in GitHub Desktop.
Read a list of `InputExample`s from a list of strings.
def read_examples(str_list):
"""Read a list of `InputExample`s from a list of strings."""
unique_id = 0
for s in str_list:
line = convert_to_unicode(s)
if not line:
continue
line = line.strip()
text_a = None
text_b = None
m = re.match(r"^(.*) \|\|\| (.*)$", line)
if m is None:
text_a = line
else:
text_a = m.group(1)
text_b = m.group(2)
yield InputExample(unique_id=unique_id, text_a=text_a, text_b=text_b)
unique_id += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment