Repository: chainer/chainer

Issue:
NStepBi_xxx 's behaviour is inconsistent with the document
I am using Chainer version: 2.0.0

Documents of NStepBi_xxx (like [this](https://docs.chainer.org/en/stable/reference/functions.html#chainer.functions.n_step_bilstm)) says that the variables like `hx` (argument of the function) and `hy` (value returned by the function) have the shape such that `(S, B, N) where S is number of layers and is equal to n_layers, B is mini-batch size, and N is dimention of hidden units.` 

However, the actual shape returned by the function is inconsistent with the document.
For example:

```
x = chainer.Variable(np.random.randn(1,5).astype('f'))
l1 = L.NStepBiLSTM(n_layers=2, in_size=5, out_size=5, dropout=0.0)
h, c, hx = l1(None, None, [x])
print(h.shape) # (S=4,B=1,N=5), thus S != n_layers
```

The actual shape is twice the value of `n_layers` (as it is bi-directional). 
Thus I guess that the document should be fixed.

This inconsistency might be due to the difference between the `L.NStepBiLSTM` and `F.n_step_bilstm`. Still, it should be noted on the document of `L.NStepBiLSTM`.


Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions.

L.NStepBiLSTM have bug, I encounter in running output size of L.NStepBiLSTM   is 2 x I pass out_size
@butsugiri 

Thank you for your report.
I agree that the document should be fixed. I will fix it.
@sharpstill 

Do you mean that output size of L.NStepBiLSTM is  2 x out_size? 
(e.g.,)
```
x = chainer.Variable(np.random.randn(1,5).astype('f'))
l1 = L.NStepBiLSTM(n_layers=2, in_size=5, out_size=5, dropout=0.0)
h, c, hx = l1(None, None, [x])
print([_.shape for _ in hx]) # [(1, 10)]   # (1, 2 x 5)
```

I think the output size should be concatenated by the hidden vector. 

Resolving patch:
diff --git a/chainer/functions/connection/n_step_gru.py b/chainer/functions/connection/n_step_gru.py
--- a/chainer/functions/connection/n_step_gru.py
+++ b/chainer/functions/connection/n_step_gru.py
@@ -79,7 +79,7 @@ def n_step_gru(
         hx (chainer.Variable): Variable holding stacked hidden states.
             Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i]``
             represents weights for i-th layer.
             Each ``ws[i]`` is a list containing six matrices.
@@ -91,7 +91,7 @@ def n_step_gru(
             represnents biases for i-th layer.
             Each ``bs[i]`` is a list containing six vectors.
             ``bs[i][j]`` is corresponding with ``b_j`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value
@@ -178,9 +178,9 @@ def n_step_bigru(
         n_layers(int): Number of layers.
         dropout_ratio(float): Dropout ratio.
         hx (chainer.Variable): Variable holding stacked hidden states.
-            Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
+            Its shape is ``(2S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i]``
             represents weights for i-th layer.
             Each ``ws[i]`` is a list containing six matrices.
@@ -192,7 +192,7 @@ def n_step_bigru(
             represnents biases for i-th layer.
             Each ``bs[i]`` is a list containing six vectors.
             ``bs[i][j]`` is corresponding with ``b_j`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value
@@ -249,7 +249,8 @@ def n_step_gru_base(n_layers, dropout_ratio, hx, ws, bs, xs,
         hx (chainer.Variable): Variable holding stacked hidden states.
             Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units. Because of bi-direction, the
+            first dimension length is ``2S``.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i]``
             represents weights for i-th layer.
             Each ``ws[i]`` is a list containing six matrices.
@@ -261,7 +262,7 @@ def n_step_gru_base(n_layers, dropout_ratio, hx, ws, bs, xs,
             represnents biases for i-th layer.
             Each ``bs[i]`` is a list containing six vectors.
             ``bs[i][j]`` is corresponding with ``b_j`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value
diff --git a/chainer/functions/connection/n_step_lstm.py b/chainer/functions/connection/n_step_lstm.py
--- a/chainer/functions/connection/n_step_lstm.py
+++ b/chainer/functions/connection/n_step_lstm.py
@@ -242,7 +242,7 @@ def n_step_bilstm(
         hx (~chainer.Variable): Variable holding stacked hidden states.
             Its shape is ``(2S, B, N)`` where ``S`` is the number of layers and
             is equal to ``n_layers``, ``B`` is the mini-batch size, and ``N``
-            is the dimension of the hidden units. Because of bi-diraction, the
+            is the dimension of the hidden units. Because of bi-direction, the
             first dimension length is ``2S``.
         cx (~chainer.Variable): Variable holding stacked cell states.
             It has the same shape as ``hx``.
diff --git a/chainer/functions/connection/n_step_rnn.py b/chainer/functions/connection/n_step_rnn.py
--- a/chainer/functions/connection/n_step_rnn.py
+++ b/chainer/functions/connection/n_step_rnn.py
@@ -569,7 +569,7 @@ def n_step_rnn(
         hx (chainer.Variable): Variable holding stacked hidden states.
             Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i]``
             represents weights for i-th layer.
             Each ``ws[i]`` is a list containing two matrices.
@@ -581,7 +581,7 @@ def n_step_rnn(
             represnents biases for i-th layer.
             Each ``bs[i]`` is a list containing two vectors.
             ``bs[i][j]`` is corresponding with ``b_j`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value
@@ -670,9 +670,10 @@ def n_step_birnn(
         n_layers(int): Number of layers.
         dropout_ratio(float): Dropout ratio.
         hx (chainer.Variable): Variable holding stacked hidden states.
-            Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
+            Its shape is ``(2S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units. Because of bi-direction, the
+            first dimension length is ``2S``.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i + di]``
             represents weights for i-th layer.
             Note that ``di = 0`` for forward-RNN and ``di = 1`` for
@@ -690,7 +691,7 @@ def n_step_birnn(
             Each ``bs[i + di]`` is a list containing two vectors.
             ``bs[i + di][j]`` is corresponding with ``b^{f}_j`` if ``di = 0``
             and corresponding with ``b^{b}_j`` if ``di = 1`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value
@@ -747,7 +748,7 @@ def n_step_rnn_base(n_layers, dropout_ratio, hx, ws, bs, xs,
         hx (chainer.Variable): Variable holding stacked hidden states.
             Its shape is ``(S, B, N)`` where ``S`` is number of layers and is
             equal to ``n_layers``, ``B`` is mini-batch size, and ``N`` is
-            dimention of hidden units.
+            dimension of hidden units.
         ws (list of list of chainer.Variable): Weight matrices. ``ws[i]``
             represents weights for i-th layer.
             Each ``ws[i]`` is a list containing two matrices.
@@ -759,7 +760,7 @@ def n_step_rnn_base(n_layers, dropout_ratio, hx, ws, bs, xs,
             represnents biases for i-th layer.
             Each ``bs[i]`` is a list containing two vectors.
             ``bs[i][j]`` is corresponding with ``b_j`` in the equation.
-            Shape of each matrix is ``(N,)`` where ``N`` is dimention of
+            Shape of each matrix is ``(N,)`` where ``N`` is dimension of
             hidden units.
         xs (list of chainer.Variable): A list of :class:`~chainer.Variable`
             holding input values. Each element ``xs[t]`` holds input value


Test patch: