Skip to content

DEFINE Prompt

Prompt Engineering - Asking for Definitions and Explanations

Section titled “Prompt Engineering - Asking for Definitions and Explanations”

A fundamental use of language models like ChatGPT is to obtain definitions or explanations of specific terms, concepts, or phenomena. This chapter focuses on how to effectively prompt an LLM to generate clear, concise, and accurate definitions, transforming it into a powerful knowledge resource.

Prompting for a definition is usually straightforward. You explicitly ask the model to define or explain something. There’s no special ‘directive’ syntax; it’s about clear, natural language.

Basic examples of prompts for definitions:

User: What is Artificial Intelligence?
User: Can you explain the concept of 'blockchain' in simple terms?
User: Define 'photosynthesis' for a 5th grader.

The LLM will then attempt to generate a relevant definition or explanation.

User: What is Artificial Intelligence?
ChatGPT: Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. The term may also be applied to any machine that exhibits traits associated with a human mind such as learning and problem-solving. Key subfields of AI include machine learning, natural language processing, computer vision, and robotics.

To get the best definitions from an LLM, consider these practices:

  • Be Specific: Clearly state the term or concept. ‘Define financial derivative’ is better than ‘Explain finance stuff.’
  • Specify Audience and Simplicity: If needed, ask for an explanation tailored to a specific audience (e.g., ‘Explain quantum computing to a high school student’ or ‘Define ‘API’ in layman’s terms’).
  • Request Conciseness or Detail: You can guide the length: ‘Provide a brief definition of CRISPR.’ or ‘Give a detailed explanation of the K-means clustering algorithm.’
  • Provide Context for Ambiguous Terms: Some terms have multiple meanings. If so, provide context: ‘What is a ‘transformer’ in the context of machine learning?’ vs. ‘What is an electrical ‘transformer’?’
  • Ask for Examples: ‘Define ‘onomatopoeia’ and give three examples.’
  • Iterate if Necessary: If the first definition isn’t clear or complete enough, ask follow-up questions or rephrase your prompt. ‘Can you elaborate on the ‘learning’ aspect of AI?‘

Example Application: Python Script for Getting Definitions

Section titled “Example Application: Python Script for Getting Definitions”

Here’s a Python script using the OpenAI API to fetch a definition. Remember to handle your API key securely.

import openai
import os
# Securely load your API key
# openai.api_key = os.getenv("OPENAI_API_KEY")
# For this example, replace 'YOUR_API_KEY_HERE' with your actual key:
openai.api_key = 'YOUR_API_KEY_HERE'
def get_definition(term, audience=None):
try:
prompt_content = f"What is the definition of '{term}'?"
if audience:
prompt_content += f" Explain it for a {audience}."
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # Or a newer model
messages=[
{"role": "system", "content": "You are a helpful assistant that provides clear definitions."},
{"role": "user", "content": prompt_content}
],
max_tokens=150, # Adjust as needed for definition length
temperature=0.3, # Lower for more factual, less creative definitions
n=1,
stop=None
)
return response.choices[0].message['content'].strip()
except Exception as e:
return f"An error occurred: {e}"
# Example usage:
term_to_define = "API (Application Programming Interface)"
audience_level = "non-technical person"
definition = get_definition(term_to_define, audience_level)
print(f"Definition of '{term_to_define}' for a {audience_level}:\n{definition}")
print("\n---\n")
term_to_define_simple = "osmosis"
definition_simple = get_definition(term_to_define_simple)
print(f"Definition of '{term_to_define_simple}':\n{definition_simple}")

Running the script might produce output like this:

Definition of 'API (Application Programming Interface)' for a non-technical person:
An API, or Application Programming Interface, is like a waiter in a restaurant. Imagine you're at a restaurant (that's an application or software). You don't go into the kitchen (the complex code) to tell the chef what you want. Instead, you tell the waiter (the API) your order, and the waiter communicates it to the kitchen. Then, the waiter brings your food (the data or functionality) back to you. So, an API allows different software programs to communicate and exchange information with each other without needing to know all the complicated details of how the other program works.
---
Definition of 'osmosis':
Osmosis is the movement of water molecules across a selectively permeable membrane from an area of higher water concentration to an area of lower water concentration. This process aims to equalize the concentration of solutes on both sides of the membrane. It is a passive process, meaning it does not require energy.

Prompting an LLM for definitions and explanations is a straightforward yet powerful application of prompt engineering. By using clear, specific language and optionally guiding the model on audience and depth, you can obtain valuable information quickly.

Remember to critically evaluate the definitions, especially for complex or nuanced topics, and cross-reference with authoritative sources if accuracy is paramount. Consider this a starting point for knowledge acquisition, not a definitive oracle. For further study, look into how LLMs handle factual recall and potential ‘hallucinations’.