intfloat / SimKGC

ACL 2022, SimKGC: Simple Contrastive Knowledge Graph Completion with Pre-trained Language Models
188 stars 36 forks source link

Additional description information during testing(inference) #29

Open meaningful96 opened 1 year ago

meaningful96 commented 1 year ago

I have a question about code implementation. First, in the doc.py section

def vectorize(self) -> dict:
head_desc, tail_desc = self.head_desc, self.tail_desc
if args.use_link_graph:
if len(head_desc.split()) < 20:
head_desc += ' ' + get_neighbor_desc(head_id=self.head_id, tail_id=self.tail_id)
if len(tail_desc.split()) < 20:
tail_desc += ' ' + get_neighbor_desc(head_id=self.tail_id, tail_id=self.head_id)

head_word = _parse_entity_name(self.head)
head_text = _concat_name_desc(head_word, head_desc)
hr_encoded_inputs = _custom_tokenize(text=head_text,
text_pair=self.relation)

head_encoded_inputs = _custom_tokenize(text=head_text)

tail_word = _parse_entity_name(self.tail)
tail_encoded_inputs = _custom_tokenize(text=_concat_name_desc(tail_word, tail_desc))

Looking at this part, when the number of tokens is less than 20, the description of the neighbors is included. By the way, in the predict.py file

args.use_link_graph = self.train_args.use_link_graph
args.is_test = True

According to this part, additional description will be included in the test, so isn't the description of the tail, which is the correct answer, even though the problem solving in the knowledge graph is to match the tail when the head and relation are given?

meaningful96 commented 1 year ago

even if the get_neighbor_desc doesn't take the true tail's id during training, isn't it possible to get the True id from the neighbors in the link graph?

intfloat commented 1 year ago

I am not entirely clear about your question, but I guess you are asking whether the groundtruth tail entity will be leaked in the input during test stage?

The link graph used to get entity neighbors is constructed based on training data. So, it is possible that the groundtruth tail entity will be included in the 2-hop or 3-hop neighbors of the head entity. But this is OK as we do not assume access to the test labels.

meaningful96 commented 1 year ago

Oh yes, that's what I wondered. Thanks!!