Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于自定义训练、测试模块的问题 #12

Closed
FujiwaraKeine opened this issue Aug 31, 2022 · 4 comments
Closed

关于自定义训练、测试模块的问题 #12

FujiwaraKeine opened this issue Aug 31, 2022 · 4 comments

Comments

@FujiwaraKeine
Copy link

为了观察、调试模型,我修改了src/neuralkg/lit_model/KGELitModel.py和src/neuralkg/eval_task/link_prediction.py中的代码。但是在使用main.py训练、测试的过程中,这些修改的代码都好像没有执行,而是保持修改之前的状态。请问这种现象出现的原因是什么,以及我如果想把这些修改的代码应用于训练,应该如何去做?

@wencolani
Copy link
Contributor

你好,希望你能提供更详细的信息,以便我们判断出现当前这种现象的原因,例如你做的具体的修改是什么,预期的运行效果是什么,以及实际执行的情况是什么等。

@FujiwaraKeine
Copy link
Author

我为了观察模型对三元组的得分情况,修改了模型测试步骤的代码,把src/neuralkg/lit_model/KGELitModel.py中test_step函数中第90行的参数prediction='all'改为prediction='tail'。
我使用的config文件是config/FreeBase/TransH_FB15K237.yaml,用这个config文件执行main.py。
我预期能看到与修改前不一样的结果,但是修改后得到的MRR、Hits@n都与修改前没有任何变化。
而且我在调试程序的时候在修改的代码里打了个断点,结果程序根本没有运行到那个断点,说明修改的代码并未被执行。

@Modberge
Copy link
Collaborator

Modberge commented Sep 1, 2022

您好,这是一个很常见的问题,在README文件中我们提供了使用pip进行安装的方法。因此在 pip install neuralkg 之后,环境中已经安装了pypi提供的NeuralKG源码文件,这包含了src文件夹下的全部内容。这可以方便您在自己设计的实验中快速调用NeuralKG提供的KGE方法。如果您的虚拟环境中已经安装了NeuralKG,即使通过
git clone https://github.com/zjukg/NeuralKG.git
在当前的工作目录中下载了NeuralKG的源码,也仅起到参考作用。程序并不会按照工作目录下的NeuralKG代码执行。
如果您想尝试更改NeuralKG的源码并进行研究,最简单的方法就是通过 pip uninstall neuralkg 在虚拟环境中卸载掉NeuralKG并在main.py文件的第一行添加模块搜索路径

import sys
sys.path.append('./src')

希望这可以帮到您。

@FujiwaraKeine
Copy link
Author

通过这个方法,现在问题已经得到了解决,对代码的改动现在可以表现出来了。十分感谢你的回复!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants