在这篇文章中,我们将全面介绍如何使用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",