def _tokenize_with_entity_markers(tokens, tokenizer, e1, e2):
  """Apply wordpiece tokenization with entity markers around entities."""

  def tokenize(start, end):
    return tokenizer.tokenize(" ".join(tokens[start:end]))

  if e1[0] < e2[0]:
    return (tokenize(0, e1[0]) + ["[E1]"] + tokenize(e1[0], e1[1] + 1) +
            ["[/E1]"] + tokenize(e1[1] + 1, e2[0]) + ["[E2]"] +
            tokenize(e2[0], e2[1] + 1) + ["[/E2]"] + tokenize(e2[1] + 1, None))
  else:
    return (tokenize(0, e2[0]) + ["[E2]"] + tokenize(e2[0], e2[1] + 1) +
            ["[/E2]"] + tokenize(e2[1] + 1, e1[0]) + ["[E1]"] +
            tokenize(e1[0], e1[1] + 1) + ["[/E1]"] + tokenize(e1[1] + 1, None))
Apply wordpiece tokenization with entity markers around entities.
language/relation_learning/data/fewrel.py