KGATE 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kgate-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 NSBD Team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kgate-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.3
2
+ Name: KGATE
3
+ Version: 0.1.0
4
+ Summary: Knowledge Graph Autoencoder Training Environment, bridging PyG encoders and TorchKGE decoders.
5
+ License: MIT
6
+ Keywords: Knowledge Graph,Knowledge Graph Embedding,Autoencoder,Machine Learning,Link Prediction
7
+ Author: Benjamin Loire
8
+ Author-email: benjamin.loire@univ-amu.fr
9
+ Requires-Python: >=3.10
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Data Scientists
12
+ Classifier: Topic :: Machine Learning :: Knowledge Graph Embedding
13
+ Requires-Dist: matplotlib (>=3.10.0,<4.0.0)
14
+ Requires-Dist: pytest (>=8.3.4,<9.0.0)
15
+ Requires-Dist: pytorch-ignite (>=0.5.1,<0.6.0)
16
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
17
+ Requires-Dist: torch-geometric (>=2.6.1,<3.0.0)
18
+ Requires-Dist: torchkge (>=0.17.7,<0.18.0)
19
+ Project-URL: Repository, https://github.com/BAUDOTlab/KGATE
20
+ Project-URL: issues, https://github.com/BAUDOTlab/KGATE/issues
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Knowledge Graph Autoencoder Training Environment (KGATE)
24
+
25
+ KGATE is a knowledge graph embedding library bridging the encoders from [Pytorch Geometric](https://github.com/pyg-team/pytorch_geometric) and the decoders from [TorchKGE](https://github.com/torchkge-team/torchkge).
26
+
27
+ This tool relies heavily on the performances of TorchKGE and its numerous implemented modules for link prediction, negative sampling and model evaluation. The main goal here is to address the lack of encoders in the original library, who is unfortunately not maintained anymore.
28
+
29
+ ## Installation
30
+
31
+ To join in the development, clone this repository and install Poetry:
32
+
33
+ ```pip install poetry```
34
+
35
+ Install the dependencies with:
36
+
37
+ ```poetry install```
38
+
39
+ ## Usage
40
+
41
+ KGATE is meant to be a self-sufficient training environment for knowledge graph embedding that requires very little code to work but can easily be expanded or modified. Everything stems from the **Architect** class, which holds all the necessary attributes and methods to fully train and test a KGE model following the autoencoder architecture, as well as run inference.
42
+
43
+ ```python
44
+ from kgate import Architect
45
+
46
+ config_path = "/path/to/your/config.toml"
47
+
48
+ architect = Architect(config = config_path)
49
+
50
+ # Train the model using KG and hyperparameters specified in the configuration
51
+ architect.train()
52
+
53
+ # Test the trained model, using the best checkpoint
54
+ architect.test()
55
+
56
+ # Run KG completion task, the empty list is the element that will be predicted
57
+ known_heads = []
58
+ known_relations = []
59
+ known_tails = []
60
+ architect.infer(known_heads, known_relations, known_tails)
61
+ ```
62
+
63
+ For a more detailed example and specific methods that are available in the package, see the upcoming readthedocs documentation.
64
+
65
+ ## License
66
+
67
+ This project is licensed under the MIT License. See the [LICENSE](#license) file for details.
kgate-0.1.0/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Knowledge Graph Autoencoder Training Environment (KGATE)
2
+
3
+ KGATE is a knowledge graph embedding library bridging the encoders from [Pytorch Geometric](https://github.com/pyg-team/pytorch_geometric) and the decoders from [TorchKGE](https://github.com/torchkge-team/torchkge).
4
+
5
+ This tool relies heavily on the performances of TorchKGE and its numerous implemented modules for link prediction, negative sampling and model evaluation. The main goal here is to address the lack of encoders in the original library, who is unfortunately not maintained anymore.
6
+
7
+ ## Installation
8
+
9
+ To join in the development, clone this repository and install Poetry:
10
+
11
+ ```pip install poetry```
12
+
13
+ Install the dependencies with:
14
+
15
+ ```poetry install```
16
+
17
+ ## Usage
18
+
19
+ KGATE is meant to be a self-sufficient training environment for knowledge graph embedding that requires very little code to work but can easily be expanded or modified. Everything stems from the **Architect** class, which holds all the necessary attributes and methods to fully train and test a KGE model following the autoencoder architecture, as well as run inference.
20
+
21
+ ```python
22
+ from kgate import Architect
23
+
24
+ config_path = "/path/to/your/config.toml"
25
+
26
+ architect = Architect(config = config_path)
27
+
28
+ # Train the model using KG and hyperparameters specified in the configuration
29
+ architect.train()
30
+
31
+ # Test the trained model, using the best checkpoint
32
+ architect.test()
33
+
34
+ # Run KG completion task, the empty list is the element that will be predicted
35
+ known_heads = []
36
+ known_relations = []
37
+ known_tails = []
38
+ architect.infer(known_heads, known_relations, known_tails)
39
+ ```
40
+
41
+ For a more detailed example and specific methods that are available in the package, see the upcoming readthedocs documentation.
42
+
43
+ ## License
44
+
45
+ This project is licensed under the MIT License. See the [LICENSE](#license) file for details.
@@ -0,0 +1,42 @@
1
+ [project]
2
+ name = "KGATE"
3
+ version = "0.1.0"
4
+ description = "Knowledge Graph Autoencoder Training Environment, bridging PyG encoders and TorchKGE decoders."
5
+ authors = [
6
+ {name = "Benjamin Loire", email = "benjamin.loire@univ-amu.fr"},
7
+ {name = "Galadriel Brière", email = "galadriel.briere@univ-amu.fr"}
8
+ ]
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ keywords = ["Knowledge Graph", "Knowledge Graph Embedding", "Autoencoder", "Machine Learning","Link Prediction"]
12
+ classifiers = [
13
+ # How mature is this project? Common values are
14
+ # 3 - Alpha
15
+ # 4 - Beta
16
+ # 5 - Production/Stable
17
+ "Development Status :: 3 - Alpha",
18
+
19
+ # Indicate who your project is intended for
20
+ "Intended Audience :: Data Scientists",
21
+ "Topic :: Machine Learning :: Knowledge Graph Embedding",
22
+ ]
23
+
24
+ requires-python = ">=3.10"
25
+
26
+ [project.urls]
27
+ repository = "https://github.com/BAUDOTlab/KGATE"
28
+ issues = "https://github.com/BAUDOTlab/KGATE/issues"
29
+
30
+ [tool.poetry]
31
+ include = [
32
+ { path = "config_template.toml", format = ["sdist","wheel"] }
33
+ ]
34
+
35
+ [tool.poetry.dependencies]
36
+ python = ">=3.10"
37
+ torchkge = "^0.17.7"
38
+ torch-geometric = "^2.6.1"
39
+ matplotlib = "^3.10.0"
40
+ pytorch-ignite = "^0.5.1"
41
+ pyyaml = "^6.0.2"
42
+ pytest = "^8.3.4"
@@ -0,0 +1,3 @@
1
+ from .data_structures import KGATEGraph
2
+ from .kgate import Architect
3
+ from .utils import HeteroMappings, init_embedding, read_training_metrics
@@ -0,0 +1,83 @@
1
+ seed = 42
2
+
3
+ # Path to the KG in CSV format with at least columns named from, to and rel
4
+ kg_csv = ""
5
+ # Path to the KG in pickle format. If both csv and pkl are set, the pickle will have priority.
6
+ kg_pkl = ""
7
+
8
+ # Path to the CSV mapping entities to their metadata, with at least columns id (must be the same as the KG id) and type
9
+ metadata_csv = ""
10
+
11
+ # Path to the analysis output directory
12
+ output_directory = ""
13
+
14
+ verbose = true
15
+ run_kg_preprocess = true
16
+ run_training = false
17
+ run_evaluation = false
18
+
19
+ [preprocessing]
20
+
21
+ remove_duplicate_triples = true
22
+
23
+ # If undirected relations are found, will make them directed by creating a reverse relation
24
+ make_directed = true
25
+ make_directed_relations = []
26
+
27
+ flag_near_duplicate_relations = true
28
+
29
+ # DL stuff, keep ?
30
+ #permute_entities = false
31
+
32
+ # Remove all flagged relations from the train set
33
+ clean_train_set = true
34
+
35
+ #mixed_test = true
36
+
37
+ [preprocessing.params]
38
+ theta = 0.8
39
+ theta1 = 0.8
40
+ theta2 = 0.8
41
+
42
+ [model]
43
+ emb_dim = 256
44
+ rel_emb_dim = 256
45
+
46
+ [model.encoder]
47
+ name = "Default" #Lookup table
48
+ gnn_layer_number = 1
49
+ #add other possible hyperparams
50
+
51
+ [model.decoder]
52
+ name = "TransE"
53
+ margin = 1 # Models using MarginLoss
54
+ dissimilarity = "L2"
55
+ #add other possible hyperparams
56
+
57
+ [sampler]
58
+ name = "Positional"
59
+ n_neg = 1
60
+
61
+ [optimizer]
62
+ name = "Adam"
63
+ [optimizer.params]
64
+ weight_decay = 0.001
65
+
66
+ [lr_scheduler]
67
+ type = "CosineAnnealingWarmRestarts"
68
+ [lr_scheduler.params]
69
+ T_0 = 10
70
+ T_mult = 2
71
+
72
+ [training]
73
+ max_epochs = 100
74
+ patience = 20
75
+ train_batch_size = 2048
76
+ eval_interval = 10
77
+ eval_batch_size = 32
78
+
79
+ [evaluation]
80
+ made_directed_relations = []
81
+ # List of relations for which link prediction will be evaluated
82
+ target_relations = []
83
+ thresholds = [10]