This Streamlit web application allows you to explore knowledge graph embeddings of municipalities and their relationships. You can make link predictions and find similar entities based on trained TransE embeddings.
- Link Prediction: Predict potential relationships between entities
- Similar Entity Search: Find municipalities with similar embedding vectors
- Entity Browser: Explore all entities in the knowledge graph
- Graph Visualization: Visual representations of prediction results
-
Clone the repository
git clone https://github.com/Chrisvenator/Knowledge-Graph-aboutAdjacent-Municipalities cd Knowledge-Graph-aboutAdjacent-Municipalities -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate -
Install dependencies
pip install -r requirements.txt -
Run the app
streamlit run kg_explorer_app.py
You can use a custom model by pasting its folder into the root dir of this project and then specifying the folder name on the left side
- streamlit
- torch
- pykeen>
- networkx
- matplotlib
- pandas
- Pillow
- numpy
- geopandas
- libpysal
- rdflib
- tqdm
- requests
This tab now offers a lean, fast-loading map for exploring inter-municipality relationships. It tries to predict how similar the municipalities are based on Nationalratswahl Voting, Population, Income, Ausgaben, Adjacency.
Here is how the same map looks, when the coloring is based on total similarity.
Overall, this view emphasises raw similarity values; since most scores cluster near the top, almost everything appears bright green.

Example of how 4000 municipalities look that are similar. The redder, the unsimilar the municipalities become.
Note that this picture uses relative colors.
This second screenshot demonstrates the “relative” (rank-based) palette: the colour scale stretches across the entire dataset so users immediately see a spectrum from strongest (green) to weakest (red) links, making differences far easier to spot than in the absolute view.

- interactive Plotly-based network visualisation with
- Node sizing based on connection degree
- Colour-coded nodes based on connectivity
- Adjustable node limits and relation filtering
- Network statistics (density, average degree, etc.)
- comprehensive attribute analysis with
- Summary statistics for all attributes
- Interactive attribute selection and visualisation
- Histogram distributions for numeric attributes
- Sample-data viewing and full attribute tables
- TransE-model-based similarity finding with
- Entity-embedding similarity calculation
- Configurable numb
- Search entities by name
- View all matching entities and their URIs
Your model directory should have the following files:
project-root/
├──dataset.ttl
├──dataset_entities_only.ttl
├──dataset_attributes.json
└──model/
├── model_state.pt # PyTorch state dict of the trained model
├── model_config.json # Model configuration (model_class, embedding_dim, etc.)
└── mappings.json # Entity and relation mappings
The model_config.json should include:
{
"model_class": "TransE",
"embedding_dim": 50,
"scoring_fct_norm": 1
}The mappings.json should include:
{
"entity_to_id": {
"http://municipality.org/entity/Municipality_1": "0",
...
},
"relation_to_id": {
"http://municipality.org/relation/adjacentTo": "0",
...
}
}- Model loading issues: Ensure your model files follow the required structure
- Memory errors: Try reducing the number of entities or embedding dimension
- Visualization problems: Adjust graph parameters in the
visualize_graphfunction
