GithubHelp home page GithubHelp logo

xiaoanshi / relation-similarity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thunlp/relation-similarity

0.0 1.0 0.0 46.55 MB

codes accompanying ACL 2019 paper Quantifying the Similarity between Relations with Fact Distributions

License: MIT License

Python 97.69% Shell 2.31%

relation-similarity's Introduction

Relation Similarity

Using fact distribution to quantify the similarity between relations in knowledge bases and real world.

If you use the code, pleace cite the following paper:

@inproceedings{chen2019quantifying,
  title={Quantifying Similarity between Relations with Fact Distribution},
  author={Chen, Weize and Zhu, Hao and Han, Xu and Liu, Zhiyuan and Sun, Maosong},
  booktitle={Proceedings of the 57th Conference of the Association for Computational Linguistics},
  pages={2882--2894},
  year={2019}
}

Requirements

  • Python 3 (tested on 3.6.7)
  • PyTorch (tested on 1.0.0)
  • Numpy (tested on 1.16.0)
  • Tqdm (tested on 4.30.0)
  • TensorboardX (tested on 1.6)

Installation

pip install -r requirements.txt

Training

You can use the following code to train a model that is capable of modeling fact distribution.

python train.py --input $Directory_to_your_own_dataset --output ./checkpoint -ent_pretrain -rel_pretrain 

If you want to train the model on the provided wikipedia dataset, you have to decompress the pretrained entity embedding file first.

Note that if you choose to add "-ent_pretrain" and "-rel_pretrain", ensure that you have pretrained embedding file "entity2vec.vec" and "relation2vec.vec" in your input directory. In our paper, the two pretrained embedding files are produced by running TransE on the dataset. We use the TransE implementation in OpenKE.

Yield relation similarity

You can use the following code to yield similarity between relations after training the model.

python get_sim.py --model_path ./checkpoint --input ./data/wikipedia/ --output ./result

Two files will be produced, "kl_prob.txt" and "kl_prob.json". They are the same except the file format. The i-th line contains the KL divergence between i-th relation and other relations.

Hyper-parameters

All the default hyper-parameters are the ones used in the paper.

Relation prediction and relation extraction

We perform relation prediction using the implementation of https://github.com/thunlp/OpenKE/tree/OpenKE-alpha. You can run "example_train_transe.py" to reproduce the result.

As for relation extraction, we put the code in "tacred" directory. Due to copyright issues, we did not publish the dataset.

relation-similarity's People

Contributors

chenweize1998 avatar prokil avatar

Watchers

James Cloos 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.