def get_rnn_cell(mode,
                 hps,
                 input_dim,
                 num_units,
                 num_layers=1,
                 dropout=0.,
                 mem_input=None,
                 use_beam=False,
                 cell_type="lstm",
                 reuse=None):
  """Construct RNN cells.

  Args:
    mode: train or eval. Keys from tf.estimator.ModeKeys.
    hps: Hyperparameters.
    input_dim: input size.
    num_units: hidden state size.
    num_layers: number of RNN layers.
    dropout: drop rate of RNN dropout.
    mem_input: mem_input
    use_beam: Use beam search or not.
    cell_type: [`lstm`, `hyperlsm`].
    reuse: Reuse option.

  Returns:
    RNN cell.
  """

  cells = []
  for i in xrange(num_layers):
    input_size = input_dim if i == 0 else num_units
    scale = 1.
    if cell_type == "lstm":
      cell = tf.contrib.rnn.LSTMCell(
          num_units=num_units,
          initializer=tf.orthogonal_initializer(scale),
          reuse=reuse)
    elif cell_type == "gru":
      cell = tf.contrib.rnn.GRUCell(
          num_units=num_units,
          kernel_initializer=tf.orthogonal_initializer(scale),
          reuse=reuse)
    elif cell_type == "hyper_lstm":
      cell = HyperLSTMCell(
          num_units=num_units,
          mem_input=mem_input,
          use_beam=use_beam,
          initializer=tf.orthogonal_initializer(scale),
          hps=hps,
          reuse=reuse)
    else:
      assert False
    if mode == tf_estimator.ModeKeys.TRAIN and dropout > 0.:
      cell = tf.nn.rnn_cell.DropoutWrapper(
          cell,
          input_size=input_size,
          output_keep_prob=1.0 - dropout,
          variational_recurrent=True,
          dtype=tf.float32)
    if hps.use_residual and num_layers > 1:
      cell = tf.nn.rnn_cell.ResidualWrapper(cell=cell)
    cells.append(cell)

  cell = tf.nn.rnn_cell.MultiRNNCell(cells)
  return cell
Construct RNN cells.

  Args:
    mode: train or eval. Keys from tf.estimator.ModeKeys.
    hps: Hyperparameters.
    input_dim: input size.
    num_units: hidden state size.
    num_layers: number of RNN layers.
    dropout: drop rate of RNN dropout.
    mem_input: mem_input
    use_beam: Use beam search or not.
    cell_type: [`lstm`, `hyperlsm`].
    reuse: Reuse option.

  Returns:
    RNN cell.
  
language/labs/exemplar_decoding/models/common.py