所有文章 > AI驱动 > 如何使用GPT-3、GPT-4、ChatGPT、GPT-J和其他生成模型进行小样本学习
如何使用GPT-3、GPT-4、ChatGPT、GPT-J和其他生成模型进行小样本学习

如何使用GPT-3、GPT-4、ChatGPT、GPT-J和其他生成模型进行小样本学习

GPT-3、GPT-4、ChatGPT、GPT-J 和一般的生成模型都是非常强大的 AI 模型。我们在这里向您展示如何通过少样本学习(也称为提示工程)有效地使用这些模型。少样本学习就像训练/微调 AI 模型一样,只需在提示中给出几个示例即可。

GPT-3、GPT-4 和 ChatGPT

OpenAI发布的GPT-3、GPT-4以及ChatGPT是迄今为止发布的最强大的文本理解和文本生成的AI模型。

GPT-3 经过了 1750 亿个参数的训练,这使得它用途极其广泛,几乎可以理解任何东西!我们不知道 GPT-4 中的参数数量,但结果更加令人印象深刻。

你可以用这些生成模型做各种各样的事情,比如聊天机器人、内容创建、实体提取、分类、总结等等。但这需要一些练习,正确使用它们可能需要一点工作。

GPT-J、GPT-NeoX 和 Dolphin

GPT-NeoX 和 GPT-J 都是开源自然语言处理模型,由致力于开源 AI 的研究人员集体创建。

GPT-J 有 60 亿个参数,GPT-NeoX 有 200 亿个参数,这使它们成为本文撰写时最先进的开源自然语言处理模型。它们是 OpenAI 专有的 GPT-3 Curie 的直接替代品。

这些模型用途广泛。它们几乎可以用于任何自然语言处理用例:文本生成、情绪分析、分类、机器翻译……等等(见下文)。然而,有效使用它们有时需要练习。它们的响应时间(延迟)也可能比更标准的自然语言处理模型更长。

GPT-J 和 GPT-NeoX 均可在 NLP Cloud API 上使用。在 NLP Cloud 上,您还可以使用 Dolphin,这是一种内部高级生成模型,可与 ChatGPT、GPT-3 甚至 GPT-4 竞争。下面,我们将向您展示使用 NLP Cloud 的 GPT-J 端点在 GPU 上获得的示例,以及 Python 客户端。如果您想复制粘贴示例,请不要忘记添加您自己的 API 令牌。要安装 Python 客户端,请首先运行以下命令:pip install nlpcloud

小样本学习

少量学习是指仅通过几个示例帮助机器学习模型做出预测。这里不需要训练新模型:GPT-3 和 GPT-4 之类的模型非常大,因此可以轻松适应许多情况而无需重新训练。

仅向模型提供几个例子确实有助于显著提高其准确性。

在自然语言处理中,想法是将这些示例与文本输入一起传递。请参阅下面的示例!

另请注意,如果少量学习还不够,您还可以在 OpenAI 网站上微调 GPT-3,在 NLP Cloud 上微调 GPT-J 和 Dolphin,以便模型完美地适合您的用例。

您可以在 NLP Cloud Playground 的文本生成部分轻松测试少样本学习。单击此处在 Playground 上尝试文本生成。 然后只需使用本文下面显示的示例之一即可亲自体验。

如果您使用能够理解自然人类指令的模型(如 ChatGPT 或 ChatDolphin),您可能不必总是使用少样本学习,但为了获得最先进的结果,尽可能应用少样本学习总是很有趣的。如果您不想使用少样本学习,请阅读我们关于如何使用 ChatGPT 和 ChatDolphin 的专门指南

