def forward(self, sentence_features: Iterable[Dict[(str, Tensor)]], labels: Tensor, document_rep: Tensor):
    reps = [self.model(sentence_feature)['sentence_embedding'] for sentence_feature in sentence_features]
    (rep_a, rep_b) = reps
    document_rep = self.relu(self.hidden2output(self.relu(self.document2hidden(document_rep.float()))))
    vectors_concat = []
    if self.concatenation_sent_rep:
        vectors_concat.append(rep_a)
        vectors_concat.append(rep_b)
    if self.concatenation_sent_difference:
        vectors_concat.append(torch.abs((rep_a - rep_b)))
        vectors_concat.append(torch.abs((rep_a - document_rep)))
    features = torch.cat(vectors_concat, 1)
    output = self.classifier(features)
    loss_fct = nn.CrossEntropyLoss()
    if (labels is not None):
        loss = ((1.0 - self.document_coef) * loss_fct(output, labels.view((- 1))))
        loss -= (self.document_coef * torch.sum(torch.cosine_similarity(document_rep, rep_b)))
        return loss
    else:
        return (reps, output)
def forward(self, sentence_features: Iterable[Dict[(str, Tensor)]], labels: Tensor, document_rep: Tensor):
    reps = [self.model(sentence_feature)['sentence_embedding'] for sentence_feature in sentence_features]
    (rep_a, rep_b) = reps
    document_rep = self.relu(self.hidden2output(self.relu(self.document2hidden(document_rep.float()))))
    vectors_concat = []
    if self.concatenation_sent_rep:
        vectors_concat.append(rep_a)
        vectors_concat.append(rep_b)
    if self.concatenation_sent_difference:
        vectors_concat.append(torch.abs((rep_a - rep_b)))
        vectors_concat.append(torch.abs((rep_a - document_rep)))
    features = torch.cat(vectors_concat, 1)
    output = self.classifier(features)
    loss_fct = nn.CrossEntropyLoss()
    if (labels is not None):
        loss = ((1.0 - self.document_coef) * loss_fct(output, labels.view((- 1))))
        loss -= (self.document_coef * torch.sum(torch.cosine_similarity(document_rep, rep_b)))
        return loss
    else:
        return (reps, output)