def forward(self, inputs, target, next_word_history, cache_history, begin_state=None): 
output, hidden, encoder_hs, _ =super(self.lm_model.__class__, self.lm_model).forward(inputs, begin_state)<EOL>encoder_h = encoder_hs[-<NUM_LIT:1>].reshape(-<NUM_LIT:3>, -<NUM_LIT:2>)<EOL>output = output.reshape(-<NUM_LIT:1>, self._vocab_size)<EOL>start_idx = len(next_word_history)if next_word_history is not None else <NUM_LIT:0><EOL>next_word_history = nd.concat(*[nd.one_hot(t[<NUM_LIT:0>], self._vocab_size, on_value=<NUM_LIT:1>, off_value=<NUM_LIT:0>)<EOL>for t in target], dim=<NUM_LIT:0>) if next_word_history is Noneelse nd.concat(next_word_history,<EOL>nd.concat(*[nd.one_hot(t[<NUM_LIT:0>], self._vocab_size, on_value=<NUM_LIT:1>, off_value=<NUM_LIT:0>)<EOL>for t in target], dim=<NUM_LIT:0>), dim=<NUM_LIT:0>)<EOL>cache_history = encoder_h if cache_history is Noneelse nd.concat(cache_history, encoder_h, dim=<NUM_LIT:0>)<EOL>out = None<EOL>softmax_output = nd.softmax(output)<EOL>for idx, vocab_L in enumerate(softmax_output):<EOL><INDENT>joint_p = vocab_L<EOL>if start_idx + idx > self._window:<EOL><INDENT>valid_next_word = next_word_history[start_idx + idx - self._window:start_idx + idx]<EOL>valid_cache_history = cache_history[start_idx + idx - self._window:start_idx + idx]<EOL>logits = nd.dot(valid_cache_history, encoder_h[idx])<EOL>cache_attn = nd.softmax(self._theta * logits).reshape(-<NUM_LIT:1>, <NUM_LIT:1>)<EOL>cache_dist = (cache_attn.broadcast_to(valid_next_word.shape)<EOL>* valid_next_word).sum(axis=<NUM_LIT:0>)<EOL>joint_p = self._lambdas * cache_dist + (<NUM_LIT:1> - self._lambdas) * vocab_L<EOL><DEDENT>out = joint_p[target[idx]] if out is Noneelse nd.concat(out, joint_p[target[idx]], dim=<NUM_LIT:0>)<EOL><DEDENT>next_word_history = next_word_history[-self._window:]<EOL>cache_history = cache_history[-self._window:]<EOL>return out, next_word_history, cache_history, hidden<EOL>
Defines the forward computation for cache cell. Arguments can be either
        :py:class:`NDArray` or :py:class:`Symbol`.

        Parameters
        ----------
        inputs: NDArray
            The input data
        target: NDArray
            The label
        next_word_history: NDArray
            The next word in memory
        cache_history: NDArray
            The hidden state in cache history


        Returns
        --------
        out: NDArray
            The linear interpolation of the cache language model
            with the regular word-level language model
        next_word_history: NDArray
            The next words to be kept in the memory for look up
            (size is equal to the window size)
        cache_history: NDArray
            The hidden states to be kept in the memory for look up
            (size is equal to the window size)