GithubHelp home page GithubHelp logo

mrphil / emgraph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bi-graph/emgraph

0.0 1.0 0.0 6.6 MB

A Python library for knowledge graph representation learning (graph embedding).

Home Page: https://bi-graph.github.io/Emgraph

License: Other

Python 100.00%

emgraph's Introduction

Emgraph

Emgraph (Embedding graphs) is a Python library for graph representation learning.

It provides a simple API for design, train, and evaluate graph embedding models. You can use the base models to easily develop your own model.

PyPI - Package version PyPI - Python Version PyPI - Downloads PyPI - Implementation GitHub last commit GitHub Repo stars PyPI - Maintenance PyPI - License PyPI - Format Status Commits Commits

Installation

Install the latest version of Emgraph:

$ pip install emgraph

Documentation

Soon

Quick start

Embedding wordnet11 graph using TransE model:

from sklearn.metrics import brier_score_loss, log_loss
from scipy.special import expit
from emgraph.datasets import BaseDataset, DatasetType
from emgraph.models import TransE


def train_transe(data):
    
    model = TransE(batches_count=64, seed=0, epochs=20, k=100, eta=20,
                   optimizer='adam', optimizer_params={'lr': 0.0001},
                   loss='pairwise', verbose=True, large_graphs=False)
    model.fit(data['train'])
    scores = model.predict(data['test'])
    return scores
    

if __name__ == '__main__':
    
    wn11_dataset = BaseDataset.load_dataset(DatasetType.WN11)
    
    scores = train_transe(data=wn11_dataset)
    print("Scores: ", scores)
    print("Brier score loss:", brier_score_loss(wn11_dataset['test_labels'], expit(scores)))

Evaluating ComplEx model after training:

import numpy as np
from emgraph.datasets import BaseDataset, DatasetType
from emgraph.models import ComplEx
from emgraph.evaluation import evaluate_performance



def complex_performance(data):
    
    model = ComplEx(batches_count=10, seed=0, epochs=20, k=150, eta=1,
                    loss='nll', optimizer='adam')
    model.fit(np.concatenate((data['train'], data['valid'])))
    filter_triples = np.concatenate((data['train'], data['valid'], data['test']))
    ranks = evaluate_performance(data['test'][:5], model=model,
                                 filter_triples=filter_triples,
                                 corrupt_side='s+o',
                                 use_default_protocol=False)
    return ranks


if __name__ == '__main__':

    wn18_dataset = BaseDataset.load_dataset(DatasetType.WN18)   
    ranks = complex_performance(data=wn18_dataset)
    print("ranks {}".format(ranks))

More examples

Embedding wordnet11 graph using DistMult model:

from sklearn.metrics import brier_score_loss, log_loss
from scipy.special import expit
from emgraph.datasets import BaseDataset, DatasetType
from emgraph.models import DistMult


def train_dist_mult(data):

    model = DistMult(batches_count=1, seed=555, epochs=20, k=10, loss='pairwise',
                     loss_params={'margin': 5})
    model.fit(data['train'])
    scores = model.predict(data['test'])
    
    return scores
    

if __name__ == '__main__':
    
    wn11_dataset = BaseDataset.load_dataset(DatasetType.WN11)
    
    scores = train_dist_mult(data=wn11_dataset)
    print("Scores: ", scores)
    print("Brier score loss:", brier_score_loss(wn11_dataset['test_labels'], expit(scores)))

Call for Contributions

The Emgraph project welcomes your expertise and enthusiasm!

Ways to contribute to Emgraph:

  • Writing code
  • Review pull requests
  • Develop tutorials, presentations, and other educational materials
  • Translate documentation and readme contents

Issues

If you happened to encounter any issue in the codes, please report it here. A better way is to fork the repository on Github and/or create a pull request.

Features

  • Support CPU/GPU
  • Vectorized operations
  • Preprocessors
  • Dataset loader
  • Standard API
  • Documentation
  • Test driven development

If you find it helpful, please give us a

License

Released under the BSD license

Copyright © 2019-2022 Emgraph Developers
Soran Ghaderi ([email protected])   follow me Github Twitter Linkedin
Taleb Zarhesh ([email protected])  follow me Github Twitter Linkedin

emgraph's People

Contributors

soran-ghaderi avatar sigma1326 avatar codacy-badger 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.