Skip to main content

✏️ Text Generation with Large Language Models

GPT 3 is a widely used text generator. GPT-4 is meant to be an order of magnitude better, with more parameters, and a better dataset. While this is progress, we still lack the means to properly give understanding to AI. This means that while AI can now put words in a sequence, it can't do the defining work of writing... giving sense and purpose to those words.

The models we wil focus on are the GPT Large Language Models (LLM) from OpenAI.

Other readers enjoyed - Chat GPT

Use Chat GPT more effectively

How LLMs work​

Large language models are functions that take text as input and generate text as output. They are trained on vast quantities of text to predict the next sequence of words. LLMs use a transformer architecture to create a probability distribution over a sequence of words. This means that it reads a sentence, and assigns an importance to each element in that sentence. This lets certain parts of a sentence have more weight than others and influence the prediction.

Through this training process, the models learns rules around various concepts, like; spelling, grammar, paraphrasing, answering questions, holding conversations, and writing in multiple languages. The magic of AI is that these are not explicitly programmed, the computer figures it out on its own

GPT-3, a popular large language model, is now used in a wide range of software applications including productivity tools, educational software, games and more.

How to influence an LLM​

The text prompt is the most crucial input to a large language model as it directs the model's output.

There are several ways to prompt a large language model, including giving it instructions, prompting it to complete a starting phrase, and providing examples through a few examples in the prompt or hundreds to thousands of examples in a fine-tuning training dataset.

We call this the art of prompt engineering. It's an art, more than a science. There are defined techniques, but it's never certain what will work. Now you'll learn basic communication skills with LLMs.

Instruction Prompts​

Instruction-based models such as GPT are tailored to follow specific instructions.

To use these models, simply provide your instruction at the beginning or end of the prompt and the model will generate output that follows to the instruction and stop.

These models can handle detailed instructions, so feel free to provide a clear and detailed explanation of the desired output in the prompt.

Example instruction:

Extract the name of the author from the quotation below.

β€œSome humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation

Output

Ted Chiang

Completion Prompts​

Completion-style prompts leverage the way large language models generate text by predicting the next likely word or phrase. To guide the model, you can start a sentence or pattern that leads to the desired output.

Compared to providing direct instructions, this method requires more experimentation and precision. Additionally, the model may not know when to stop, so it may require additional stop sequences or post-processing to limit the generated text to the desired output.

Example completion prompt:

β€œSome humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation

The author of this quote is

Output:

Ted Chiang

Demonstration Prompts​

Similar to completion-style prompts, demonstrations can show the model what you want it to do. This approach is sometimes called few-shot learning, as the model learns from a few examples provided in the prompt.

Example demonstration prompt:

Quote:
β€œWhen the reasoning mind is forced to confront the impossible again and again, it has no choice but to adapt.”
― N.K. Jemisin, The Fifth Season
Author: N.K. Jemisin

Quote:
β€œSome humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation
Author:

Output:

Ted Chiang

Fine Tuning​

When using a custom model trained with a large number of examples, instructions become unnecessary as the model can learn the task from the provided training data. When the usecase becomes important enough, fine tuning may make sense.

You can fine tune a model to respond to emails in your tone of voice. You could also use a fine tuned model to answer questions in a specifc way, like the following prompt.

Example fine-tuned prompt (for a model that has been custom trained on similar prompt-completion pairs):

β€œSome humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation
###

Output:

Ted Chiang