def get_dictionary_from_flags(params, input_flags):
  """Generate dictionary from non-null flags.

  Args:
    params: Python dictionary of model parameters.
    input_flags: All the flags with non-null value of overridden model
    parameters.

  Returns:
    Python dict of overriding model parameters.
  """
  if not isinstance(params, dict):
    raise ValueError('The base parameter set must be a dict. '
                     'Was: {}'.format(type(params)))
  flag_dict = {}
  for k, v in params.items():
    if isinstance(v, dict):
      d = get_dictionary_from_flags(v, input_flags)
      flag_dict[k] = d
    else:
      try:
        flag_value = input_flags.get_flag_value(k, None)
        if flag_value is not None:
          flag_dict[k] = flag_value
      except AttributeError:
        flag_dict[k] = v

  return flag_dict