code: def save_model(directory, model, vocab):
      """Saves a model to a given directory.
  
      Args:
          directory (str): Path to a directory where you store a model.
          model (chainer.Chain): Model to store.
          vocab (dict): Vocaburaly dictionary.
  
      """
      encoder = model.predictor.encoder
      if encoder == bow_encode:
          sentence_repr = "bow"
      elif encoder == position_encode:
          sentence_repr = "pe"
      else:
          raise ValueError(
              "Cannot serialize encoder: %s" % str(encoder)
          )
  
      os.makedirs(directory, exist_ok=True)
      parameters = {
          "unit": model.predictor.n_units,
          "hop": model.predictor.hops,
          "max_memory": model.predictor.max_memory,
          "sentence_repr": sentence_repr,
          "vocabulary": vocab,
      }
      with open(os.path.join(directory, "parameter.json"), "w") as f:
          json.dump(parameters, f)
      chainer.serializers.save_npz(
          os.path.join(directory, "model.npz"), model
      )
  
imports: import collections
  import json
  import os
  import numpy
  import six
  import chainer
  from chainer import backend
  import chainer.functions
  from chainer import initializers
  import chainer.links
  import babi
label_desc: Use image node_id 5 for calling a global function with example usage: save_model(directory, model, vocab) without return types