Git Product home page Git Product logo

openke's Introduction

OpenKE

An Open-source Framework for Knowledge Embedding forked from github.org/thunlp/OpenKE. The original API changed drastically to look more intuitively on a python notebook.

Overview

This is an implementation based on TensorFlow for knowledge representation learning (KRL). It includes native C++ implementations for underlying operations such as data preprocessing and negative sampling. For each specific model, it is implemented by TensorFlow with Python interfaces so that there is a convenient platform to run models on GPUs.

Installation

  1. Install requirements

    $ pip install tensorflow

  2. Clone the OpenKE repository:

    $ git clone https://github.com/thunlp/OpenKE

    $ cd OpenKE

  3. Build the library

    $ bash make.sh

Data

This framework requires datasets to contain a line with one number of elements followed by as many lines, each containing three whitespace-separated indices head tail label where head and tail denote indices of entities and label denotes the index of a relation. Make sure to separate your data early on into at least two separate parts for training and testing.

Quickstart

To compute a knowledge graph embedding, first import datasets and set configure parameters for training, then train models and export results. For instance, we write an example_train_transe.py to train TransE:

from openke import Dataset
from openke.models import TransE

#   Input training files from benchmarks/FB15K/ folder.
with open("./benchmarks/FB15K/entity2id.txt") as f:
    E = int(f.readline())
with open("./benchmarks/FB15K/relation2id.txt") as f:
    R = int(f.readline())

#   Read the dataset.
base = Dataset("./benchmarks/FB15K/train2id.txt", E, R)

#   Set the knowledge embedding model class.
model = TransE(50, 1.0, base.shape)

#   Train the model.
base.train(500, model, count=100, negatives=(1,0), bern=False, workers=4)

#   Save the result.
model.save("./result")

Interfaces

Config

class openke.Dataset in openke/Config.py sets up the native library, handles the currently loaded dataset and defines the basic training algorithm.

Model Class

class openke.models.ModelClass in openke/models/Base.py declares the methods that all implemented model classes share, including the loss function neccessairy for training (inserting information into the model) and prediction (aka. retrieving information from the model). This project implements the following model classes:

class openke.models.RESCAL
class openke.models.TransE
class openke.models.TransH
class openke.models.TransR
class openke.models.TransD
class openke.models.HolE
class openke.models.ComplEx
class openke.models.DistMult

openke's People

Contributors

xeren avatar thucsthanxu13 avatar shulincao avatar erickguan avatar

Stargazers

Jan Kalo avatar

Watchers

 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.