使用LlamaIndex和Gradient微调GPT-3.5-Turbo以获得更好的结果

在这篇文章中,我们将全面介绍如何使用LlamaIndex和Gradient,微调GPT-3.5-turbo以获得更好的模型输出效果。我们将通过生成训练数据和评估数据集,使用OpenAIFinetuneEngine进行微调,并最终进行评估,详细探讨在微调后的性能提升效果。

数据设置

首先,我们需要下载用于生成训练数据的PDF文件。

!curl https://www.ipcc.ch/report/ar6/wg2/downloads/report/IPCC_AR6_WGII_Chapter03.pdf --output IPCC_AR6_WGII_Chapter03.pdf

生成训练集和评估集

我们会从下载的PDF文件中生成40个不同部分的问题进行训练数据集和评估数据集的创建。

训练集生成

from llama_index.core import SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
from llama_index.core.evaluation import DatasetGenerator
import random

documents = SimpleDirectoryReader(
    input_files=["IPCC_AR6_WGII_Chapter03.pdf"]
).load_data()

random.seed(42)
random.shuffle(documents)

gpt_35_llm = OpenAI(model="gpt-3.5-turbo", temperature=0.3)

question_gen_query = (
    "You are a Teacher/ Professor. Your task is to setup "
    "a quiz/examination. Using the provided context, formulate "
    "a single question that captures an important fact from the "
    "context. Restrict the question to the context information provided."
)

dataset_generator = DatasetGenerator.from_documents(
    documents[:50],
    question_gen_query=question_gen_query,
    llm=gpt_35_llm,
)

questions = dataset_generator.generate_questions_from_nodes(num=40)
print("Generated ", len(questions), " questions")

with open("train_questions.txt", 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值