(self, x1, x1_f, x1_pos, x1_ner, x1_mask, x2, x2_mask)
return start_scores, end_scores
Inputs:
        x1 = document word indices             [batch * len_d]
        x1_f = document word features indices  [batch * len_d * nfeat]
        x1_pos = document POS tags             [batch * len_d]
        x1_ner = document entity tags          [batch * len_d]
        x1_mask = document padding mask        [batch * len_d]
        x2 = question word indices             [batch * len_q]
        x2_mask = question padding mask        [batch * len_q]
Inputs:
        x1 = document word indices             [batch * len_d]
        x1_f = document word features indices  [batch * len_d * nfeat]
        x1_pos = document POS tags             [batch * len_d]
        x1_ner = document entity tags          [batch * len_d]
        x1_mask = document padding mask        [batch * len_d]
        x2 = question word indices             [batch * len_q]
        x2_mask = question padding mask        [batch * len_q]
Inputs : x1 = document word indices [ batch * len_d ] x1_f = document word features indices [ batch * len_d * nfeat ] x1_pos = document POS tags [ batch * len_d ] x1_ner = document entity tags [ batch * len_d ] x1_mask = document padding mask [ batch * len_d ] x2 = question word indices [ batch * len_q ] x2_mask = question padding mask [ batch * len_q ]
def forward(self, x1, x1_f, x1_pos, x1_ner, x1_mask, x2, x2_mask):
        """Inputs:
        x1 = document word indices             [batch * len_d]
        x1_f = document word features indices  [batch * len_d * nfeat]
        x1_pos = document POS tags             [batch * len_d]
        x1_ner = document entity tags          [batch * len_d]
        x1_mask = document padding mask        [batch * len_d]
        x2 = question word indices             [batch * len_q]
        x2_mask = question padding mask        [batch * len_q]
        """
        # Embed both document and question
        x1_emb = self.embedding(x1)
        x2_emb = self.embedding(x2)

        if self.opt['dropout_emb'] > 0:
            x1_emb = nn.functional.dropout(x1_emb, p=self.opt['dropout_emb'],
                                               training=self.training)
            x2_emb = nn.functional.dropout(x2_emb, p=self.opt['dropout_emb'],
                                           training=self.training)

        drnn_input_list = [x1_emb, x1_f]
        # Add attention-weighted question representation
        if self.opt['use_qemb']:
            x2_weighted_emb = self.qemb_match(x1_emb, x2_emb, x2_mask)
            drnn_input_list.append(x2_weighted_emb)
        if self.opt['pos']:
            x1_pos_emb = self.pos_embedding(x1_pos)
            if self.opt['dropout_emb'] > 0:
                x1_pos_emb = nn.functional.dropout(x1_pos_emb, p=self.opt['dropout_emb'],
                                               training=self.training)
            drnn_input_list.append(x1_pos_emb)
        if self.opt['ner']:
            x1_ner_emb = self.ner_embedding(x1_ner)
            if self.opt['dropout_emb'] > 0:
                x1_ner_emb = nn.functional.dropout(x1_ner_emb, p=self.opt['dropout_emb'],
                                               training=self.training)
            drnn_input_list.append(x1_ner_emb)
        drnn_input = torch.cat(drnn_input_list, 2)

        # Encode document with RNN
        doc_hiddens = self.doc_rnn(drnn_input, x1_mask)

        # Encode question with RNN + merge hiddens
        question_hiddens = self.question_rnn(x2_emb, x2_mask)
        if self.opt['question_merge'] == 'avg':
            q_merge_weights = layers.uniform_weights(question_hiddens, x2_mask)
        elif self.opt['question_merge'] == 'self_attn':
            q_merge_weights = self.self_attn(question_hiddens, x2_mask)
        question_hidden = layers.weighted_avg(question_hiddens, q_merge_weights)

        # Predict start and end positions
        start_scores = self.start_attn(doc_hiddens, question_hidden, x1_mask)
        end_scores = self.end_attn(doc_hiddens, question_hidden, x1_mask)
        return start_scores, end_scores
def forward ( self , x1 , x1_f , x1_pos , x1_ner , x1_mask , x2 , x2_mask ) : # Embed both document and question x1_emb = self . embedding ( x1 ) x2_emb = self . embedding ( x2 ) if self . opt [ 'dropout_emb' ] > 0 : x1_emb = nn . functional . dropout ( x1_emb , p = self . opt [ 'dropout_emb' ] , training = self . training ) x2_emb = nn . functional . dropout ( x2_emb , p = self . opt [ 'dropout_emb' ] , training = self . training ) drnn_input_list = [ x1_emb , x1_f ] # Add attention-weighted question representation if self . opt [ 'use_qemb' ] : x2_weighted_emb = self . qemb_match ( x1_emb , x2_emb , x2_mask ) drnn_input_list . append ( x2_weighted_emb ) if self . opt [ 'pos' ] : x1_pos_emb = self . pos_embedding ( x1_pos ) if self . opt [ 'dropout_emb' ] > 0 : x1_pos_emb = nn . functional . dropout ( x1_pos_emb , p = self . opt [ 'dropout_emb' ] , training = self . training ) drnn_input_list . append ( x1_pos_emb ) if self . opt [ 'ner' ] : x1_ner_emb = self . ner_embedding ( x1_ner ) if self . opt [ 'dropout_emb' ] > 0 : x1_ner_emb = nn . functional . dropout ( x1_ner_emb , p = self . opt [ 'dropout_emb' ] , training = self . training ) drnn_input_list . append ( x1_ner_emb ) drnn_input = torch . cat ( drnn_input_list , 2 ) # Encode document with RNN doc_hiddens = self . doc_rnn ( drnn_input , x1_mask ) # Encode question with RNN + merge hiddens question_hiddens = self . question_rnn ( x2_emb , x2_mask ) if self . opt [ 'question_merge' ] == 'avg' : q_merge_weights = layers . uniform_weights ( question_hiddens , x2_mask ) elif self . opt [ 'question_merge' ] == 'self_attn' : q_merge_weights = self . self_attn ( question_hiddens , x2_mask ) question_hidden = layers . weighted_avg ( question_hiddens , q_merge_weights ) # Predict start and end positions start_scores = self . start_attn ( doc_hiddens , question_hidden , x1_mask ) end_scores = self . end_attn ( doc_hiddens , question_hidden , x1_mask ) return start_scores , end_scores