范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

GPT3微调分步指南

  从2022年底开始,OpenAI推出ChatGPT,被我们很多人认为是AI的iPhone时刻。然而,OpenAI的聊天机器人并不是第一个生成式人工智能文本机器学习模型,它是在两年前推出的GPT-3之后推出的。
  OpenAI为我们提供了一个现成的GPT-3训练模型。此外,可以在较小的数据集上对特定任务进行微调。例如,假设您要创建特定于您公司的电子邮件响应生成器。首先,您必须收集大量关于您的特定业务领域的数据,如客户电子邮件查询和响应。然后,您可以使用此数据来微调GPT-3,以了解公司的特定语言模式和短语。通过微调GPT-3,可以创建高度自定义和专业化的电子邮件响应生成器,专门针对特定业务领域中使用的语言模式和单词进行定制。
  在这篇博文中,我将向您展示如何微调GPT-3。我们将使用python代码来执行此操作,而不需要事先了解GPT-3。前提预备
  不像在HuggingFace(写这篇博客的时候)上提供的GPT-2模型,我们不能直接访问GPT-3模型。因此,首先需要从OpenAI获取API密钥并安装Python包 奥佩奈 ,可通过以下方式快速完成 尖点。
  对于OpenAI的API密钥:请访问 https://platform.openai.com/account/api-keys ,创建帐户,单击"创建新密钥" 以及复制一把钥匙。
  密钥是一个以"sk-"开头的长字符串。一定要保密!获得密钥后,访问密钥的简单方法是在终端中执行以下操作:(我个人,为了简单起见,我把它放在我的 .bachrc):export OPENAI_API_KEY=sk-t59pgejhtrff5(...)
  使用GPT-3型号是有成本的。我们需要学分。在撰写本文时,当您创建一个新帐户时,您可以获得免费的积分来试用该工具。我不知道这会不会继续下去...
  现在我们有了key和Python包,是时候考虑需要微调的数据了。首先,我们需要一个用于微调的示例文件,其中每个示例都是一个 提示符 ,后跟适当的 完成。描述生成工具
  我们将为这个演示构建一个工具来创建虚构的超级英雄的描述。最后,这个工具会接收到超级英雄的年龄、性别和力量,它会自动生成我们的超级英雄的描述。
  在下面的例子中,在微调模型之后,我们只需要说"40,woman,Healing ->",然后我们将自动从模型中获得一个描述。
  这就是一切!!创建用于微调的数据集
  在某些情况下,您可能有一个要用于微调的数据集。但是,由于我没有一个,让我们看看如何直接从GPT-3创建一个包含超级英雄描述的合成数据集。下面的代码将给予我一个CSV文件,其中包含 提示 和相应的 完成示例。import os import openai import pandas as pd  openai.api_key = os.getenv("OPENAI_API_KEY")  l_age = ["18", "20", "30", "40", "50", "60", "90"] l_gender = ["man", "woman"] l_power = ["invisibility", "read in the thoughts", "turning lead into gold", "immortality", "telepathy", "teleport", "flight"]   f_prompt = "Imagine a complete and detailed description of a {age}-year-old {gender} fictional character who has the superpower of {power}. Write out the entire description in a maximum of 100 words in great detail:" f_sub_prompt = "{age}, {gender}, {power}"  df = pd.DataFrame() for age in l_age:  for gender in l_gender:   for power in l_power:    for i in range(3): ## 3 times each     prompt = f_prompt.format(age=age, gender=gender, power=power)     sub_prompt = f_sub_prompt.format(age=age, gender=gender, power=power)     print(sub_prompt)      response = openai.Completion.create(      model="text-davinci-003",      prompt=prompt,      temperature=1,      max_tokens=500,      top_p=1,      frequency_penalty=0,      presence_penalty=0     )          finish_reason = response["choices"][0]["finish_reason"]     response_txt = response["choices"][0]["text"]          new_row = {       "age":age,        "gender":gender,        "power":power,        "prompt":prompt,        "sub_prompt":sub_prompt,        "response_txt":response_txt,        "finish_reason":finish_reason}     new_row = pd.DataFrame([new_row])     df = pd.concat([df, new_row], axis=0, ignore_index=True)  df.to_csv("out_openai_completion.csv")
  让我们看看这段代码是如何工作的。
  变量 f_prompt 包含以下句子,其中缺少 {age}、 {gender} 和 {power} 。
  想象一个{age}岁的{gender}虚构人物拥有{power}超能力的完整而详细的描述。用最多100字的篇幅详细写出整个描述:
  在代码的前三个 for 循环中,我们迭代{age}、{gender}和{power}的不同值。在循环的每一步,我们用不同的值替换3个缺失的变量。然后使用 openai.Completion.create 函数要求GPT生成对提示的响应。
  此函数最重要的参数包括model :用于生成响应的模型。OpenAI提供了四种标准的GPT-3模型(ada, babbage, curie,或 davinci),它们的大小...和使用价格各不相同。这是 达芬奇 -最大的模型。瞬发:要使用GPT-3完成的提示。温度:温度是一个介于0和1之间的数字,控制输出的随机性。我们将温度设置为最大值,以使模型在创建响应时尽可能具有创造性。最大令牌数:定义响应的最大长度。
  在此脚本的结尾,我们有一个Pandas表存储在文件 out_openai_complement. csv中。& nbsp; 此表中我们感兴趣的两个主要列是 sub_prompt 和 response_txt。该 子提示符 例如 ‘18岁,伙计,隐形人。 它包含被替换的三个值,以逗号分隔。该 响应_文本 包含GPT模型的输出。微调GPT模型
  下面的代码检索以前创建的文件 out_openai_completion.csv ,并使用 openai 微调GPT-3模型。import pandas as pd import openai import subprocess  df = pd.read_csv("out_openai_completion.csv")  prepared_data = df.loc[:,["sub_prompt","response_txt"]] prepared_data.rename(columns={"sub_prompt":"prompt", "response_txt":"completion"}, inplace=True) prepared_data.to_csv("prepared_data.csv",index=False)   ## prepared_data.csv --> prepared_data_prepared.json subprocess.run("openai tools fine_tunes.prepare_data --file prepared_data.csv --quiet".split())  ## Start fine-tuning subprocess.run("openai api fine_tunes.create --training_file prepared_data_prepared.jsonl --model davinci --suffix "SuperHero"".split())
  让我们花点时间来理解这段代码吧!
  一、档案的内容 输出_打开_完成. csv 被载入数据帧 df。作为提醒,在我们的任务中,如果用户输入"40,女性,治疗",我们希望有一个具有治疗能力的40岁女性角色的描述。要执行微调,必须向GPT提供用户可能键入的内容和相应的期望响应的示例。在数据框中 df ,列 子提示符 以及 响应_文本 包含具有相应期望响应的输入示例。在上面的代码中,我们首先提取这两个冒号,然后将它们重命名为 瞬发 以及 完成分别为。生成的数据框存储在新文件中 准备好的数据. csv 仅包含这两列。
  此文件 prepared_data.csv 如下所示:prompt,completion "18, man, invisibility","He looks to be in his late teens, with dark eyes and unruly black hair which reach his shoulders. His build is athletic and strong, but not muscular. He often wears clothing that makes him blend in with his surroundings, in order to stay as inconspicuous as possible.He has the ability of invisibility, which he can use to become an invisible observer or to make himself or objects around him disappear from view. He has honed his skills to make himself undetectable, able to even make sounds vanish, allowing him to go unnoticed. His invisibility power is his greatest asset, and he uses it to protect those he cares about." "18, man, invisibility","18 year-old Jackson is a powerful young man with the incredible power of invisibility. He stands at 6"2 and has a strong athletic frame with wavy brown hair, startling blue eyes and a warm and gentle smile. His strength and agility make him especially good at using his ability. He can become invisible in an instant, moving through walls and other obstacles without being detected. What"s more, he can move objects with his mind and use his power to protect those he loves. His power is a blessing and a curse, as it can be abused to do harm. Jackson is a brave and noble person who uses his power to do good and make the world a better place." "18, man, invisibility","Brandon is an 18-year-old of average build, standing roughly 5"10 with an inquisitive look. He has naturally wavy chestnut brown hair and bright blue eyes. His demeanor is usually quite serious, but he also has an easy and gentle smile. He has a natural gift of invisibility, which he uses to protect himself and his family from harm. He"s an inquisitive and creative young man who uses his gift to explore the world, observe people, and uncover the truth. His consistent practice of mindfulness helps him remain unseen, even when his emotions are visible. His intelligence and persistent passion for truth drives him to help those in need." "18, man, read in the thoughts","This 18-year-old man has a muscular stature and long, ash blonde hair. His bright blue eyes are full of knowledge and power, hinting at the strange ability he has - he can read minds. Now and then, strange sparks of electricity streak from his eyes when he concentrates hard enough. He is often calm and collected, but when provoked has the ability to blend his learning of your thoughts with his immense strength. His wit, intelligence and empathy are weapons that are often underestimated - yet, very lethal." "18, man, read in the thoughts","He"s an 18-year-old man with short, cropped dark hair and bright green eyes. His usual outfit consists of an olive green hoodie, blue jeans and purple trainers. He"s relaxed, confident and always reads the atmosphere well. One of his great skills is read in the thoughts of others. By doing so, he is able to understand people more easily and relate to their concerns out of the blue. He always uses his superpower with the utmost dignity and respect, never using it to manipulate. He uses it to seek the truth, identify people"s emotions and gain insight into their perspectives. He"s the sort of person that can make anyone feel comfortable and is never afraid of a challenge. His superpower is merely an extension of his already charismatic disposition." (...)
  Python的 subprocess.run() 函数将命令作为子进程运行。它经常被用来执行外部程序,就好像它们在终端中运行一样。
  我们使用 subprocess.run () 来执行"openai工具微调.准备数据"。此函数接受输入文件 prepared_data.csv,检查数据是否正确,并生成一个名为 prepared_data_prepared.jsonl的JSONL文件。JSONL文件是一种将每个JSON对象存储在单独行中的格式。JSONL文件包含一系列JSON对象,每个对象由换行符分隔。
  请注意,我们添加了选项"- - quiet"来自动接受"openai tools fine_tunes.prepare_data"提供的所有建议。例如 ,它建议在所有提示符的末尾添加一个"-->",并在每个响应的末尾添加一个标记 END 。
  该JSONL文件的第一行如下所示:{"prompt":"18, man, invisibility ->","completion":"   He looks to be in his late teens, with dark eyes and unruly black hair which reach his shoulders. His build is athletic and strong, but not muscular. He often wears clothing that makes him blend in with his surroundings, in order to stay as inconspicuous as possible.  He has the ability of invisibility, which he can use to become an invisible observer or to make himself or objects around him disappear from view. He has honed his skills to make himself undetectable, able to even make sounds vanish, allowing him to go unnoticed. His invisibility power is his greatest asset, and he uses it to protect those he cares about. END"} {"prompt":"18, man, invisibility ->","completion":"   18 year-old Jackson is a powerful young man with the incredible power of invisibility. He stands at 6"2 and has a strong athletic frame with wavy brown hair, startling blue eyes and a warm and gentle smile. His strength and agility make him especially good at using his ability. He can become invisible in an instant, moving through walls and other obstacles without being detected. What"s more, he can move objects with his mind and use his power to protect those he loves. His power is a blessing and a curse, as it can be abused to do harm. Jackson is a brave and noble person who uses his power to do good and make the world a better place. END"} (...)
  GPT-3模型的微调是在第二阶段真正实现的 subprocess.run (), 其中 openai api微调.创建 被执行。在这个函数中,我们首先给出之前创建的JSONL文件的名称。然后,您需要选择要微调的型号。OpenAI提供四种主要模型,具有不同的性能水平,适用于各种任务。& nbsp; 达温奇 是最强大的模型,而Ada是最快的。nbsp; 达温奇 也是最贵的型号。
  由于我的模型的目的是创建对超级英雄的描述,我们给我的新模型加了后缀"超级英雄"。
  就这样几分钟后,您将拥有一个微调好的模型,可以随时使用。现在是时候测试你的新模型了
  有不同的方式来使用模型来完成。主要通过OpenAI提供的Playground或通过Python等编程语言。
  最简单的方法可能是使用 操场。请访问 https://platform.openai.com/playground。点击"型号"并搜索后缀为""的型号超级英雄".在"停止序列"中添加标记"END"。
  现在是时候让我们的模型做出新的预测了。我们会要求描述一个18岁的男性角色,他真的拥有不必要的力量。我们会要求描述一个拥有力量的角色......"可以吃很多"......看看会发生什么......
  不算太糟
  你想用Python来做吗?简单!点击屏幕右上角的"查看代码"。
  在我们的例子中,在"查看代码"中,我们有:import os import openai  openai.api_key = os.getenv("OPENAI_API_KEY")  response = openai.Completion.create(   model="davinci:ft-klhm:superhero-2023-02-01-14-56-48",   prompt="18, Man, can eat a lot -> ",   temperature=0.7,   max_tokens=256,   top_p=1,   frequency_penalty=0,   presence_penalty=0,   stop=["END"] )
  只需要复制粘贴就可以了。结论
  在这个博客中,我们已经看到了如何生成合成数据来完善我们的模型,以及如何进行微调。我们使用了一个创建超级英雄的用例,但是同样的方法可以用于您可能有的任何用例。最重要的是要有足够的高质量的例子,有提示和期望的反应。

