Exemple #1
0
    def _call(self, hs, xs, **kwargs):
        if kwargs:
            argument.check_unexpected_kwargs(
                kwargs,
                train="train argument is not supported anymore. "
                "Use chainer.using_config",
            )
            argument.assert_kwargs_empty(kwargs)

        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        assert self.ws[0][0].shape[1] == xs[0].shape[1]  # input check

        xs = permutate_list(xs, indices, inv=False)
        hxs = []
        for hx in hs:
            if hx is None:
                hx = self.init_hx(xs)
            else:
                hx = permutate.permutate(hx, indices, axis=1, inv=False)
            hxs.append(hx)

        trans_x = transpose_sequence.transpose_sequence(xs)

        args = [self.n_layers, self.dropout] + hxs + [self.ws, self.bs, trans_x]
        result = self.rnn(*args)

        hys = [permutate.permutate(h, indices, axis=1, inv=True) for h in result[:-1]]
        trans_y = result[-1]
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hys, ys
Exemple #2
0
    def forward(self, xs, ys, reduce='mean', transpose=False):
        """Computes negative log-likelihood of linear-chain CRF

        Args:
            xs (list of Variable): Input vector for each label
            ys (list of Variable): Expected output labels.
            transpose (bool): If ``True``, input/output sequences
            will be sorted in descending order of length.

        Returns:
            ~chainer.Variable: A variable holding the average negative
            log-likelihood of the input sequences.

        .. seealso:: See :func:`~chainer.frunctions.crf1d` for more detail.
        """

        if transpose:
            indices = argsort_list_descent(xs)
            xs = permutate_list(xs, indices, inv=False)
            ys = permutate_list(ys, indices, inv=False)
            trans_x = transpose_sequence.transpose_sequence(xs)
            trans_y = transpose_sequence.transpose_sequence(ys)
            loss = crf1d.crf1d(self.cost, trans_x, trans_y, reduce)

        else:
            loss = crf1d.crf1d(self.cost, xs, ys, reduce)

        return loss
