Repository: pykeen/pykeen
Issue: Load Model - But what about the triples factory?
Root cause: Documentation Deficiency

### How to load a Triples Factory used to train a loaded Pre-trained model?

Hello,

I am training an embedding model using a pipeline, and then saving the model using the pipeline's `save_to_directory()` method. When I am looking to load the model again for use, I follow the documentation's guidance by using `torch.load('trained_model.pkl')`.

This part works fine, I am able to save the model and load back a new model object.

However, I am looking to use the new model object to make head and tail predictions from entity labels. When I try to run methods such as `get_tail_prediction_df()` I am told that I am "missing 1 keyword-only argument: 'triples_factory'".

I am aware that I may need the triples_factory that was used when training the model to map labels to ids. It seems that this is not saved directly as part of the model. I am aware that a directory "training_triples" is made when the model is saved and this appears to contain zipped tsv files that I am assuming are what i need to load.

My main issues/questions/feedback on this are:

- Do I have to load the `numeric_triples.tsv` as the data for the triples factory?
- The Triples documentation only contains details for a method `from_path_binary()` for loading PyTorch files. Reading the [Bring Your Own Data](https://pykeen.readthedocs.io/en/stable/byo/data.html) section, it implies there is also a method `from_path()`,  to load tsv files but this method does not appear in the Triples section of the documentation. 
- The above Bring Your Own Data section also suggests the ability to set the attributes `entity_to_id` and `relation_to_id` using this `from_path()` method, however these are passed to the loading of the test set by accessing the attributes of the loaded training set directly.
- The above example is presumably the equivalent of using the `from_path()` method to load the equivalent `numeric_triples.tsv` file that is saved by the pipeline. However, this example is to set up a model for training. As I am using a pretrained model, there is no guarantee that the mapping made when loading this tsv is the same as the ones used by my pretrained model, as such I assume I will need to load these mappings myself?
- The directory that contains this tsv also has two further tsvs:  `entity_to_id.tsv` and `relation_to_id.tsv`. If these files are needed to be loaded as the mappings for the model, how do I go about loading them? There are no examples in the documentation of loading a mapping from a tsv.
- The examples for loading/reusing models in the documentation and on your github do not at any point cover the loading of the triples factory. The examples found for loading use prepackaged datasets and so can make use of other methods such as `get_dataset()`.
- There is no documentation within the Triples section of the documentation to cover loading a triples factory from tsv, and nor is there documentation on loading entity and relation mappings to a triples factory.
- In fact there is no mention of the `entity_to_id` and `relation_to_id` attributes in this part of the documentation at all.
- For usability, if you are saving a model from a pipeline using `save_to_directory()`, should there not be a corresponding `load_from_directory()` or load methods in the Model/Triples classes that can take input in this way?  

Thanks for any help you can provide, and I hope the documentation feedback is useful. :)


### Environment

| Key             | Value                    |
|-----------------|--------------------------|
| OS              | nt                       |
| Platform        | Windows                  |
| Release         | 10                       |
| Time            | Sun May  8 14:07:57 2022 |
| Python          | 3.9.7                    |
| PyKEEN          | 1.8.1                    |
| PyKEEN Hash     | UNHASHED                 |
| PyKEEN Branch   |                          |
| PyTorch         | 1.10.1                   |
| CUDA Available? | true                     |
| CUDA Version    | 11.3                     |
| cuDNN Version   | 8200                     |

### Issue Template Checks

- [X] This is not a bug report (use a different issue template if it is)
- [X] This is not a feature request (use a different issue template if it is)
- [X] I've read the text explaining why including environment information is important and understand if I omit this information that my issue will be dismissed

Hi @cosmiccreepers ,

does https://github.com/pykeen/pykeen/discussions/909 already help you? 

We'll try to update our documentation soon, too.

Hello,

Yes, thanks! It was definitely what I was looking for in terms of guidance for loading the triples. I seem to still be having some trouble with the mappings, I get a KeyError when using `get_tail_prediction_df()` now, but from a couple of checks I've run this also occurs when i run it direct from training, so i suspect the problem is elsewhere.

Thanks for the help, I do think having some more examples that show the loading of data / models would be really beneficial if possible.

If you created the triples factories yourself, did you check that you use the _same_ label-to-id for training & evaluation factory? This issue may also be related: https://github.com/pykeen/pykeen/issues/105

Hello,

I resolved the bug, it was an error on my part. It was loading a model that had been trained on a different set of triples by error.

Thanks for your help!