Config¶
-
class
config.
Config
[source]¶ In this class, we set the configuration parameters, adopt C library for data and memory processing. In the following, we train models and test models.
Getting Statistics of Dataset¶
Setting Configuration Parameters¶
-
Config.
set_alpha
(alpha)[source]¶ This mothod sets the learning rate for gradient descent.
Parameters: alpha (float) – the learning rate.
-
Config.
set_margin
(margin)[source]¶ This method sets the margin for the widely used pairwise margin-based ranking loss.
Parameters: margin (float) – margin for margin-based ranking function
-
Config.
set_bern
(bern)[source]¶ This method sets the strategy for negative sampling.
Parameters: bern – “bern” or “unif”
-
Config.
set_dimension
(dim)[source]¶ This method sets the entity dimension and relation dimension at the same time.
Parameters: dim (int) – the dimension of entity and relation.
-
Config.
set_ent_dimension
(dim)[source]¶ This method sets the dimension of entity.
Parameters: dim (int) – the dimension of entity.
-
Config.
set_rel_dimension
(dim)[source]¶ This method sets the dimension of relation.
Parameters: dim (int) – the dimension of relation.
-
Config.
set_train_times
(times)[source]¶ This method sets the rounds for training.
Parameters: times (int) – rounds for training.
-
Config.
set_nbatches
(nbatches)[source]¶ This method sets the number of batch.
Parameters: nbatches (int) – number of batch.
-
Config.
set_work_threads
(threads)[source]¶ We can use multi-threading trainning for accelaration. This method sets the numebr of threads.
Parameters: threads (int) – number of working threads.
-
Config.
set_ent_neg_rate
(rate)[source]¶ the number of negatives generated per positive training sample influnces the experiment results. This method sets the number of negative entities constructed per positive sample.
Parameters: rate (int) – the number of negative entities per positive sample.
-
Config.
set_rel_neg_rate
(rate)[source]¶ This method sets the number of negative relations per positive sample.
Parameters: rate (int) – the number of negative relations per positive sample.
-
Config.
set_lr_decay
(lr_decay)[source]¶ This method sets the learning rate decay for
Adagrad
optim method.Parameters: lr_decay (float) – learning rate decay
-
Config.
set_weight_decay
(weight_decay)[source]¶ This method sets the weight decay for
Adagrad
optim method.Parameters: weight_decay (float) – weight decay for Adagrad
.
Setting Inpath and Outpath¶
-
Config.
set_import_files
(path)[source]¶ Model paramters are exported automatically every few rounds. This method sets the path to find exported model parameters.
Parameters: path – path to automatically exported model parameters.
Saving and Loading Models¶
-
Config.
save_pytorch
()[source]¶ This method saves the model paramters to
self.exportName
which was set byset_export_files()
.
-
Config.
export_variables
(path=None)[source]¶ This method export model paramters through
torch.save
.Parameters: path – If None, this function euquals to save_pytorch()
, else save paramters topath
-
Config.
import_variables
(path=None)[source]¶ This method export model paramters through
torch.load
.Parameters: path – If None, this function euquals to restore_pytorch()
, else save paramters topath
-
Config.
get_parameters
(mode='numpy')[source]¶ This method gets the model paramters.
Parameters: mode – if numpy
, returns model parameters as numpy array, iflist
, returns those as list
-
Config.
save_parameters
(path=None)[source]¶ This method save model parameters as json files when training finished.
Parameters: path – if None, save parameters to self.out_path
which was set byset_out_files()
.