Skip to content

Instantly share code, notes, and snippets.

@fomkin
Last active November 24, 2019 14:59
Show Gist options
  • Save fomkin/e8553e620c2867eae88e4f8551368c43 to your computer and use it in GitHub Desktop.
Save fomkin/e8553e620c2867eae88e4f8551368c43 to your computer and use it in GitHub Desktop.
def PPR(ref, hyp):
def find_words_before_commas(tokens):
words_before_commas = set()
for i, token in enumerate(tokens):
if token == "," and i > 0:
word = tokens[i-1]
words_before_commas.add(word)
return words_before_commas
hyp_words_before_commas = find_words_before_commas(hyp.split())
ref_words_before_commas = find_words_before_commas(ref.split())
diff = hyp_words_before_commas.symmetric_difference(ref_words_before_commas)
return len(diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment