---
description: Some interesting properties and suggestions in prompts
---

# Prompts for LLM

{% hint style="warning" %}
It is likely that any of the examples can produce different results in a particular moment, due to LLM evolution. However the main concepts will remain valid in other examples.
{% endhint %}

## Elements of a prompt

Generally speaking, and at a high level, a prompt can have any of the following:

1. Instructions
2. Question
3. Input data
4. Examples

In order to obtain a result, either 1 or 2 must be present. Everything else is optional.

## Prompt engineering?

Prompt engineering is a very recent but rapidly growing discipline that has the goal of designing the optimal prompt given a generative model and a goal. Prompt engineering is growing so quickly that many believe that it will replace other aspects of machine learning such as feature engineering or architecture engineering for large neural networks.

Prompt engineering requires some domain understanding to incorporate the goal into the prompt (e.g. by determining what good and bad outcomes should look like). It also requires understanding of the model. Different models will respond differently to the same kind of prompting.

Generating prompts at some scale requires a programmatic approach. At the most basic level you want to generate prompt templates that can be programmatically modified according to some dataset or context.

Finally, prompt engineering, as any engineering discipline, is iterative and requires some exploration in order to find the right solution. While this is not something that I have heard of, prompt engineering will require many of the same engineering processes as software engineering (e.g. version control, and regression testing).

## Instructions + Question

Beyond asking a simple question, possibly the next level of sophistication in a prompt is to include some instructions on how the model should answer the question.

Here I ask for advice on how to write a university essay, but also include instructions on the different aspects we are interested to hear about in the answer.

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FCiOi2is4QN3P8fZkpL2s%2FCleanShot%202023-01-17%20at%2020.03.40%402x.png?alt=media&#x26;token=bd34b28b-e589-4719-988c-4ab5cdda518a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FyRC2PRTVQ4Y6gTC7tM3f%2FCleanShot%202023-01-17%20at%2020.05.59%402x.png?alt=media&#x26;token=58e7808e-5ce8-4163-a82c-15b6ec386529" alt=""><figcaption></figcaption></figure>

## Instructions + Input data

Back to the example, let’s see what happens when we input some data about someone and give some instructions:

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2Fl9I9mq4zP9KFDKdEk2Z3%2FCleanShot%202023-01-17%20at%2020.11.32%402x.png?alt=media&#x26;token=73a75129-790a-4796-a192-38f77c203cf3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FiAdV3VS1UWzvmFRLQitO%2FCleanShot%202023-01-17%20at%2020.14.00%402x.png?alt=media&#x26;token=b408cff0-8d3a-47c5-ba8b-9b0d0ccd068a" alt=""><figcaption></figcaption></figure>

## Errors and different results

We must not forget we are working with a Language Model, so predicting the next word is what it really does, and some possibilities they manage to solve are considered emergence abilities.

{% hint style="danger" %}
Any of these errors can be solved at any time, and new errors can arise.
{% endhint %}

Let's see an example:

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FRCPQj1vNiqlzZrBUrxGV%2FCleanShot%202023-01-18%20at%2005.24.52%402x.png?alt=media&#x26;token=3d430397-b863-4c71-858b-5cefc8b9e4a4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FkIgqeshSBCsmRvs7S1Pr%2FCleanShot%202023-01-18%20at%2005.26.47%402x.png?alt=media&#x26;token=92a44520-2ad3-4f9f-99cd-a3dbdf28b971" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FvgriOih0LDUjgLjUfHHk%2FCleanShot%202023-01-18%20at%2005.29.55%402x.png?alt=media&#x26;token=61b4320c-ab39-4c18-9372-6e0fb73cf84f" alt=""><figcaption></figcaption></figure>

## Role prompting

Very interesting to adapt the answer to specific areas, jargons, roles, etc. and, sometimes, it helps also to generate more accurate results.

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FFcImKftsVGee8h9Wm8n1%2FCleanShot%202023-01-18%20at%2005.41.18%402x.png?alt=media&#x26;token=57104334-8454-421f-906c-85ad6646e977" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FpVGjqKl2wCUVVb4lgvsC%2FCleanShot%202023-01-18%20at%2005.43.32%402x.png?alt=media&#x26;token=6a29e600-819a-42fa-85a6-696438be4f02" alt=""><figcaption></figcaption></figure>

## Few shot learning

Language models are pre-trained in a unsupervised way, but they allowed subsequent processes called 'fine-tuning', which generally means the use of a collection of examples used in a supervised training.

But, we can improve and get much more accurate results in our tasks using few shot learning, i.e., by providing examples before the question or task to solve:

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FeKrLvYZBQRL5OobsFJw8%2FCleanShot%202023-01-18%20at%2005.48.50%402x.png?alt=media&#x26;token=3764c61c-0776-48cc-b445-ee33189eadb2" alt=""><figcaption></figcaption></figure>

## Chain of thought prompting

In chain of thought prompting, we explicitly encourage the model to be factual/correct by forcing it to follow a series of steps in its “reasoning”.

Example:

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FMmKANJK0F91AnammXUyi%2FCleanShot%202023-01-18%20at%2005.53.05%402x.png?alt=media&#x26;token=6a436125-5376-46d0-ae14-503395a6d351" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FnlSqnlohR9eeigzkFl08%2FCleanShot%202023-01-18%20at%2005.53.35%402x.png?alt=media&#x26;token=91d9d6a1-6155-4e8a-aeaa-c2813b918f66" alt=""><figcaption></figcaption></figure>

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2FHPLhybLDbm3zlUDKnpTN%2FCleanShot%202023-01-18%20at%2005.54.31%402x.png?alt=media&#x26;token=37a1720e-8445-43f8-a76e-04c3ee56ae1b" alt=""><figcaption></figcaption></figure>

## Help the system

Use interaction to force the LLM to acquire reasoning skills in finding the answer:

<figure><img src="https://611771019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKbwWlyksi3uskbTdLFc1%2Fuploads%2F05XiIk5HW74JRfqBskjc%2FCleanShot%202023-01-19%20at%2007.45.44%402x.png?alt=media&#x26;token=4e30af9f-bf49-4fd8-8b3b-8c2ec9b1d13d" alt=""><figcaption></figcaption></figure>

References: [https://learnprompting.org/](https://learnprompting.org/)
