{"action":"closed","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2779","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2779/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2779/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2779/events","html_url":"https://github.com/tensorflow/tensorflow/issues/2779","id":159600143,"number":2779,"title":"dynamic_rnn execution with EmbeddingWrapper","user":{"login":"lhlmgr","id":400331,"avatar_url":"https://avatars.githubusercontent.com/u/400331?v=3","gravatar_id":"","url":"https://api.github.com/users/lhlmgr","html_url":"https://github.com/lhlmgr","followers_url":"https://api.github.com/users/lhlmgr/followers","following_url":"https://api.github.com/users/lhlmgr/following{/other_user}","gists_url":"https://api.github.com/users/lhlmgr/gists{/gist_id}","starred_url":"https://api.github.com/users/lhlmgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lhlmgr/subscriptions","organizations_url":"https://api.github.com/users/lhlmgr/orgs","repos_url":"https://api.github.com/users/lhlmgr/repos","events_url":"https://api.github.com/users/lhlmgr/events{/privacy}","received_events_url":"https://api.github.com/users/lhlmgr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tensorflow/tensorflow/labels/triaged","name":"triaged","color":"c2e0c6"}],"state":"closed","locked":false,"assignee":{"login":"ebrevdo","id":1794715,"avatar_url":"https://avatars.githubusercontent.com/u/1794715?v=3","gravatar_id":"","url":"https://api.github.com/users/ebrevdo","html_url":"https://github.com/ebrevdo","followers_url":"https://api.github.com/users/ebrevdo/followers","following_url":"https://api.github.com/users/ebrevdo/following{/other_user}","gists_url":"https://api.github.com/users/ebrevdo/gists{/gist_id}","starred_url":"https://api.github.com/users/ebrevdo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebrevdo/subscriptions","organizations_url":"https://api.github.com/users/ebrevdo/orgs","repos_url":"https://api.github.com/users/ebrevdo/repos","events_url":"https://api.github.com/users/ebrevdo/events{/privacy}","received_events_url":"https://api.github.com/users/ebrevdo/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2016-06-10T09:56:04Z","updated_at":"2016-06-20T13:12:21Z","closed_at":"2016-06-20T13:12:21Z","body":"Hi Guys,\r\n\r\nI'm currently working on a sequence to sequence model for sequences with variable length. Instead of using buckets (like in the example of seq2seq) I used the `rnn.dynamic_rnn` function. But when I use an EmbeddingWrapper around my RNNCell I'll get exceptions because of two reasons:\r\n\r\n- EmbeddingWrapper doesn't implement the derived property `def output_size(self):` (used in the function `dynamic_rnn`)\r\n\r\n- Since I want to use word embeddings and `dynamic_rnn`, my input has the datatype `tf.int32` (like in the seq2seq example) and shape (batch_size, n_steps, 1). But then I get following error: \r\n\r\n> ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor(\"RNN/while/BasicRNNCell/Tanh:0\", shape=(3, 4), dtype=float32)'\r\n\r\nSince I'm new to tensorflow I don't know whats the best way to fix this issue. However, If I change the datatype of the input to `tf.float32` and the modify EmbeddingWrapper class as follows it works.\r\n\r\n```\r\nclass EmbeddingWrapper(RNNCell):\r\n    if not isinstance(cell, RNNCell):\r\n      raise TypeError(\"The parameter cell is not RNNCell.\")\r\n    if embedding_classes <= 0 or embedding_size <= 0:\r\n      raise ValueError(\"Both embedding_classes and embedding_size must be > 0: \"\r\n                       \"%d, %d.\" % (embedding_classes, embedding_size))\r\n    self._cell = cell\r\n    self._embedding_classes = embedding_classes\r\n    self._embedding_size = embedding_size\r\n    self._initializer = initializer\r\n\r\n  @property\r\n  def state_size(self):\r\n    return self._cell.state_size\r\n\r\n  @property\r\n  def output_size(self):\r\n    return self._cell.output_size\r\n\r\n  def __call__(self, inputs, state, scope=None):\r\n    inputs = tf.cast(inputs, tf.int32) # <<<< if I cast the input (tf.float32) to tf.int32 it works\r\n\r\n    with vs.variable_scope(scope or type(self).__name__):  # \"EmbeddingWrapper\"\r\n      with ops.device(\"/cpu:0\"):\r\n        if self._initializer:\r\n          initializer = self._initializer\r\n        elif vs.get_variable_scope().initializer:\r\n          initializer = vs.get_variable_scope().initializer\r\n        else:\r\n          # Default initializer for embeddings should have variance=1.\r\n          sqrt3 = math.sqrt(3)  # Uniform(-sqrt(3), sqrt(3)) has variance=1.\r\n          initializer = init_ops.random_uniform_initializer(-sqrt3, sqrt3)\r\n        embedding = vs.get_variable(\"embedding\", [self._embedding_classes,\r\n                                                  self._embedding_size],\r\n                                    initializer=initializer)\r\n        embedded = embedding_ops.embedding_lookup(\r\n            embedding, array_ops.reshape(inputs, [-1]))\r\n    return self._cell(embedded, state)\r\n```\r\n\r\nI attached a simple working example: [simplernn.txt](https://github.com/tensorflow/tensorflow/files/308766/simplernn.txt)\r\n\r\nMy Environment:\r\n- Ubuntu 16.04, installed tensorflow 0.9rc0 over pip, python 3.5.1\r\n\r\nThanks in advance!"}}
{"actor":{"display_login":"lhlmgr"}}