Code Monkey home page Code Monkey logo

kg-embeddings's Introduction

KG Embeddings

Generate embeddings on the graph, with RDF2Vec - using pyRDF2Vec -, TransE, DistMult - using pyKEEN.

Training

In the config folder, edit appropriately the following files:

  • object_properties.txt the list of object properties which will be taken into account for the random walks (1 per line);
  • prefixes.txt to be added to the SPARQL queries
  • get_entities.rq the query for getting the URIs of all entities of interest.

Run the following commands for downloading the data on your machine:

pip install -r requirements.txt
python preprocessing.py

Finally, generate the embeddings using:

python main.py [entities list] [-a algorith_name]

where entities list is a list of entities uri (1 per line) in a textual file. Following the generated files by the preprocessing, you can run (for example):

python main.py voc
python main.py smells -a TransE

This is producing an [entity].kv file, which is a gensim's KeyedVector file.

Selecting a dense subraph

For generating a dense subgraph, you should run the following scripts

python reduce_graph.py
python generate_dense_subgraph.py

and run again the embedding script with

python main.py [entities list] [-a algorith_name] -d dense_graph.csv

Load and use embeddings

Load embeddings in this way:

emb = KeyedVectors.load('emb.kv')

Search the most similar to a term:

emb.most_similar('http://data.odeuropa.eu/vocabulary/olfactory-objects/269', topn=10) # incense

# 0.7755   http://data.odeuropa.eu/vocabulary/olfactory-objects/267   Frankincense

Refer to gensim's documentation for further possibilities.

Clustering and link predicting

We performed experiment for clustering and link predicting using the following code:

  • Clustering: notebook - [notebook with dense graph](./Clustering-Dense Graph.ipynb)
  • Link prediction with TransE and DistMult: script

kg-embeddings's People

Contributors

pasqlisena avatar

Watchers

Daniel Schwabe avatar Arno Bosse avatar Raphael Troncy avatar Thibault Ehrhart avatar Ali Hürriyetoğlu avatar  avatar Sara Tonelli avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.