def forward(self, x, x_mask, state_word):
x_emb = self.drop(self.lookup(x))<EOL>output_word, state_word = self.word_lstm(x_emb, state_word)<EOL>output_word = self.drop(output_word)<EOL>if self.attention:<EOL><INDENT>"""<STR_LIT>"""<EOL>word_squish = torch.tanh(self.attn_linear_w_1(output_word))<EOL>word_attn = self.attn_linear_w_2(word_squish)<EOL>word_attn.data.masked_fill_(x_mask.data.unsqueeze(dim=<NUM_LIT:2>), float("<STR_LIT>"))<EOL>word_attn_norm = torch.sigmoid(word_attn.squeeze(<NUM_LIT:2>))<EOL>word_attn_vectors = torch.bmm(<EOL>output_word.transpose(<NUM_LIT:1>, <NUM_LIT:2>), word_attn_norm.unsqueeze(<NUM_LIT:2>)<EOL>).squeeze(<NUM_LIT:2>)<EOL>output = (<EOL>self.linear(word_attn_vectors)<EOL>if self.final_linear<EOL>else word_attn_vectors<EOL>)<EOL><DEDENT>else:<EOL><INDENT>"""<STR_LIT>"""<EOL>x_lens = x_mask.data.eq(<NUM_LIT:0>).long().sum(dim=<NUM_LIT:1>)<EOL>if self.use_cuda:<EOL><INDENT>weights = torch.ones(x.size()).cuda() / x_lens.unsqueeze(<NUM_LIT:1>).float()<EOL><DEDENT>else:<EOL><INDENT>weights = torch.ones(x.size()) / x_lens.unsqueeze(<NUM_LIT:1>).float()<EOL><DEDENT>weights.data.masked_fill_(x_mask.data.unsqueeze(dim=<NUM_LIT:2>), <NUM_LIT:0.0>)<EOL>word_vectors = torch.bmm(<EOL>output_word.transpose(<NUM_LIT:1>, <NUM_LIT:2>), weights.unsqueeze(<NUM_LIT:2>)<EOL>).squeeze(<NUM_LIT:2>)<EOL>output = self.linear(word_vectors) if self.final_linear else word_vectors<EOL><DEDENT>return output<EOL>
Forward function.

        :param x: Input sequence tensor.
        :type x: torch.Tensor of shape (batch_size * length)
        :param x_mask: Use use_cuda or not.
        :type x_mask: torch.Tensor of shape (batch_size * length)
        :param state_word: Initial state of LSTM.
        :type state_word: torch.Tensor (see init_hidden() for more information)
        :return: Output of LSTM layer, either after mean pooling or attention.
        :rtype: torch.Tensor with shape (batch_size, num_directions * hidden_size)
            if num_classes > 0 otherwise with shape (batch_size, num_classes)