202404051341 Prompt Engineering

Frameworks for constructing prompts

Most prompt engineering workshops or frameworks will build forth on the same elements

  • https://www.craftingaiprompts.org/
  • https://medium.com/@jelkhoury880/some-methodologies-in-prompt-engineering-fa1a0e1a9edb
  • APE: Automatic Prompt Engineer

Common elements in prompt templates

  • Define the actions to take or the task
  • Specify the role the chatbot should assume while answering
  • Context: provide relevant details of the situation
  • Discuss the purpose, intention, goal, objective.
  • Expectation: State the desired outcome, possibly via an example

Enhanced and automated prompting

  • Self-consistency to amplify response accuracy
  • Automatic instruction generation
  • Generated Knowledge Prompting
  • Metacognitive prompting

Prompting based on examples: zero-shot and few-shot

  • Zero-shot prompting without any examples
    • LLMs make this possible because they work well out of the box for a variety of tasks
  • Few-shot prompting with a few examples
    • You can see this as a mini learning session

Example of few-shot from MS Learn for using chat completions for sentiment analysis:

User: That was an awesome experience
Assistant: positive
User: I won't do that again
Assistant: negative
User: That was not worth my time
Assistant: negative
User: You can't miss this
Assistant:

Chain-of-thought (CoT) techniques

Humans (at least the ones that are good at problem solving) tend to break down complex tasks in smaller sub-problems.

You can entice the model to explain its (hopefully logical) reasoning steps, it's "chain of thought", using prompting.

You can do this in a zero-shot manner to simply ask the model to explain it's reasoning. There are some phrases that are known to work quite well.

Example: "Let's say you have bought 10 apples, gave 2 to your neighbor, bought 5 more, and ate 1. How many apples are left? Let's take a deep breath and work on this step by step."

Why does this work? An LLM is not inherently logical, but predicts the most likely next word. This prediction does not necessarily respect logical or mathematical rules. By stimulating "step by step" reasoning with prompting, you ensure that the model generates the context it needs to perform the next logical step.

Another advantage is that you can inspect where the model took a wrong turn. This gives you more insight on how to improve your prompt.

