Skip to content

Repository files navigation

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 versionPyPI - Python VersionPyPI - DownloadsPyPI - ImplementationGitHub last commitGitHub Repo starsPyPI - MaintenancePyPI - LicensePyPI - FormatStatusCommitsCommits

Installation

Install the latest version of Emgraph:

$ pip install emgraph

Quick start

Embedding wordnet11 graph using TransE model:

fromsklearn.metricsimportbrier_score_loss, log_lossfromscipy.specialimportexpitfromemgraph.datasetsimportBaseDataset, DatasetTypefromemgraph.modelsimportTransEdeftrain_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'])
returnscoresif__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:

importnumpyasnpfromemgraph.datasetsimportBaseDataset, DatasetTypefromemgraph.modelsimportComplExfromemgraph.evaluationimportevaluate_performancedefcomplex_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)
returnranksif__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:

fromsklearn.metricsimportbrier_score_loss, log_lossfromscipy.specialimportexpitfromemgraph.datasetsimportBaseDataset, DatasetTypefromemgraph.modelsimportDistMultdeftrain_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'])
returnscoresif__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 this project helpful, please consider giving it a .

License

Released under the BSD license

Credit

This repository is a transformation of the AmpliGraph library for TensorFlow 2, with a modular architecture implementation. It also draws inspiration from PyKEEN and Spectral. Credit is extended to these exceptional projects.

Contact

Copyright © 2019-2024 Emgraph Developers
Soran Ghaderi (soran.gdr.cs@gmail.com) follow me GithubTwitterLinkedinTaleb Zarhesh (taleb.zarhesh@gmail.com) follow me GithubTwitterLinkedin

About

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

Topics

Resources

Stars

39 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages