top of page

Prompt Engineering


Prompt Engineering

What is Prompt Engineering?

Prompt engineering is a process of creating a set of prompts, or questions, that are used to guide the user toward a desired outcome. It is an effective tool for designers to create user experiences that are easy to use and intuitive. This method is often used in interactive design and software development, as it allows users to easily understand how to interact with a system or product.


What is a Prompt ?

  • Prompts are short pieces of text that are used to provide context and guidance to machine learning models.

  • Prompts involve instructions and context passed to a language model to achieve a desired task

  • Prompt engineering is the practice of developing and optimizing prompts to efficiently use language models (LMs) for a variety of applications

  • Prompt engineering is a useful skill for AI engineers and researchers to improve and efficiently use language models



Why we need Prompt Engineering?

  • Important for research, discoveries, and advancement

  • Helps to test and evaluate the limitations of LLMs

  • Enables all kinds of innovative applications on top of LLMs

  • More specific formats of input as prompts help in better interpretability of the requirements for a task.

  • Specific prompts with a detailed explanation of the requirements mean output matches more with the desired one.

  • Better results for NLP tasks, through prompts also mean a better-trained model for future tasks.


What are the challenges of prompt engineering?

A major challenge turns out to be striking a perfect balance in the prompts. This means the prompt should be general enough not to produce irrelevant prompts and specific enough to solve the purpose.


First Basic Prompt


The sky is blue

Response:

The sky is a beautiful blue color during the day. The blue of the sky is created by the Earth’s atmosphere scattering the sun’s light. The blue is a result of the air molecules in the atmosphere reflecting the shorter wavelength of blue light back to our eyes.


Elements of a Prompt

  • A prompt is composed with the following components:

  • Instructions : Classify the text into neutral

  • Context : Gives Meaning

  • Input data : negative or positive Text: I think the food was okay.

  • Output indicator: Sentiment


Settings to keep in mind

When prompting a language model, you should keep in mind a few settings

• You can get very different results with prompts when using different settings

• One important setting is controlling how deterministic the model is when generating completion for prompts

• Temperature and top_p are two important parameters to keep in mind

• Generally, keep these low if you are looking for exact answers

• keep them high if you are looking for more diverse responses


Parameters in Prompt Engineering

Temperature:

Definition: In the context of prompt engineering, the "temperature" parameter is associated with controlling the randomness of the output generated by a language model.

Role in Prompt Engineering

  • High Temperature (e.g., 0.8-1.0):

    • Results in more diverse and creative responses.

    • Introduces randomness and exploration in the generated text.

  • Low Temperature (e.g., 0.2-0.5):

    • *Produces more focused and deterministic responses.

    • *Reduces randomness and increases adherence to training data patterns.

Max Tokens:

Definition: Limits the length of the generated output.

Role in Prompt Engineering: Controls the verbosity and length of responses.


Top-K (Top-K Sampling):

Definition: Samples from the top-K most likely next words.

Role in Prompt Engineering: Influences the diversity and relevance of generated responses.

Top-P (Nucleus Sampling):

Definition: Samples from the smallest set of words whose cumulative probability exceeds a predefined threshold P.

Role in Prompt Engineering: Balances between diversity and relevance, preventing overly rare or common words.

Frequency Penalties:

Definition: Penalizes frequently generated tokens to encourage diversity.

Role in Prompt Engineering: Mitigates issues like repetitive or overly common responses.



Designing Prompts for Different Tasks

  • Text Summarization

  • Question Answering

  • Text Classification

  • Role Playing

  • Code Generation

  • Reasoning

Text Summarization


Context: Antibiotics are a type of medication used to treat bacterial infections. bacteria or preventing them They work by either killing the from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes against viral infections, and using them administered intravenously. They are not effective inappropriately can lead to antibiotic resistance.


Instruction: Explain the above in one sentence

Answer: Antibiotics are medications used to treat bacterial infections by either killing the bacteria or stopping them from reproducing, but they are not effective against viruses and overuse can lead to antibiotic resistance.


Question Answering

Answer the question based on context below.

Keep the answer short and concise Respond "Unsure about answer if not short sure about the answer.


Context:

Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical.

There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was bind to the surface of T cells and limit their able to cell killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.


Question: What was OKT3 originally sourced from?

Answer: Mice.


Text Classification

Classify the text into neutral, negative or positive.

Text: I think the food was okay.

Sentiment: Neutral


Role Playing

The following assistant. The is a conversation assistant tone is technical with an AI research and scientific.

Human: Hello, who are you? AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of blackholes?

