Code for Editing Factual Knowledge in Language Models

Overview

KnowledgeEditor

Code for Editing Factual Knowledge in Language Models (https://arxiv.org/abs/2104.08164).

@inproceedings{decao2021editing,
  title={Editing Factual Knowledge in Language Models}, 
  author={Nicola De Cao and Wilker Aziz and Ivan Titov},
  journal={Proceedings of the 2021 Conference on Empirical Methods in 
           Natural Language Processing (EMNLP2021)},
  url={https://arxiv.org/abs/2104.08164},
  year={2021},
}

Please consider citing our works if you use code from this repository.

Models and Data

This folder contains the datasets and the base models used for this work.

Comments
  • Link to the Models and Data folder is invalid

    Link to the Models and Data folder is invalid

    Nice work, but it seems the link is invalid. Could you check what is going on.

    Besides, still waiting instructions to run the code and reproduce the results. Thanks.

    opened by kailigo 5
  • Validation step error when training bert binary augmented

    Validation step error when training bert binary augmented

    I'm using python3.8.7 with the libraries in the requirement.txt

    I have a problem when running: train_bert_binary_augmented_kilt.py

    I got: ValueError: The 'target' has to be an integer tensor. at the following line: https://github.com/nicola-decao/KnowledgeEditor/blob/80b86e41a780161b5479862184d5d0b62f579acf/src/models/bert_binary_augmented_kilt.py#L257

    Indeed batch["labels"] is a Tensor with dtype = torch.float32. I tried to cast the tensor to integer with batch['labels'].to(torch.int). It works but then i got:

    ValueError: The 'preds' should be probabilities, but values were detected outside of [0,1] range.

    So I changed logits with: torch.IntTensor([x > 0 for x in logits])

    The same holds for these lines: https://github.com/nicola-decao/KnowledgeEditor/blob/80b86e41a780161b5479862184d5d0b62f579acf/src/models/bert_binary_augmented_kilt.py#L262-L265

    Is this a viable fix? Thank you.

    opened by gianlucagiudice 4
  • Cannot run the code

    Cannot run the code

    Can not run the code for train_bert_binary_augmented_kilt.sh First, it says ModuleNotFoundError: No module named 'pytorch_lightning.metrics'. Then, I import torchmetrics and change the original lines of pl.metrics.Accuracy() to torchmetrics.Accuracy(). The code can work. However, new problems occur in https://github.com/nicola-decao/KnowledgeEditor/blob/668aca6d01cc12e9a5fda17fe29a2334b6d0a359/src/models/bert_binary_augmented_kilt.py#L257 with the message below: ValueError: Thetargethas to be an integer tensor.

    Please advise how to debug it.

    opened by xingbow 2
  • Runtime error when using DDP

    Runtime error when using DDP

    Hii, I just wanted to highlight that when using the 'ddp' with the following command: python scripts/train_bert_binary_augmented_kilt.py --gpus 1 --accelerator ddp --num_workers 32 --batch_size 256 --max_steps 50000 --divergences kl

    There is an error: RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by (1) passing the keyword argument find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel; (2) making sure all forward function outputs participate in calculating loss. If you already have done the above two steps, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's forward function. Please include the loss function and the structure of the return value of forward of your module when reporting this issue (e.g. list, dict, iterable).

    But after removing the --accelerator ddp, it is running fine. Is there any workaround to use it with DDP? I have tried setting find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel;. But somehow this is also not working.

    opened by himanshubeniwal 1
  • Questions about testing Retain acc

    Questions about testing Retain acc

    Hi: Thanks for your excellent work and providing the nice codebase. There is one question I have been bothered by. When testing retrain acc, do you test this while updating the model parameters? And do you update the model parameters with batch[-1:] and then use batch[:-1] to test the stability of the model when testing?

    Any help is appreciated.

    opened by QQQrookie 0
Owner
Nicola De Cao
PhD in NLP @ University of Amsterdam / University of Edinburgh
Nicola De Cao
A design of MIDI language for music generation task, specifically for Natural Language Processing (NLP) models.

MIDI Language Introduction Reference Paper: Pop Music Transformer: Beat-based Modeling and Generation of Expressive Pop Piano Compositions: code This

Robert Bogan Kang 3 May 25, 2022
Watson Natural Language Understanding and Knowledge Studio

Material de demonstração dos serviços: Watson Natural Language Understanding e Knowledge Studio Visão Geral: https://www.ibm.com/br-pt/cloud/watson-na

Vanderlei Munhoz 4 Oct 24, 2021
Knowledge Oriented Programming Language

KoPL: 面向知识的推理问答编程语言 安装 | 快速开始 | 文档 KoPL全称 Knowledge oriented Programing Language, 是一个为复杂推理问答而设计的编程语言。我们可以将自然语言问题表示为由基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,

THU-KEG 62 Dec 12, 2022
A collection of Classical Chinese natural language processing models, including Classical Chinese related models and resources on the Internet.

GuwenModels: 古文自然语言处理模型合集, 收录互联网上的古文相关模型及资源. A collection of Classical Chinese natural language processing models, including Classical Chinese related models and resources on the Internet.

Ethan 66 Dec 26, 2022
A library for finding knowledge neurons in pretrained transformer models.

knowledge-neurons An open source repository replicating the 2021 paper Knowledge Neurons in Pretrained Transformers by Dai et al., and extending the t

EleutherAI 96 Dec 21, 2022
A framework for evaluating Knowledge Graph Embedding Models in a fine-grained manner.

A framework for evaluating Knowledge Graph Embedding Models in a fine-grained manner.

NEC Laboratories Europe 13 Sep 8, 2022
EdiTTS: Score-based Editing for Controllable Text-to-Speech

Official implementation of EdiTTS: Score-based Editing for Controllable Text-to-Speech

Neosapience 99 Jan 2, 2023
This repository contains the code for "Generating Datasets with Pretrained Language Models".

Datasets from Instructions (DINO ?? ) This repository contains the code for Generating Datasets with Pretrained Language Models. The paper introduces

Timo Schick 154 Jan 1, 2023
Code for our ACL 2021 (Findings) Paper - Fingerprinting Fine-tuned Language Models in the wild .

?? Fingerprinting Fine-tuned Language Models in the wild This is the code and dataset for our ACL 2021 (Findings) Paper - Fingerprinting Fine-tuned La

LCS2-IIITDelhi 5 Sep 13, 2022
Code for text augmentation method leveraging large-scale language models

HyperMix Code for our paper GPT3Mix and conducting classification experiments using GPT-3 prompt-based data augmentation. Getting Started Installing P

NAVER AI 47 Dec 20, 2022
Code for paper Multitask-Finetuning of Zero-shot Vision-Language Models

Code for paper Multitask-Finetuning of Zero-shot Vision-Language Models

Zhenhailong Wang 2 Jul 15, 2022
Guide to using pre-trained large language models of source code

Large Models of Source Code I occasionally train and publicly release large neural language models on programs, including PolyCoder. Here, I describe

Vincent Hellendoorn 947 Dec 28, 2022
Code for the paper in Findings of EMNLP 2021: "EfficientBERT: Progressively Searching Multilayer Perceptron via Warm-up Knowledge Distillation".

This repository contains the code for the paper in Findings of EMNLP 2021: "EfficientBERT: Progressively Searching Multilayer Perceptron via Warm-up Knowledge Distillation".

Chenhe Dong 28 Nov 10, 2022
Code for Findings at EMNLP 2021 paper: "Learn Continually, Generalize Rapidly: Lifelong Knowledge Accumulation for Few-shot Learning"

Learn Continually, Generalize Rapidly: Lifelong Knowledge Accumulation for Few-shot Learning This repo is for Findings at EMNLP 2021 paper: Learn Cont

INK Lab @ USC 6 Sep 2, 2022
A python framework to transform natural language questions to queries in a database query language.

__ _ _ _ ___ _ __ _ _ / _` | | | |/ _ \ '_ \| | | | | (_| | |_| | __/ |_) | |_| | \__, |\__,_|\___| .__/ \__, | |_| |_| |___/

Machinalis 1.2k Dec 18, 2022
A Domain Specific Language (DSL) for building language patterns. These can be later compiled into spaCy patterns, pure regex, or any other format

RITA DSL This is a language, loosely based on language Apache UIMA RUTA, focused on writing manual language rules, which compiles into either spaCy co

Šarūnas Navickas 60 Sep 26, 2022
Indobenchmark are collections of Natural Language Understanding (IndoNLU) and Natural Language Generation (IndoNLG)

Indobenchmark Toolkit Indobenchmark are collections of Natural Language Understanding (IndoNLU) and Natural Language Generation (IndoNLG) resources fo

Samuel Cahyawijaya 11 Aug 26, 2022