GraphTranslator: Aligning Graph Model to LLM for Open-ended Tasks;GNN+LLMs;图神经网络和大模型对齐

25 篇文章 1 订阅
18 篇文章 1 订阅

1. 文章描述 

 

我们提出了一个名为GraphTranslator的翻译器将预训练好的GM和LLM连接起来,旨在利用GM有效地处理预定义的任务,并利用LLM的扩展接口为GM提供各种开放式任务。为了训练这样的翻译器,我们提出了 一个能够根据节点信息、邻居信息和模型信息构建图-文本对齐数据的Producer。 通过将节点表示转换为token, Graph-Translator使LLM能够基于语言指令进行预测,为预定义和开放式任务提供了统一的视角。 广泛的结果证明了所提出的图翻译器在零样本节点分类上的有效性。

如上图所示:GraphTranslator的直观说明

(a) GraphTranslator与将llm应用于图形的流行范例的比较。与使用LLM作为增强器或唯一的预测器不同, GraphTranslator连接了LLM和GM,处理预定义和开放式任务。

(b) GraphTranslator中的任务演示,其中GM被用于预定义的任务,LLM被扩展为GM的接口,用于开放式任务。 

我们强调我们的贡献如下:

•我们提出了一种新颖的模型GraphTranslator,它将图形模型与大型语言模型相结合,为预定义和开放式任务提供了统一的视角。

•GraphTranslator引入了一个Translator模块,通过将GM学习到的节点嵌入转换为一组令牌,来弥合模态差距。对于进一步的训练,设计了一个生成器模块,通过无缝地将节点嵌入中编码的信息纹理化来生成对齐数据。

•在真实数据集上的实验结果证明了GraphTranslator在零采样节点分类上的有效性。 

GraphTranslator由四个部分组成:

(1)冻结图模型(Frozen graph model, GM),在大规模图上进行预训练,例如具有数十亿个节点的电子商务图,为下游任务编码图信息的所有节点生成嵌入层。在这项工作中,我们使用预训练的GraphSAGE模型作为示例。

(2) Frozen LLM,在广泛的文本语料库上进行训练,当参数数量达到一定规模时,显示出突现能力。我们使用预训练的ChatGLM2-6B进行演示。

(3)生产者,旨在构建对齐用于训练翻译模块的数据,即(节点嵌入,文本描述)对。

(4) Translator模块,将GM学习到的节点嵌入投影到LLM空间中,消除GM与LLM之间的模态差距。

模型训练过程,如图所示,分为两个阶段:

一阶段:translator部分:用现有的Graph Model,去生成的节点的向量表示Zv;用大模型LLM作为producer,利用graph的text文本去生成一些固定样式的文本,对应的Q和A如上图所示。对生成的答案A和提问Q用LLM进行embedding,然后用Q去和GM生成的Zv去做一个交叉注意力,让模型去关注Zv中更重要的部分,生成Hv;同时,用Q和tv做自注意力,生成的文本提取[CLS]用作文本的表示Tv,计算Hv和Tv的损失,完成反向传播,对齐graph部分特征和文本部分特征;

二阶段:用translator的输出Hv和instruction输入到LLM中,用生成的A和原始的A进行对齐,计算损失,完成模型训练。

数据集。我们在真实世界的数据集上进行了实验,包括工业数据集淘宝和广泛使用的基准数据集ArXiv:

•淘宝数据集是从淘宝电子商务平台中提取的子集。它由98万个 节点组成,代表唯一的淘宝用户。相关属性包括用户行为,如购买、搜索、浏览、收藏和添加购物车。提取的图包含了179万条 边,表示用户之间的社交联系。

•ArXiv数据集是由ArXiv研究论文集合构建的图,具有169,343 个节点和1,166,243条边。每个节点代表一篇单独的研究论文,具有包括论文标题和摘要在内的文本属性,边反映了论文的引用关系。为了训练图模型,我们按照[12]将节点分为90, 941个训练节点和29,799个验证节点。考虑到LLM的推理速度,我们的测试集包含40个计算机科学类别的4000个数据点,根据公开分割中的标签按比例选择。 