使用 GPT-J 进行情绪分析

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Message: Support has been terrible for 2 weeks...
Sentiment: Negative
###
Message: I love your API, it is simple and so fast!
Sentiment: Positive
###
Message: GPT-J has been released 2 months ago.
Sentiment: Neutral
###
Message: The reactivity of your team has been amazing, thanks!
Sentiment:""",
min_length=1,
max_length=1,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

Positive

如你所见,我们首先给出了 3 个具有适当格式的示例,这使得 GPT-J 能够理解我们想要进行情绪分析。而且它的结果也不错。

您可以使用如下所示的自定义分隔符来帮助 GPT-J 理解不同的部分:###。我们完全可以使用其他类似的东西: 。或者只是一个新行。然后我们设置“end_sequence”,这是一个 NLP Cloud 参数,它告诉 GPT-J 在新行 + :---之后停止生成内容。###end_sequence="###"

使用 GPT-J 生成 HTML 代码

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""description: a red button that says stop
code: <button style=color:white; background-color:red;>Stop</button>
###
description: a blue box that contains yellow circles with red borders
code: <div style=background-color: blue; padding: 20px;><div style=background-color: yellow; border: 5px solid red; border-radius: 50%; padding: 20px; width: 100px; height: 100px;>
###
description: a Headline saying Welcome to AI
code:""",
max_length=500,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

<h1 style=color: white;>Welcome to AI</h1>


使用 GPT-J 生成代码确实非常了不起。这在一定程度上要归功于 GPT-J 是在庞大的代码库上进行训练的。

使用 GPT-J 生成 SQL 代码

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Question: Fetch the companies that have less than five people in it.
Answer: SELECT COMPANY, COUNT(EMPLOYEE_ID) FROM Employee GROUP BY COMPANY HAVING COUNT(EMPLOYEE_ID) < 5;
###
Question: Show all companies along with the number of employees in each department
Answer: SELECT COMPANY, COUNT(COMPANY) FROM Employee GROUP BY COMPANY;
###
Question: Show the last record of the Employee table
Answer: SELECT * FROM Employee ORDER BY LAST_NAME DESC LIMIT 1;
###
Question: Fetch three employees from the Employee table;
Answer:""",
max_length=100,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])


输出:

SELECT * FROM Employee ORDER BY ID DESC LIMIT 3;


自动 SQL 生成与 GPT-J 配合得非常好,尤其是由于 SQL 的声明性质,以及 SQL 是一种功能有限的语言,可能性相对较少(与大多数编程语言相比)。

使用 GPT-J 进行高级实体提取 (NER)

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""[Text]: Fred is a serial entrepreneur. Co-founder and CEO of Platform.sh, he previously co-founded Commerce Guys, a leading Drupal ecommerce provider. His mission is to guarantee that as we continue on an ambitious journey to profoundly transform how cloud computing is used and perceived, we keep our feet well on the ground continuing the rapid growth we have enjoyed up until now.
[Name]: Fred
[Position]: Co-founder and CEO
[Company]: Platform.sh
###
[Text]: Microsoft (the word being a portmanteau of "microcomputer software") was founded by Bill Gates on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. Steve Ballmer replaced Gates as CEO in 2000, and later envisioned a "devices and services" strategy.
[Name]: Steve Ballmer
[Position]: CEO
[Company]: Microsoft
###
[Text]: Franck Riboud was born on 7 November 1955 in Lyon. He is the son of Antoine Riboud, the previous CEO, who transformed the former European glassmaker BSN Group into a leading player in the food industry. He is the CEO at Danone.
[Name]: Franck Riboud
[Position]: CEO
[Company]: Danone
###
[Text]: David Melvin is an investment and financial services professional at CITIC CLSA with over 30 years’ experience in investment banking and private equity. He is currently a Senior Adviser of CITIC CLSA.
""",
top_p=0,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

[Name]: David Melvin
[Position]: Senior Adviser
[Company]: CITIC CLSA

如您所见,GPT-J 非常擅长从非结构化文本中提取结构化数据。GPT-J 无需任何重新训练就能解决实体提取问题,这真是令人印象深刻!通常,提取新类型的实体(如姓名、职位、国家等)需要全新的注释、训练、部署过程……在这里,它是完全无缝的。

使用 GPT-J 进行问答

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Context: NLP Cloud was founded in 2021 when the team realized there was no easy way to reliably leverage Natural Language Processing in production.
Question: When was NLP Cloud founded?
Answer: 2021
###
Context: NLP Cloud developed their API by mid-2020 and they added many pre-trained open-source models since then.
Question: What did NLP Cloud develop?
Answer: API
###
Context: All plans can be stopped anytime. You only pay for the time you used the service. In case of a downgrade, you will get a discount on your next invoice.
Question: When can plans be stopped?
Answer: Anytime
###
Context: The main challenge with GPT-J is memory consumption. Using a GPU plan is recommended.
Question: Which plan is recommended for GPT-J?
Answer:""",
min_length=1,
max_length=20,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

GPU plan

问答系统效果很好。其他专用的自然语言处理模型也可以实现,但准确度可能不及后者。

使用 GPT-J 创建教程

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Here is a tutorial about how to make a cake.

1. Take some flour.
2. Take some sugar.""",
max_length=500)
print(generation["generated_text"])

