Coder Social home page Coder Social logo

quad's Introduction

QUAD

A PyTorch implementation of the paper "Learning Representations for Hyper-Relational Knowledge Graphs".

Abstract

Knowledge graphs (KGs) have gained prominence for their ability to learn representations for uni-relational facts. Recently, research has focused on modeling hyper-relational facts, which move beyond the restriction of uni-relational facts and allow us to represent more complex and real-world information. However, existing approaches for learning representations on hyper-relational KGs majorly focus on enhancing the communication from qualifiers to base triples while overlooking the flow of information from base triple to qualifiers. This can lead to suboptimal qualifier representations, especially when a large amount of qualifiers are presented. It motivates us to design a framework that utilizes multiple aggregators to learn representations for hyper-relational facts: one from the perspective of the base triple and the other one from the perspective of the qualifiers. Experiments demonstrate the effectiveness of our framework for hyper-relational knowledge graph completion across multiple datasets. Furthermore, we conduct an ablation study that validates the importance of the various components in our framework.

Requirements

All experiments were conducted using python 3.8.5. Python>=3.8 is required.

For the required python packages, please see requirements.txt.

tqdm>=4.64.0
torch>=1.9.0
numpy>=1.19.12
torch_geometric>=2.0.2
pytorch_warmup>=0.0.4

Running the Code

First clone our repository and install the required python packages.

git clone https://github.com/HarryShomer/QUAD.git
cd QUAD
pip install -r requirements.txt

To reproduce the results on each dataset you can run the following bash scripts. Each script contains the command to replicate both the parallel and non-parallel version of the model.

# Reproduce results on JF17K
bash scripts/run_jf17k.sh

# Reproduce results on WD50K
bash scripts/run_wd50k.sh

# Reproduce results on Wikipeople
bash scripts/run_wikipeople.sh

# Reproduce results on the WD50K splits - (33, 66, 100)
bash scripts/wd50k_splits.sh

By default the scripts try to run on cuda. To run on the cpu add the argument --device cpu

Acknowledgement

The code is modified from the StarE codebase (https://github.com/migalkin/StarE). We sincerely thank them for their contributions.

Cite

@article{shomer2022learning,
  title={Learning Representations for Hyper-Relational Knowledge Graphs},
  author={Shomer, Harry and Jin, Wei and Li, Juanhui and Ma, Yao and Tang, Jiliang},
  journal={arXiv preprint arXiv:2208.14322},
  year={2022}
}

quad's People

Contributors

harryshomer avatar

Stargazers

Alfredo Serafini avatar  avatar  avatar zhu ke avatar Yuning You avatar  avatar 爱可可-爱生活 avatar  avatar Dongkwan Kim avatar Wei Jin avatar  avatar

Watchers

 avatar

quad's Issues

Dependency

Hi, thanks for the code.
I tried to run the code, but some libraries are crashing.
Could you specify the version you used to run the code?
Thanks in advance

ValueError: not enough values to unpack (expected 5, got 2)

File "src/run.py", line 272, in
main()
File "src/run.py", line 267, in main
training_loop_gcn(**args)
File "/work/zhiweihu/reproduce-code/new_try/QUAD-master/src/loops/loops.py", line 89, in training_loop_gcn
obj_preds, aux_preds = model(_sub, _rel, _quals, aux_ent=aux_ent_dict)
File "/home/hzw/.conda/envs/cole/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/work/zhiweihu/reproduce-code/new_try/QUAD-master/src/models/hyper_gcn.py", line 124, in forward
s_emb, r_emb, qe_emb, qr_emb, o_emb = self.index_embs_aux(x, r, aux_ent['base_sub_ix'], aux_ent['base_rel_ix'], aux_ent['base_obj_ix'], aux_ent['quals'])
ValueError: not enough values to unpack (expected 5, got 2)

when I run the script:
python src/run.py wd50k_100 --clean-data --alpha .6 --aux-ent --aux-weight 1
--qual-layers 1 --encoder-drop1 .2 --encoder-drop2 .2
--batch-size 256 --trans-dim 768 --mask --label-smooth 0.1
--aux-ent-smooth 0.1 --parallel --parallel-drop .3 --device cuda:5

error

Traceback (most recent call last):
File "src/run.py", line 272, in
main()
File "src/run.py", line 267, in main
training_loop_gcn(**args)
File "/home/lnh/code/QUAD/src/loops/loops.py", line 89, in training_loop_gcn
obj_preds, aux_preds = model(_sub, _rel, _quals, aux_ent=aux_ent_dict)
File "/home/lnh/.conda/envs/QUD/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lnh/code/QUAD/src/models/hyper_gcn.py", line 108, in forward
x1, r1 = self.trip_encoder("trip", init_ent, init_rel)
File "/home/lnh/.conda/envs/QUD/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lnh/code/QUAD/src/models/encoders.py", line 57, in forward
x, r = self.conv1(
File "/home/lnh/.conda/envs/QUD/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lnh/code/QUAD/src/models/gnn_layer.py", line 155, in forward
loop_res = self.propagate(
TypeError: propagate() missing 6 required positional arguments: 'ent_embed', 'qualifier_ent', 'qualifier_rel', 'qual_index', 'trip_obj_ix', and 'trip_rel_ix'

when I run python src/run.py jf17k --alpha .8 --aux-ent --aux-weight .25 --qual-layers 2 --encoder-drop1 .1 --encoder-drop2 .1
--trans-dim 768 --lr-decay --lr-lambda .999 --mask --label-smooth 0.6
--aux-ent-smooth 0.6 --device cuda

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.