def encode_map_fn(example):
      """Read example from tfds and constructed named tensor inputs."""
      tensors = tf.py_function(
          encode,
          inp=[
              example['claim_text'], example['evidence_text'],
              example['claim_label'], example['evidence_label'],
              example['metadata'], example['wikipedia_url'],
              example['sentence_id']
          ],
          Tout=(tf.int64, tf.int64, tf.int64, tf.int64, tf.string))
      # Keras expects (x, y), where x can be a dictionary.
      x = {
          'claim_text': tensors[0],
          'evidence_text': tensors[1],
          'claim_label': tensors[2],
          'evidence_label': tensors[3],
          'metadata': tensors[4]
      }
      y = {'claim_classification': tensors[2], 'evidence_matching': tensors[3]}
      return x, y
Read example from tfds and constructed named tensor inputs.
language/serene/preprocessing.py