def _get_assignment_map_from_checkpoint(tvars, init_checkpoint,
                                        reinitialize_type_embeddings):
  """Compute the intersection of the current variables and checkpoint variables."""
  initialized_variable_names = {}

  name_to_variable = {}
  for var in tvars:
    name = var.name

    # This does not load the token type embeddings from BERT, and will force
    # re-initialization.
    if reinitialize_type_embeddings and "token_type_embeddings" in name:
      continue

    m = re.match("^(.*):\\d+$", name)
    if m is not None:
      name = m.group(1)
    name_to_variable[name] = var

  init_vars = tf.train.list_variables(init_checkpoint)

  assignment_map = collections.OrderedDict()
  for x in init_vars:
    (name, var) = (x[0], x[1])
    if name not in name_to_variable:
      continue
    assignment_map[name] = name
    initialized_variable_names[name] = 1
    initialized_variable_names[name + ":0"] = 1

  return (assignment_map, initialized_variable_names)
Compute the intersection of the current variables and checkpoint variables.
language/xsp/model/load_from_checkpoint.py