BishopPhillips
BishopPhillips
BPC Home BPC AI Topic Home BPC RiskManager BPC SurveyManager BPC RiskWiki Learn HTML 5 and CSS Enquiry

LARGE LANGUAGE MODELS - Prompt Engineering

Basic Techniques.
AI Revolution

The art of prompting is essentially to “program” the LLM to produce an output using natural language as your programming language. The clearer you are with your directions the better, or at least the more focussed, will be the result. Treat the LLM like an intelligent expert on the topic at hand but one that needs direction in how you want the response delivered and be prepared to have a conversation with it to clarify and refine the answer.

At the start of a query, the AI knows nothing about what you want, what you know, how it should pitch the response, the level of detail required, etc. It is literally starting from zero. It comes to the table with a vast ability to find the required information quickly, but more like a super librarian than a close friend. It is important to keep that in mind when you approach it with your request or conversation in the form of a prompt. The prompt is literally that: a prompt to start a conversation. A prompt can have many sentences. The basic techniques for optimising the AI’s behaviour revolve around resolving these issues. Basic prompt design strategies for achieving successful responses from LLMs include:

Technique

Explanation

Example

  1. Define the Roles

Tell the LLM who it should be and who it should assume you are.

“Assume you are a university lecturer expert in biology and I am an intermediate student.  Explain ..”

“Adopt the role of…”

“Assume the role of Oscar Wilde and create a poem about… using his speech patterns.”

  1. Define the length

The length of the desired response goes a long way to influencing the level of detail to which the LLM goes.

“Write 1000 words on…”

“List 10 differences between…”

  1. Define the output format

Words like list, table, essay, screen-play, dialogue, conversation, poem, headings, etc.  Have meaning.  If you want a specific format and length of response say it.

“Write a 1000 word essay on …”

“List 10 examples of..”

“Put each example in a separate paragraph…”

  1. Focus the Response

A general request like “tell me about trees” could get you anything, some of which may be useful but probably not.

A human would generally come back with “what do you want to know about trees?” to focus the answer if the request was too broad, but an LLM will just try and satisfy the request.  Try and be specific about what you want.

“Explain the difference between plants that are trees versus other plants such as grasses and shrubs.”

  1. Tell the AI how to organise the response with multi-step prompts.

Instruct the LLM how and the order in which you want the response organised.  This helps build answers in a logical order and ensures coverage of the sub-topics you want addressed.

“First define trees, shrubs and grasses. Second highlight three differences between each. Third detail roles of each in colonising sand dunes.”

  1. Provide background

Backgrounding the AI can help it understand what you know or are assuming and how you want the response to respond to that data.

“Peter is a pirate with a lisp that changes his r's to w's and loves parrots, rum and his girl called Ruby. You are Peter. As Peter write me a sea shanty about these things.”

“LLMs are a significant development in AI.  Write me a 1000 word essay on recent developments in neural networks, mentioning LLMs but focussing on other areas of development.”

  1. Establish the Boundary

Where the topic is potentially large or has many subdivisions, consider defining the domain in which the AI should be focusing its response.  This can be literally by stating the context or field or by examples, etc.

"Discuss environmental management in the context of South American brines."

  1. Define the Emotion or Tone

Inspiring, technical, serious, sad, heartwarming, heart-wrenching, patriotic are examples of words that can be used to describe a story or text desired that set the tone of the work produced. By specifying the tone you colour the emotional slant as well as potentially the direction of a creative work in particular.

"Write a heart-wrenching 1000 word story about a bee called Belinda that has lost her way and cannot find her hive as the sun is setting. Conclude with a relevant inspiring message."

  1. Manage factuality

Where you are not seeking a creative (made up) answer you should be aware of the tendency for even a moderate temperature (see section on control codes) LLM to invent information where it does not know the answer.  You can minimise this in few shot learning by including prompt exemplars with unknown responses (see section on bias in Few-Shot Prompting), reducing the temperature (at the expense of readability) or by providing a direction about the expected handling uncertainty in a more general prompt. In the latter case you will need to "train" the model first.

"For all questions going forward in this session, respond "I don't know." if you cannot find any information about the question."

Then ask your questions:

"What is the meaning of dropletongug?"

  1. Optioning

Adding options to the prompt directs the LLM to work across a defined subdomain of the problem space. Providing options from which the LLM can choose focusses the response to the issues in which you are interested. The LLM will then compare and contrast the options rather than delivering a generalised, perhaps unfocussed discussion of the topic. Inclusion of options outside the normal, expected range along with some that are within the range of realistic or expected selections can also have the effect of introducing "out of the box" thinking to the response which might be desired where the LLM is being asked to propose ideas rather than analyse an existing thing.

"What is the better method of transport from [A] to [B], and explain why ? Car, bicycle, Train, Bus, or Dromedary "


...Advanced Techniques of Prompt Engineering....