Cover image for Few shot learnings

Few shot learnings

06/29/2023· 3 min read

Today, I’ll show you how you can train ChatGPT to perform different tasks in few minutes with few-shot learnings technique

ChatGPT is a jack of all trades. But you can train it to be a master of one or two tasks that you need it to do. All it takes is an understanding of few-shot learning and a few well-crafted examples. If you’ve been underwhelmed with the output ChatGPT produces, wait until you try few-shot learning

Now, let's dive in.

Before large language model (LLM)

Before the advent of LLM with ChatGPT being the most well known, AI experts have to train machine learning models for a specific task they wanted the AI perform. This requires extensive data and compute power and it could take days or even weeks. This also means the trained model is excelled at their specific task but faltered at nearly everything else

LLM models like ChatGPT is capable of performing a wide range of task adequately. Furthermore, they possess the remarkable ability to learn new tasks with just a few examples - a concept known as few short learning.

Write ads headline with few-shot learnings

To use few-shot learning, all you have to do it provide examples of how to complete a certain task in your prompt

For example, I use promotional copy from Apple Vision Pro & the Iphone as examples and asked ChatGPT to generate similar headlines for an unrelated product - french fries. Here is the prompt

I want you to generate headline for a product based on examples. I'll provide examples below

- Welcome to the era of spatial computing.
- Apple Vision Pro seamlessly blends digital content with your physical space.
- You navigate simply by using your eyes, hands, and voice.
- So you can do the things you love in ways never before possible.
- You’ve never seen everything like this before.
- Free your desktop. And your apps will follow.
- Dynamic Island. A magical way to interact with iPhone.
- Always-On display. A subtle way to stay in the know.

Here is what it came up with


"Introducing Flavor Fusion: French Fries that redefine taste sensations."
"The Future of Snacking is here: Smart Fries revolutionize your taste buds."
"Crisp & Crunch 2.0: French Fries reimagined for an unparalleled eating experience."
"Unlock the Extraordinary: Discover the next-level French Fries that defy expectations."
"Indulge in Fries like never before: Immerse yourself in a symphony of flavors."

I must say, those are some impressively Apple-esque french fries!

Teach ChatGPT to prompt Midjourney

ChatGPT, as powerful as it is, it currently can only output text. However, with few-shot learning you can teach it to generate prompt for other LLM, like Midjourney to produce image

For folks who are unfamiliar with Midjourney, imagine ChatGPT but for creating images. It's currently accessible through a Discord bot, and users generate images using the /imagine command followed by a prompt. You can check out images generated by Midjourney in its community showcase 

When I use a simple prompt to generate a male hero

/imagine a male her

Here is what Midjourney produces

Male hero image generated with simple prompt

I then teach ChatGPT to generate Midjourney prompt using few-shot learnings with the following prompt.

I want you to help me generate MidJourney prompt to create image. Here are examples of prompts, delimited by ```

```
Hyper realistic photograph, portrait of a beautiful happy southamerican woman, big silver earings, tied hair, summer

Film grain, Kodak portra 800, f1. 8, golden hour
```

```
Portrait photo of a african old warrior chief, tribal panther make up, gold on white, side profile, looking away, serious eyes, 50mm portrait photography, hard rim lighting photography - - beta```

Generate an image of a male hero

ChatGPT generate the following prompt for Midjourney

A hyper-realistic photograph, capturing a heroic male figure, age around 30. His broad shoulders and chiseled jaw are accentuated in the low, dramatic lighting of a stormy twilight. His eyes, deep and wise, gaze into the distance, symbolizing his vision for a brighter future. He is attired in a rustic leather jacket, symbolic of his rugged resilience. The background hints at a desolate urban landscape, reflecting the trials he's overcome. The photograph employs high dynamic range techniques, providing excellent contrast and depth, while the dominant colors are deep blues and greys, lending to the moody atmosphere. The image quality should be exceptional, making use of the best available photographic technology, and the aspect ratio should be cinematic to heighten the epic feel of the portrait.

Which generates the following image.

Image generated after few-shot learnings

Quite a difference, isn’t it?

Limitations of few-shot learnings

However few-shot learnings is highly dependent on the selection of examples so it’s crucial to have human verify and correct the output. It’s also best practice include keeping track of prompts & examples used to ensure quality of the output doesn’t decrease over time

To wrap it up, few-shot prompting let you train ChatGPT to perform new tasks with a few examples. It opens up many creative way to leverage ChatGPT than just a simple question & answer chat bot. However, because the way you write examples and prompt affect the output, it’s important to review the output to ensure correctness

What task will you take on with few-shot promptings?


If you find the content useful, please complete a quick poll to help us deliver even more value to you

Trung Vu

About Trung Vu

Trung Vu, a former software engineer, founded Hoss in 2019 to enhance developer experiences, swiftly attracting Silicon Valley backers and a $1.6 million seed round. In 2021, his venture was acquired by Niantic Labs, of Pokemon Go fame, to bolster their Lightship platform.

Post-acquisition, Trung leads engineering teams at Niantic and invests in promising AI startups. An AI enthusiast even before ChatGPT's rise, he equates its potential to electricity. Through AI Growth Pad, his education platform, Trung teaches entrepreneurs to leverage AI for growth, embodying his commitment to ethical, transformative technology.

AI Growth Pad Logo
Where entrepreneurs and marketing professionals learn best practices to leverage AI tools to 10x their productivity and business growth
© Copyright 2023, AI Growth Pad