XiaoxinHe/G-Retriever
소개
NeurIPS 2024 논문 「G-Retriever: 텍스트 그래프 이해와 질의응답을 위한 검색 증강 생성」의 공식 구현
AI 및 머신러닝측정된 스타 증가
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalG-Retriever
This repository contains the source code for the paper "G-Retriever: Retrieval-Augmented Generation for Textual Graph Understanding and Question Answering".
We introduce G-Retriever, a flexible question-answering framework targeting real-world textual graphs, applicable to multiple applications including scene graph understanding, common sense reasoning, and knowledge graph reasoning.
G-Retriever integrates the strengths of Graph Neural Networks (GNNs), Large Language Models (LLMs), and Retrieval-Augmented Generation (RAG), and can be fine-tuned to enhance graph understanding via soft prompting.
News
[2024.09] PyG 2.6 now supports G-Retriever! 🎉 [Dataset][Model]
Citation
@inproceedings{
he2024gretriever,
title={G-Retriever: Retrieval-Augmented Generation for Textual Graph Understanding and Question Answering},
author={Xiaoxin He and Yijun Tian and Yifei Sun and Nitesh V Chawla and Thomas Laurent and Yann LeCun and Xavier Bresson and Bryan Hooi},
booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
year={2024},
url={https://openreview.net/forum?id=MPJ3oXtTZl}
}
Environment setup
conda create --name g_retriever python=3.9 -y
conda activate g_retriever
# https://pytorch.org/get-started/locally/
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
python -c "import torch; print(torch.__version__)"
python -c "import torch; print(torch.version.cuda)"
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.1+cu118.html
pip install peft
pip install pandas
pip install ogb
pip install transformers
pip install wandb
pip install sentencepiece
pip install torch_geometric
pip install datasets
pip install pcst_fast
pip install gensim
pip install scipy==1.12
pip install protobuf
Download the Llama 2 Model
- Go to Hugging Face: https://huggingface.co/meta-llama/Llama-2-7b-hf. You will need to share your contact information with Meta to access this model.
- Sign up for a Hugging Face account (if you don’t already have one).
- Generate an access token: https://huggingface.co/docs/hub/en/security-tokens.
- Add your token to the code file as follows:
From transformers import AutoModel
access_token = "hf_..."
model = AutoModel.from_pretrained("private/model", token=access_token)
Data Preprocessing
# expla_graphs
python -m src.dataset.preprocess.expla_graphs
python -m src.dataset.expla_graphs
# scene_graphs, might take
python -m src.dataset.preprocess.scene_graphs
python -m src.dataset.scene_graphs
# webqsp
python -m src.dataset.preprocess.webqsp
python -m src.dataset.webqsp
Training
Replace path to the llm checkpoints in the src/model/__init__.py, then run
1) Inference-Only LLM
python inference.py --dataset scene_graphs --model_name inference_llm --llm_model_name 7b_chat
2) Frozen LLM + Prompt Tuning
# prompt tuning
python train.py --dataset scene_graphs_baseline --model_name pt_llm
# G-Retriever
python train.py --dataset scene_graphs --model_name graph_llm
3) Tuned LLM
# finetune LLM with LoRA
python train.py --dataset scene_graphs_baseline --model_name llm --llm_frozen False
# G-Retriever with LoRA
python train.py --dataset scene_graphs --model_name graph_llm --llm_frozen False
Reproducibility
Use run.sh to run the codes and reproduce the published results in the main table.
관련 프로젝트 살펴보기
불러오는 중…