lixin4sky/ProGraph

Model

1. Introduction of this repository

1

9 commits

3 linked in READMEs

updated Nov 1, 2024

See the code

README

1. Introduction of this repository

Official Repository of "Can Large Language Models Analyze Graphs like Professionals? A Benchmark, Datasets and Models". NeurIPS 2024

2. Pipelines and Experimental Results

The pipeline of ProGraph benchmark construction

The pipeline of LLM4Graph dataset construction and corresponding model enhancement.

The pass rate (left) and accuracy (right) of open-source models with instruction tuning.

Compilation error statistics for open source models.

Performance (%) of open-source models regarding different question types.

ModelMethodTrue/FalseDrawingCalculationHybrid
Pass RateAccuracyPass RateAccuracyPass RateAccuracyPass RateAccuracy
Llama 3No Fine-tune43.633.328.310.015.612.526.88.3
Code Only82.171.859.242.034.431.360.743.6
Code+RAG 384.644.056.929.050.037.566.137.2
Code+RAG 566.736.853.525.437.528.160.736.3
Code+RAG 766.737.250.924.450.035.964.339.3
Doc+Code82.173.164.443.740.631.867.941.3
Deepseek CoderNo Fine-tune66.741.547.822.153.139.446.418.2
Code Only71.861.560.041.150.045.362.542.1
Code+RAG 371.848.357.732.253.145.344.622.8
Code+RAG 571.853.950.729.340.634.439.328.6
Code+RAG 774.454.750.428.737.534.448.231.4
Doc+Code79.568.066.246.037.534.466.142.3

3. How to Use

Here give some examples of how to use our models.

Chat Model Inference

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, StoppingCriteria, StoppingCriteriaList
from peft import PeftModel

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

model_name_or_path = '../models/deepseek-ai/deepseek-coder-7b-instruct-v1.5'
# You can use Llama-3-8B by 'meta-llama/Meta-Llama-3-8B-Instruct'.
# You can also use your local path.
peft_model_path = 'https://huggingface.co/lixin4sky/ProGraph/tree/main/deepseek-code-only' 
# Or other models in the repository.

tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path).to(device)
peft_model = PeftModel.from_pretrained(model, peft_model_path).to(device)

input_text = '' # the question.

message = [
    {"role": "user", "content": f"{input_text}"},
]

input_ids = tokenizer.apply_chat_template(conversation=message,
                                        tokenize=True,
                                        add_generation_prompt=False,
                                        return_tensors='pt')

input_ids = input_ids.to("cuda:0" if torch.cuda.is_available() else "cpu")
with torch.inference_mode():
    output_ids = model.generate(input_ids=input_ids[:, :-3], max_new_tokens=4096, do_sample=False, pad_token_id=2)
response = tokenizer.batch_decode(output_ids.detach().cpu().numpy(), skip_special_tokens = True)

print(response)

You can find more tutorials in our GitHub repository: (https://github.com/BUPT-GAMMA/ProGraph)

4. Next Level

question-answering
safetensors
transformers, alignment-handbook

Contributors

lixin4sky

9 commits

lixin4sky/ProGraph

Model

1. Introduction of this repository

1

9 commits

3 linked in READMEs

updated Nov 1, 2024

See the code

README

1. Introduction of this repository

Official Repository of "Can Large Language Models Analyze Graphs like Professionals? A Benchmark, Datasets and Models". NeurIPS 2024

2. Pipelines and Experimental Results

The pipeline of ProGraph benchmark construction

The pipeline of LLM4Graph dataset construction and corresponding model enhancement.

The pass rate (left) and accuracy (right) of open-source models with instruction tuning.

Compilation error statistics for open source models.

Performance (%) of open-source models regarding different question types.

ModelMethodTrue/FalseDrawingCalculationHybrid
Pass RateAccuracyPass RateAccuracyPass RateAccuracyPass RateAccuracy
Llama 3No Fine-tune43.633.328.310.015.612.526.88.3
Code Only82.171.859.242.034.431.360.743.6
Code+RAG 384.644.056.929.050.037.566.137.2
Code+RAG 566.736.853.525.437.528.160.736.3
Code+RAG 766.737.250.924.450.035.964.339.3
Doc+Code82.173.164.443.740.631.867.941.3
Deepseek CoderNo Fine-tune66.741.547.822.153.139.446.418.2
Code Only71.861.560.041.150.045.362.542.1
Code+RAG 371.848.357.732.253.145.344.622.8
Code+RAG 571.853.950.729.340.634.439.328.6
Code+RAG 774.454.750.428.737.534.448.231.4
Doc+Code79.568.066.246.037.534.466.142.3

3. How to Use

Here give some examples of how to use our models.

Chat Model Inference

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, StoppingCriteria, StoppingCriteriaList
from peft import PeftModel

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

model_name_or_path = '../models/deepseek-ai/deepseek-coder-7b-instruct-v1.5'
# You can use Llama-3-8B by 'meta-llama/Meta-Llama-3-8B-Instruct'.
# You can also use your local path.
peft_model_path = 'https://huggingface.co/lixin4sky/ProGraph/tree/main/deepseek-code-only' 
# Or other models in the repository.

tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path).to(device)
peft_model = PeftModel.from_pretrained(model, peft_model_path).to(device)

input_text = '' # the question.

message = [
    {"role": "user", "content": f"{input_text}"},
]

input_ids = tokenizer.apply_chat_template(conversation=message,
                                        tokenize=True,
                                        add_generation_prompt=False,
                                        return_tensors='pt')

input_ids = input_ids.to("cuda:0" if torch.cuda.is_available() else "cpu")
with torch.inference_mode():
    output_ids = model.generate(input_ids=input_ids[:, :-3], max_new_tokens=4096, do_sample=False, pad_token_id=2)
response = tokenizer.batch_decode(output_ids.detach().cpu().numpy(), skip_special_tokens = True)

print(response)

You can find more tutorials in our GitHub repository: (https://github.com/BUPT-GAMMA/ProGraph)

4. Next Level

question-answering
safetensors
transformers, alignment-handbook

Contributors

lixin4sky

9 commits