【问题标题】:How to save pre-trained API on GPT-3?如何在 GPT-3 上保存预训练的 API?
【发布时间】:2021-07-23 07:30:12
【问题描述】:

我有一个关于 GPT-3 的问题。正如我们所知,我们可以为网络提供一些示例并“调整”模型。

  1. 向模型展示示例。
  2. 保存这些示例。
  3. 重复使用 API。

import openai

class Example():
    """Stores an input, output pair and formats it to prime the model."""
def __init__(self, inp, out):
    self.input = inp
    self.output = out

def get_input(self):
    """Returns the input of the example."""
    return self.input

def get_output(self):
    """Returns the intended output of the example."""
    return self.output

def format(self):
    """Formats the input, output pair."""
    return f"input: {self.input}\noutput: {self.output}\n"


class GPT:
    """The main class for a user to interface with the OpenAI API.
    A user can add examples and set parameters of the API request."""
def __init__(self, engine='davinci',
             temperature=0.5,
             max_tokens=100):
    self.examples = []
    self.engine = engine
    self.temperature = temperature
    self.max_tokens = max_tokens

def add_example(self, ex):
    """Adds an example to the object. Example must be an instance
    of the Example class."""
    assert isinstance(ex, Example), "Please create an Example object."
    self.examples.append(ex.format())

现在,当我对模型使用“给出”示例时,我有以下代码:

gpt2 = GPT(engine="davinci", temperature=0.5, max_tokens=100)
gpt2.add_example(Example('Two plus two equals four', '2 + 2 = 4'))
gpt2.add_example(Example('The integral from zero to infinity', '\\int_0^{\\infty}'))

prompt1 = "x squared plus y squared plus equals z squared"
output1 = gpt2.submit_request(prompt1)

但是,我无法保存这个“预训练”的 API。每次我都必须重新训练它 - 有没有办法重复使用它?

【问题讨论】:

    标签: python gpt-3


    【解决方案1】:

    每次我都必须重新训练它 - 有没有办法重复使用它?

    不,没有任何方法可以重复使用它。您混淆了这些术语:您不需要训练 GPT-3,您需要将示例传递给提示。由于您没有任何类型的容器可以存储以前的结果(从而“训练”您的模型),因此每次都需要传递包括您的任务在内的示例。

    完善工程流程(从而降低每个请求的成本)是一个艰难的过程,需要很长时间的反复试验。

    但说实话:即使每次都通过示例,GPT-3 仍然非常具有成本效益。根据您的具体情况,您(平均而言)只需花费几百个代币即可使用 Davinci 完成复杂的任务。

    【讨论】:

    • 谢谢! - 我尝试过文档,最后不确定我的理解是否正确!
    • 是的!我也建议对 Slack 频道进行更改,但怀疑他们不会很快调整。
    猜你喜欢
    • 2022-12-08
    • 2020-04-07
    • 2022-10-17
    • 2023-01-11
    • 1970-01-01
    • 2019-05-25
    • 2020-02-13
    • 2022-08-23
    • 2019-07-20
    相关资源
    最近更新 更多