Accenture / AmpliGraph

Python library for Representation Learning on Knowledge Graphs https://docs.ampligraph.org
Apache License 2.0
2.12k stars 252 forks source link

Model selection of inverse relation? #246

Closed lzw950905 closed 3 years ago

lzw950905 commented 3 years ago

Problems:

  1. When I process model selection, I don't know how to select inverse relation? I want to add inverse relation = [True, False] in param_grid for random select.
  2. And how could I optimize the label smoothing? Do I just set 'label_smoothing': .....in param_gird?
  3. For numbers, I am confused about [0.1, 0.01] means a range or two choices?
sumitpai commented 3 years ago
  1. This cannot be done in parameter grid, since this is dataset related. You can only do hyperparameter selection of model related params in the grid. In order to do what you mentioned, you can run 2 different experiments by loading the datasets in the required way: dataset = load_fb15k_237(add_reciprocal_rels=True)

  2. In the hyperparam grid, you can set the label_smoothing key of the loss_parameters dict to the values that you require. Here is a dummy grid. Please note that this parameter is only used with BCE loss and ConvE model.

    param_grid = {
                     "batches_count": [10],
                     "seed": 0,
                     "epochs": [4000],
                     "k": [100, 50],
                     "eta": [5,10],
                     "loss": ["bce"],
                     # We take care of mapping the params to corresponding classes
                     "loss_params": {
                         "label_smoothing": [True, False]
                     },
                     "embedding_model_params": {
    
                     },
                     "regularizer": [None, "LP"],
                     "regularizer_params": {
                         "p": [2],
                         "lambda": [1e-4, 1e-5]
                     },
                     "optimizer": ["adam"],
                     "optimizer_params":{
                         "lr": [0.01, 0.0001]
                     },
                     "verbose": True
                 }
  3. If you specify the learning rate or other parameters as a list of values, then only the values specified in the list are used. If you want random sampling then you need to pass a callable instead.

For example, see how lr is specified using a callable see the example shown in this page