输出:

Here is a tutorial how to make a cake.

1. Take some flour.
2. Take some sugar.
3. Take some butter.
4. Take some eggs.
5. Take some water.
6. Take some baking powder.
7. Take some vanilla.
8. Mix all together.
9. Bake in a pan.
10. Enjoy.

Well, that's it. You can make this for your birthday or a party or you can even make it for your kids. They will love this.

正如您所看到的,GPT-J 自动遵循您的初始格式非常令人印象深刻,并且生成的内容也非常好。您可以用它制作一个合适的蛋糕(虽然还没有尝试过)。

使用 GPT-J 纠正语法和拼写

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""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:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])


输出:

I do not want to go.


拼写和语法纠正功能如预期般正常。不过,如果你想要更准确地指出句子中错误的位置,你可能需要使用专用模型。

使用 GPT-J 进行机器翻译

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Hugging Face a révolutionné le NLP.
Translation: Hugging Face revolutionized NLP.
###
Cela est incroyable!
Translation: This is unbelievable!
###
Désolé je ne peux pas.
Translation: Sorry but I cannot.
###
NLP Cloud permet de deployer le NLP en production facilement.
Translation:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

NLP Cloud makes it easy to deploy NLP to production.

机器翻译通常采用专用模型(通常每种语言一个)。在这里,所有语言都由 GPT-J 开箱即用,这非常令人印象深刻。

使用 GPT-J 生成推文

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""keyword: markets
tweet: Take feedback from nature and markets, not from people
###
keyword: children
tweet: Maybe we die so we can come back as children.
###
keyword: startups
tweet: Startups should not worry about how to put out fires, they should worry about how to start them.
###
keyword: NLP
tweet:""",
max_length=200,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

People want a way to get the benefits of NLP without paying for it.


这是一个根据上下文生成简短推文的有趣且简单的方法。

使用 GPT-J 的聊天机器人和对话式 AI

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""This is a discussion between a [human] and a [robot].
The [robot] is very nice and empathetic.

[human]: Hello nice to meet you.
[robot]: Nice to meet you too.
###
[human]: How is it going today?
[robot]: Not so bad, thank you! How about you?
###
[human]: I am ok, but I am a bit sad...
[robot]: Oh? Why that?
###
[human]: I broke up with my girlfriend...
[robot]:""",
min_length=1,
max_length=20,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])


输出:

Oh? How did that happen?


如你所见,GPT-J 正确地理解了你处于对话模式。而且非常强大的是,如果你在上下文中改变语气,模型的响应也会遵循相同的语气(讽刺、愤怒、好奇……)。

实际上,我们专门写了一篇博客文章,介绍如何使用 GPT-3/GPT-J 构建聊天机器人,请随意阅读!

使用 GPT-J 进行意图分类

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""I want to start coding tomorrow because it seems to be so fun!
Intent: start coding
###
Show me the last pictures you have please.
Intent: show pictures
###
Search all these files as fast as possible.
Intent: search files
###
Can you please teach me Chinese next week?
Intent:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

learn chinese


GPT-J 能够从你的句子中检测出意图,这令人印象深刻。它对更复杂的句子非常有效。如果你愿意,你甚至可以要求它以不同的格式格式化意图。例如,你可以自动生成一个 JavaScript 函数名称,如“learnChinese”。

使用 GPT-J 进行释义

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""[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]:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True,
min_length=0,
max_length=50)
print(generation["generated_text"])

输出:

French President Emmanuel Macron hopes the diplomatic tension with Algeria will calm down. He wants to make progress in the relations with the former French colony. President Macron says he has a good relationship with his Algerian counterpart and he is glad that they have a cordial relationship. The president was quoted as saying that Algeria was ruled by a "political-military system" with an official history that was based not on truth, but on hatred of France. France cut the number of visas it issues for citizens of Algeria and other North African countries.