Exemple #3
0
    def __call__(self, hx, cx, xs):
        """Calculate all hidden states and cell states.

        Args:
            hx (~chainer.Variable): Initial hidden states.
            cx (~chainer.Variable): Initial cell states.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        hx = permutate.permutate(hx, indices, axis=1, inv=False)
        cx = permutate.permutate(cx, indices, axis=1, inv=False)
        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = rnn.n_step_lstm(
            self.n_layers, self.dropout, hx, cx, ws, bs, trans_x,
            use_cudnn=self.use_cudnn)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        cy = permutate.permutate(cy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #4
0
    def argmax(self, xs, transpose=False):
        """Computes a state that maximizes a joint probability.

        Args:
            xs (list of Variable): Input vector for each label.
            transpose (bool): If ``True``, input/output sequences
            will be sorted in descending order of length.

        Returns:
            tuple: A tuple of :class:`~chainer.Variable` representing each
            log-likelihood and a list representing the argmax path.

        .. seealso:: See :func:`~chainer.frunctions.crf1d_argmax` for more
           detail.

        """

        if transpose:
            indices = argsort_list_descent(xs)
            xs = permutate_list(xs, indices, inv=False)
            trans_x = transpose_sequence.transpose_sequence(xs)
            score, path = crf1d.argmax_crf1d(self.cost, trans_x)

            path = transpose_sequence.transpose_sequence(path)
            path = [p.array for p in path]
            path = permutate_list(path, indices, inv=True)

        else:
            score, path = crf1d.argmax_crf1d(self.cost, xs)

        return score, path
Exemple #5
0
    def __call__(self, hx, cx, xs, train=True):
        """Calculate all hidden states and cell states.

        Args:
            hx (~chainer.Variable): Initial hidden states.
            cx (~chainer.Variable): Initial cell states.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        hx = permutate.permutate(hx, indices, axis=1, inv=False)
        cx = permutate.permutate(cx, indices, axis=1, inv=False)
        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = rnn.n_step_lstm(
            self.n_layers, self.dropout, hx, cx, ws, bs, trans_x,
            train=train, use_cudnn=self.use_cudnn)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        cy = permutate.permutate(cy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #6
0
    def argmax(self, xs, transpose=False):
        """Computes a state that maximizes a joint probability.

        Args:
            xs (list of Variable): Input vector for each label.
            transpose (bool): If ``True``, input/output sequences
            will be sorted in descending order of length.

        Returns:
            tuple: A tuple of :class:`~chainer.Variable` representing each
            log-likelihood and a list representing the argmax path.

        .. seealso:: See :func:`~chainer.frunctions.crf1d_argmax` for more
           detail.

        """

        if transpose:
            indices = argsort_list_descent(xs)
            xs = permutate_list(xs, indices, inv=False)
            trans_x = transpose_sequence.transpose_sequence(xs)
            score, path = crf1d.argmax_crf1d(self.cost, trans_x)

            path = transpose_sequence.transpose_sequence(path)
            path = [p.array for p in path]
            path = permutate_list(path, indices, inv=True)

        else:
            score, path = crf1d.argmax_crf1d(self.cost, xs)

        return score, path
Exemple #7
0
    def forward(self, xs, ys, reduce='mean', transpose=False):
        """Computes negative log-likelihood of linear-chain CRF

        Args:
            xs (list of Variable): Input vector for each label
            ys (list of Variable): Expected output labels.
            transpose (bool): If ``True``, input/output sequences
            will be sorted in descending order of length.

        Returns:
            ~chainer.Variable: A variable holding the average negative
            log-likelihood of the input sequences.

        .. seealso:: See :func:`~chainer.frunctions.crf1d` for more detail.
        """

        if transpose:
            indices = argsort_list_descent(xs)
            xs = permutate_list(xs, indices, inv=False)
            ys = permutate_list(ys, indices, inv=False)
            trans_x = transpose_sequence.transpose_sequence(xs)
            trans_y = transpose_sequence.transpose_sequence(ys)
            loss = crf1d.crf1d(self.cost, trans_x, trans_y, reduce)

        else:
            loss = crf1d.crf1d(self.cost, xs, ys, reduce)

        return loss
Exemple #8
0
    def __call__(self, hx, xs, train=True):
        """Calculate all hidden states and cell states.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        if hx is None:
            hx = self.init_hx(xs)
        else:
            hx = permutate.permutate(hx, indices, axis=1, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1] for w in self]
        bs = [[w.b0, w.b1] for w in self]

        hy, trans_y = self.rnn(
            self.n_layers, self.dropout, hx, ws, bs, trans_x,
            train=train, use_cudnn=self.use_cudnn, activation=self.activation)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hy, ys
Exemple #9
0
 def _Transpose(X, indices=None, inv=False):
     if not inv:
         indices = argsort_list_descent(X)
         transpose = list(transpose_sequence.transpose_sequence(permutate_list(X, indices, inv=inv)))
         return indices, transpose
     else:
         transpose = permutate_list(transpose_sequence.transpose_sequence(X), indices, inv=inv)
         return transpose
    def __call__(self, hx, cx, xs, **kwargs):
        """__call__(self, hx, cx, xs)

        Calculate all hidden states and cell states.

        .. warning::

           ``train`` argument is not supported anymore since v2.
           Instead, use ``chainer.using_config('train', train)``.
           See :func:`chainer.using_config`.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            cx (~chainer.Variable or None): Initial cell states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chainer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        argument.check_unexpected_kwargs(
            kwargs,
            train='train argument is not supported anymore. '
            'Use chainer.using_config')
        argument.assert_kwargs_empty(kwargs)

        assert isinstance(xs, (list, tuple))
        xp = cuda.get_array_module(hx, *xs)
        indices = n_step_rnn.argsort_list_descent(xs)
        indices_array = xp.array(indices)

        xs = n_step_rnn.permutate_list(xs, indices, inv=False)
        if hx is None:
            hx = self.init_hx(xs)
        else:
            hx = permutate.permutate(hx, indices_array, axis=1, inv=False)

        if cx is None:
            cx = self.init_hx(xs)
        else:
            cx = permutate.permutate(cx, indices_array, axis=1, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = self.rnn(self.n_layers, self.dropout, hx, cx, ws, bs,
                                   trans_x)

        hy = permutate.permutate(hy, indices_array, axis=1, inv=True)
        cy = permutate.permutate(cy, indices_array, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = n_step_rnn.permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #11
0
    def __call__(self, hx, cx, xs, train=True):
        """Calculate all hidden states and cell states.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            cx (~chainer.Variable or None): Initial cell states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        if hx is None:
            with cuda.get_device(self._device_id):
                hx = chainer.Variable(self.xp.zeros(
                    (self.n_layers, len(xs), self.out_size),
                    dtype=xs[0].dtype),
                                      volatile='auto')
        else:
            hx = permutate.permutate(hx, indices, axis=1, inv=False)

        if cx is None:
            with cuda.get_device(self._device_id):
                cx = chainer.Variable(self.xp.zeros(
                    (self.n_layers, len(xs), self.out_size),
                    dtype=xs[0].dtype),
                                      volatile='auto')
        else:
            cx = permutate.permutate(cx, indices, axis=1, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = rnn.n_step_lstm(self.n_layers,
                                          self.dropout,
                                          hx,
                                          cx,
                                          ws,
                                          bs,
                                          trans_x,
                                          train=train,
                                          use_cudnn=self.use_cudnn)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        cy = permutate.permutate(cy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #12
0
    def __call__(self, hx, cx, xs, **kwargs):
        """__call__(self, hx, cx, xs)

        Calculate all hidden states and cell states.

        .. warning::

           ``train`` argument is not supported anymore since v2.
           Instead, use ``chainer.using_config('train', train)``.
           See :func:`chainer.using_config`.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            cx (~chainer.Variable or None): Initial cell states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        argument.check_unexpected_kwargs(
            kwargs, train='train argument is not supported anymore. '
            'Use chainer.using_config')
        argument.assert_kwargs_empty(kwargs)

        assert isinstance(xs, (list, tuple))
        indices = n_step_rnn.argsort_list_descent(xs)

        xs = n_step_rnn.permutate_list(xs, indices, inv=False)
        if hx is None:
            hx = self.init_hx(xs)
        else:
            hx = permutate.permutate(hx, indices, axis=1, inv=False)

        if cx is None:
            cx = self.init_hx(xs)
        else:
            cx = permutate.permutate(cx, indices, axis=1, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = self.rnn(
            self.n_layers, self.dropout, hx, cx, ws, bs, trans_x)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        cy = permutate.permutate(cy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = n_step_rnn.permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #13
0
    def __call__(self, hx, cx, xs, train=True):
        """Calculate all hidden states and cell states.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            cx (~chainer.Variable or None): Initial cell states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.
        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        if hx is None:
            with cuda.get_device(self._device_id):
                hx = chainer.Variable(
                    self.xp.zeros(
                        (self.n_layers, len(xs), self.out_size),
                        dtype=xs[0].dtype),
                    volatile='auto')
        else:
            hx = permutate.permutate(hx, indices, axis=1, inv=False)

        if cx is None:
            with cuda.get_device(self._device_id):
                cx = chainer.Variable(
                    self.xp.zeros(
                        (self.n_layers, len(xs), self.out_size),
                        dtype=xs[0].dtype),
                    volatile='auto')
        else:
            cx = permutate.permutate(cx, indices, axis=1, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5, w.w6, w.w7] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5, w.b6, w.b7] for w in self]

        hy, cy, trans_y = rnn.n_step_lstm(
            self.n_layers, self.dropout, hx, cx, ws, bs, trans_x,
            train=train, use_cudnn=self.use_cudnn)

        hy = permutate.permutate(hy, indices, axis=1, inv=True)
        cy = permutate.permutate(cy, indices, axis=1, inv=True)
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hy, cy, ys
Exemple #14
0
    def _call(self, hs, xs, **kwargs):
        """Calls RNN function.

        Args:
            hs (list of ~chainer.Variable or None): Lisit of hidden states.
                Its length depends on its implementation.
                If ``None`` is specified zero-vector is used.
            xs (list of ~chainer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.

        Returns:
            tuple: hs
        """
        if kwargs:
            argument.check_unexpected_kwargs(
                kwargs,
                train='train argument is not supported anymore. '
                'Use chainer.using_config')
            argument.assert_kwargs_empty(kwargs)

        assert isinstance(xs, (list, tuple))
        xp = cuda.get_array_module(*(list(hs) + list(xs)))
        indices = argsort_list_descent(xs)
        indices_array = xp.array(indices)

        xs = permutate_list(xs, indices, inv=False)
        hxs = []
        for hx in hs:
            if hx is None:
                hx = self.init_hx(xs)
            else:
                hx = permutate.permutate(hx, indices_array, axis=1, inv=False)
            hxs.append(hx)

        trans_x = transpose_sequence.transpose_sequence(xs)

        args = [self.n_layers, self.dropout] + hxs + \
               [self.ws, self.bs, trans_x]
        result = self.rnn(*args)

        hys = [
            permutate.permutate(h, indices_array, axis=1, inv=True)
            for h in result[:-1]
        ]
        trans_y = result[-1]
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hys, ys
Exemple #15
0
    def _call(self, hs, xs, **kwargs):
        """Calls RNN function.

        Args:
            hs (list of ~chainer.Variable or None): Lisit of hidden states.
                Its length depends on its implementation.
                If ``None`` is specified zero-vector is used.
            xs (list of ~chainer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.

        Returns:
            tuple: hs
        """
        if kwargs:
            argument.check_unexpected_kwargs(
                kwargs, train='train argument is not supported anymore. '
                'Use chainer.using_config')
            argument.assert_kwargs_empty(kwargs)

        assert isinstance(xs, (list, tuple))
        xp = cuda.get_array_module(*(list(hs) + list(xs)))
        indices = argsort_list_descent(xs)
        indices_array = xp.array(indices)

        xs = permutate_list(xs, indices, inv=False)
        hxs = []
        for hx in hs:
            if hx is None:
                hx = self.init_hx(xs)
            else:
                hx = permutate.permutate(hx, indices_array, axis=1, inv=False)
            hxs.append(hx)

        trans_x = transpose_sequence.transpose_sequence(xs)

        args = [self.n_layers, self.dropout] + hxs + \
               [self.ws, self.bs, trans_x]
        result = self.rnn(*args)

        hys = [permutate.permutate(h, indices_array, axis=1, inv=True)
               for h in result[:-1]]
        trans_y = result[-1]
        ys = transpose_sequence.transpose_sequence(trans_y)
        ys = permutate_list(ys, indices, inv=True)

        return hys, ys
Exemple #16
0
    def __call__(self, xs):
        """

        Args:
            xs (list or tuple): batch-length list of Variable, each with shape
                (

        Returns:

        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        h = self.rnn.init_h(xs)
        c = self.rnn.init_c(xs)
        # list of Variable, each with shape (batch, features)
        trans_x = transpose_sequence.transpose_sequence(xs)

        z_lst = []
        pz_lst = []
        for x in trans_x:
            if len(x) < len(h):
                # a sequence ended
                h = h[:len(x)]
                c = [c_i[:len(x)] for c_i in c]
            pz, z, h, c = self._forward_single(x, h, c)
            z_lst.append(z)
            pz_lst.append(pz)

        # h_lst and c_lst basically have same order as x
        z_lst = transpose_sequence.transpose_sequence(z_lst)
        z_lst = permutate_list(z_lst, indices, inv=True)
        z_lst = [F.squeeze(z, 1).data for z in z_lst]

        # h_lst and c_lst basically have same order as x
        pz_lst = transpose_sequence.transpose_sequence(pz_lst)
        pz_lst = permutate_list(pz_lst, indices, inv=True)
        pz_lst = [F.squeeze(pz, 1) for pz in pz_lst]

        return pz_lst, z_lst
Exemple #17
0
    def __call__(self, xs):
        """

        Args:
            xs (list or tuple): batch-length list of Variable, each with shape
                (

        Returns:

        """
        assert isinstance(xs, (list, tuple))
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)
        h = self.init_h(xs)
        c = self.init_c(xs)
        # list of Variable, each with shape (batch, features)
        trans_x = transpose_sequence.transpose_sequence(xs)

        c_lst = []
        h_lst = []
        for x in trans_x:
            if len(x) < len(h):
                # a sequence ended
                h = h[:len(x)]
                c = [c_i[:len(x)] for c_i in c]
            h, c = self.forward_single(x, h, c)
            c_lst.append(F.hstack(c))
            h_lst.append(h)

        # h_lst and c_lst basically have same order as x
        h_lst = transpose_sequence.transpose_sequence(h_lst)
        h_lst = permutate_list(h_lst, indices, inv=True)

        c_lst = transpose_sequence.transpose_sequence(c_lst)
        c_lst = permutate_list(c_lst, indices, inv=True)

        return h_lst, c_lst
Exemple #18
0
    def __call__(self, h0, hx, xs, **kwargs):
        """__call__(self, hx, xs)

        Calculate all hidden states and cell states.

        .. warning::

           ``train`` argument is not supported anymore since v2.
           Instead, use ``chainer.using_config('train', train)``.
           See :func:`chainer.using_config`.

        Args:
            hx (~chainer.Variable or None): Initial hidden states. If ``None``
                is specified zero-vector is used.
            xs (list of ~chianer.Variable): List of input sequences.
                Each element ``xs[i]`` is a :class:`chainer.Variable` holding
                a sequence.

        """
        argument.check_unexpected_kwargs(
            kwargs,
            train='train argument is not supported anymore. '
            'Use chainer.using_config')
        argument.assert_kwargs_empty(kwargs)

        assert isinstance(
            xs, (list, tuple)), "xs in not a list or tupple: %r" % type(xs)
        indices = argsort_list_descent(xs)

        xs = permutate_list(xs, indices, inv=False)

        if h0 is None:
            h0 = self.init_hx(xs)
        else:
            h0 = permutate.permutate(h0, indices, axis=1, inv=False)

        hx = permutate_list(hx, indices, inv=False)

        trans_x = transpose_sequence.transpose_sequence(xs)

        ws = [[w.w0, w.w1, w.w2, w.w3, w.w4, w.w5] for w in self]
        bs = [[w.b0, w.b1, w.b2, w.b3, w.b4, w.b5] for w in self]
        for w in self:
            w1 = w.w6
            w2 = w.w7
            w3 = w.w8
            b1 = w.b6
            b2 = w.b7
            b3 = w.b8
        W = [w1, w2, w3]
        B = [b1, b2, b3]

        h_list, h_bar_list, c_s_list, z_s_list = self.rnn(
            self.n_layers, self.dropout, h0, hx, ws, bs, trans_x, W, B)
        '''
        print(type(h_list),len(h_list))
        print(type(h_list[0]),len(h_list[0]))
        print(type(h_list[0][0]),len(h_list[0][0]))
        '''

        #batch内で入れ替え
        h_list = transpose_sequence.transpose_sequence(h_list)
        h_list = permutate_list(h_list, indices, inv=True)
        '''
        print(type(h_list),len(h_list))
        print(type(h_list[0]),len(h_list[0]))
        print(type(h_list[0][0]),len(h_list[0][0]))
        '''
        h_bar_list = transpose_sequence.transpose_sequence(h_bar_list)
        h_bar_list = permutate_list(h_bar_list, indices, inv=True)
        '''
        print(type(c_s_list),len(c_s_list))
        print(type(c_s_list[0]),len(c_s_list[0]))
        print(type(c_s_list[0][0]),len(c_s_list[0][0]), c_s_list[0][0])
        
        print(type(z_s_list), len(z_s_list))
        print(type(z_s_list[0]), len(z_s_list[0]), z_s_list[0])
        '''
        c_s_list = transpose_sequence.transpose_sequence(c_s_list)
        c_s_list = permutate_list(c_s_list, indices, inv=True)
        z_s_list = transpose_sequence.transpose_sequence(z_s_list)
        z_s_list = permutate_list(z_s_list, indices, inv=True)

        return h_list, h_bar_list, c_s_list, z_s_list