Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #6521 and issue #6810 #6808

Merged
merged 5 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions chainer/links/connection/n_step_lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ class NStepLSTM(NStepLSTMBase):

.. seealso::
:func:`chainer.functions.n_step_lstm`

.. admonition:: Example

>>> '''Read forward() method below first'''
>>> import chainer
>>> from chainer import Variable
>>> from chainer import links as L
>>> import numpy as np
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports are done here.

>>> chainer.global_config.dtype = np.float64 # setting default tenspr dtype.
>>> dropout_ratio = 0.0
>>> in_size , seq_len, n_layers, out_size = 2, 4, 2, 3
>>> batch = 5
>>> xs = [Variable(np.random.rand(seq_len, in_size)) for i in range(batch)]
>>> [x.shape for x in xs]
[(4, 2), (4, 2), (4, 2), (4, 2), (4, 2)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would present general usage to give xs with different sequence lengths.

>>> lstm = L.NStepLSTM(n_layers, in_size, out_size, dropout_ratio)
>>> hy, cy, ys = lstm(None, None, xs) # passing no hidden or cell state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style requires two space before # that starts a comment

Suggested change
>>> hy, cy, ys = lstm(None, None, xs) # passing no hidden or cell state
>>> hy, cy, ys = lstm(None, None, xs) # passing no hidden or cell state

>>> hy.shape # shape should be (n_layers, batch, out_size)
(2, 5, 3)
>>> ys[0].shape # should be (seq_len, out_size)
(4, 3)
>>> len(ys) # should be equal to batch
5
>>> h_shape = (n_layers, batch, out_size)
>>> hx = Variable(np.ones(h_shape))
>>> cx = Variable(np.ones(h_shape))
>>> hy, cy, ys = lstm(hx, cx, xs) # passing hidden and cell state
>>> hy.shape # shape should be (n_layers, batch, out_size)
(2, 5, 3)
>>> ys[0].shape # should be (seq_len, out_size)
(4, 3)

"""

Expand Down
4 changes: 2 additions & 2 deletions chainer/links/connection/n_step_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def forward(self, hx, xs, **kwargs):
the hidden units.
xs (list of :class:`~chainer.Variable`): List of input sequences.
Each element ``xs[i]`` is a :class:`chainer.Variable` holding
a sequence. Its shape is ``(L_i, I)``, where ``L_t`` is the
a sequence. Its shape is ``(L_i, I)``, where ``L_i`` is the
length of a sequence for batch ``i``, and ``I`` is the size of
the input and is equal to ``in_size``.

Expand All @@ -156,7 +156,7 @@ def forward(self, hx, xs, **kwargs):
``ys[i]`` holds hidden states of the last layer corresponding
to an input ``xs[i]``. Its shape is ``(L_i, N)`` for
uni-directional RNN and ``(L_i, 2N)`` for bi-directional RNN
where ``L_t`` is the length of a sequence for batch ``i``,
where ``L_i`` is the length of a sequence for batch ``i``,
and ``N`` is size of hidden units.
"""
(hy,), ys = self._call([hx], xs, **kwargs)
Expand Down