Git Product home page Git Product logo

kg-s2s's Introduction

KG-S2S

Knowledge Is Flat: A Seq2Seq Generative framework For Various Knowledge Graph Completion

Overview of KG-S2S ...

This repository includes the source code of the paper accepted by COLING'2022.

"Knowledge Is Flat: A Seq2Seq Generative framework For Various Knowledge Graph Completion".

Dependencies

  • Compatible with PyTorch 1.11.0 and Python 3.x.
  • Dependencies can be installed using requirements.txt.

Dataset:

  • We use WN18RR, FB15k-237N, FB15k-237, ICEWS14 and NELL-One dataset for knowledge graph link prediction.
  • All the preprocessed data are included in the ./data/processed/ directory. Alternatively, you can download the raw dataset into ./data/raw/ and run ./preprocess.sh to generate the processed data.
  • Raw data source:

Pretrained Checkpoint:

To enable a quick evaluation, we upload the trained model. Download the checkpoint folders to ./checkpoint/, and run the evaluation commandline for corresponding dataset.

The results are:

Dataset MRR H@1 H@3 H@10 checkpoint
WN18RR 0.575838 52.97% 60.05% 66.59% download
FB15k-237 0.335011 25.73% 36.91% 49.61% -
FB15k-237N 0.354474 28.42% 39.04% 49.22% download
ICEWS14 0.589678 51.09% 63.78% 73.20% -
Dataset MRR H@1 H@5 H@10 checkpoint
NELL 0.318289 23.68% 41.20% 49.72% download

Training and testing:

  • Install all the requirements from ./requirements.txt.

  • Commands for reproducing the reported results:

    WN18RR
    python3 main.py -dataset 'WN18RR' \
                    -lr 0.001 \
                    -epoch 100 \
                    -batch_size 64 \
                    -src_descrip_max_length 40 \
                    -tgt_descrip_max_length 10 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -seq_dropout 0.1 \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -skip_n_val_epoch 30 \
    
    # evaluation commandline:
    python3 main.py -dataset 'WN18RR' \
                    -src_descrip_max_length 40 \
                    -tgt_descrip_max_length 10 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -model_path path/to/trained/model \
                    -use_prefix_search
    FB15k-237N
    python3 main.py -dataset 'FB15k-237N' \
                    -lr 0.001 \
                    -epoch 50 \
                    -batch_size 32 \
                    -src_descrip_max_length 80 \
                    -tgt_descrip_max_length 80 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -seq_dropout 0.2 \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -skip_n_val_epoch 30
    
    # evaluation commandline:
    python3 main.py -dataset 'FB15k-237N' \
                    -src_descrip_max_length 80 \
                    -tgt_descrip_max_length 80 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -model_path path/to/trained/model \
                    -use_prefix_search  
    FB15k-237
    python3 main.py -dataset 'FB15k-237' \
                    -lr 0.001 \
                    -epoch 40 \
                    -batch_size 32 \
                    -src_descrip_max_length 80 \
                    -tgt_descrip_max_length 80 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -seq_dropout 0.2 \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -skip_n_val_epoch 20
    
    # evaluation commandline:
    python3 main.py -dataset 'FB15k-237' \
                    -src_descrip_max_length 80 \
                    -tgt_descrip_max_length 80 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 30 \
                    -model_path path/to/trained/model \
                    -use_prefix_search 
    ICEWS14
    python3 main.py -dataset 'ICEWS14' \
                    -lr 0.0005 \
                    -epoch 100
                    -batch_size 32 \
                    -src_descrip_max_length 40 \
                    -tgt_descrip_max_length 40 \
                    -temporal  \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -seq_dropout 0.1 \ 
                    -num_beams 40 \
                    -eval_tgt_max_length 26 \
                    -skip_n_val_epoch 50
    
    # evaluation commandline:
    python3 main.py -dataset 'ICEWS14' \
                    -src_descrip_max_length 40 \
                    -tgt_descrip_max_length 40 \
                    -temporal  \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 26 \
                    -model_path path/to/trained/model \
                    -use_prefix_search  
    NELL-One
    python3 main.py -dataset 'NELL' \
                    -lr 0.0005 \
                    -epoch 30 \
                    -batch_size 128 \
                    -src_descrip_max_length 0 \
                    -tgt_descrip_max_length 0 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 25 \
                    -skip_n_val_epoch 15
    
    
    # evaluation commandline:
    python3 main.py -dataset 'NELL' \
                    -src_descrip_max_length 0 \
                    -tgt_descrip_max_length 0 \
                    -use_soft_prompt \
                    -use_rel_prompt_emb \
                    -num_beams 40 \
                    -eval_tgt_max_length 25 \
                    -model_path path/to/trained/model \
                    -use_prefix_search  
    • -src_descrip_max_length denotes the training batch size
    • -src_descrip_max_length denotes the maximum description length for source entity during training
    • -tgt_descrip_max_length denotes the maximum description length for target entity during training
    • -eval_tgt_max_length denotes the maximum description length for generation during inference
    • -use_soft_prompt denotes the option whether to use soft prompt
    • -use_rel_prompt_emb denotes the option whether to use relation-specific soft prompt (need to enable -use_soft_prompt)
    • -seq_dropout denotes the value for sequence dropout
    • -use_prefix_search denotes to use constrained decoding method
    • -temporal denotes the dataset is for temporal knowledge graph completion
    • -skip_n_val_epoch denotes the number of training epochs without evaluation (evaluation is costly due to the auto-regressive decoding)

