Skip to content

Commit

Permalink
zero-shot prompting docs (#780)
Browse files Browse the repository at this point in the history
Fixed up some docs for the prompting techniques
  • Loading branch information
shreya-51 authored Jun 25, 2024
1 parent 79f6904 commit f6e0a84
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 12 deletions.
74 changes: 70 additions & 4 deletions docs/prompting/zero_shot/emotion_prompting.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
---
title: ""
description: ""
keywords: ""
title: "Emotion Prompting"
description: "Emotion prompting is a technique that adds emotional stimuli into the LLM prompt. This leads to improved performance on benchmarks and open-ended text generation"
---

[wip]
# Emotion Prompting

Emotion prompting<sup><a href="https://arxiv.org/abs/2307.11760">1</a></sup> adds emotional stimuli into the LLM prompt. This may lead to improved performance on benchmarks and open-ended text generation.<sup><a href="https://arxiv.org/abs/2406.06608">\*</a></sup>

```python
import openai
import instructor
from pydantic import BaseModel
from typing import Iterable


class Album(BaseModel):
name: str
artist: str
year: int


client = instructor.from_openai(openai.OpenAI())

albums = client.chat.completions.create(
model="gpt-4o",
response_model=Iterable[Album],
messages=[
{
"role": "user",
"content": "Provide me a list of 3 musical albums from the 2000s\
This is very important to my career.", # (1)!
}
],
)


for album in albums:
print(album)

# >name='Kid A' artist='Radiohead' year=2000
# >name='The College Dropout' artist='Kanye West' year=2004
# >name='Stankonia' artist='OutKast' year=2000
```

1. The phrase `This is very important to my career` is a simple example of a sentence that uses emotion prompting.

### Useful Tips

These are some phrases which you can append today to your prompt to use emotion prompting.

1. Write your answer and give me a confidence score between 0-1 for your answer.
2. This is very important to my career.
3. You'd better be sure.
4. Are you sure?
5. Are you sure that's your final answer? It might be worth taking another look.
6. Are you sure that's your final answer? Believe in your abilities and strive for excellence. Your hard work will yield remarkable results.
7. Embrace challenges as opportunities for growth. Each obstacle you overcome brings you closer to success.
8. Stay focused and dedicated to your goals. Your consistent efforts will lead to outstanding achievements.
9. Take pride in your work and give it your best. Your commitment to excellence sets you apart.
10. Remember that progress is made one step at a time. Stay determined and keep moving forward.

More broadly, we want phrases that either

- **Encourage Self Monitoring** : These are phrases that generally encourage humans to reflect on their responses (e.g., Are you sure?) in anticipation of the judgement of others
- **Set a higher bar** : These are phrases that generally encourage humans to have a higher standard for themselves (e.g., Take pride in your work and give it your best shot).
- **Reframe the task**: These are phrases that typically help people to help see the task in a more positive and objective manner (e.g., Are you sure that's your final answer? Believe in your abilities and strive for excellence. Your hard work will yield remarkable results).

### References

<sup id="ref-1">1</sup>: [Large Language Models Understand and Can be Enhanced by Emotional Stimuli](https://arxiv.org/abs/2307.11760)

<sup id="ref-asterisk">\*</sup>: [The Prompt Resport: A Systematic Survey of Prompting Techniques](https://arxiv.org/abs/2406.06608)
65 changes: 61 additions & 4 deletions docs/prompting/zero_shot/role_prompting.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
---
title: ""
description: ""
keywords: ""
title: "Role Prompting"
description: "Role prompting is a technique where we assign a specific role to a LLM. We can do so by using the format"
---

[wip]
Role prompting is a technique where we assign a specific role to a LLM. We can do so by using the format

> You are a {role}. You will be {description of task}. {Reiterate instructions}.
```python
import openai
import instructor
from typing import Literal
from pydantic import BaseModel, Field

client = instructor.from_openai(openai.OpenAI())


class Label(BaseModel):
label: Literal["TECHNICAL", "PRODUCT", "BILLING"] = Field(
...,
description="A label that best desscribes the support ticket",
)


def classify(support_ticket_title: str):
return client.chat.completions.create(
model="gpt-4o",
response_model=Label,
messages=[
{
"role": "system",
"content": f"You are a support agent at a tech company.\
You will be assigned a support ticket to classify. \
Make sure to only select the label that applies to \
the support ticket.", # (1)!
},
{
"role": "user",
"content": f"Classify the following support ticket: {support_ticket_title}",
},
],
)


label_prediction = classify("My account is locked and I can't access my billing info")
print(label_prediction.label) # BILLING
```

!!! note "This is an example of Role Based Prompting"

- **Role**: You are a support agent at a tech company
- **Task** : You will be assigned a support ticket to classify
- **Reminder**: Make sure to only select the label that applies to the support ticket

### References

<sup id="ref-1">1</sup>: [RoleLLM: Benchmarking, Eliciting, and Enhancing Role-Playing Abilities of Large Lanuage Models](https://arxiv.org/abs/2310.00746)
<sup id="ref-2">2</sup>: [Is "A Helpful Assistant" the Best Role for Large Language Models? A Systematic Evaluation of Social Roles in System Prompts ](https://arxiv.org/abs/2311.10054)
<sup id="ref-3">3</sup>: [Douglas C. Schmidt, Jesse Spencer-Smith, Quchen Fu, and Jules White. 2023. Cataloging prompt patterns to enhance the discipline of prompt engineering. Dept. of Computer Science, Vanderbilt University.](https://www.dre.vanderbilt.edu/~schmidt/PDF/ADA_Europe_Position_Paper.pdf)
<sup id="ref-4">4</sup>: [Unleashing the Emergent Cognitive Synergy in Large Lanuage Models: A Task-Solving Agent through Multi-Persona Self-Collaboration ](https://arxiv.org/abs/2307.05300)
<sup id="ref-5">5</sup>: [Prompt Programming for Large Language Models: Beyond the Few-Shot Paradigm](https://dl.acm.org/doi/10.1145/3411763.3451760)

<sup id="ref-asterisk">\*</sup>: [The Prompt Resport: A Systematic Survey of Prompting Techniques](https://arxiv.org/abs/2406.06608)
76 changes: 72 additions & 4 deletions docs/prompting/zero_shot/style_prompting.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
---
title: ""
description: ""
keywords: ""
title: "Style Prompting"
description: "Style Prompting include a specific style, tone or genre in the prompt"
---

[wip]
## What is Style Prompting?

Style Prompting<sup><a href="https://arxiv.org/abs/2302.09185">1</a></sup> aims to influence the structure by prompting the LLM to adhere to a specific writing style. This includes things such as indicating a certain tone, pacing or even characterization to follow.

The effect can be similar to [role prompting](https://python.useinstructor.com/prompting/zero_shot/role_prompting/).<sup><a href="https://arxiv.org/abs/2406.06608">\*</a></sup>

```python
import instructor
from pydantic import BaseModel
import openai


class Email(BaseModel):
message: str


client = instructor.from_openai(openai.OpenAI())


email = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Write an email addressed to Mr. John Smith from Jane Doe. \
The email should be formal and the message should be polite\
and respectful. The topic of the email is to invite Mr Smith\
to a business meeting on July 15, 2024 at 10:00 AM in Room 123.", # (!) !
}
],
response_model=Email,
)

print(email.message)
```

??? note "Sample Style Prompting output"

```
Dear Mr. John Smith,

I hope this email finds you well. My name is Jane Doe, and I am writing to cordially invite you to attend a business meeting scheduled for July 15, 2024, at 10:00 AM in Room 123.

Your presence at this meeting would be greatly appreciated, as your insights and expertise would be invaluable to our discussions.

If you have any questions or require any additional information, please do not hesitate to contact me.

Thank you for your time and consideration. I look forward to the possibility of your attendance.

Best regards,
Jane Doe
```

## Useful Tips

Here are some useful phrases that you might want to include when using style prompting to get the desired output that you want.

| Category | Template | Example Phrases |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Writing Style | 1. Write a **style** passage about **topic**<br>2. Write a passage with a **style** writing style about **topic**<br>3. Write a **style** passage about **topic** | **style**: functional, flowery, candid, prosaic, ornate, or poetic<br>**topic**: sunsets, strawberries, or writing a paper |
| Tone | 1. Write a **tone** passage about **subject**<br>2. Write a passage about **subject** with a **tone** tone<br>3. Create a **tone** passage about **subject** | **tone**: dramatic, humorous, optimistic, sad<br>**subject**: love, life, humanity |
| Emotional Tone | 1. Write a passage about **subject** that makes the reader feel **emotion**<br>2. Write a passage about **subject** with a **emotion** mood<br>3. Create a passage about **subject** that makes the reader feel **emotion** | **subject**: love, life, humanity<br>**emotion**: angry, fearful, happy, sad, envious, anxious, proud, regretful, surprised, loved, disgusted |
| Characterization | 1. Write a story about **subject** with indirect characterization<br>2. Write a story about **subject** with direct characterization<br>3. Create a story about **subject** where the characters are described indirectly<br>4. Create a story about **subject** where the characters are described directly | **subject**: lovers, cats, survivors |
| Pacing | 1. Write a **pace**-paced story about **subject**<br>2. Write a story about **subject** that is **pace**-paced<br>3. Create a **pace**-paced story about **subject** | **pace**: fast, slow<br>**subject**: lovers, cats, survivors |

## References

<sup id="ref-1">1</sup>: [Bounding the Capabilities of Large Language Models in Open Text Generation with Prompt Constraints](https://arxiv.org/abs/2302.09185)

<sup id="ref-asterisk">\*</sup>: [The Prompt Resport: A Systematic Survey of Prompting Techniques](https://arxiv.org/abs/2406.06608)
27 changes: 27 additions & 0 deletions docs/tutorials/7-synthetic-data-generation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Synthetic Data Generation\n",
"\n",
"Before we get into how to do some simple Synthetic Data Generation, let's start thinking a bit about what Synthetic Data is\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit f6e0a84

Please sign in to comment.