GithubHelp home page GithubHelp logo

pegx / instructgraph-code Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wjn1996/instructgraph

0.0 0.0 0.0 49.55 MB

A framework to empover LLMs on graph reasoning and generation. Refer to our paper: https://arxiv.org/pdf/2402.08785.pdf

License: MIT License

Python 5.58% Jupyter Notebook 94.42%

instructgraph-code's Introduction

InstructGraph

arXiv License

This repository is implemented for our paper InstructGraph: Boosting Large Language Models via Graph-centric Instruction Tuning and Preference Alignment.

๐Ÿ†• [24-05-16] Our paper has been accepted to the Findings of ACL 2024.


What's InstructGraph?

InstructGraph is a framework for empowering large language models (LLMs) on graph-centric tasks via graph instruction tuning and preference alignment. We collect 29 standard graph datasets and decompose them into four groups, including graph structure modeling, graph language modeling, graph generation modeling, and graph thought modeling.

To better bridge the gap between textual LLMs with the graph data, we introduce a structured format verbalizer, which aims to transform the graph data into a code-like format. This interface can enable the LLM to reuse the ability of code understanding and generation. In addition, the LLM can generate a graph by outputting a code-like sequence.

We also explore four hallucination problems in graph reasoning and generation, respectively. We use direct preference optimization (DPO) to perform preference alignment.

More details can be found in our paper.


Quick Start

Download the open-resource llama2-7b to a folder, e.g., "./pre-trained-lm/Llama-2-7b-hf".

Step1: Perform graph instruction tuning by llama2-7b with lora:

bash examples/instruction_tuning/run_llama2_flashattn.sh

You can obtain a resulting folder in "./output/" with two files, i.e., "adapter_config.json" and "adapter_model.bin".

Step2: Perform graph preference alignment by llama2-7b with lora:

You must first set the argument "--peft_model" as the folder of instruction tuning checkpoint, and then:

bash examples/preference_tuning/run_llama2_flashattn.sh

Step3: Perform inference on graph instruction tasks:

bash examples/inference/run_llama2.sh

Step4: perform inference on preference task:

bash examples/inference/run_llama2_for_preference.sh

Step5: Calculate metrics on graph instruction tasks, e.g., "graph-language-modeling-graph-question-answering-pathquestion":

python3 examples/inference/calculate_metrics.py \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--inference_save_dir output/instruction_tuning/fsdp_peft_flash_1500k/llama2-peft-2epoch/predictions \
--is_graph_instruction \
--inference_task graph-language-modeling-graph-question-answering-pathquestion

Step5: Calculate metrics on graph preference tasks.

python3 examples/inference/calculate_preference_metrics.py \
--inference_save_dir output/preference_tuning/llama2/instructgraph_hallucination_predictions \
--inference_task all

Demo Play

Please see in the jupyter file instruction.ipynb.

Citation

@article{Wang2024InstructGraph,
  author       = {Jianing Wang and
                  Junda Wu and
                  Yupeng Wu and
                  Yao Liu and
                  Ming Gao and
                  Julian McAuley},
  title        = {InstructGraph: Boosting Large Language Models via Graph-centric Instruction Tuning and Preference Alignment},
  eprinttype    = {arXiv},
  eprint       = {2402.08785},
}

instructgraph-code's People

Contributors

wjn1996 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.