结论:为了利用LLM的扩展接口为GM提供各种开放式任务,本文提出了一种新的图形模型与LLM对齐框架——GraphTranslator, GraphTranslator引入了一个Translator模块,通过将GM学习到 的节点嵌入转换为一组令牌来消除模态差距。对于进一步的训练,设计了一个生成器模块,通过无缝地将节点嵌入中编码的信息纹理化来生成对齐数据。在开放式任务的真实世界数据集上评估了所提出的方法。实验结果证明了GraphTranslator在zero-shot节点分类上的有效性。初步的图形问答实验表明,我们的GraphTranslator能够对图形信息进行提取、解释和推理,揭示了其潜力和商业价值。 

2. 代码实践 

  • Pre-training Graph Model Phase. In the pre-training phase, we employ link prediction as the self-supervised task for pre-training the graph model.

  • Producer Phase. In the Producer phase, we employ LLM to summary Node/Neighbor Information.

  • Translator Training Phase.

    ​ Stage 1: Training the Translator for GraphModel-Text alignment.

    ​ Stage 2: Training the Translator for GraphModel-LLM alignment.

  • Translator Generate Phase. Generate the predictions with the pre-trained Translator model.

Installation

We run our experiment with the following settings.

  • CPU: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
  • GPU: Tesla V100-SXM2-32GB
  • OS: Linux (Ubuntu 18.04.6 LTS)
  • Python==3.9, CUDA==11.4, Pytorch==1.12.1

The ./requirements.txt list all Python libraries that GraphTranslator depend on, and you can install using:

conda create -n graphtranslator python=3.9
conda activate graphtranslator
git clone https://github.com/alibaba/GraphTranslator.git
cd GraphTranslator/
pip install -r requirements.txt

Datasets & Models

Download datasets and model checkpoints used in this project with huggingface.

ArXiv Dataset

Download files bert_node_embeddings.ptgraphsage_node_embeddings.pt and titleabs.tsv from link and insert them to ./data/arxiv.

cd ./data/arxiv
git lfs install
git clone git@hf.co:datasets/Hualouz/GraphTranslator-arxiv

Translator Model

Download bert-base-uncased.zip from link and unzip it to ./Translator/models.

cd Translator/models/
git lfs install
git clone git@hf.co:Hualouz/Qformer
unzip bert-base-uncased.zip

ChatGLM2-6B Model

Download the ChatGLM2-6B model from link and insert it to ./Translator/models

cd ./Translator/models
git lfs install
git clone git@hf.co:THUDM/chatglm2-6b

Run

Producer Phase
  • Generate node summary text with LLM (ChatGLM2-6B).
cd ./Producer/inference
python producer.py
Training Phase

Train the Translator model with the prepared ArXiv dataset.

  • Stage 1 Training

Train the Translator for GraphModel-Text alignment. The training configurations are in the file ./Translator/train/pretrain_arxiv_stage1.yaml.

cd ./Translator/train
python train.py --cfg-path ./pretrain_arxiv_stage1.yaml

After stage 1, you will get a model checkpoint stored in ./Translator/model_output/pretrain_arxiv_stage1/checkpoint_0.pth

  • Stage 2 Training

Train the Translator for GraphModel-LLM alignment. The training configurations are in the file ./Translator/train/pretrain_arxiv_stage2.yaml.

cd ./Translator/train
python train.py --cfg-path ./pretrain_arxiv_stage2.yaml

After stage 2, you will get a model checkpoint stored in ./Translator/model_output/pretrain_arxiv_stage2/checkpoint_0.pth

After all the training stages , you will get a model checkpoint that can translate GraphModel information into that the LLM can understand.

  • Note: Training phase is not necessary if you only want to obtain inference results with our pre-trained model checkpoint. You can download our pre-trained checkpoint checkpoint_0.pth from link and place it in the ./Translator/model_output/pretrain_arxiv_stage2 directory. Then skip the whole Training Phase and go to the Generate Phase.
Generate Phase
  • generate prediction with the pre-trained Translator model. The generate configurations are in the file ./Translator/train/pretrain_arxiv_generate_stage2.yaml. As to the inference efficiency, it may take a while to generate all the predictions and save them into file.
cd ./Translator/train
python generate.py

The generated prediction results will be saved in ./data/arxiv/pred.txt

Evaluation

Evaluate the accuracy of the generated predictions.

cd ./Evaluate
python eval.py
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

医学小达人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值