You can do a more "manual" or few-shot CoT prompt by including at least one example of a chain of thought (let's say a Q&A) before the query.

You can also automate this proces by retrieving and constructing a relevant Q&A example.

Advanced topics:

  • Graph of Thoughts (GoT)
  • LogiCoT, incorporating logic into CoT

Formatting prompts

Recency bias

Models tend to pay more attention to the most recent information, so often it's worthwhile to place the most important information at the end of the prompt (or repeat it at the end, if you started with it).

Primary, supporting, grounding content

Primary content: the subject of the query, e.g. a sentence to translate or something to summarize, with the main instructions what to do with it. Often included at the beginning or end (see recency bias).

Depending on the model, it works quite well to differentiate primary and supporting content, e.g. place it in fences. Example:

---
<insert full article here, as primary content>
---

Summarize this article and identify three takeaways in a bulleted list

Supporting content further qualifies the response. For example, you could add a supporting sentence to qualify the primary content from above: "Topics I'm very interested in: AI, webinar dates, submission deadlines".

Grounding content is content that contains information the model can draw on when answering your question. It's a source of information, and not the information being acted upon (which is the primary content). This becomes essential if you ask questions about content that is not generally available and thus not part of the model's training data.

RAG retrieval augmented generation is a way of adding grounding content using information retrieval.

Cues

LLMs work by predicting the next work, so simple cues are a good way to get desired results. For example, if you ask for a particular SQL query, you can ask the question "Write a join query to get (...)", but if you already know it's going to be a SELECT statement, end with the queue SELECT.

Output format

Specifying the desired output format has a large impact on the results. Examples from MS Learn:

Write a table in markdown with 6 animals in it, with their genus and species
Put two fictional characters into JSON of the following format

{
  firstNameFictional:
  jobFictional:
}

System prompt

If you can edit the system prompt, the best place to describe the role for answering is here, instead of the user query.

Tips for writing code

The newer GPT models are so good in writing code (in addition to natural language) that you don't necessarily need LLMs specialized in code anymore (e.g. Codex models).

  • Specify language
  • You can have an implementation in one language and ask GPT to convert it to another
  • Ask for help in understanding what a code snippet does
  • Complete partial code
  • Write unit tests
  • Add comments and docstrings to existing functions without documentation
  • Ask how to improve performance of a function
  • Refactor inefficient code

Example bug fixing from MS Learn:

Fix bugs in this function:

def calculate_average(numbers): total = 0 for i in range(len(numbers)): number = numbers[i] total += number average = total rerun averave

This is what I got back:

It looks like there are multiple issues in the given function. Here's the modified and fixed version of the function:

```python
def calculate_average(numbers):
    total = 0
    for number in numbers:  # Iterate directly over the numbers
        total += number
    average = total / len(numbers)  # Calculate the average by dividing the total by the number of elements
    return average  # Return the calculated average

I've made the following changes: 1. Changed the for loop to directly iterate over the elements of numbers. 2. Corrected the calculation of the average by dividing the total by the number of elements. 3. Returned the calculated average at the end of the function.

With these changes, the function should now correctly calculate the average of the given list of numbers.


Pretty good!


## Personas

A list of possible personas:

- the "mad hatter"
- the mock interviewer
- the Tech Support Bot
- the Sports Coach
- the Pirate Captain
-

## Examples of possible use cases

Ideas to work out:

- Suggest title for a paper
- Suggest a catchy headline for an article
- I'm working on project [ description here ]. Can you help me split this project up in smaller steps? For each step, explain why this step is important.
- I'm dealing with problem [ X ]. Can you help me brainstorm about possible solutions? Solutions should at least contain [Y and Z].
    * Or: assume a "crazy" persona for out of the box thinking.
- Ik heb een meeting met [groep personen] over onderwerp [onderwerp]. Help me om de belangrijkste gesprekspunten op een rijtje te zetten gesorteerd van belangrijk naar minst belangrijk.
- Plak een vacature met alle relevante informatie. Neem rol aan van interviewer met een bepaalde expertise, bijv. een HR-medewerker of een IT-specialist.
    * Voer je CV in en laat de interviewer kritische vragen stellen of je skills en ervaring in relatie tot de vacature om je voor te bereiden op lastige vragen.
- Samenvatten
- ELI5: Explain it like I'm 5
- Planning an event, breaking it down in sub tasks:
    * Select the event location, considering accessibility, facilities, supporting the desired activities
    * Plan the event timeline of the desired length (e.g. full day or evening) and make a schedule outlining session times, titles, breaks, including a mix of informational sessions, workshops, guest speakers, leisure activities.
    * Design the specific sessions
    * Compile a list of the necessary items and equipment needed for organizing the event in table format, indicating the required item, the required actions, and the stakeholders.
    * Craft an event invitation mail with a fixed format that you specify in the prompt.


### Prepare for an interview or meeting

Q: "Neem de rol aan van interviewer tijdens een sollicitatie en stel me 10 vragen die ik zou kunnen krijgen tijdens mijn sollicitatiegesprek voor de functie van treinmonteur."

A:

Natuurlijk, ik help je graag voorbereiden op je sollicitatiegesprek voor de functie van treinmonteur. Hier zijn 10 mogelijke vragen die je zou kunnen krijgen:

  1. Kun je ons wat vertellen over je ervaring in de technische sector en waarom je geïnteresseerd bent in een functie als treinmonteur?
  2. Wat weet je over het onderhoud van treinen en welke specifieke vaardigheden breng je mee die hierbij van pas zouden kunnen komen?
  3. Hoe ga je om met onverwachte technische problemen en wat is volgens jou de belangrijkste eigenschap van een goede treinmonteur?
  4. Kun je een voorbeeld geven van een uitdagend project waarbij je betrokken was en hoe je hebt bijgedragen aan het succes ervan?
  5. Hoe belangrijk vind je veiligheidsvoorschriften en -procedures bij het uitvoeren van onderhoudswerkzaamheden aan treinen?
  6. Wat zijn volgens jou de belangrijkste verschillen tussen het onderhoud van verschillende soorten treinen (bijvoorbeeld intercitytreinen, sprinters, hogesnelheidstreinen, enz.)?
  7. Hoe blijf je op de hoogte van de laatste ontwikkelingen in treintechnologie en hoe pas je deze kennis toe in je werk?
  8. Kun je een situatie beschrijven waarin je effectief hebt samengewerkt met collega's om een complex technisch probleem op te lossen?
  9. Wat motiveert jou om in de spoorwegsector te werken en wat zijn volgens jou de grootste uitdagingen waar treinmonteurs mee te maken hebben?
  10. Stel dat je een conflict hebt met een collega over de beste aanpak voor het oplossen van een technisch probleem. Hoe zou je hiermee omgaan?

Ik hoop dat deze vragen je helpen om je voor te bereiden op je sollicitatiegesprek. Veel succes!"


Q: Vervolgvraag: "Kun je vraag 7 toespitsen op het repareren van NS treinen, bijvoorbeeld de FLIRT?"

A:

Zeker! Hier is een aangepaste versie van vraag 7 die specifiek gericht is op het repareren van NS treinen, zoals de FLIRT:

  1. Hoe blijf je op de hoogte van de laatste ontwikkelingen in treintechnologie, met name met betrekking tot het onderhoud en de reparatie van NS treinen zoals de FLIRT, en hoe pas je deze kennis toe in je werk als treinmonteur?

Deze vraag is gericht op je vermogen om op de hoogte te blijven van de specifieke technische aspecten van de FLIRT-treinen die in dienst zijn bij NS, en hoe je deze kennis effectief kunt gebruiken bij reparaties en onderhoudswerkzaamheden.


### Self-development: Help with developing certain behaviors

Q: "Ik vind het lastig om me te concentreren op kantoor, vooral als ik veel berichtjes en emails ontvang. Op welke manier kan ik mijn concentratie verbeteren? Welke technieken kan ik inzetten?"

A: Het is begrijpelijk dat het ontvangen van veel berichten en e-mails een uitdaging kan zijn als het gaat om concentratie op kantoor. Hier zijn enkele technieken die je kunt gebruiken om je concentratie te verbeteren:

  1. Time blocking: Plan specifieke tijdvakken in je dag in voor taken die ononderbroken concentratie vereisen. Stel bijvoorbeeld in de ochtend of aan het einde van de dag tijd apart om e-mails te beantwoorden.
  2. Pomodoro-techniek: Werk in blokken van bijvoorbeeld 25 minuten gevolgd door een korte pauze. Dit kan je helpen om gefocust te blijven en productief te zijn.
  3. Gebruik van notificaties: Schakel meldingen van e-mails en berichten uit tijdens de periodes waarin je je wilt concentreren.
  4. E-mailbeheer: Maak gebruik van mapjes en labels om je inbox georganiseerd te houden. Plan vaste momenten in om je e-mails te verwerken en beantwoorden.
  5. Creëer een opgeruimde omgeving: Een opgeruimde en georganiseerde werkplek kan helpen om afleiding te minimaliseren en focus te bevorderen.

Door deze technieken toe te passen, kun je je concentratie verbeteren en effectiever omgaan met de stroom van berichten en e-mails op kantoor.



Q: "Ik vind het lastig mij te concentreren in kantoortuinen. Op welke manier kan ik mijn concentratie verbeteren? Welke tips heb jij voor me?"

A: "Het is begrijpelijk dat kantoortuinen afleidend kunnen zijn. Hier zijn een paar tips om je concentratie te verbeteren:

  1. Gebruik geluidsonderdrukkende koptelefoons of oordopjes om storende geluiden te verminderen.
  2. Maak gebruik van planten of scheidingswanden om je werkplek visueel af te bakenen en afleiding te verminderen.
  3. Werk in blokken met geconcentreerde tijd samen met kleine pauzes, zoals de "Pomodoro-techniek" (25 minuten gefocust werken, dan 5 minuten pauze).
  4. Communiceer duidelijk met je collega's over de behoefte aan ongestoorde werktijd.
  5. Creëer een comfortabele en ergonomische werkplek om fysieke afleiding te minimaliseren.

Probeer deze tips uit en kijk wat voor jou het beste werkt!"


### Learning a language

Q: "Neem de rol aan van leraar Duits. Stel me telkens een vraag in het Duits en wacht tot ik antwoord. Vraag telkens door op mijn antwoorden. Als ik een fout maak, geef me dan feedback en vertel me waarom mijn antwoord onjuist was."

A: Natürlich, lassen Sie uns beginnen! Wie heißt du?

Q: Ich heisse Edwin

A: Sehr gut, Edwin! Wie alt bist du?

Q: Ich bin 30 Jahre ald

A: Fast richtig, Edwin! Das Wort "alt" sollte ohne "d" geschrieben werden, also "Ich bin 30 Jahre alt". Können Sie mir sagen, woher Sie kommen?

Q: Ich kom aus Nimwegen

A: Fast richtig! Es sollte "Ich komme aus Nimwegen" heißen. Welche Sprachen sprichst du außer Deutsch?


### Polishing your CV

Q: Construct a resume based on the following narrative:


Jacques Derrida (/ˈdɛrɪdə/; French: [ʒak dɛʁida]; born Jackie Élie Derrida;[6] 15 July 1930 – 9 October 2004) was an Algerian-born French philosopher. He developed the philosophy of deconstruction, which he utilized in a number of his texts, and which was developed through close readings of the linguistics of Ferdinand de Saussure and Husserlian and Heideggerian phenomenology.[7][8][9] He is one of the major figures associated with post-structuralism and postmodern philosophy[10][11][12] although he distanced himself from post-structuralism and disowned the word "postmodernity".[13]

During his career, Derrida published over 40 books, together with hundreds of essays and public presentations. He had a significant influence on the humanities and social sciences, including philosophy, literature, law,[14][15][16] anthropology,[17] historiography,[18] applied linguistics,[19] sociolinguistics,[20] psychoanalysis,[21] music, architecture, and political theory.

Into the 2000s, his work retained major academic influence throughout the United States,[22] continental Europe, South America and all other countries where continental philosophy has been predominant, particularly in debates around ontology, epistemology (especially concerning social sciences), ethics, aesthetics, hermeneutics, and the philosophy of language. In most of the Anglosphere, where analytic philosophy is dominant, Derrida's influence is most presently felt in literary studies due to his longstanding interest in language and his association with prominent literary critics from his time at Yale. He also influenced architecture (in the form of deconstructivism), music[23] (especially in the musical atmosphere of hauntology), art,[24] and art criticism.[25]

Particularly in his later writings, Derrida addressed ethical and political themes in his work. Some critics consider Speech and Phenomena (1967) to be his most important work. Others cite: Of Grammatology (1967) Writing and Difference (1967), and Margins of Philosophy (1972). These writings influenced various activists and political movements.[26] He became a well-known and influential public figure, while his approach to philosophy and the notorious abstruseness of his work made him controversial.[26][27]

A: Jacques Derrida

Personal Information - Name: Jacques Derrida - Birthdate: July 15, 1930 - Birthplace: El Biar, French Algeria - Death Date: October 9, 2004 - Nationality: French

Summary Jacques Derrida was an Algerian-born French philosopher renowned for his groundbreaking contributions to post-structuralism and postmodern philosophy. He developed the philosophy of deconstruction, employing it extensively in his numerous publications. Derrida's work, heavily influenced by the linguistics of Ferdinand de Saussure and phenomenology of Husserl and Heidegger, left an indelible mark on diverse fields including philosophy, literature, law, anthropology, and more. Despite controversies surrounding the complexity of his ideas, Derrida emerged as a highly influential public figure and intellectual powerhouse.

Education - Doctorate in Philosophy, École Normale Supérieure, Paris, France (1956) - Aggregation in Philosophy (Highest Teaching Credential), University of Paris (1952) - Bachelor's Degree in Philosophy, University of Paris (1950)

Career Highlights - Authored over 40 books, along with hundreds of essays and public presentations. - Pioneered the philosophy of deconstruction, reshaping discourse in fields ranging from literature to law. - Influenced diverse disciplines including philosophy, literature, law, anthropology, historiography, linguistics, psychoanalysis, music, architecture, and political theory. - Addressed ethical and political themes in later works, influencing various activists and political movements. - Notable Works: "Speech and Phenomena" (1967), "Of Grammatology" (1967), "Writing and Difference" (1967), "Margins of Philosophy" (1972).

Professional Experience - Professor of Philosophy, École Normale Supérieure, Paris, France (1960-1984) - Visiting Professor, University of California, Irvine, USA (1986-1987) - Visiting Professor, Yale University, USA (1975-1986) - Founding Director, International College of Philosophy, Paris, France (1983)

Influence - Retained significant academic influence across continents, notably in the United States, continental Europe, and South America. - Major contributions to debates in ontology, epistemology, ethics, aesthetics, hermeneutics, and the philosophy of language. - Influential in literary studies due to his emphasis on language and association with prominent literary critics. - Extended influence into architecture (deconstructivism), music (hauntology), art, and art criticism.

Publications - "Speech and Phenomena" (1967) - "Of Grammatology" (1967) - "Writing and Difference" (1967) - "Margins of Philosophy" (1972) - Numerous other books, essays, and public presentations.

Jacques Derrida's multidisciplinary contributions continue to shape intellectual discourse and inspire critical inquiry across the globe.


Source of the input writing is the English Wikipedia entry on Jacques Derrida.

We can also do the reverse, take a CV (this CV is AI generated with the above technique) and construct a biography:


Q: KATE BUSH 123 Main Street, London, UK | 555-555-5555 | katebush@email.com

PROFESSIONAL SUMMARY English singer, songwriter, record producer, and dancer with over 40 years of experience in the music industry. Known for her unique voice and self-written songs, Kate Bush has achieved numerous UK Top 40 singles and albums, including three number one albums.

WORK EXPERIENCE Musician | 1978 - Present - Released 10 studio albums, all of which reached the UK Top 10, with three reaching number one - Produced and wrote all of her own music, including hit singles "Wuthering Heights", "Babooshka", and "Running Up That Hill" - Collaborated with other artists, including Peter Gabriel on the duet "Don't Give Up" - Toured extensively throughout the UK and internationally, including a residency at the Hammersmith Apollo in 2014

EDUCATION None listed

SKILLS - Songwriting and music production - Live performance and stage presence - Collaborating with other artists - Strong vocal ability and range - Creative and innovative approach to music making


Given the above resume, construct a short biography

A:

Kate Bush, the iconic English singer, songwriter, and record producer, has left an indelible mark on the music industry with her extraordinary talent and innovative approach to music-making. Born on July 30, 1958, in Bexleyheath, Kent, Kate embarked on her musical journey at a young age, displaying an innate gift for both singing and songwriting.

Since bursting onto the scene in 1978, Kate has captivated audiences worldwide with her unique voice, mesmerizing stage presence, and thought-provoking lyrics. Over the span of four decades, she has released 10 studio albums, each showcasing her boundless creativity and musical prowess. Notably, all her albums have soared into the UK Top 10, with three claiming the coveted number one spot.

Kate's discography is adorned with timeless classics, including the haunting "Wuthering Heights," the enigmatic "Babooshka," and the anthemic "Running Up That Hill." Her ability to weave intricate narratives into her music, coupled with her ethereal vocals, has earned her a dedicated fanbase and critical acclaim.

Beyond her solo endeavors, Kate has also collaborated with esteemed artists, such as Peter Gabriel, delivering unforgettable performances like their duet "Don't Give Up." Her willingness to explore diverse musical avenues and embrace experimentation has solidified her status as a true trailblazer in the industry.

In addition to her studio work, Kate is renowned for her captivating live performances. Throughout her career, she has embarked on numerous tours, enchanting audiences with her theatrical flair and magnetic stage presence. One of her most memorable moments includes a celebrated residency at the Hammersmith Apollo in 2014, where fans flocked to witness her unparalleled artistry firsthand.

Kate Bush's contributions to music extend far beyond her chart-topping hits and accolades. She is revered for her fearless creativity, unwavering dedication to her craft, and ability to push the boundaries of conventional music. As a visionary artist, Kate continues to inspire generations of musicians and fans alike, leaving an indelible legacy that will echo through the annals of music history.


### Write an essay

Without prompt engineering:

Q: Schrijf een essay van 100 woorden over de geschiedenis van NS.

A: De Nederlandse Spoorwegen (NS) hebben een rijke geschiedenis die teruggaat tot de 19e eeuw. De eerste trein in Nederland reed in 1839 tussen Amsterdam en Haarlem, waarmee de basis werd gelegd voor het latere NS-netwerk. Gedurende de jaren heeft NS belangrijke ontwikkelingen doorgemaakt, zoals de elektrificatie van het spoorwegnet en de introductie van hogesnelheidstreinen. Tijdens de Tweede Wereldoorlog speelde NS een complexe rol, waarbij de organisatie onder dwang van de Duitse bezetters moest opereren. Tegenwoordig staat NS bekend om zijn inzet voor duurzame mobiliteit en het bieden van innovatieve diensten aan reizigers.


With role and tone:
TODO gaat niet goed met ChatNS, wel met ChatGPT.

Q: Schrijf een opstel van 100 woorden over de geschiedenis van NS als scholier met B1 Nederlands taalniveau. Gebruik geen moeilijke woorden.

A: De Nederlandse Spoorwegen (NS) zijn begonnen in de 19e eeuw. Mensen wilden makkelijker reizen en goederen vervoeren. In 1839 reed de eerste trein tussen Amsterdam en Haarlem. Later breidde het spoorwegnet uit naar andere steden. Tijdens de Tweede Wereldoorlog heeft NS moeilijke keuzes gemaakt. Na de oorlog begon de wederopbouw en modernisering van de spoorwegen. Tegenwoordig is NS de belangrijkste treinmaatschappij in Nederland. Ze werken aan duurzame en moderne treinen. Ook denken ze aan de veiligheid en comfort van de reizigers. Zo blijft NS een belangrijk deel van het Nederlandse leven. ```