Skip to content

Feature suggestion: expose weights for RNNCell #812

Closed

Description

@alquraishi

I realize that the API for RNNs hasn't been finalized yet but eventually it would be nice if the weights of the RNNCell are exposed so that they can be tracked using the summary ops like histogram_summary. Maybe just a property that returns all the internal weights.

Activity

  1. rafaljozefowicz commented on Jan 19, 2016

    @rafaljozefowicz

    You can already retrieve the weights easily with variable scope, e.g.:

    cell = RNNCell(...)
    with tf.variable_scope("RNN") as vs:
      # use cell here.
      for var in tf.trainable_variables():
        if var.name.startswith(vs.name):
          print var.name, var.get_shape()
          tf.histogram_summary(var.name, var)
    
  2. alquraishi commented on Jan 19, 2016

    @alquraishi
    Author

    This strikes me as a very hacky solution.

  3. rafaljozefowicz commented on Jan 19, 2016

    @rafaljozefowicz

    If you just need histogram summaries for all the variables, then you don't need to use it in any specific variable scopes:

    for var in tf.trainable_variables():
      tf.histogram_summary(var.name, var)
    
  4. alquraishi commented on Jan 19, 2016

    @alquraishi
    Author

    That's a nice way to track everything, thanks. My initial point wasn't that it's impossible, but that it would be useful to provide a convenient mechanism to get at the variables for a specific cell.

  5. rafaljozefowicz commented on Jan 19, 2016

    @rafaljozefowicz

    Yes, I understand. For common use cases this doesn't seem to be needed .. and you can always use variable scope to get specific variables, like: rnn_matrix = tf.get_variable(vs.name + "/Matrix") but you need to be in the proper scope and know the names.

    With the current design, the rnn cells are not associated with any specific variables (and are stateless) unless in a specific variable scope so having properties to keep references to them sounds hacky as well.

  6. alquraishi commented on Jan 19, 2016

    @alquraishi
    Author

    Ok. Thanks for clarifying.

  7. ziofil commented on Jan 28, 2018

    @ziofil

    Two years later now. Is there a better solution or should we still use the code in @rafaljozefowicz 's example?

  8. matthijsvk commented on Apr 4, 2018

    @matthijsvk

    I'm looking for a better solution to this as well

  9. AzizCode92 commented on Nov 21, 2018

    @AzizCode92

    In tensorboard, if you use the LSTMCell class of tensorflow you can visualize the kernel variable in tensorboard.
    You can instead define your weights in the call method. By saying weights I mean the W_xh and W_hh.

    W_xh = tf.get_variable('W_xh',
    				[x_size, 4 * self.num_units], initializer=w_init)
    
    W_hh = tf.get_variable('W_hh_i',
    				[self.num_units, 4*self.num_units], initializer=h_init)
    
    

    and then during training, you add

    for var in tf.trainable_variables():
      tf.histogram_summary(var.name, var)
    
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions