def percent_unique_ngrams_in_train(train_ngrams_dict, gen_ngrams_dict):
  """Compute the percent of ngrams generated by the model that are
  present in the training text and are unique."""

  # *Total* number of n-grams produced by the generator.
  total_ngrams_produced = 0

  for _, value in gen_ngrams_dict.iteritems():
    total_ngrams_produced += value

  # The unique ngrams in the training set.
  unique_ngrams_in_train = 0.

  for key, _ in gen_ngrams_dict.iteritems():
    if key in train_ngrams_dict:
      unique_ngrams_in_train += 1
  return float(unique_ngrams_in_train) / float(total_ngrams_produced)