Citation

If you used our work or found it helpful, please use the following citation:

@inproceedings{KG_S2S,
    title = "Knowledge Is Flat: A Seq2Seq Generative Framework for Various Knowledge Graph Completion",
    author = "Chen, Chen  and
      Wang, Yufei  and
      Li, Bing  and 
      Lam, Kwok-Yan",
    booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
}

kg-s2s's People

Contributors

ccchobits avatar chenchens190009 avatar

Stargazers

Cocoa avatar Nikolaus Schlemm avatar Roberto Barile avatar  avatar  avatar Boris avatar Yulki avatar Geonwoo Ko avatar  avatar  avatar Jihee Ryu avatar hhh avatar  avatar TzuRen avatar Dongkwan Kim avatar  avatar Linhao Luo (Raymond) avatar Dawei Li avatar cgh avatar Men Tianyi avatar Cong  avatar LingZhi WiseMed 瓴智医学人工智能 avatar 燃之 avatar funny soul avatar  avatar Apoorv Saxena avatar  avatar  avatar  avatar

Watchers

 avatar

kg-s2s's Issues

IsADirectoryError: [Errno 21] Is a directory

When running this piece of code, model_path cannot be output and the "IsADirectoryError: [Errno 21] Is a directory" error occurs. What does this model_path refer to? Also, there is no training ckpt file in the checkpoint folder.
1

Hello, how to solve the problem of error when running the code?

Namespace(batch_size=64, dataset='WN18RR', dataset_path='./data/processed', decoder='beam_search', diversity_penalty=0.0, epochs=100
, eval_tgt_max_length=30, gpu='0', log_text=False, lr=0.001, model='T5Finetuner', model_dim=768, model_path='', n_ent=40943, n_rel=1
1, num_beam_groups=1, num_beams=40, num_workers=4, optim='Adam', pretrained_model='t5-base', save_dir='./checkpoint\WN18RR-2023-10-
18 20-38-04', seed=41504, seq_dropout=0.1, skip_n_val_epoch=30, src_descrip_max_length=40, src_max_length=512, temporal=False, tgt_d
escrip_max_length=10, train_tgt_max_length=512, use_prefix_search=False, use_rel_prompt_emb=True, use_soft_prompt=True, val_batch_si
ze=8, vocab_size=32128)
Global seed set to 41504
tokenizing entities...
35%|██████████████████████████████▍ | 14332/40943 [00:29<00:53, 499.61it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████| 40943/40943 [01:24<00:00, 483.42it/s]
datamodule construction done.
Traceback (most recent call last):
File "main.py", line 169, in
main()
File "main.py", line 98, in main
trainer = pl.Trainer(**trainer_params)
File "D:\anaconda\envs\torch_1.12\lib\site-packages\pytorch_lightning\utilities\argparse.py", line 348, in insert_env_defaults
return fn(self, **kwargs)
TypeError: init() got an unexpected keyword argument 'checkpoint_callback'

Question about evaluation on WN18RR.

hi, nice work.
After I reproduced the experiment with your model, the MRR just 0.16. I don't know why it is so different from the results in your paper. Are there any details I need to pay attention to during the experiment?

problem of checkpoint

Dear author Hello, I can train normally and generate folders normally in the case of initial training ( there is no checkpoint file ), but I can 't save the model file. Can you help me
QQ截图20240317220933

Inquiry about Experimental Setup and Runtime

Hi, @chenchens190009
First of all, thank you for sharing your excellent work on KG-S2S. I am particularly interested in reproducing the results presented in this paper. To ensure that I accurately replicate the experiments, I would like to ask for some details regarding the experimental setup:
Hardware Configuration: Could you please share the details of the hardware configuration used for running the experiments? Specifically, information on the GPU, would be very helpful.
Runtime: I would also appreciate it if you could give an estimate of the time it took to run the main experiments. This will help me plan my experiments more effectively.
Best regards,
yw3l

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.