GPT-J 修改了我们的段落,同时保留了主要含义,这就是释义的意义所在。通过在输入中传递不同的示例,并使用温度、top_p、重复惩罚等 API 参数,您可以完美地鼓励 GPT-J 返回更多原始释义……

使用 GPT-J 进行总结

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""[Original]: America has changed dramatically during recent years. Not only has the number of graduates in traditional engineering disciplines such as mechanical, civil, electrical, chemical, and aeronautical engineering declined, but in most of the premier American universities engineering curricula now concentrate on and encourage largely the study of engineering science. As a result, there are declining offerings in engineering subjects dealing with infrastructure, the environment, and related issues, and greater concentration on high technology subjects, largely supporting increasingly complex scientific developments. While the latter is important, it should not be at the expense of more traditional engineering.
Rapidly developing economies such as China and India, as well as other industrial countries in Europe and Asia, continue to encourage and advance the teaching of engineering. Both China and India, respectively, graduate six and eight times as many traditional engineers as does the United States. Other industrial countries at minimum maintain their output, while America suffers an increasingly serious decline in the number of engineering graduates and a lack of well-educated engineers.
(Source: Excerpted from Frankel, E.G. (2008, May/June) Change in education: The cost of sacrificing fundamentals. MIT Faculty
[Summary]: MIT Professor Emeritus Ernst G. Frankel (2008) has called for a return to a course of study that emphasizes the traditional skills of engineering, noting that the number of American engineering graduates with these skills has fallen sharply when compared to the number coming from other countries.
###
[Original]: So how do you go about identifying your strengths and weaknesses, and analyzing the opportunities and threats that flow from them? SWOT Analysis is a useful technique that helps you to do this.
What makes SWOT especially powerful is that, with a little thought, it can help you to uncover opportunities that you would not otherwise have spotted. And by understanding your weaknesses, you can manage and eliminate threats that might otherwise hurt your ability to move forward in your role.
If you look at yourself using the SWOT framework, you can start to separate yourself from your peers, and further develop the specialized talents and abilities that you need in order to advance your career and to help you achieve your personal goals.
[Summary]: SWOT Analysis is a technique that helps you identify strengths, weakness, opportunities, and threats. Understanding and managing these factors helps you to develop the abilities you need to achieve your goals and progress in your career.
###
[Original]: Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.
Jupiter is primarily composed of hydrogen with a quarter of its mass being helium, though helium comprises only about a tenth of the number of molecules. It may also have a rocky core of heavier elements,[21] but like the other giant planets, Jupiter lacks a well-defined solid surface. Because of its rapid rotation, the planet's shape is that of an oblate spheroid (it has a slight but noticeable bulge around the equator).
[Summary]: Jupiter is the largest planet in the solar system. It is a gas giant, and is the fifth planet from the sun.
###
[Original]: For 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.
[Summary]:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True,
min_length=20,
max_length=200)
print(generation["generated_text"])

输出:

Season 3 of Succession ended with Logan Roy trying to sell his company to Lukas Matsson.


文本摘要是一项棘手的任务。只要你给 GPT-J 提供正确的示例,它就能很好地完成这项工作。摘要的大小和摘要的语气在很大程度上取决于你创建的示例。例如,无论你是想为孩子制作简单的摘要,还是为医生制作高级医学摘要,你创建的示例类型可能都不一样。如果 GPT-J 的输入大小对于你的摘要示例来说太小,你可能需要对 GPT-J 进行微调以完成摘要任务。