春晚看点多!秦岚落泪嗓子哑,马丽炸毛,撒贝宁穿高跟赢麻了爆竹声中一岁除,春风送暖入屠苏。在全国观众的期待下,2023兔年春晚已经拉开了帷幕,每个节目都充满了年味儿和欢声笑语。不出意外,每年都是大型的真香现场,那么今年春晚都有哪些看点呢?正月初五破五节,牢记1不出,2要做,吃3样,忌2事,送穷迎吉祥天南地北大拜年导读我一直觉得,初一到初三才能称之为大年,到了初三之后,应该称之为正月,现在说的初五,也就是正月初五,俗称破五。到了这个时间段,我们就应该好好准备一下,开始踏上返程的东北的丈母娘来了女婿很着急张先生家有台美菱冰箱,他反映,最近制冷功能突然坏了,怕是要等到年后才能修好。1818黄金眼一家子留杭过年冰箱坏了能否提供备用张先生上周三左右,因为我们冰箱有很多包好的饺子和面条之类狂飙红颜祸水,大佬的女人陈书婷,才是强哥黑化的催化剂花煜寒文此文为花煜寒对狂飙电视剧人物剧情的解读,每一期涉及不同的人物与剧情,如果喜欢的话,请右上角点关注文接上回。还记得那一夜吗?强哥被一个艳丽的女人勒着脖子差点挂掉,还流下了痛苦大年初四,快来迎灶神扔穷!今天是大年初四按照传统习俗是家家户户迎灶神的日子人们往往在这一天选择在家中团聚灶神又叫灶王灶君灶王爷是中国古代神话传说中的司饮食之神传说中的灶神体态臃肿圆滑世故掌管着一家人的财气祸Dunk海盐蓝成2023首匹黑马!3招教你如何避雷!兔年到了,你是否穿上了自己喜欢的新鞋了呢?最近,小编发现,得物上有一双很火的鞋NikeDunkLowIvoryHyperRoyal白蓝配色,不仅有2。7万名得物er已经入手,更有6POP流行趋势网风衣女装TOP款式热搜排行榜综述报告数据基于7月份用户下载互动数据榜单TOP100,其中新锐设计占据大部分比率,设计点上环绕这解构拼接荷叶边装饰等工艺应用,应用帽口延长浮水等部位塑造出披肩视觉的风衣比率12,DIOR用一场高订秀告诉我们WhoisJosephineBaker在一群花花绿绿夸张廓形的高订发布秀中,DIOR如一股清流出现在大众视野中。正如DIOR女装创意总监MariaGraziaChiuri所说,这一高订系列是奢华20年代的当下演绎,更干一个吃过大苦的人,会有以下五个表现,值得尊重和学习作者拾壹言01序言每个人的一生,都不是一帆风顺的,吃过苦的人会变得更加坚强和努力。对于每个人来说,吃过苦之后,都会有不同程度的变化和成长。在人生的道路上,吃过苦,才知道什么是真正的不要试图改变任何人不要试图改变任何人,也不要指望身边的人会因为你而改变。他们只会因为你的口袋而自动改变。成年人的世界就一条准则,利益面前,先小人后君子。永远别替别人做决定不然到时候背锅的人可就是你了年是我的劫像我这样逃避过年的人,应该没谁了吧?来头条看看别人的快乐,心里算算假期还剩下好几天。小时候逃避过年,是害怕父母的争吵,虽然平时也吵,但过年更凶。现在逃避过年,是害怕这种孤独的冷漠,
公认口碑不错的四款手机,最低仅1768,国产优质手机太香了手机市场内卷之后,越来越多的好手机开始出现,并且价格都还不高。今天要和大家聊的这四款手机都是公认口碑不错的国产手机。红米K50ProK50Pro搭载了三星2K120Hz柔性直屏,下聊聊OPPOFindX6标准版是否值得入手为什么这么说呢?通过最近OPPO的样张传播,就能看出猫腻了。先是丢出来样张大吹特吹暗光长焦厉害,然后官宣都是标准版拍摄,从而得出FindX6标准版没有阉割的逻辑,看似挺符合逻辑,但三天吃透MySQL面试八股文事务的四大特性?事务特性ACID原子性(Atomicity)一致性(Consistency)隔离性(Isolation)持久性(Durability)。原子性是指事务包含的所有操作ChatGPT带动游戏板块拉升,游戏行业的春天到来了吗?游戏板块今天开盘大涨,并且手机游戏网络游戏云游戏等细分板块领涨全天,今天的游戏板块大涨背后原因在于1。ChatGPT最新的gpt4的发布,可以有效降低游戏的美术,设计成本并且改变游何院士认为华为不懂理论研究的重要性华为有没有懂得研究理论的重要意义不好确定,但华为在研发投入上是国内,包括各类科研院所,以及各类性质单位里最多的,华为每年研发投入费用大概长年可以可以排全球前十,华为也事实上取得了很AI对话隐私保护问题,让我们都裸奔了吗?当前,随着人工智能技术的发展,越来越多的AI对话系统进入了人们的生活。在使用这些系统的同时,我们也应该重视其安全性和隐私保护问题,以保障自己的利益。不过能不能做到是一回事,但是起码股息率排行榜24只股连续三年股息率超一年定存已公布分配方案公司中,151家公司分配方案中包含现金分红,以每股派现金额与当年末收盘价为基准计算,19只股股息率超3。证券时报数据宝统计显示,截至3月20日,沪深两市共有152家公金税四期来了,初创期的企业关于税务知识储备够了吗?金税四期的时代1什么是金税四期?(1)金税四期时代已经到来!2023年1月1日金税四期已上线,先在广东上海内蒙四川厦门陕西重庆青岛大连天津等10个省市试点,之后才会在全国推广。(2(经济)北京助力昌平新城东区发展打造首都北部消费新地标新华社北京3月20日电(记者熊琳)北京市人民政府新闻办20日发布,北京市积极助力昌平新城东区建设发展,打造首都北部消费新地标,为群众生产生活提供更多便利和选择。北京市规划和自然资源广东省计划加快发展钠离子储能电池产业新京报贝壳财经讯(记者王琳琳)3月20日,新京贝壳财经记者从广东省人民政府办公厅发布的广东省推动新型储能产业高质量发展的指导意见(以下简称意见)中获悉,为抢占新型储能产业制高点和产交通运输部3月13日至19日全国民航累计保障航班98880班环比增长4。44来源央视新闻客户端交通运输部今日(20日)发布3月13日3月19日全国物流保通保畅运行情况。根据国务院物流保通保畅工作领导小组办公室监测汇总数据,3月13日3月19日,全国货运物流