def generate_symbolic_data(num_pairs):
  """Generates a sequence of key-value pairs followed by a query key.

  Args:
    num_pairs (int): Number of pairs

  Returns:
    seq_text (str): Sequence of kv pairs, followed by a ?,
      followed by the query key.
    seq_encoded (numpy arr): Sequence of kv pairs, encoded into vocab indices.
    target_val (str): Digit, the value we expect to retrieve for the key.
    target_val_encoded (int): Encoded target_val
    target_idx (int): The index into the list of pairs for the target
  """
  pairs = zip(
      np.random.choice(list(string.ascii_lowercase), num_pairs, replace=False),
      np.random.choice(list("0123456789"), num_pairs)
  )

  vocab = get_symbolic_vocab()

  # Choose a query key
  target_idx = random.choice(range(num_pairs))
  target_key, target_val_text = pairs[target_idx]
  target_val_encoded = vocab.index(target_val_text)

  seq_text = "".join([k + v for k, v in pairs]) + "?" + target_key
  seq_encoded = [vocab.index(char) for char in seq_text]

  return seq_text, seq_encoded, target_val_text, target_val_encoded, target_idx
Generates a sequence of key-value pairs followed by a query key.

  Args:
    num_pairs (int): Number of pairs

  Returns:
    seq_text (str): Sequence of kv pairs, followed by a ?,
      followed by the query key.
    seq_encoded (numpy arr): Sequence of kv pairs, encoded into vocab indices.
    target_val (str): Digit, the value we expect to retrieve for the key.
    target_val_encoded (int): Encoded target_val
    target_idx (int): The index into the list of pairs for the target
  
language/labs/memory/synthetic_dataset.py