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

超参数优化 #22

Closed
jenfung opened this issue Mar 21, 2023 · 6 comments
Closed

超参数优化 #22

jenfung opened this issue Mar 21, 2023 · 6 comments

Comments

@jenfung
Copy link

jenfung commented Mar 21, 2023

您好!请问官方文档可以再详细一点吗?很感兴趣但是上手有点难度

@jenfung
Copy link
Author

jenfung commented Mar 21, 2023

.yaml文件定义完以后是在sh文件中使用--load_config和--config_path导入吗?

@hzwy3c
Copy link
Collaborator

hzwy3c commented Mar 23, 2023

非常感谢您对我们工作的关注,我们会在后续的更新中进一步完善说明文档。
关于.yaml文件的使用,.yaml和.sh文件是两种运行方式,这在README中的Training部分有对应的命令介绍,二者是二选一的关系,如果您在.yaml中配置好了所有的参数,可以直接按照下面的命令运行:
python main.py --load_config --config_path <your-config>
但是我们更建议您用.sh运行您的代码,因为.sh中已经列出了涉及到模型的超参数,可以更方便地修改和调整:
sh ./scripts/your-sh

@jenfung
Copy link
Author

jenfung commented Mar 25, 2023

明白,我目前比较好奇的还是wandb的超参数优化。当我使用sweep跑完后,图上metric为null。以下是我的yaml配置,可以帮我看一下哪里出了问题吗?

`command:

  • ${env}
  • ${interpreter}
  • ${program}
  • ${args}
    program: main.py
    method: grid
    metric:
    goal: maximize
    name: Eval|hits@10
    parameters:
    dataset_name:
    value: aptnotes
    model_name:
    value: TransE
    max_epochs:
    value: 50
    loss_name:
    values: [Margin_Loss]
    train_sampler_class:
    values: [UniSampler]
    emb_dim:
    values: [200, 400]
    lr:
    values: [1e-4, 5e-5, 1e-6]
    train_bs:
    values: [1024, 512]
    num_neg:
    values: [64, 128]`

image
image

@hzwy3c
Copy link
Collaborator

hzwy3c commented Mar 27, 2023

这个问题需要您手动将源码里的超参数use_wandb改为True,因为在优化目标时需要在wandb.log()中跟踪对应的目标变量

@jenfung
Copy link
Author

jenfung commented Mar 29, 2023

非常感谢,可以了!再请教一个问题,filter或者说反向三元组,在哪里实现呢?没有在超参数那里看到,--filter_flag应该跟这个无关吧?

@hzwy3c
Copy link
Collaborator

hzwy3c commented Mar 29, 2023

您好,下面是filter和反向三元组在源码中实现的地方:

  1. 超参数--filter_flag用于控制在破坏头或尾实体生成负样本的时候将那些已经出现过的正样本过滤掉,避免生成的负样本中出现已知的正样本,源码中的实现在Datapreprocess.py中corrupt_head()和corrupt_tail()这两个function中。另外一个filtered setting是在链接预测计算test triple排名的时候,在与之比较的候选三元组中将那些在训练集或验证集中出现过的三元组删去,源码中的实现在link_prediction.py的calc_ranks()中。
  2. 添加反向三元组是在Datapreprocess.py的RevSampler类中,需要添加反向三元组的方法例如ConvE对应的ConvSampler继承自该类,添加反向三元组后再做链接预测只需要去预测尾实体。

希望我的回答对你能有所帮助。

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