intfloat / SimKGC

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

关于关闭 Re-ranking 的设定 #13

Closed EurusNotes closed 1 year ago

EurusNotes commented 1 year ago

Hi, Liang.

我根据您的readme进行了模型了训练,一切都很顺利,非常感谢您提供的代码。 在我读取模型的时候,我发现reranking的设定是默认的。 因为我想做一些reranking的尝试,所以想要关闭您的reranking的设定。 请问我该在哪里关闭它呢? 期待您能回复我,这将会对我非常有帮助。

I have trained the model according to your readme and everything is going well, thank you very much for the code. When I was reading the model, I noticed that the reranking setting defaulted. I want to turn off your reranking setting as I would like to do some reranking experiments. Where do I turn it off, please? I look forward to hearing from you as this would be very helpful.

EurusNotes commented 1 year ago

浏览了一下全部的代码,发现使用函数 rerank_by_graph 的地方是config.py的75 行 和 evaluate.py 的66行。

因为我还是不大清楚您的代码构造,所以不能很肯定应该在哪一个部分做修改。 个人猜想是不是只要把 evaluate.py 的这一部分删除掉就可以了?

for start in tqdm.tqdm(range(0, total, batch_size)):
        end = start + batch_size
        # batch_size * entity_cnt
        batch_score = torch.mm(hr_tensor[start:end, :], entities_tensor.t())
        assert entity_cnt == batch_score.size(1)
        batch_target = target[start:end]

        # re-ranking based on topological structure
        rerank_by_graph(batch_score, examples[start:end], entity_dict=entity_dict)
intfloat commented 1 year ago

You are right, there are several ways to disable rerank:

  1. Comment out the following line in evaluate.py:
# rerank_by_graph(batch_score, examples[start:end], entity_dict=entity_dict)
  1. Change options by passing in --neighbor_weight 0.0 in scripts/eval.sh and scripts/eval_wiki5m_trans.sh
EurusNotes commented 1 year ago

Thank you for your reply!!! It's very helpful to me!