Closed ck471 closed 3 years ago
Hi, @ck471, My understanding is you were trying to conduct inference over the model pre-trained against your own dataset. When using custom datasets, this naming convention needs to be followed: say you named your dataset as "mydataset" and your ./dataset/custom_dataset
folder needs to have mydataset-train.txt, mydataset-test.txt and mydataset-valid.txt ready. If you don't use your own hyperparameters yaml, you need to pass in the dataset name on both training and inferring. So try the followings and see if they work or not:
pykg2vec-train -mn TransM -ds mydataset -dsp ./dataset/custom_dataset
pykg2vec-infer -mn TransM -ds mydataset -ld dataset/custom_dataset/intermediate/transm -dsp ./dataset/custom_dataset
Hello @baxtree. Thank you for the quick response.
The inference works if I provide train/test/valid. I was wondering if I am able to infer entities and relations without train, test and valid after my model is trained. Looking at the code, the trainer class relies on the KnowledgeGraph, which needs train/test/valid. Same goes if i try to create a model object, for example a TransM(PairwiseModel)
object.
Your help is much appreciated.
Glad it works! The inference will still need the index-to-entity and index-to-relation mappings for returning the original labels of entities or relations rather than the index numbers. But you are right, the inference should not require users to pass in the path to the training dataset coz those mappings are already stored in the cache after training, see in idx2entity.pkl
and idx2relation.pkl
under ./dataset/custom_dataset
.
I can smell a new improvement of removing the requirement on datasets when performing certain tasks. Any thoughts @louisccc ?
Hi, @ck471 . Just let you know PR https://github.com/Sujit-O/pykg2vec/pull/209 has made other params redundant for inference and you will be able to do
pykg2vec-infer -ld dataset/custom_dataset/intermediate/transm
.
I trained a model (TransM) based on a custom Dataset and now I am trying to export it. Afiu I only need the
-ld
parameter with the model config and vec.pt. When I try to infer I cannot build or load the model since its complaining there is no train data available because it iss trying to build the KnowledgeGraph. Naturally, I do not want to export the model with all the training data. This behaviour is the same for the infernce.py example. If you load the pretrained model it will still download the data.How can I accomplish loading the model independent of the train, test, val data?
To Reproduce
config_def, model_def = Importer().import_model_config(args.model_name.lower()) config = config_def(args)
args = ["-mn", "TransM", "-ld", "dataset/custom_dataset/intermediate/transm",] args = KGEArgParser().get_args(args)
config_def, model_def = Importer().import_model_config(args.model_name.lower()) config = config_def(args)