def write_flags_to_file(flags, filename):
  """Write hyperparameter settings in flags to a file."""
  task_flags = {
      "num_examples": flags.num_examples,
      "num_sets_per_sequence": flags.num_sets_per_sequence,
      "num_patterns_store": flags.num_patterns_store,
      "pattern_size": flags.pattern_size,
      "selective_task": flags.selective_task,
      "task_name": flags.task_name,
  }

  model_flags = {
      "model_name": flags.model_name,
      "hidden_size": flags.hidden_size,
      "learning_rate": flags.learning_rate,
      "lr_decay_step": flags.lr_decay_step,
      "max_gradient_norm": flags.max_gradient_norm,
      "batch_size": flags.batch_size,
      "num_epochs": flags.num_epochs,
      "fast_steps": flags.fast_steps,
      "fast_decay_rate": flags.fast_decay_rate,
      "fast_lr": flags.fast_lr,
      "use_oja": flags.use_oja,
      "update_mem_with_prev_timestep": flags.update_mem_with_prev_timestep,
      "learn_fast_lr": flags.learn_fast_lr,
      "learn_plasticity_coeffs": flags.learn_plasticity_coeffs,
      "fast_lr_learning_rule": flags.fast_lr_learning_rule,
      "fast_lr_activation": flags.fast_lr_activation
  }

  if not os.path.exists(os.path.dirname(filename)):
    os.makedirs(os.path.dirname(filename))

  with open(filename, "w") as f:
    f.write("=== TASK PARAMS ===\n")
    f.write(json.dumps(task_flags))
    f.write("=== MODEL PARAMS ===\n")
    f.write(json.dumps(model_flags))
Write hyperparameter settings in flags to a file.
language/labs/memory/model_utils.py