OpenAI微调模型测试与应用

释放双眼,带上耳机,听听看~!
本文介绍了使用OpenAI平台进行模型微调和测试的过程,展示了模型在验证集和推文预测中的应用,以及对微调分类器的通用性进行讨论。

本文正在参加platform.openai.com/playground 里的模型选择栏中看到自己微调后的模型。

训练信息打印

我们通过任务编码可以获取该任务训练的各种信息,比如随着 epoch 变化的 loss 、acc 等信息。可以看出在我们的训练集上训练的分类准确率为 100% 。

!openai api fine_tunes.results -i ft-aEHXhd8q9dfG8MOKt43ph7wk > result.csv
results = pd.read_csv('result.csv')
results[results['classification/accuracy'].notnull()].tail(1)

打印信息:

	step	elapsed_tokens	elapsed_examples	training_loss	training_sequence_accuracy	training_token_accuracy	validation_loss	validation_sequence_accuracy	validation_token_accuracy	classification/accuracy	classification/precision	classification/recall	classification/auroc	classification/auprc	classification/f1.0
316	317	143557	317	0.02417	1.0	1.0	NaN	NaN	NaN	1.0	1.0	1.0	1.0	1.0	1.0

模型测试

我们随机挑选验证集中的一条文本,使用微调后的模型进行测试,打印出来的分类标签是正确的。

test = pd.read_json('sport2_prepared_valid.jsonl', lines=True)
res = openai.Completion.create(model= 'ada:ft-personal-2023-03-28-02-15-26', prompt=test['prompt'][0] + 'nn###nn', max_tokens=1, temperature=0)
res['choices'][0]['text']

打印:

' hockey'

另外我们的微调分类器是非常通用的,不仅在我们使用的训练集和验证集上游泳,它也能用来预测推文。

sample_hockey_tweet = """Thank you to the 
@Canes
 and all you amazing Caniacs that have been so supportive! You guys are some of the best fans in the NHL without a doubt! Really excited to start this new chapter in my career with the 
@DetroitRedWings
 !!"""
res = openai.Completion.create(model='ada:ft-personal-2023-03-28-02-15-26', prompt=sample_hockey_tweet + 'nn###nn', max_tokens=1, temperature=0, logprobs=2)
res['choices'][0]['text']

打印:

' baseball'

总结

其实使用 openai 的微调 api 只需要四步:

  • 准备环境和 key
  • 准备规定格式的数据
  • 训练模型
  • 模型推理

是不是很简单!

本网站的内容主要来自互联网上的各种资源,仅供参考和信息分享之用,不代表本网站拥有相关版权或知识产权。如您认为内容侵犯您的权益,请联系我们,我们将尽快采取行动,包括删除或更正。
AI教程

扩散模型:文本生成图像领域的核心方法

2023-12-10 21:23:14

AI教程

轻量化网络优化技术及应用实例

2023-12-10 21:41:14

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索