def _get_triple_score(self, head: BoxTensor, tail: BoxTensor, relation: BoxTensor) -> torch.Tensor: """ Gets score using conditionals. :: note: We do not need to worry about the dimentions of the boxes. If it can sensibly broadcast it will. """ if self.is_eval(): if len(head.data.shape) > len(tail.data.shape): tail.data = torch.cat(head.data.shape[-3] * [tail.data]) elif len(head.data.shape) < len(tail.data.shape): head.data = torch.cat(tail.data.shape[-3] * [head.data]) head_tail_box_vol = head.intersection_log_soft_volume( tail, temp=self.softbox_temp, gumbel_beta=self.gumbel_beta, bayesian=True) # score = tail_head_relation_box_vol - tail_relation_box.log_soft_volume( # temp=self.softbox_temp) score = head_tail_box_vol - tail.log_soft_volume( temp=self.softbox_temp) if len(np.where(score > 0)[0]): breakpoint() return score
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
def _get_triple_score(self, head: BoxTensor, tail: BoxTensor, relation_head: torch.Tensor, relation_tail: torch.Tensor) -> torch.Tensor: head = self.get_relation_transform(box=head, relation=relation_head) tail = self.get_relation_transform(tail, relation_tail) head_tail_box_vol = head.intersection_log_soft_volume( tail, temp=self.softbox_temp) score = head_tail_box_vol - tail.log_soft_volume( temp=self.softbox_temp) return score
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)
def _get_triple_score(self, head: BoxTensor, tail: BoxTensor, relation: BoxTensor) -> torch.Tensor: """ Gets score using conditionals. :: note: We do not need to worry about the dimentions of the boxes. If it can sensibly broadcast it will. """ transformed_box = self.get_relation_transform(head, relation) head_tail_box_vol = transformed_box.intersection_log_soft_volume( tail, temp=self.softbox_temp) score = head_tail_box_vol - tail.log_soft_volume( temp=self.softbox_temp) return score
def _get_triple_score(self, head: BoxTensor, tail: BoxTensor, relation: BoxTensor) -> torch.Tensor: """ Gets score using conditionals. :: note: 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) # tail_head_relation_box_vol = tail.intersection_log_soft_volume( # head_relation_box, temp=self.softbox_temp) # score = tail_head_relation_box_vol - head_relation_box.log_soft_volume( # temp=self.softbox_temp) head_tail_box_vol = head.intersection_log_soft_volume( tail, temp=self.softbox_temp) # score = tail_head_relation_box_vol - tail_relation_box.log_soft_volume( # temp=self.softbox_temp) score = head_tail_box_vol - tail.log_soft_volume( temp=self.softbox_temp) return score