Git Product home page Git Product logo

swea's Introduction

SWE $\oplus$ OS

This is a repository for "SWEA: Updating Factual Knowledge in Large Language Models via Subject Word Embedding Altering"


Overview of SWEA$\oplus$OS. In fusion stage, we first optimize a learnable embedding vector for target knowledge "Currently, Nvidia's most advanced GPU is the \underline{B200}." Second, using knowledge attribution method, we find the KEDs of `Nvidia' regarding "its most advanced GPU". Finally, we fuse the optimized embedding vector with these KEDs subtracted to obtain the editing embeddings. In inference stage, we add these editing embeddings to the embedding of the subject `Nvidia' for inference.

Requirements

  • At least one A100/A800 80G GPU.
  • Environment
    conda create -n swea python=3.10
    pip install -r requirements.txt

Quick Start

An example for editing Llama-2 (7B) on counterfact dataset using SWE $\oplus$ OS, you can also edit GPT-J (6B).

1. Edit Llama-2 model

python evaluate.py --model_path [your model path] --model_name Llama-2-7b-hf --alg_name SWEAOS --hparams_fname Llama-2-7b-hf.json --ds_name mcf --num_edits [num]

2. Summarize the results

python summarize.py --dir_name SWEAOS --runs run_<run1>

3. Sequential Editing on Llama-2

python main_counterfact_zsre_squen.py --model_path [your model path] --model_name Llama-2-7b-hf --hparams_fname Llama-2-7b-hf.json

Then just summarize the results

Another example for editing Llama-2 (7B) on RippleEdits benchmark.

We have released the filtered datasets in filtered datasets. If you want to filter the datasets from scratch, using `./fileter_benchmark.sh' or refer to RippleEdits.

python main_ripple_edits.py

Acknowledgment

Our code is based on MEMIT, PMET, and RippleEdits.

Citation

Xiaopeng Li, Shasha Li, Bin Ji, Shezheng Song, Xi Wang, Jun Ma, Jie Yu, Xiaodon Liu, Jing Wang, Weimin Zhang.
SWEA: Updating Factual Knowledge in Large Language Models via Subject Word Embedding Altering.
arXiv preprint arXiv:2401.17809 (2024).
@article{li2024swea,
  title={SWEA: Updating Factual Knowledge in Large Language Models via Subject Word Embedding Altering},
  author={Li, Xiaopeng and Li, Shasha and Ji, Bin and Song, Shezheng and Wang, Xi and Ma, Jun and Yu, Jie and Liu, Xiaodong and Wang, Jing and Zhang, Weimin},
  journal={arXiv preprint arXiv:2401.17809},
  year={2024}
}

swea's People

Contributors

xpq-tech avatar

Stargazers

 avatar Xiaojie Gu avatar

Watchers

 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.