正在为人工智能或全栈开发而苦恼?我们的专家将为您提供指导:量身定制的建议、技术整合等。联系我们 [email protected].

使用斯坦福大学羊驼数据集的GPT-J的指导性版本

在NLP Cloud,我们想看看GPT-J是否可以作为一个指示模型进行微调,以便正确理解自然语言中的人类指令,而不使用几次学习。其他的尝试在开源社区已经给出了有趣的结果,如Flan-T5、BloomZ或斯坦福大学的Alpaca,所以我们想用Alpaca的数据集对GPT-J做同样的尝试。结果非常好!

斯坦福羊驼

少数人学习 VS 自然语言指示

生成式人工智能模型并不擅长理解人类的请求,默认情况下是如此。

为了让这些文本生成模型理解你想要的东西,最好的解决方法是使用少数学习。我们做了一个关于少数派学习的特别指南 你可以在这里找到它. GPT-J是一个很好的例子,它是一个非常有能力的模型,但只有在很少的学习中才能正确工作。

即使建立这些例子通常不需要花费太多时间,但对于想要正确使用这些人工智能模型的新人来说,仍然非常困惑。像对人类那样自然地问东西要容易得多。

例如,我们假设你想用GPT-J来纠正拼写错误。下面是一个你必须使用的提示的例子。

I love goin to the beach.
Correction: I love going to the beach.
###
Let me hav it!
Correction: Let me have it!
###
It have too many drawbacks.
Correction: It has too many drawbacks.
###
I do not wan to go
Correction:

正如你所看到的,这并不复杂,但也不简单。如果你适当地微调GPT-J,它可以变成一个 "指示 "模型,这意味着你现在可以提出以下问题。

Correct spelling and grammar from the following text.
I do not wan to go

而它将返回以下内容。

I do not want to go.

好多了,不是吗?我们如何才能实现这一点?

斯坦福羊驼

斯坦福羊驼已于几天前发布。这是由Facebook开发的Llama模型的微调版本。 点击这里查看更多关于这个项目的信息。

基本上,斯坦福大学的Alpaca团队通过在由人类指令组成的相当小的数据集(52k个例子)上对Llama进行微调,成功地得出了一个最先进的指令模型。有趣的是,他们使用一个更大的语言模型(GPT-3)以编程方式生成了这个数据集。 你可以在这里下载该数据集。

在NLP Cloud,我们试图用这个数据集对GPT-J进行微调,我们得到了令人惊讶的好结果!

指导GPT-J

我们创建的新Instruct GPT-J模型现在在Hugging Face Hub上,所以你可以很容易地使用它。 点击这里查看模型.

下面是你如何使用这个模型,使用拥抱脸部的变形金刚。

from transformers import pipeline
import torch

generator = pipeline(model="nlpcloud/instruct-gpt-j-fp16", torch_dtype=torch.float16, device=0)

prompt = "Correct spelling and grammar from the following text.\nI do not wan to go\n"

print(generator(prompt))

这里有一些提示,你可以尝试。

Write a short story about space.\n

Generate a C++ program that sorts a list of integers in ascending order.\n

Paraphrase the following text.\nAfter 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.\n

Summarize the following text.\nFor all its whizz-bang caper-gone-wrong energy, and for all its subsequent emotional troughs, this week’s Succession finale might have been the most important in its entire run. Because, unless I am very much wrong, Succession – a show about people trying to forcefully mount a succession – just had its succession. And now everything has to change. The episode ended with Logan Roy defying his children by selling Waystar Royco to idiosyncratic Swedish tech bro Lukas Matsson. It’s an unexpected twist, like if King Lear contained a weird new beat where Lear hands the British crown to Jack Dorsey for a laugh, but it sets up a bold new future for the show. What will happen in season four? Here are some theories. Season three of Succession picked up seconds after season two ended. It was a smart move, showing the immediate swirl of confusion that followed Kendall Roy’s decision to undo his father, and something similar could happen here. This week’s episode ended with three of the Roy siblings heartbroken and angry at their father’s grand betrayal. Perhaps season four could pick up at that precise moment, and show their efforts to reorganise their rebellion against him. This is something that Succession undoubtedly does very well – for the most part, its greatest moments have been those heart-thumping scenes where Kendall scraps for support to unseat his dad – and Jesse Armstrong has more than enough dramatic clout to centre the entire season around the battle to stop the Matsson deal dead in its tracks.\n

请注意,由于这个模型的微调方式,你应该总是在指令的末尾使用新行。

硬件要求

这个模型是我们微调模型的fp16版本,在像NVIDIA Tesla T4这样拥有16GB VRAM的GPU上运行得非常好。

我们没有注意到fp32和fp16版本在质量上有任何区别。

总结

GPT-J本来就是一个非常好的模型,现在作为一个指导模型使用时,它甚至更好。

由于这个技术,任何人现在都可以把他的人工智能生成模型变成一个指示模型!

如果你对上述内容有疑问或意见,请不要犹豫,立即联系我们.

François
NLP云的数据科学家