Sujit-O / pykg2vec

Python library for knowledge graph embedding and representation learning.
MIT License
602 stars 109 forks source link

Tuning hyperparameters on custom dataset #204

Closed bhaskarkvvsr closed 3 years ago

bhaskarkvvsr commented 3 years ago

Hi, I am training a TransE model on a custom dataset using the script train.py from examples directory. How can I tune the hyperparameters of the model using tune_model.py? In the comments, it is only mentioned about tuning the parameters on the existing datasets but not on the custom ones.

baxtree commented 3 years ago

Hi, @Bhaskarkvvsr, I don't think pykg2vec officially supports hyperparameter tuning using custom datasets (all the models are using freebase15k) and we need to make the documentation more clear on that. Nonetheless, please try this and see if it works for you. Say you have a custom dataset named as "userdefineddataset" and a folder containing userdefineddataset-train.txt, userdefineddataset-valid.txt and userdefineddataset-test.txt. You also need a hyperparameter YAML file referring to that dataset. Here is an example using the test fixture: (pykg2vec) $ pykg2vec-tune -exp True -mn TransE -ds userdefineddataset -dsp ./pykg2vec/test/resource/custom_dataset -hpf ./your_hyperparameters.yaml where your_hyperparameters.yaml has the following content:

model_name: "TransE"
datasets:
  - dataset: "userdefineddataset"
    parameters:
      learning_rate: 0.01
      l1_flag: True
      hidden_size: 50
      batch_size: 128
      epochs: 1000
      margin: 1.00
      optimizer: "sgd"
      sampling: "bern"
      neg_rate: 1
baxtree commented 3 years ago

Hi, @louisccc, looks like readthedocs has not been updated after multi-datesets were introduced and it is showing the old schema.

bhaskarkvvsr commented 3 years ago

Hi @baxtree, It worked. Thanks a lot