Lab: Training Graph Embeddings: Difference between revisions

From info216
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Lab 14: Training Graph Embeddings=


==Topics==
==Topics==
Training knowledge graph embeddings with TorchKGE.
Training knowledge graph embeddings with TorchKGE.


<!-- ==Tutorial== -->
==Useful readings==
 
* [https://torchkge.readthedocs.io/en/latest/ Welcome to TorchKGE’ s documentation!]


==Classes and methods==
'''Classes and methods:'''
The following TorchKGE classes from the previous lab remain central:
The following TorchKGE class from the previous lab remains central:
* '''KG''' - contains the knowledge graph (KG)
* ''Model'' - contains the embeddings (entity and relation vectors) for the KG
* '''Model''' - contains the embeddings (entity and relation vectors) for the KG


More classes will be suggested below.
In addition, we will also use:
 
* ''KnowledgeGraph'' - contains the knowledge graph (KG)
<!--
<syntaxhighlight>
</syntaxhighlight>
-->


==Tasks==
==Tasks==
 
'''Task: pre-trained models''':
'''Pre-trained models''':
* Choose a KG and TransE model you want to work with. It should have a [https://torchkge.readthedocs.io/en/latest/reference/utils.html#pre-trained-models pre-trained model] available. (Freebase FB15k is still a good choice, see the note below if you want to use Wikidata.)
* Choose a KG and TransE model you want to work with. It should have a [https://torchkge.readthedocs.io/en/latest/reference/utils.html#pre-trained-models pre-trained model] available.
* Load the pre-trained model (you do no need the KG yet). and evaluate it using the examples given here: https://torchkge.readthedocs.io/en/latest/tutorials/evaluation.html .
* Load the pre-trained model (you do no need the KG yet). and evaluate it using the examples given here: https://torchkge.readthedocs.io/en/latest/tutorials/evaluation.html .
* ''Extra:'' You can also evaluate the model on [https://torchkge.readthedocs.io/en/latest/reference/evaluation.html#relation-prediction relation prediction] but, the way TransE is pre-trained, it is awful on this task.
* ''Extra:'' You can also evaluate the model on [https://torchkge.readthedocs.io/en/latest/reference/evaluation.html#relation-prediction relation prediction] but, the way TransE is pre-trained, it is awful on this task.


'''Train your own''':
''Note:'' The Wikidata dataset returns two graphs. They are not train/test, but the dataset with and without additional attributes. Start with the one without attributes. You need to split it into train/validation/test yourself using [https://torchkge.readthedocs.io/en/latest/reference/data.html#knowledge-graph KG.split_kg()].
 
'''Task: train your own''':
* Load the corresponding KG using a [https://torchkge.readthedocs.io/en/latest/reference/utils.html#datasets-loaders dataset loader].
* Load the corresponding KG using a [https://torchkge.readthedocs.io/en/latest/reference/utils.html#datasets-loaders dataset loader].
* Run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Shortest training] example, '''but use a much lower value for epoch''' (for example 200).
* Run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Shortest training] example, '''but use a much lower value for epoch''' (for example 200).
Line 33: Line 27:
* Also run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Simplest training] example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do.
* Also run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Simplest training] example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do.


'''Train with early stopping''':
'''Task: train with early stopping''':
* Run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Training with Ignite] example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do. How do the results compare with your exploration of different ''epoch'' values?
* Run the [https://torchkge.readthedocs.io/en/latest/tutorials/training.html Training with Ignite] example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do. How do the results compare with your exploration of different ''epoch'' values?
<!--
==Code to get started==
<syntaxhighlight>
</syntaxhighlight>
-->


==If You Have More Time==
==If You Have More Time==
* Try this out on the other models supported by TorchKGE, both other TransX models and a deep model (ConvKB).
* Try this out on the other models supported by TorchKGE, both other TransX models and a deep model (ConvKB).
* Try it out with different datasets, for example one you create youreself using SPARQL queries on an open KG.
* Try it out with different datasets, for example one you create youreself using SPARQL queries on an open KG.
==Useful readings==
* [https://torchkge.readthedocs.io/en/latest/ Welcome to TorchKGE’ s documentation!]

Latest revision as of 06:38, 18 April 2023

Topics

Training knowledge graph embeddings with TorchKGE.

Useful readings

Classes and methods: The following TorchKGE class from the previous lab remains central:

  • Model - contains the embeddings (entity and relation vectors) for the KG

In addition, we will also use:

  • KnowledgeGraph - contains the knowledge graph (KG)

Tasks

Task: pre-trained models:

Note: The Wikidata dataset returns two graphs. They are not train/test, but the dataset with and without additional attributes. Start with the one without attributes. You need to split it into train/validation/test yourself using KG.split_kg().

Task: train your own:

  • Load the corresponding KG using a dataset loader.
  • Run the Shortest training example, but use a much lower value for epoch (for example 200).
  • Take note of the evaluation metrics and final loss, and re-run the example using different numbers of epochs. What happens when you increase the number?
  • Also run the Simplest training example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do.

Task: train with early stopping:

  • Run the Training with Ignite example. Use the documentation to make sure you have an idea of what the different parts of the algorithm do. How do the results compare with your exploration of different epoch values?

If You Have More Time

  • Try this out on the other models supported by TorchKGE, both other TransX models and a deep model (ConvKB).
  • Try it out with different datasets, for example one you create youreself using SPARQL queries on an open KG.