ShulinCao / OpenNRE-PyTorch

Neural Relation Extraction implemented in PyTorch
MIT License
219 stars 45 forks source link

about multi-instance leanring #10

Closed liyucheng09 closed 5 years ago

liyucheng09 commented 5 years ago

By reading source code, I think this project reduce noise impact in distant supervision data set is by use sentence-level attention, rather than multi-instance learning. see code as follow:

def forward(self, x):
        attention_logit = self._attention_train_logit(x)
        tower_repre = []
        for i in range(len(self.scope) - 1):
            sen_matrix = x[self.scope[i] : self.scope[i + 1]]
            attention_score = F.softmax(torch.transpose(attention_logit[self.scope[i] : self.scope[i + 1]], 0, 1), 1)
            final_repre = torch.squeeze(torch.matmul(attention_score, sen_matrix))
            tower_repre.append(final_repre)
        stack_repre = torch.stack(tower_repre)
        stack_repre = self.dropout(stack_repre)
        logits = self.get_logits(stack_repre)
        return logits

This section is forward() in selector.py, it dose not chose the most reliable sentence as what is mentioned in multi-instance learning paper. so am I right?

Appreciate for your help.

ShulinCao commented 5 years ago

This is multi-instance learning, sen_matrix = x[self.scope[i] : self.scope[i + 1]] represents all the sentence in the bag.