コード例 #1
0
    def _get_triple_score(self, head: BoxTensor, tail: BoxTensor,
                          relation: BoxTensor) -> torch.Tensor:
        head_relation_box = relation.intersection(head)
        tail_relation_box = relation.intersection(tail)
        head_tail_relation_intersection_vol = tail_relation_box.intersection_log_soft_volume(
            head_relation_box, temp=self.softbox_temp)
        relation_box_vol = relation.log_soft_volume(temp=self.softbox_temp)
        score = head_tail_relation_intersection_vol - relation_box_vol

        return score
コード例 #2
0
    def _get_triple_score(self, head: BoxTensor, tail: BoxTensor,
                          relation: BoxTensor) -> torch.Tensor:
        """ Gets score using three way intersection

        We do not need to worry about the dimentions of the boxes. If
            it can sensibly broadcast it will.
        """
        head_relation_box = relation.intersection(head)
        tail_relation_box = relation.intersection(tail)
        score = head_relation_box.intersection_log_soft_volume(
            tail_relation_box, temp=self.softbox_temp)

        return score
コード例 #3
0
    def _get_triple_score(self,
                          head: BoxTensor,
                          tail: BoxTensor,
                          relation: BoxTensor,
                          head_rev: BoxTensor,
                          tail_rev: BoxTensor,
                          relation_rev: BoxTensor) -> torch.Tensor:


        tail_relation_box = relation.intersection(tail)
        tail_head_relation_box_vol = tail_relation_box.intersection_log_soft_volume(
            head, temp=self.softbox_temp)
        tail_vol = tail.log_soft_volume(temp=self.softbox_temp) 
        score_fwd = tail_head_relation_box_vol - tail_vol

        tail_relation_box_rev = relation_rev.intersection(tail_rev)
        tail_head_relation_box_rev_vol = tail_relation_box_rev.intersection_soft_volume(head_rev, temp=self.softbox_temp)

        tail_rev_vol = tail_rev.log_soft_volume(temp=self.softbox_temp)
        score_rev = tail_head_relation_box_rev_vol - tail_rev_vol


        return 0.5*(score_fwd + score_rev)