使用 GPT-J 进行零样本文本分类

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Message: When the spaceship landed on Mars, the whole humanity was excited
Topic: space
###
Message: I love playing tennis and golf. I'm practicing twice a week.
Topic: sport
###
Message: Managing a team of sales people is a tough but rewarding job.
Topic: business
###
Message: I am trying to cook chicken with tomatoes.
Topic:""",
min_length=1,
max_length=5,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

food

这是一种简单而有效的方法,可以利用所谓的“零样本学习”技术对一段文本进行分类,而无需事先声明类别。

使用 GPT-J 提取关键字和关键短语

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Information Retrieval (IR) is the process of obtaining resources relevant to the information need. For instance, a search query on a web search engine can be an information need. The search engine can return web pages that represent relevant resources.
Keywords: information, search, resources
###
David Robinson has been in Arizona for the last three months searching for his 24-year-old son, Daniel Robinson, who went missing after leaving a work site in the desert in his Jeep Renegade on June 23.
Keywords: searching, missing, desert
###
I believe that using a document about a topic that the readers know quite a bit about helps you understand if the resulting keyphrases are of quality.
Keywords: document, understand, keyphrases
###
Since transformer models have a token limit, you might run into some errors when inputting large documents. In that case, you could consider splitting up your document into paragraphs and mean pooling (taking the average of) the resulting vectors.
Keywords:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])


输出:

paragraphs, transformer, input, errors


关键词提取是指从一段文本中获取主要思想。这是一个有趣的自然语言处理子领域,GPT-J 可以很好地处理。请参阅下文的关键词提取(同样的事情,但有多个单词)。

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Information Retrieval (IR) is the process of obtaining resources relevant to the information need. For instance, a search query on a web search engine can be an information need. The search engine can return web pages that represent relevant resources.
Keywords: information retrieval, search query, relevant resources
###
David Robinson has been in Arizona for the last three months searching for his 24-year-old son, Daniel Robinson, who went missing after leaving a work site in the desert in his Jeep Renegade on June 23.
Keywords: searching son, missing after work, desert
###
I believe that using a document about a topic that the readers know quite a bit about helps you understand if the resulting keyphrases are of quality.
Keywords: document, help understand, resulting keyphrases
###
Since transformer models have a token limit, you might run into some errors when inputting large documents. In that case, you could consider splitting up your document into paragraphs and mean pooling (taking the average of) the resulting vectors.
Keywords:""",
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

large documents, paragraph, mean pooling


与上面的例子相同,只是这次我们不想提取一个单词而是几个单词(称为关键短语)。

使用 GPT-J 进行产品描述和广告生成

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""Generate a product description out of keywords.

