Skip to content

RNN cells parameter naming inconsistency #13137

Closed

Description

@w4nderlust

In most RNN cells the size is spified by the num_units parameter.
This is true for LSTMCell, LSTMBlockCell and GRUCell.
For GRUBlockCell the same parameter is called cell_size.
This discrepancy could be problematic in some cases like this code I'm using to create a RNN cell depending on a string parameter passed by the user:

def get_cell_fn(cell_type):
    if cell_type == 'rnn':
        cell_fn = tf.nn.rnn_cell.BasicRNNCell
    elif cell_type == 'lstm_basic':
        cell_fn = tf.nn.rnn_cell.BasicLSTMCell
    elif cell_type == 'lstm_basic_ln':
        cell_fn = tf.contrib.rnn.LayerNormBasicLSTMCell
    elif cell_type == 'lstm_block':
        cell_fn = tf.contrib.rnn.LSTMBlockCell
    elif cell_type == 'lstm':
        cell_fn = tf.nn.rnn_cell.LSTMCell
    elif cell_type == 'gru':
        cell_fn = tf.nn.rnn_cell.GRUCell
    elif cell_type == 'gru_block':
        # Faster version of GRU (25% faster in my tests)
        cell_fn = tf.contrib.rnn.GRUBlockCell
    else:
        cell_fn = tf.nn.rnn_cell.BasicRNNCell
    return cell_fn

cell = get_cell_fn(cell_type)(num_units=256)

As this will return an error in case of GRUBlockCell.

The solution is just renaming that parameter and possibly add **kwargs to all cell constructors,as right now only RNNCell has **kwargs.

Activity

  1. yongtang commented on Sep 19, 2017

    @yongtang
    Member

    Added a PR #13153 for num_units in GRUBlockCell.

  2. added
    stat:contribution welcome
    on Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:contribution welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions