def to_tydi_example(entry: Mapping[Text, Any],
                    is_training: bool) -> TyDiExample:
  """Converts a TyDi 'entry' from `create_entry_from_json` to `TyDiExample`."""

  if is_training:
    answer = make_tydi_answer(entry["contexts"], entry["answer"])
    start_byte_offset = answer.offset
    end_byte_offset = answer.offset + byte_len(answer.text)
  else:
    answer = None
    start_byte_offset = None
    end_byte_offset = None

  return TyDiExample(
      example_id=int(entry["id"]),
      language_id=get_language_id(entry["language"]),
      question=entry["question"]["input_text"],
      contexts=entry["contexts"],
      plaintext=entry["plaintext"],
      context_to_plaintext_offset=entry["context_to_plaintext_offset"],
      answer=answer,
      start_byte_offset=start_byte_offset,
      end_byte_offset=end_byte_offset)
Converts a TyDi 'entry' from `create_entry_from_json` to `TyDiExample`.
language/canine/tydiqa/data.py