Keywords: shoes, women, $59
Sentence: Beautiful shoes for women at the price of $59.
###
Keywords: trousers, men, $69
Sentence: Modern trousers for men, for $69 only.
###
Keywords: gloves, winter, $19
Sentence: Amazingly hot gloves for cold winters, at $19.
###
Keywords: t-shirt, men, $39
Sentence:""",
min_length=5,
max_length=30,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

Extraordinary t-shirt for men, for $39 only.


可以要求 GPT-J 生成包含特定关键字的产品描述或广告。这里我们只生成一个简单的句子,但如果需要,我们可以轻松生成整个段落。

使用 GPT-J 生成博客文章

import nlpcloud
client = nlpcloud.Client("gpt-j", "your_token", gpu=True)
generation = client.generation("""[Title]: 3 Tips to Increase the Effectiveness of Online Learning
[Blog article]: <h1>3 Tips to Increase the Effectiveness of Online Learning</h1>
<p>The hurdles associated with online learning correlate with the teacher’s inability to build a personal relationship with their students and to monitor their productivity during class.</p>
<h2>1. Creative and Effective Approach</h2>
<p>Each aspect of online teaching, from curriculum, theory, and practice, to administration and technology, should be formulated in a way that promotes productivity and the effectiveness of online learning.</p>
<h2>2. Utilize Multimedia Tools in Lectures</h2>
<p>In the 21st century, networking is crucial in every sphere of life. In most cases, a simple and functional interface is preferred for eLearning to create ease for the students as well as the teacher.</p>
<h2>3. Respond to Regular Feedback</h2>
<p>Collecting student feedback can help identify which methods increase the effectiveness of online learning, and which ones need improvement. An effective learning environment is a continuous work in progress.</p>
###
[Title]: 4 Tips for Teachers Shifting to Teaching Online
[Blog article]: <h1>4 Tips for Teachers Shifting to Teaching Online </h1>
<p>An educator with experience in distance learning shares what he’s learned: Keep it simple, and build in as much contact as possible.</p>
<h2>1. Simplicity Is Key</h2>
<p>Every teacher knows what it’s like to explain new instructions to their students. It usually starts with a whole group walk-through, followed by an endless stream of questions from students to clarify next steps.</p>
<h2>2. Establish a Digital Home Base</h2>
<p>In the spirit of simplicity, it’s vital to have a digital home base for your students. This can be a district-provided learning management system like Canvas or Google Classrooms, or it can be a self-created class website. I recommend Google Sites as a simple, easy-to-set-up platform.</p>
<h2>3. Prioritize Longer, Student-Driven Assignments</h2>
<p>Efficiency is key when designing distance learning experiences. Planning is going to take more time and require a high level of attention to detail. You will not be able to correct mistakes on the fly or suddenly pivot when kids are disengaged.</p>
<h2>4. Individual Touchpoints Are Game-Changers</h2>
<p>You can create these touchpoints through any medium you like: emails, video messages, phone calls, messages through your learning management system, comments on shared documents, etc.</p>
###
[Title]: 3 Best Free Image Converter Software Programs
[Blog article]: <h1>3 Best Free Image Converter Software Programs</h1>
<p>Best free image converters for JPG, BMP, PSD, TIF, GIF, RAW, and more</p>
<h2>1. XnConvert</h2>
<p>XnConvert is the Swiss Army knife of image converters. With XnView, you can convert any of around 500 image formats to your choice of around 80 others. If you have a rare image format that you can't open, XnView can probably convert it.</p>
<h2>2. CoolUtils Online Image Converter</h2>
<p>The CoolUtils Online Image Converter is just that—an image converter that exists completely online, no download required. Unlike some online image converters, this one does the image converting for you in real-time—no waiting on an email link.</p>
<h2>3. FileZigZag</h2>
<p>FileZigZag is another online image converter service that will convert most common graphics formats. Just upload the original image, choose the desired output, and then wait for the download link to appear on the page.</p>
###
[Title]: 4 Best Tips to Find a Girlfriend
[Blog article]: """,
max_length=500,
length_no_input=True,
end_sequence="###",
remove_end_sequence=True,
remove_input=True)
print(generation["generated_text"])

输出:

<h1>Text Generation API</h1>
<h2>What is Text Generation?</h2>
<p>Text generation is the process of generating text from a block of text. It is not simply the inverse of summarization: a text generator will take a short piece of text as an input and generate a longer one.</p>
<p>For example you have the following text:</p>
Ahead of the opening of the meeting,
<p>In this case the goal of the API is to automatically generate the following:</p>
Ahead of the opening of the meeting, Prime Minister Justin Trudeau spoke to reporters at the Montreal airport where he was travelling to speak at the conference.
<p>So basically we want to leverage the output of the API as the input for the text generator, and we will then be able to generate some sentences based on the input we already have.</p>
<h2>Text generation with GPT-2</h2>
<p>We will leverage GPT-2 in order to have a starting point for the text generator. In this case, we will use the API as the input for the text generator, and we will use the output of the API as the input for GPT-2.
However, we want to fine-tune GPT-2 to generate more complex sentences and to have better results.</p>

是不是令人印象深刻?生成的博客文章很小,但你可以生成更长的文章。生成的博客文章的结构实际上取决于你在少样本示例中使用的结构。为了获得更复杂的结构和更相关的内容,微调 GPT-J 是关键。

如何找到NLP Cloud模型GPT-J

幂简集成是国内领先的API集成管理平台,专注于为开发者提供全面、高效、易用的API集成解决方案。幂简API平台可以通过以下两种方式找到所需API:通过关键词搜索NLP Cloud(例如,输入’NLP Cloud‘这类品类词,更容易找到结果)、或者从API Hub分类页进入寻找。

此外,幂简集成博客会编写API入门指南、多语言API对接指南、API测评等维度的文章,让开发者快速使用目标API。

结论

如您所见,小样本学习是一项很棒的技术,它可以帮助 GPT-3、ChatGPT、GPT-4 和一般的生成模型取得惊人的成就!这里的关键是在发出请求之前传递正确的上下文。

即使对于简单的文本生成,也建议传递尽可能多的上下文,以帮助模型。

本文转载自: 如何使用 GPT-3、GPT-4、ChatGPT、GPT-J 和其他生成模型进行小样本学习

#你可能也喜欢这些API文章!