AI: Sure! Black holes are regions of spacetime where the gravitational force is so strong that nothing, not even light, can escape from it. They are created when a very massive star dies and its core collapses in on itself, forming a singularity of infinite density. The intense gravity of the singularity pulls in all the matter and radiation around it, creating the black hole.


Code Generation


“”” Table departments, columns = [DepartmentId, DepartmentName] Table students, columns = StudentName] [DepartmentId, StudentId, Create a MySQL query for all students in the Computer Science Department “””

Code:

SELECT StudentId, StudentName FROM students WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = 'Computer Science');


Reasoning

The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.

Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.

Odd numbers: 15, 5, 13, 7, 1

Sum: 41

41 is an odd number.


Techniques in Prompt Engineering

Basic Techniques

Role-playing: Tailor the model's responses by instructing it to embody a specific entity, such as a historian or a scientist. For instance, prompting, "As a nutritionist, evaluate the following diet plan," can yield responses grounded in nutritional science.


Iterative Refinement: Initiate with a broad prompt and progressively refine it based on the model's responses. This iterative process allows for the honing of prompts to achieve optimal results.

Feedback Loops: Utilize the model's outputs to inform and adjust subsequent prompts. This dynamic interaction ensures that the model's responses align more closely with user expectations over time.


Advanced Techniques

Zero-shot Prompting: Challenge the model with a task it hasn't encountered during training. This tests the model's ability to generalize and produce relevant outputs without relying on prior examples.


Few-shot Prompting/In-context Learning: Provide the model with a few examples (shots) to guide its response. By presenting context or previous instances, the model gains a better understanding and can generate desired outputs. For instance, show the model translated sentences before asking it to translate a new one.


Chain-of-Thought (CoT): Employ an advanced technique that guides the model through a series of reasoning steps. By breaking down complex tasks into intermediate chains of reasoning, the model achieves enhanced language understanding and more accurate outputs. This approach is akin to guiding someone step-by-step through a complex problem-solving process.



Why is Prompt Engineering Important to AI?


Task Customization:

Importance: Different users have specific tasks or goals when interacting with AI models.

Role of Prompt Engineering: Crafting tailored prompts allows users to customize the AI's behaviour, ensuring that it aligns with the specific requirements of the intended task.


Precision and Specificity:

Importance: Precision is vital in obtaining accurate and relevant outputs from language models.

Role of Prompt Engineering: Well-crafted prompts provide clear instructions, reducing ambiguity and guiding the model to generate more precise and contextually appropriate responses.


Domain Expertise:

Importance: Many tasks require domain-specific knowledge or language.

Role of Prompt Engineering: Prompt engineering enables users to inject domain-specific context, terminology, or roles, enhancing the model's understanding and performance in specialized fields.


Bias Mitigation:

Importance: AI models may inadvertently produce biased or undesired outputs.

Role of Prompt Engineering: By carefully constructing prompts, users can guide the model to produce fair and unbiased responses, helping to mitigate unintended biases.


Complex Task Resolution:

Importance: Complex tasks may require breaking them down into intermediate steps.

Role of Prompt Engineering: Advanced techniques like Chain-of-Thought (CoT) guide the model through a series of reasoning steps, enhancing its ability to handle complex tasks with improved language understanding.


The Future of Prompt Engineering

As we stand on the cusp of an AI-driven era, prompt engineering is poised to play a pivotal role in shaping the future of human-AI interactions. The field, though relatively nascent, holds immense promise and potential for growth.


Ongoing research and developments

The world of AI is dynamic, with research and innovations emerging at a rapid pace. In the context of prompt engineering:


Adaptive prompting:

Researchers are exploring ways for models to adaptively generate their own prompts based on the context, reducing the need for manual input.


Multimodal prompts:

With the rise of multimodal AI models that can process both text and images, the scope of prompt engineering is expanding to include visual cues.


Ethical prompting:

As AI ethics gains prominence, there's a focus on crafting prompts that ensure fairness, transparency, and bias mitigation.


Challenges and opportunities

Like any emerging field, prompt engineering comes with its set of challenges:


Complexity of models. As models grow in size and complexity, crafting effective prompts becomes more challenging.


Bias and fairness. Ensuring that prompts don't inadvertently introduce or amplify biases in model outputs.


Interdisciplinary collaboration. Prompt engineering sits at the intersection of linguistics, psychology, and computer science, necessitating collaboration across disciplines.

However, these challenges also present opportunities. They drive innovation, foster interdisciplinary collaboration, and pave the way for the next generation of AI tools and solutions.

Comments


bottom of page