README.md

April 30, 2023 · View on GitHub

A Library for Dynamically Editing PLMs-Based Knowledge Graph Embeddings.


OverviewInstallationHow To RunOthers

Overview

Knowledge graph embedding (KGE) is a method for representing symbolic facts in low-dimensional vector spaces, with the goal of projecting relations and entities into a continuous vector space. This approach enhances knowledge reasoning capabilities and facilitates application to downstream tasks.

We introduce DeltaKG (MIT License), a dynamic, PLM-based library for KGEs that equips with numerous baseline models, such as K-Adapter, CaliNet, KnowledgeEditor, MEND, and KGEditor, and supports a variety of datasets, including E-FB15k237, A-FB15k237, E-WN18RR, and A-WN18RR.

Model Architecture

Illustration of KGEditor for a) The external model-based editor, b) The additional parameter-based editor and c) KGEditor.

Installation

Step1 Download the basic code

git clone https://github.com/AnonymousForPapers/DeltaKG.git

Step2 Create a virtual environment using Anaconda and enter it

conda create -n deltakg python=3.8
conda activate deltakg

Step3 Install library

pip install -r requirements.txt

Data & Checkpoints Download

Data

The datasets that we used in our experiments are as follows,

  • E-FB15k237

    This dataset is based on FB15k237 and a pre-trained language-model-based KGE. You can download the E-FB15k237 dataset from Google Drive.

For other datasets A-FB15k237, E-WN18RR, and A-WN18RR, you can also download from the above link.

Checkpoints

The checkpoints that we used in our experiments are as follows,

  • PT_KGE_E-FB15k237

    This checkpoint is based on FB15k237 and a pre-trained language model. You can download the PT_KGE_E-FB15k237 checkpoint from Google Drive.

For other checkpoints PT_KGE_A-FB15k237, PT_KGE_E-WN18RR, and PT_KGE_A-WN18RR, you can also download from the above link.

The expected structure of files is:

DeltaKG
 |-- checkpoints  # checkpoints for tasks
 |-- datasets  # task data
 |    |-- FB15k237  # dataset's name
 |    |    |-- AddKnowledge  # data for add task, A-FB15k237
 |    |    |    |-- train.jsonl    
 |    |    |    |-- dev.jsonl     
 |    |    |    |-- test.jsonl     
 |    |    |    |-- stable.jsonl  
 |    |    |    |-- relation2text.txt  
 |    |    |    |-- relation.txt 
 |    |    |    |-- entity2textlong.txt   
 |    |    |-- EditKnowledge # data for edit task, E-FB15k237
 |    |    |    |-- ... #  consistent with A-FB15k237
 |    |-- WN18RR  # dataset's name
 |    |    |-- AddKnowledge  # data for add task, A-WN18RR
 |    |    |    |-- train.jsonl    
 |    |    |    |-- dev.jsonl     
 |    |    |    |-- test.jsonl     
 |    |    |    |-- stable.jsonl  
 |    |    |    |-- relation2text.txt  
 |    |    |    |-- relation.txt 
 |    |    |    |-- entity2text.txt   
 |    |    |-- EditKnowledge # data for edit task, E-WN18RR
 |    |    |    |-- ... #  consistent with A-WN18RR
 |-- models  # KGEditor and baselines
 |    |-- CaliNet
 |    |    |-- run.py    
 |    |    |-- ...
 |    |-- K-Adapter
 |    |-- KE  # KnowledgeEditor
 |    |-- KGEditor
 |    |-- MEND
 |-- resource  # image resource
 |-- scripts  # running scripts
 |    |-- CaliNet
 |    |    |-- CaliNet_FB15k237_edit.sh
 |    |    |-- ...
 |    |-- K-Adapter
 |    |-- KE  # KnowledgeEditor
 |    |-- KGEditor
 |    |-- MEND
 |-- src
 |    |-- data       # data process functions
 |    |-- models     # source code of models
 |-- README.md
 |-- requirements.txt
 |-- run.sh  #  script to quick start

How to run

  • script

    • The script run.sh has three arguments -m, -d, and -t, which stand for model, dataset, and task.
      • -m: should be the name of a model in models (e.g. KGEditor, MEND, KE);
      • -d: should be either FB15k237 or WN18RR;
      • -t: should be either edit or add.
  • Edit Task

    • To train the KGEditor model in the paper on the dataset E-FB15k237, run the command below.

          bash run.sh -m KGEditor -d FB15k237 -t edit
      
    • To train the KGEditor model in the paper on the dataset E-WN18RR, run the command below.

          bash run.sh -m KGEditor -d WN18RR -t edit
      
  • Add Task

    • To train the KGEditor model in the paper on the dataset A-FB15k237, run the command below.

          bash run.sh -m KGEditor -d FB15k237 -t add
      
    • To train the KGEditor model in the paper on the dataset A-WN18RR, run the command below.

          bash run.sh -m KGEditor -d WN18RR -t add
      

Experiments

Up to now, baseline models include K-Adapter, CaliNet, KE, MEND, and KGEditor. The results of these models are as follows,

  • E-FB15k237

    ModelSucc@1Succ@1Succ@3Succ@3ERrocER_{roc}RK@3RK@3RKrocRK_{roc}
    Finetune0.4720.7460.9980.5430.977
    Zero-Shot Learning0.0000.000-1.0000.000
    K-Adapter0.3290.3480.9260.0010.999
    CaliNet0.3280.3480.9370.3530.997
    KE0.7020.9690.9990.9120.685
    MEND0.8280.9500.9540.7500.993
    KGEditor0.8660.9860.9990.8740.635
  • E-WN18RR

    ModelSucc@1Succ@1Succ@3Succ@3ERrocER_{roc}RK@3RK@3RKrocRK_{roc}
    Finetune0.7580.8630.9980.8470.746
    Zero-Shot Learning0.0000.000-1.0000.000
    K-Adapter0.6380.7520.9920.0090.999
    CaliNet0.5380.6490.9910.4460.994
    KE0.5990.6820.9780.9350.041
    MEND0.8150.8270.9480.9570.772
    KGEditor0.8330.8440.9910.9560.256
  • A-FB15k237

    ModelSucc@1Succ@1Succ@3Succ@3ERrocER_{roc}RK@3RK@3RKrocRK_{roc}
    Finetune0.9060.9760.9990.2230.997
    Zero-Shot Learning0.0000.000-1.0000.000
    K-Adapter0.8710.9810.9990.0000.999
    CaliNet0.7140.8700.9970.0340.999
    KE0.6480.8840.9970.9260.971
    MEND0.5170.7450.9910.4990.977
    KGEditor0.7960.9230.9980.8990.920
  • A-WN18RR

    ModelSucc@1Succ@1Succ@3Succ@3ERrocER_{roc}RK@3RK@3RKrocRK_{roc}
    Finetune0.9970.9990.9990.5540.996
    Zero-Shot Learning0.0000.000-1.0000.000
    K-Adapter0.8980.9780.9990.0020.999
    CaliNet0.8320.9130.9950.5110.989
    KE0.9860.9960.9990.9750.090
    MEND0.9991.00.9990.8100.987
    KGEditor0.9981.00.9990.9560.300

Other KG Representation Open-Source Projects