【问题标题】:Using EluetherAPI GPT models for NLP tasks将 EluetherAPI GPT 模型用于 NLP 任务
【发布时间】:2022-12-09 18:24:05
【问题描述】:

EluetherAPI 基于 PILE 数据集发布了很多 GPT 模型,等同于原始的 GPT 模型。由于它们是在更大的数据集上训练的,我们可以在同一个模型上执行多个 NLP 任务,而无需重新训练模型,只需很少的提示或使用少样本学习提供一些上下文。

我正在努力实现同样的目标。但问题是返回文本有时太大或太短。这是我的示例代码:

generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B', device=0)
prompt= """[Original]: The diplomatic spat came days after France cut the number of visas it issues for citizens of Algeria and other North African countries.
[Paraphrase]: """
result = generator(prompt, do_sample=True, min_length=10, max_new_tokens=50, top_p=0.9, temperature=1)

结果给了我这个:

France has been forced to temporarily remove two of its citizens who are on a tourist visa from Algeria and Morocco, which have had a long and acrimonious history over the past decade.
[Original]: The two visa holders, who

如您所见,它给我的结果包括输入文本,我删除了输入文本,它工作正常但最后它仍然显示 [Original]: 提示,如何删除它并给出完全相同的结果?

我尝试了多次,甚至提供了上下文,但有时效果很好,有时却不行。我什至尝试使用数据进行少量学习:

"""[Original]: Algeria recalled its ambassador to Paris on Saturday and closed its airspace to French military planes a day later after the French president made comments about the northern Africa country. 
[Paraphrase]: Last Saturday, the Algerian government recalled its ambassador and stopped accepting French military airplanes in its airspace. It happened one day after the French president made comments about Algeria.
###
[Original]: President Macron was quoted as saying the former French colony was ruled by a "political-military system" with an official history that was based not on truth, but on hatred of France.
[Paraphrase]: Emmanuel Macron said that the former colony was lying and angry at France. He also said that the country was ruled by a "political-military system".
###
[Original]: The diplomatic spat came days after France cut the number of visas it issues for citizens of Algeria and other North African countries.
[Paraphrase]: Diplomatic issues started appearing when France decided to stop granting visas to Algerian people and other North African people.
###
[Original]: After a war lasting 20 years, following the decision taken first by President Trump and then by President Biden to withdraw American troops, Kabul, the capital of Afghanistan, fell within a few hours to the Taliban, without resistance.
[Paraphrase]:""

我想知道有什么方法可以传递 end_sequence 以便它在之后停止生成,还有参数 top_p 和 temperature 以获得良好的结果?

【问题讨论】:

    标签: python nlp gpt gpt-3 text-generation


    【解决方案1】:

    你的小样本学习方法很好,但你需要在文本生成管道中使用一个名为eos_token_id的特定参数@:https://huggingface.co/docs/transformers/v4.25.1/en/main_classes/text_generation#transformers.GenerationMixin.generate

    这个eos_token_id 应该是### 的等价物。 此 ID 取决于您使用的分词器。 EleutherAI/gpt-neo-1.3B 在后台使用的分词器是 GPT-2 分词器:https://huggingface.co/docs/transformers/model_doc/gpt2#transformers.GPT2Tokenizer

    当使用 GPT-2 分词器进行分词时,### 返回 21017

    所以你应该设置eos_token_id=21017,一旦遇到###序列就会停止生成。

    【讨论】:

      猜你喜欢
      • 2020-07-08
      • 2020-06-19
      • 2016-11-29
      • 2013-05-05
      • 2020-10-29
      • 2019-12-06
      • 2019-10-13
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多