def unflatten(flat_config):
  """Transforms a flat configuration dictionary into a nested dictionary.

  Example:
    {
      "a": 1,
      "b.c": 2,
      "b.d.e": 3,
      "b.d.f": 4,
    }
  would be transformed to:
    {
      "a": 1,
      "b": {
        "c": 2,
        "d": {
          "e": 3,
          "f": 4,
        }
      }
    }

  Args:
    flat_config: A dictionary with strings as keys where nested configuration
      parameters are represented with period-separated names.

  Returns:
    A dictionary nested according to the keys of the input dictionary.
  """
  config = {}
  for path, value in flat_config.items():
    path = path.split(".")
    final_key = path.pop()
    nested_config = config
    for key in path:
      nested_config = nested_config.setdefault(key, {})
    nested_config[final_key] = value
  return config