diff --git a/README.md b/README.md index 18821b4..4724798 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Motivated by the high interest in developing with LLMs, we have created this new 🌐 [Prompt Engineering Guide (Web Version)](https://www.promptingguide.ai/) +📺 [YouTube Mini Lectures on Prompting Engineering](https://www.youtube.com/playlist?list=PLGSHbNsNO4Vha1jB0wMtuYYEVO4laSo0m) + We've partnered with Maven to deliver the following live cohort-based courses on prompt engineering: - [LLMs for Everyone ](https://maven.com/dair-ai/llms-for-everyone) (Beginner) - learn about the latest prompt engineering techniques and how to effectively apply them to real-world use cases. @@ -23,12 +25,14 @@ Happy Prompting! - 👩‍🎓 We crossed 3 million learners in January 2024! - 🎉 We have launched a new web version of the guide [here](https://www.promptingguide.ai/) - 🔥 We reached #1 on Hacker News on 21 Feb 2023 -- 🎉 The Prompt Engineering Lecture went live [here](https://youtu.be/dOxUroR57xs) +- 🎉 The First Prompt Engineering Lecture went live [here](https://youtu.be/dOxUroR57xs) [Join our Discord](https://discord.com/invite/SKgkVT8BGJ) [Follow us on Twitter](https://twitter.com/dair_ai) +[Subscribe to our YouTube](https://www.youtube.com/channel/UCyna_OxOWL7IEuOwb7WhmxQ) + [Subscribe to our Newsletter](https://nlpnews.substack.com/) --- diff --git a/ar-pages/about.ar.mdx b/ar-pages/about.ar.mdx new file mode 100644 index 0000000..f601c16 --- /dev/null +++ b/ar-pages/about.ar.mdx @@ -0,0 +1,11 @@ +# About + +The Prompt Engineering Guide is a project by [DAIR.AI](https://github.com/dair-ai). It aims to educate researchers and practitioners about prompt engineering. + +DAIR.AI aims to democratize AI research, education, and technologies. Our mission is to enable the next-generation of AI innovators and creators. + +We welcome contributions from the community. Lookout for the Edit buttons. + +License information [here](https://github.com/dair-ai/Prompt-Engineering-Guide#license). + +We borrow inspirations from many open resources like [OpenAI CookBook](https://github.com/openai/openai-cookbook), [Pretrain, Prompt, Predict](http://pretrain.nlpedia.ai/), [Learn Prompting](https://learnprompting.org/), and many others. \ No newline at end of file diff --git a/ar-pages/applications.ar.mdx b/ar-pages/applications.ar.mdx new file mode 100644 index 0000000..6ba5d5e --- /dev/null +++ b/ar-pages/applications.ar.mdx @@ -0,0 +1,10 @@ +# LLM Applications + +import { Callout } from 'nextra-theme-docs' +import {Cards, Card} from 'nextra-theme-docs' +import {FilesIcon} from 'components/icons' +import ContentFileNames from 'components/ContentFileNames' + +In this section, we will cover advanced and interesting ways we can use prompt engineering to perform useful and more advanced tasks with large language models (LLMs). + + \ No newline at end of file diff --git a/ar-pages/applications/_meta.ar.json b/ar-pages/applications/_meta.ar.json new file mode 100644 index 0000000..3a47c68 --- /dev/null +++ b/ar-pages/applications/_meta.ar.json @@ -0,0 +1,9 @@ +{ + "function_calling": "استدعاء الدوال", + "generating": "توليد البيانات", + "synthetic_rag": "توليد مجموعة بيانات لـ RAG", + "generating_textbooks": "معالجة تنوع مجموعات البيانات المولدة", + "coding": "توليد الأكواد", + "workplace_casestudy": "دراسة حالة: تصنيف الوظائف للخريجين الجدد", + "pf": "أمر على صيغة دالّة برمجية" +} diff --git a/ar-pages/applications/coding.ar.mdx b/ar-pages/applications/coding.ar.mdx new file mode 100644 index 0000000..563ba6a --- /dev/null +++ b/ar-pages/applications/coding.ar.mdx @@ -0,0 +1,196 @@ +# Generating Code + +import { Callout, FileTree } from 'nextra-theme-docs' +import {Screenshot} from 'components/screenshot' +import CODE1 from '../../img/code-generation/chat-mode.png' + + + This section is under development. + + +LLMs like ChatGPT are very effective at code generation. In this section, we will cover many examples of how to use ChatGPT for code generation. + +The OpenAI's Playground (Chat Mode) and the `gpt-3.5-turbo` model are used for all examples below. + +As with all chat models from OpenAI, you can use a `System Message` to define the behavior and format of the responses. We will use the following System Message for the prompt examples: + +``` +You are a helpful code assistant that can teach a junior developer how to code. Your language of choice is Python. Don't explain the code, just generate the code block itself. +``` + +## Basic Example + +The `User Message` will then be the prompt itself with the instruction of the specific code you want the model to generate. Below is a snapshot of the first basic prompt for code generation. Note that the final code was generated by the `Assistant`. + + + +Here is the prompt if you want to try it yourself: + +``` +Write code that asks the user for their name and say "Hello" +``` + +## Turn Comments Into Code + +You can also use the code generation capabilities of these LLMs to generate code from comments alone. Let's look at another example that passes the instructions as a comment block: + +*Prompt:* +``` +""" +1. Create a list of movies +2. Create a list of ratings for these movies +3. Combine them to make a json object of 10 movies with their ratings. +""" +``` + +*Output:* +```python +movies = ["The Shawshank Redemption", "The Godfather", "The Dark Knight", "Schindler's List", "Pulp Fiction", "The Lord of the Rings: The Return of the King", "Forrest Gump", "Star Wars: Episode V - The Empire Strikes Back", "Inception", "The Silence of the Lambs"] + +ratings = [9.3, 9.2, 9.0, 8.9, 8.9, 8.9, 8.8, 8.7, 8.7, 8.6] + +movie_ratings = {} + +for i in range(len(movies)): + movie_ratings[movies[i]] = ratings[i] + +json_object = json.dumps(movie_ratings, indent=4) + +print(json_object) +``` + +The generated code looks like working code. However, the output doesn't contain an important `import` statement, i.e., `import json`. While these models generate working code, you must pay close attention to small details like this and always make sure to test your code. + +## Complete Functions or Next Line + +These LLMs have also been incorporated into tools like GitHub Copilot which makes them useful for developers. One useful feature is the ability of the model to complete functions. + +*Prompt:* +```python +# function to multiply two numbers and add 75 to it + +def multiply( +``` + +*Output:* +```python +a, b): + result = a * b + result += 75 + return result +``` + +## MySQL Query Generation + +Besides the basic code generation example above, you can use the model to generate useful code that could be used in other aspects of programming like creating and testing MySQL queries. + +Let's say you have a dataset with some information which you can include as part of the prompt and then instruct it to generate a specific query. For example: + +``` +""" +Table departments, columns = [DepartmentId, DepartmentName] +Table students, columns = [DepartmentId, StudentId, StudentName] +Create a MySQL query for all students in the Computer Science department +""" +``` + +*Output:* +```mysql +SELECT students.StudentId, students.StudentName +FROM students +INNER JOIN departments +ON students.DepartmentId = departments.DepartmentId +WHERE departments.DepartmentName = 'Computer Science'; +``` + +The model generates a query! However, in this example we made up the database so we don't have a database to test the generated query. If you are testing this example, it could be useful to have this database created. Fortunately, you can use ChatGPT to generate this for you as well. One approach is using a modified version of the prompt above with slightly different instructions to generate a database schema: + +```mysql +Table departments, columns = [DepartmentId, DepartmentName] +Table students, columns = [DepartmentId, StudentId, StudentName] +Create a valid database schema with the above tables and columns +``` + +The model generated the following schema: + +```mysql +CREATE TABLE departments ( + DepartmentId INT PRIMARY KEY, + DepartmentName VARCHAR(50) +); + +CREATE TABLE students ( + DepartmentId INT, + StudentId INT PRIMARY KEY, + StudentName VARCHAR(50), + FOREIGN KEY (DepartmentId) REFERENCES departments(DepartmentId) +); +``` + +You can create a temporary database using something like [sqliteonline.com](https://sqliteonline.com/). + +You will also need dummy data to test if the original generated query was valid. Let's use ChatGPT for this too! The prompt could look something like the following: + +```mysql +CREATE TABLE departments ( + DepartmentId INT PRIMARY KEY, + DepartmentName VARCHAR(50) +); + +CREATE TABLE students ( + DepartmentId INT, + StudentId INT PRIMARY KEY, + StudentName VARCHAR(50), + FOREIGN KEY (DepartmentId) REFERENCES departments(DepartmentId) +); + +Given the database schema above, generate valid insert statements include 4 rows for each table. +``` + +The output with the insert statements: + +```mysql +INSERT INTO departments (DepartmentId, DepartmentName) +VALUES (1, 'Computer Science'), (2, 'Mathematics'), (3, 'Physics'), (4, 'Biology'); + +INSERT INTO students (DepartmentId, StudentId, StudentName) +VALUES (1, 101, 'John Doe'), (1, 102, 'Jane Doe'), (2, 201, 'Alice Smith'), (2, 202, 'Bob Johnson'); +``` + +Now that you have the database and the dummy data, you can test the original query. Based on the dummy data, the result should be two rows with `Jane Doe` and `John Doe`. + +## Explain Code +If you are learning to program in a certain language, it might be useful to prompt the model to explain certain bits of code. Let's reuse the query generated above and ask the model to explain it. + +If you are using the same System Message from before, be careful of how you are instructing the model. For example, if we use the following example, the model will complain that it is a code assistant in Python but it still provides an explanation. Sometimes the model refuses to generate what you are instructing because it's designed to follow the System Message. + +*Prompt:* + +```mysql +SELECT students.StudentId, students.StudentName +FROM students +INNER JOIN departments +ON students.DepartmentId = departments.DepartmentId +WHERE departments.DepartmentName = 'Computer Science'; + +Explain the above SQL statement. +``` + +*Output:* + +``` +Sorry, as a code assistant in Python, I cannot generate SQL code. However, I can explain the purpose of the SQL statement provided. + +This SQL statement selects the `StudentId` and `StudentName` columns from the `students` table, where the `DepartmentName` column in the `departments` table is equal to 'Computer Science'. To achieve this, the statement performs an inner join on the `DepartmentId` column between the `students` and `departments` tables. + +In simpler terms, it is selecting the names and IDs of students who are enrolled in the Computer Science department. +``` + +## Editing Code +Example coming soon! + +## Debugging Code +Example coming soon! + +## Best practices +Coming soon! diff --git a/ar-pages/applications/function_calling.ar.mdx b/ar-pages/applications/function_calling.ar.mdx new file mode 100644 index 0000000..dd44248 --- /dev/null +++ b/ar-pages/applications/function_calling.ar.mdx @@ -0,0 +1,143 @@ +# Function Calling with LLMs + +import {Cards, Card} from 'nextra-theme-docs' +import {CodeIcon} from 'components/icons' + +## Getting Started with Function Calling + +Function calling is the ability to reliably connect LLMs to external tools to enable effective tool usage and interaction with external APIs. + +LLMs like GPT-4 and GPT-3.5 have been fine-tuned to detect when a function needs to be called and then output JSON containing arguments to call the function. The functions that are being called by function calling will act as tools in your AI application and you can define more than one in a single request. + +Function calling is an important ability for building LLM-powered chatbots or agents that need to retrieve context for an LLM or interact with external tools by converting natural language into API calls. + +Functional calling enables developers to create: + +- conversational agents that can efficiently use external tools to answer questions. For example, the query "What is the weather like in Belize?" will be converted to a function call such as `get_current_weather(location: string, unit: 'celsius' | 'fahrenheit')` +- LLM-powered solutions for extracting and tagging data (e.g., extracting people names from a Wikipedia article) +- applications that can help convert natural language to API calls or valid database queries +- conversational knowledge retrieval engines that interact with a knowledge base + +In this guide, we demonstrate how to prompt models like GPT-4 and open-source models to perform function calling for different use cases. + +## Function Calling with GPT-4 + +As a basic example, let's say we asked the model to check the weather in a given location. + +The LLM alone would not be able to respond to this request because it has been trained on a dataset with a cutoff point. The way to solve this is to combine the LLM with an external tool. You can leverage the function calling capabilities of the model to determine an external function to call along with its arguments and then have it return a final response. Below is a simple example of how you can achieve this using the OpenAI APIs. + +Let's say a user is asking the following question to the model: + +``` +What is the weather like in London? +``` + +To handle this request using function calling, the first step is to define a weather function or set of functions that you will be passing as part of the OpenAI API request: + +```python +tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + }, + } +] +``` + +The `get_current_weather` function returns the current weather in a given location. When you pass this function definition as part of the request, it doesn't actually executes a function, it just returns a JSON object containing the arguments needed to call the function. Here are some code snippets of how to achieve this. + +You can define a completion function as follows: + +```python +def get_completion(messages, model="gpt-3.5-turbo-1106", temperature=0, max_tokens=300, tools=None): + response = openai.chat.completions.create( + model=model, + messages=messages, + temperature=temperature, + max_tokens=max_tokens, + tools=tools + ) + return response.choices[0].message +``` + +This is how you can compose the user question: + +```python +messages = [ + { + "role": "user", + "content": "What is the weather like in London?" + } +] +``` + +Finally, you can call the `get_completion` above and passing both the `messages` and `tools`: + +```python +response = get_completion(messages, tools=tools) +``` + +The `response` object contains the following: + +```python +ChatCompletionMessage(content=None, role='assistant', function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='...', function=Function(arguments='{"location":"London","unit":"celsius"}', name='get_current_weather'), type='function')]) +``` + +In particular, the `arguments` object contains the important arguments extracted by the model and that will be needed to complete the request. + +You can then choose to call an external weather API for the actual weather. Once you have the weather information available you can pass it back to the model to summarize a final response given the original user question. + +## Notebooks + +Here is a notebook with a simple example that demonstrates how to use function calling with the OpenAI APIs: + + + } + title="Function Calling with OpenAI APIs" + href="https://github.com/dair-ai/Prompt-Engineering-Guide/blob/main/notebooks/pe-function-calling.ipynb" + /> + + +## Function Calling with Open-Source LLMs +More notes on function calling with open-source LLMs coming soon. + +## Function Calling Use Cases + +Below is a list of use cases that can benefit from the function calling capability of LLMs: + +- **Conversational Agents**: Function calling can be used to create complex conversational agents or chatbots that answer complex questions by calling external APIs or external knowledge base and providing more relevant and useful responses. + +- **Natural Language Understanding**: It can convert natural language into structured JSON data, extract structured data from text, and perform tasks like named entity recognition, sentiment analysis, and keyword extraction. + +- **Math Problem Solving**: Function calling can be used to define custom functions to solve complex mathematical problems that require multiple steps and different types of advanced calculations. + +- **API Integration**: It can be used to effectively integrate LLMs with external APIs to fetch data or perform actions based on the input. This could be helpful to build either a QA system or creative assistant. In general, function calling can convert natural language into valid API calls. + +- **Information Extraction**: Function calling be effectively used to extract specific information from a given input, such as retrieving relevant news stories or references from an article. + + +## References +- [Fireworks Raises the Quality Bar with Function Calling Model and API Release](https://blog.fireworks.ai/fireworks-raises-the-quality-bar-with-function-calling-model-and-api-release-e7f49d1e98e9) +- [Benchmarking Agent Tool Use and Function Calling](https://blog.langchain.dev/benchmarking-agent-tool-use/) +- [Function Calling](https://ai.google.dev/docs/function_calling) +- [Interacting with APIs](https://python.langchain.com/docs/use_cases/apis) +- [OpenAI's Function Calling](https://platform.openai.com/docs/guides/function-calling) +- [How to call functions with chat models](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models) +- [Pushing ChatGPT's Structured Data Support To Its Limits](https://minimaxir.com/2023/12/chatgpt-structured-data/) +- [Math Problem Solving with Function Calling](https://github.com/svpino/openai-function-calling/blob/main/sample.ipynb) \ No newline at end of file diff --git a/ar-pages/applications/generating.ar.mdx b/ar-pages/applications/generating.ar.mdx new file mode 100644 index 0000000..28719cd --- /dev/null +++ b/ar-pages/applications/generating.ar.mdx @@ -0,0 +1,44 @@ +# Generating Data +LLMs have strong capabilities to generate coherent text. Using effective prompt strategies can steer the model to produce better, consistent, and more factual responses. LLMs can also be especially useful for generating data which is really useful to run all sorts of experiments and evaluations. For example, we can use it to generate quick samples for a sentiment classifier like so: + +*Prompt:* +``` +Produce 10 exemplars for sentiment analysis. Examples are categorized as either positive or negative. Produce 2 negative examples and 8 positive examples. Use this format for the examples: +Q: +A: +``` + +*Output:* +``` +Q: I just got the best news ever! +A: Positive + +Q: We just got a raise at work! +A: Positive + +Q: I'm so proud of what I accomplished today. +A: Positive + +Q: I'm having the best day ever! +A: Positive + +Q: I'm really looking forward to the weekend. +A: Positive + +Q: I just got the best present ever! +A: Positive + +Q: I'm so happy right now. +A: Positive + +Q: I'm so blessed to have such an amazing family. +A: Positive + +Q: The weather outside is so gloomy. +A: Negative + +Q: I just got some terrible news. +A: Negative +``` + +This is very useful. We actually use this example for a different test in another section of the guides. \ No newline at end of file diff --git a/ar-pages/applications/generating_textbooks.ar.mdx b/ar-pages/applications/generating_textbooks.ar.mdx new file mode 100644 index 0000000..78c0d3b --- /dev/null +++ b/ar-pages/applications/generating_textbooks.ar.mdx @@ -0,0 +1,144 @@ +# Tackling Generated Datasets Diversity + +import {Screenshot} from 'components/screenshot' + +import IMG1 from '../../img/synthetic_diversity/textbooks_1.png' +import IMG2 from '../../img/synthetic_diversity/textbooks_2.png' + +In the previous [chapter](https://www.promptingguide.ai/applications/synthetic_rag), we discussed the potential of using LLM for synthetic dataset generation to further finetune a local Retriever model. This method is possible due to the availability of a large corpus of unlabeled documents. Each document is used to generate one or more synthetic queries and form a query-document pair. + +But what if Information Retrieval is not your task? Let's say you are working on a legal document classification problem but are not permitted to send any data to an external API. In this situation, you would need to train a local model. However, collecting data could become a significant obstacle, causing delays in product development. + +For simplicity, let’s suppose the goal is to generate children's stories. This task was the starting point for research by [Eldan et al. (2023)](https://arxiv.org/abs/2305.07759). Each story consists of 2-3 paragraphs that follow a straightforward plot and theme, while the entire dataset covers a child's vocabulary and factual knowledge. + +Language is not just a system of rules and symbols; it conveys and interprets meaning. The main challenge of using large language models to produce training data is ensuring dataset diversity. Even with high [generation temperature](https://www.promptingguide.ai/introduction/settings), models can produce repetitive datasets lacking the necessary diversity (even for a child's language). Coherence and relevance are other natural language generation challenges. + +To tackle the diversity issue, the authors prepared a vocabulary of around 1500 basic words, mirroring a typical child's vocabulary, divided into nouns, verbs, and adjectives. In each generation, one verb, one noun, and one adjective were randomly selected. The model then generates a story integrating these random words. + +This technique significantly broadened the dataset's diversity, ensuring stories cover a child's entire vocabulary and diverse concept combinations. Additionally, the authors integrated potential story features (like dialogue, plot twists, bad endings, or moral lessons). A random subset of these features was chosen for each story, and the model was prompted to include them. + +*Prompt:* +``` +Write a short story (3-5 paragraphs) which only uses very simple words that a 3 year old child would likely understand. The story should use the verb ”{random.choice(verbs_list)}”, the noun ”{random.choice(nouns_list)}” and the adjective ”{random.choice(adjectives_list)}”. The story should have the following features: {random.choice(features_list)}, {random.choice(features_list)}. Remember to only use simple words! +``` + +Let's assume the gaps were filled as follows: + +*Prompt:* +``` +Write a short story (3-5 paragraphs) which only uses very simple words that a 3 year old child would likely understand. The story should use the verb ”decorate”, the noun ”thunder” and the adjective ”ancient”. The story should have the following features: the story should contain at least one dialogue, the story has a bad ending. Remember to only use simple words! +``` + +*Output:* +``` +Once upon a time, in an ancient house, there lived a girl named Lily. She loved to decorate her room with pretty things. One day, she found a big box in the attic. She opened it and saw many shiny decorations. Lily was very happy and decided to use them in her room. As Lily was decorating her room, the sky outside became dark. There was a loud thunder sound, and Lily got scared. She ran to her mom and said, ”Mommy, the thunder is so loud!” Her mom hugged her and said, ”Don’t worry, it will pass soon.” But the thunder did not stop. It got louder and louder, and the ancient house started to shake. Suddenly, the roof fell down on the pretty decorations. Lily was sad because her room was not pretty anymore. The end. +``` + +Here we rely on the latest text generation models (GPT-3.5 and GPT-4), which can produce vast amounts of synthetic content, following the instructions. Since we formulate the prompt randomly each time, and the model adheres to it precisely, the stories turn out to be incredibly varied. The narrative will be entirely different even if one or two words remain the same. In essence, we apply this technique to inject randomness into the prompt, generating a diverse dataset. + +You get the idea: + +1. Identify which parameters/entities might vary between different samples in your synthetic dataset; +2. Generate or manually compile a collection of these entities to fill in the gaps; +3. Produce the dataset by randomly selecting entities for insertion. It's best to set the generation temperature higher than the default but below the maximum; +4. Train a local model on the generation results of ChatGPT/GPT-4. + +It is important to note that one of the entities used to seed your generation could be a class label. For example, in the sentiment classification task, you can directly mention "positive" or "negative" in the prompt to receive a generated text with the corresponding label. Then, a local classifier is trained on this data. + +# Iterative (Hierarchical) Synthetic Data Generation + +The format can be made more complex by using even more entities, some of which are generated beforehand by the LLM itself. For example, one could start with a request to generate a story summary and pen down one sentence that must appear in the story. Later, just use that generated intermediate data in the final request. + +*Prompt:* +``` +Summary: {a short summary generated by LLM, using the approach above} +Features: {copy the features from the initial prompt} +Sentence: {a sentence generated by LLM, which should be present in the story} +Words: {copy the words from the initial prompt} +Story: +``` + +Example of a filled-in prompt: + +*Prompt:* +``` +Summary: Lily and Timmy build a sandcastle together and learn to compromise, but it gets knocked over by a gust of wind. They find beauty in the broken sandcastle and play happily with a butterfly. +Features: Dialogue, Foreshadowing, Twist +Sentence: One day, she went to the park and saw a beautiful butterfly. +Words: disagree, network, beautiful +Story: +``` + +*Output:* +``` +Once upon a time, there was a little girl named Lily. She loved to play with her toys and her friends. One day, she went to the park and saw a beautiful butterfly. She tried to catch it, but it flew away. Lily’s friend, Timmy, came to play with her. They decided to build a sandcastle, but they disagreed on how to build it. Lily wanted to make it tall, while Timmy wanted to make it wide. They argued for a while, but finally agreed to make it both tall and wide. As they were building the sandcastle, they noticed a group of ants working together. They realized that the ants were building a network of tunnels. Suddenly, a gust of wind came and knocked over their sandcastle. They were sad, but then they saw the butterfly again. It landed on the remains of their sandcastle and they realized that it was still beautiful, even in its broken state. They smiled and played together happily. +``` + +Thus, it's possible to generate hundreds of thousands of very diverse examples to train the model on. Let's say you need to train a classifier that determines whether a text contains a dialogue or a plot twist. As the initial prompt contains labels, it's known which target value needs to be predicted for each generated sample. + +# Textbooks Are All You Need + +A crucial question arising from this approach is whether the synthesis of a dataset can truly provide benefits when training networks for real-world applications. Fortunately, the authors addressed this question by conducting their investigation and validating the efficacy of training smaller language models using synthetic data derived from State-of-the-Art LLMs. + +In their study, [Gunasekar et al. (2023)](https://arxiv.org/abs/2306.11644) emphasize the importance of high-quality training data in their model. They argue that language models would be more effective if they were trained on materials that resemble the characteristics of a well-regarded "textbook": clear, comprehensive, informative, and unbiased. + +These principles formed the basis for creating a semi-synthetic dataset to train LLM called Phi-1. The main evaluation task is to generate a Python function that follows a given text description or docstring. The model's quality is evaluated using the HumanEval benchmark ([Chen et al., 2021](https://arxiv.org/abs/2107.03374)). + +The authors highlight the importance of diversity in this approach for several reasons. It exposes the language model to a variety of coding expressions and problem-solving approaches, reduces the risk of overfitting or relying on specific patterns, and improves the model's ability to handle unfamiliar or innovative tasks. + +To address the code-writing challenge, the authors created textbook-like documents that focus on topics promoting reasoning and basic algorithmic skills. They achieved diversity by imposing restrictions on: + +- topics +- target audience + +Unfortunately, the authors did not provide specific information about the prompt template used to generate the synthetic data. However, they did demonstrate the resulting output. They chose to use ChatGPT (GPT-3.5) instead of GPT-4, and even this strategy yielded excellent results as they fine-tuned the model using synthetic data. + + + +Image Source: [Gunasekar et al. (2023)](https://arxiv.org/abs/2306.11644) + +It's essential to pay attention to the target audience constraint. Designating a target audience is an excellent way to enhance synthetic data diversity. A high school student, a CS undergraduate, and a PhD candidate certainly phrase their explanations and process information differently, making the generated data even more varied. Let's attempt to recreate the prompt. + + +*Prompt:* +``` +Write an extract from a Computer Science textbook for a 1st-year bachelor. The coding language is Python 3.6. + +This is an extract from the middle of the following topic: Singular matrices. + +The extract starts with a high-level overview of the topic. Then, it presents an example and describes the solution in natural language. After that, it provides 1-2 code snippets, following the example. Each snippet has no more than 10 rows. There should be no text after code snippets. + +Keep in mind that the extract should be concise and explain only one concept at a time. The code should represent a Python function & its call. All the common ML/DS libraries are available. + +Don't be too verbose. The expected length of the extract is 2 paragraphs at most. +``` + +*Output:* +``` +**Singular Matrices** + +In linear algebra, a matrix is termed as "singular" if it doesn't have an inverse. Another equivalent definition is when the determinant of the matrix is zero. Singular matrices are crucial because they represent systems of linear equations that do not have a unique solution. + +Consider a 2x2 matrix `[[a, b], [c, d]]`. If the product of `ad` and `bc` is the same (i.e., `ad = bc`), then this matrix is singular. Let's explore this with an example: given the matrix `[[2, 4], [1, 2]]`, you'll find that the product of the diagonals yields the same result (2 * 2 = 4 * 1), thus it's a singular matrix. + +import numpy as np + +def is_singular(matrix): + determinant = np.linalg.det(matrix) + return abs(determinant) < 1e-9 + +matrix_example = np.array([[2, 4], [1, 2]]) +print(is_singular(matrix_example)) # returns True +``` + +Quite close! + +In total, the authors generated 1B tokens to augment the model's training set, allowing a smaller model (only 1.5B parameters) to rival models ten times its size (for details, refer to the article [Gunasekar et al. (2023)](https://arxiv.org/abs/2306.11644)). + + + +Image Source: [Gunasekar et al. (2023)](https://arxiv.org/abs/2306.11644) + +For your task, you probably don't need such a large amount of synthetic data (since the authors studied the pretraining, which requires significant resources). However, even as an estimate, at a price of `$0.002` per 1k tokens (standard ChatGPT pricing), it would cost `$2000` for the generated tokens and approximately the same amount for the prompts. + +Keep in mind that fine-tuning on synthetic data becomes more valuable as the domain becomes more niche, especially if the language deviates from English (among other factors). Additionally, this method works well with [Chain-of-Thought (CoT)](https://www.promptingguide.ai/techniques/cot), helping the local model improve its reasoning capabilities. Other prompting techniques work, too. And don't forget that open-source models like Alpaca ([Taori et al., (2023)](https://crfm.stanford.edu/2023/03/13/alpaca.html)) and Vicuna ([Zheng et al., (2023)](https://lmsys.org/blog/2023-03-30-vicuna/)) excel through fine-tuning on synthetic data. diff --git a/ar-pages/applications/pf.ar.mdx b/ar-pages/applications/pf.ar.mdx new file mode 100644 index 0000000..4438aab --- /dev/null +++ b/ar-pages/applications/pf.ar.mdx @@ -0,0 +1,107 @@ +# Prompt Function + +## Introduction +When we draw a parallel between GPT's dialogue interface and a programming language's shell, the encapsulation prompt can be thought of as forming a function. This function has a unique name, and when we call this name with the input text, it produces results based on the set internal rules. In a nutshell, we build a reusable prompt with a name that makes it easy to engage with GPT. It's like having a handy tool that lets GPT carry out particular tasks on our behalf – we just need to give the input, and we receive the desired output. + +By encapsulating prompts into functions, you can create a series of functions to establish a workflow. Each function represents a specific step or task, and when combined in a particular order, they can automate complex processes or solve problems more efficiently. This approach allows for a more structured and streamlined interaction with GPT, ultimately enhancing its capabilities and making it a powerful tool to accomplish a wide range of tasks. + +So before we can use a function, we need to let GPT know about it. Here is a prompt that defines the function. + +*Prompt:* +> Let's call this prompt with **meta prompt**. +This prompt has been tested on GPT3.5 and performs even better on GPT4 + +``` +Hello, ChatGPT! I hope you are doing well. I am reaching out to you for assistance with a specific function. I understand that you have the capability to process information and perform various tasks based on the instructions provided. In order to help you understand my request more easily, I will be using a template to describe the function, input, and instructions on what to do with the input. Please find the details below: + +function_name: [Function Name] +input: [Input] +rule: [Instructions on how to process the input] + +I kindly request you to provide the output for this function, based on the details I have provided. Your assistance is greatly appreciated. Thank you! +I will replace the text inside the brackets with the relevant information for the function I want you to perform. This detailed introduction should help you understand my request more efficiently and provide the desired output. The format is function_name(input) If you understand, just answer one word with ok. + +``` + + +## Examples + +### English study assistant +For example, let's say we want to use GPT to aid us in our English studies. We can simplify the process by creating a series of functions. + +This example has been tested on GPT3.5 and performs even better on GPT4 + +#### Function description + +We need to paste the **meta prompt** that was defined above the section in GPT + +Then we will create a function `trans_word`. +This function prompts GPT to translate Chinese into English. + +*Prompt:* +``` +function_name: [trans_word] +input: ["text"] +rule: [I want you to act as an English translator, spelling corrector and improver. I will provide you with input forms including "text" in any language and you will detect the language, translate it and answer in the corrected of my text, in English.] +``` + + +Write a function that expands text. + +*Prompt:* +``` +function_name: [expand_word] +input: ["text"] +rule: [Please serve as a Chatterbox, spelling corrector, and language enhancer. I will provide you with input forms including "text" in any language, and output the original language.I want you to Keep the meaning same, but make them more literary.] +``` + +Write a function that corrects text. + +*Prompt:* +``` +function_name: [fix_english] +input: ["text"] +rule: [Please serve as an English master, spelling corrector, and language enhancer. I will provide you with input forms including "text", I want you to improve the text's vocabulary and sentences with more natural and elegent. Keep the meaning same.] +``` +Finally, you can run the function independently or chain them together. + +*Prompt:* +``` +trans_word('婆罗摩火山处于享有“千岛之国”美称的印度尼西亚. 多岛之国印尼有4500座之多的火山, 世界著名的十大活火山有三座在这里.') +fix_english('Finally, you can run the function independently or chain them together.') +fix_english(expand_word(trans_word('婆罗摩火山处于享有“千岛之国”美称的印度尼西亚. 多岛之国印尼有4500座之多的火山, 世界著名的十大活火山有三座在这里.'))) +``` +By representing the functions in this format, you can clearly see each function's name, input, and the rule to process the input. It provides an organized way to understand the functionality and purpose of each step in the workflow + +_tips:_ +If you don't want ChatGPT to output excessive information, you can simply add a sentence after defining the function's rules. +``` +DO NOT SAY THINGS ELSE OK, UNLESS YOU DONT UNDERSTAND THE FUNCTION +``` + +### Multiple params function +Let's create a function that generates a password by taking five input parameters, and outputs the generated password. + +*Prompt:* +``` +function_name: [pg] +input: ["length", "capitalized", "lowercase", "numbers", "special"] +rule: [I want you to act as a password generator for individuals in need of a secure password. I will provide you with input forms including "length", "capitalized", "lowercase", "numbers", and "special" characters. Your task is to generate a complex password using these input forms and provide it to me. Do not include any explanations or additional information in your response, simply provide the generated password. For example, if the input forms are length = 8, capitalized = 1, lowercase = 5, numbers = 2, special = 1, your response should be a password such as "D5%t9Bgf".] +``` +``` +pg(length = 10, capitalized = 1, lowercase = 5, numbers = 2, special = 1) +pg(10,1,5,2,1) +``` + +### Thought +Now, there already have many projects that are working on programming GPT, such as: +- [GitHub Copilot](https://github.com/features/copilot) +- [Microsoft AI](https://www.microsoft.com/en-us/ai) +- [chatgpt-plugins](https://openai.com/blog/chatgpt-plugins) +- [LangChain](https://github.com/hwchase17/langchain) +- [marvin](https://github.com/PrefectHQ/marvin) + +But those projects are designed either for product customer or for users who can code with Python or other programming languages. +For the average user, use this easy template for daily work and iterate a couple of times. Use a note application to document the function, and it can even be updated to a library. +Alternatively, some open source ChatGPT tools, such as [ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web), [chatbox](https://github.com/Bin-Huang/chatbox), [PromptAppGPT](https://github.com/mleoking/PromptAppGPT), and [ChatGPT-Desktop](https://github.com/lencx/ChatGPT), can be used. Currently, ChatGPT-Next-Web allows adding a few shots before initializing the new chat. And PromptAppGPT supports low-code development of web applications based on prompt templates and enables anyone to develop AutoGPT-like applications with a few lines of prompts. +We can use this feature to add our function, which can then be used. diff --git a/ar-pages/applications/synthetic_rag.ar.mdx b/ar-pages/applications/synthetic_rag.ar.mdx new file mode 100644 index 0000000..9e9c707 --- /dev/null +++ b/ar-pages/applications/synthetic_rag.ar.mdx @@ -0,0 +1,88 @@ +# Generating Synthetic Dataset for RAG + +import {Screenshot} from 'components/screenshot' +import remarkMath from 'remark-math' +import rehypeKatex from 'rehype-katex' + +import IMG1 from '../../img/synthetic_rag/synthetic_rag_1.png' +import IMG2 from '../../img/synthetic_rag/synthetic_rag_2.png' +import IMG3 from '../../img/synthetic_rag/synthetic_rag_3.png' +import IMG4 from '../../img/synthetic_rag/synthetic_rag_4.png' + + +## Synthetic Data for RAG Setup +Unfortunately, in the life of a Machine Learning Engineer, there's often a lack of labeled data or very little of it. Typically, upon realizing this, projects embark on a lengthy process of data collection and labeling. Only after a couple of months can one start developing a solution. + +However, with the advent of LLM, the paradigm shifted in some products: now one can rely on LLM’s generalization ability and test an idea or develop an AI-powered feature almost immediately. If it turns out to work (almost) as intended, then the traditional development process can begin. + + + +Image Source: [The Rise of the AI Engineer, by S. Wang](https://www.latent.space/p/ai-engineer) + +One of the emerging approaches is [Retrieval Augmented Generation (RAG)](https://www.promptingguide.ai/techniques/rag). It's used for knowledge-intensive tasks where you can't solely rely on the model's knowledge. RAG combines an information retrieval component with a text generator model. To learn more about this approach, refer to [the relevant section in the guide](https://www.promptingguide.ai/techniques/rag). + +The key component of RAG is a Retrieval model that identifies relevant documents and passes them to LLM for further processing. The better the performance of the Retrieval model, the better the product or feature outcome. Ideally, Retrieval works well right out of the box. However, its performance often drops in different languages or specific domains. + +Imagine this: you need to create a chatbot answering questions based on Czech laws and legal practices (in Czech, of course). Or design a tax assistant (a use case presented by OpenAI during the GPT-4 presentation) tailored for the Indian market. You'll likely find that the Retrieval model often misses the most relevant documents and doesn't perform as well overall, thus limiting the system's quality. + +But there's a solution. An emerging trend involves using existing LLMs to synthesize data for the training of new generations of LLMs/Retrievers/other models. This process can be viewed as distilling LLMs into standard-sized encoders via prompt-based query generation. While the distillation is computationally intensive, it substantially reduces inference costs and might greatly enhance performance, particularly in low-resource languages or specialized domains. + +In this guide, we will rely on the latest text generation models, like ChatGPT and GPT-4, which can produce vast amounts of synthetic content following instructions. [Dai et al. (2022)](https://arxiv.org/abs/2209.11755) proposed a method where with only 8 manually labeled examples and a large corpus of unlabeled data (documents for retrieval, e.g., all the parsed laws), one can achieve a near State-of-the-Art performance. This research confirms that synthetically generated data facilitates training task-specific retrievers for tasks where supervised in-domain fine-tuning is a challenge due to data scarcity. + +## Domain-Specific Dataset Generation +To utilize LLM, one needs to provide a short description and manually label a few examples. It's important to note that different retrieval tasks possess varying search intents, meaning different definitions of "relevance." In other words, for the same pair of (Query, Document), their relevance might differ entirely based on the search intent. For instance, an argument retrieval task might seek supporting arguments, while other tasks require counter-arguments (as seen in [ArguAna dataset](https://aclanthology.org/P18-1023/)). + +Consider the example below. Though written in English for easier understanding, remember that data can be in any language since ChatGPT/GPT-4 efficiently processes even low-resource languages. + +*Prompt:* +``` +Task: Identify a counter-argument for the given argument. + +Argument #1: {insert passage X1 here} + +A concise counter-argument query related to the argument #1: {insert manually prepared query Y1 here} + +Argument #2: {insert passage X2 here} +A concise counter-argument query related to the argument #2: {insert manually prepared query Y2 here} + +<- paste your examples here -> + +Argument N: Even if a fine is made proportional to income, you will not get the equality of impact you desire. This is because the impact is not proportional simply to income, but must take into account a number of other factors. For example, someone supporting a family will face a greater impact than someone who is not, because they have a smaller disposable income. Further, a fine based on income ignores overall wealth (i.e. how much money someone actually has: someone might have a lot of assets but not have a high income). The proposition does not cater for these inequalities, which may well have a much greater skewing effect, and therefore the argument is being applied inconsistently. + +A concise counter-argument query related to the argument #N: +``` + +*Output:* +``` +punishment house would make fines relative income +``` + +In general, such a prompt can be expressed as: + +$(e_{prompt}, e_{doc}(d_{1}), e_{query}(q_1), . . . , e_{doc}(d_k), e_{query}(q_k), e_{doc}(d))$ + +, where $e_{doc}$ and $e_{query}$ are task-specific document, query descriptions respectively, $e_{prompt}$ is a task-specific prompt/instruction for ChatGPT/GPT-4, and $d$ is a new document, for which LLM will generate a query. + +From this prompt, only the last document $d$ and the generated query will be used for further training of the local model. This approach can be applied when a target retrieval corpus $D$ is available, but the number of annotated query-document pairs for the new task is limited. + +The whole pipeline overview: + + + +Image Source: [Dai et al. (2022)](https://arxiv.org/abs/2209.11755) + +It's crucial to handle manual annotation of examples responsibly. It's better to prepare more (for instance, 20), and randomly pick 2-8 of them to the prompt. This increases the diversity of generated data without significant time costs in annotation. However, these examples should be representative, correctly formatted, and even detail specifics such as the target query length or its tone. The more precise the examples and instructions, the better the synthetic data will be for training Retriever. Low-quality few-shot examples can negatively impact the resulting quality of the trained model. + +In most cases, using a more affordable model like ChatGPT is sufficient, as it performs well with unusual domains and languages other than English. Let's say, a prompt with instructions and 4-5 examples typically takes up 700 tokens (assuming each passage is no longer than 128 tokens due to Retriever constraints) and generation is 25 tokens. Thus, generating a synthetic dataset for a corpus of 50,000 documents for local model fine-tuning would cost: `50,000 * (700 * 0.001 * $0.0015 + 25 * 0.001 * $0.002) = 55`, where `$0.0015` and `$0.002` are the cost per 1,000 tokens in the GPT-3.5 Turbo API. It's even possible to generate 2-4 query examples for the same document. However, often the benefits of further training are worth it, especially if you're using Retriever not for a general domain (like news retrieval in English) but for a specific one (like Czech laws, as mentioned). + +The figure of 50,000 isn't random. In the research by [Dai et al. (2022)](https://arxiv.org/abs/2209.11755), it's stated that this is approximately the number of manually labeled data needed for a model to match the quality of one trained on synthetic data. Imagine having to gather at least 10,000 examples before launching your product! It would take no less than a month, and the labor costs would surely exceed a thousand dollars, much more than generating synthetic data and training a local Retriever Model. Now, with the technique you learned today, you can achieve double-digit metric growth in just a couple of days! + + + +Image Source: [Dai et al. (2022)](https://arxiv.org/abs/2209.11755) + +And here are prompt templates from the same paper for some of the datasets in BeIR benchmark. + + + +Image Source: [Dai et al. (2022)](https://arxiv.org/abs/2209.11755) diff --git a/ar-pages/applications/workplace_casestudy.ar.mdx b/ar-pages/applications/workplace_casestudy.ar.mdx new file mode 100644 index 0000000..d5297af --- /dev/null +++ b/ar-pages/applications/workplace_casestudy.ar.mdx @@ -0,0 +1,56 @@ +# Graduate Job Classification Case Study + +[Clavié et al., 2023](https://arxiv.org/abs/2303.07142) provide a case-study on prompt-engineering applied to a medium-scale text classification use-case in a production system. Using the task of classifying whether a job is a true "entry-level job", suitable for a recent graduate, or not, they evaluated a series of prompt engineering techniques and report their results using GPT-3.5 (`gpt-3.5-turbo`). + +The work shows that LLMs outperforms all other models tested, including an extremely strong baseline in DeBERTa-V3. `gpt-3.5-turbo` also noticeably outperforms older GPT3 variants in all key metrics, but requires additional output parsing as its ability to stick to a template appears to be worse than the other variants. + +The key findings of their prompt engineering approach are: + +- For tasks such as this one, where no expert knowledge is required, Few-shot CoT prompting performed worse than Zero-shot prompting in all experiments. +- The impact of the prompt on eliciting the correct reasoning is massive. Simply asking the model to classify a given job results in an F1 score of 65.6, whereas the post-prompt engineering model achieves an F1 score of 91.7. +- Attempting to force the model to stick to a template lowers performance in all cases (this behaviour disappears in early testing with GPT-4, which are posterior to the paper). +- Many small modifications have an outsized impact on performance. + - The tables below show the full modifications tested. + - Properly giving instructions and repeating the key points appears to be the biggest performance driver. + - Something as simple as giving the model a (human) name and referring to it as such increased F1 score by 0.6pts. + +### Prompt Modifications Tested + +| Short name | Description | +|------------|----------------------------------------------------------------------------| +| Baseline | Provide a a job posting and asking if it is fit for a graduate. | +| CoT | Give a few examples of accurate classification before querying. | +| Zero-CoT | Ask the model to reason step-by-step before providing its answer. | +| rawinst | Give instructions about its role and the task by adding to the user msg. | +| sysinst | Give instructions about its role and the task as a system msg. | +| bothinst | Split instructions with role as a system msg and task as a user msg. | +| mock | Give task instructions by mocking a discussion where it acknowledges them. | +| reit | Reinforce key elements in the instructions by repeating them. | +| strict | Ask the model to answer by strictly following a given template. | +| loose | Ask for just the final answer to be given following a given template. | +| right | Asking the model to reach the right conclusion. | +| info | Provide additional information to address common reasoning failures. | +| name | Give the model a name by which we refer to it in conversation. | +| pos | Provide the model with positive feedback before querying it. | + + +### Performance Impact of All Prompt Modifications + +| | Precision | Recall | F1 | Template Stickiness | +|----------------------------------------|---------------|---------------|---------------|------------------------| +| _Baseline_ | _61.2_ | _70.6_ | _65.6_ | _79%_ | +| _CoT_ | _72.6_ | _85.1_ | _78.4_ | _87%_ | +| _Zero-CoT_ | _75.5_ | _88.3_ | _81.4_ | _65%_ | +| _+rawinst_ | _80_ | _92.4_ | _85.8_ | _68%_ | +| _+sysinst_ | _77.7_ | _90.9_ | _83.8_ | _69%_ | +| _+bothinst_ | _81.9_ | _93.9_ | _87.5_ | _71%_ | +| +bothinst+mock | 83.3 | 95.1 | 88.8 | 74% | +| +bothinst+mock+reit | 83.8 | 95.5 | 89.3 | 75% | +| _+bothinst+mock+reit+strict_ | _79.9_ | _93.7_ | _86.3_ | _**98%**_ | +| _+bothinst+mock+reit+loose_ | _80.5_ | _94.8_ | _87.1_ | _95%_ | +| +bothinst+mock+reit+right | 84 | 95.9 | 89.6 | 77% | +| +bothinst+mock+reit+right+info | 84.9 | 96.5 | 90.3 | 77% | +| +bothinst+mock+reit+right+info+name | 85.7 | 96.8 | 90.9 | 79% | +| +bothinst+mock+reit+right+info+name+pos| **86.9** | **97** | **91.7** | 81% | + +Template stickiness refers to how frequently the model answers in the desired format. diff --git a/ar-pages/course.ar.mdx b/ar-pages/course.ar.mdx new file mode 100644 index 0000000..61e0be2 --- /dev/null +++ b/ar-pages/course.ar.mdx @@ -0,0 +1,41 @@ +# Prompt Engineering Courses + +import { Callout } from 'nextra/components' + + +We've partnered with Maven to deliver the following live cohort-based courses on prompt engineering: + +- [LLMs for Everyone ](https://maven.com/dair-ai/llms-for-everyone) (Beginner) - learn about the latest prompt engineering techniques and how to effectively apply them to real-world use cases. + +- [Prompt Engineering for LLMs ](https://maven.com/dair-ai/prompt-engineering-llms) (Advanced) - learn advanced prompt engineering techniques to build complex use cases and applications with LLMs. + +We are now offering a special discount for our learners. Use promo code MAVENAI20 for a 20% discount. + + +These hands-on courses are built to compliment this prompt engineering guide. They are designed to help expand your skills and knowledge by teaching you how to effectively apply the concepts learned in this guide to real-world use cases and applications. + +[Elvis Saravia](https://www.linkedin.com/in/omarsar/), who has worked at companies like Meta AI and Elastic, and has years of experience in AI and LLMs, is the instructor for both courses. + +Our past learners range from software engineers to AI researchers and practitioners in organizations like Microsoft, Google, Apple, Airbnb, LinkedIn, Amazon, JPMorgan Chase & Co., Asana, Intuit, Fidelity Investments, Coinbase, Guru, and many others. + +Topics we provide training on: + +- Taxonomy of Prompting Techniques +- Tactics to Improve Reliability +- Structuring LLM Outputs +- Zero-shot Prompting +- Few-shot In-Context Learning +- Chain of Thought Prompting +- Self-Reflection & Self-Consistency +- ReAcT +- Retrieval Augmented Generation +- Fine-Tuning & RLHF +- Function Calling +- AI Safety & Moderation +- LLM-Powered Agents +- LLM Evaluation +- Adversarial Prompting (Jailbreaking and Prompt Injections) +- Judge LLMs +- Common Real-World Use Cases of LLMs + +Reach out to training@dair.ai for any questions about the courses, corporate training, and available group discounts. diff --git a/ar-pages/datasets.ar.mdx b/ar-pages/datasets.ar.mdx new file mode 100644 index 0000000..df2fe22 --- /dev/null +++ b/ar-pages/datasets.ar.mdx @@ -0,0 +1,12 @@ +# Datasets +#### (Sorted by Name) + +- [Anthropic's Red Team dataset](https://github.com/anthropics/hh-rlhf/tree/master/red-team-attempts), [(paper)](https://arxiv.org/abs/2209.07858) +- [Awesome ChatGPT Prompts](https://huggingface.co/datasets/fka/awesome-chatgpt-prompts) +- [DiffusionDB](https://github.com/poloclub/diffusiondb) +- [Midjourney Prompts](https://huggingface.co/datasets/succinctly/midjourney-prompts) +- [P3 - Public Pool of Prompts](https://huggingface.co/datasets/bigscience/P3) +- [PartiPrompts](https://parti.research.google) +- [Real Toxicity Prompts](https://allenai.org/data/real-toxicity-prompts) +- [Stable Diffusion Dataset](https://huggingface.co/datasets/Gustavosta/Stable-Diffusion-Prompts) +- [WritingPrompts](https://www.reddit.com/r/WritingPrompts) diff --git a/ar-pages/introduction.ar.mdx b/ar-pages/introduction.ar.mdx new file mode 100644 index 0000000..a1160e3 --- /dev/null +++ b/ar-pages/introduction.ar.mdx @@ -0,0 +1,15 @@ +# Introduction + +import {Cards, Card} from 'nextra-theme-docs' +import { CardsIcon, OneIcon, WarningIcon, FilesIcon} from 'components/icons' +import ContentFileNames from 'components/ContentFileNames' + +Prompt engineering is a relatively new discipline for developing and optimizing prompts to efficiently apply and build with large language models (LLMs) for a wide variety of applications and use cases. + +Prompt engineering skills help to better understand the capabilities and limitations of LLMs. Researchers use prompt engineering to improve safety and the capacity of LLMs on a wide range of common and complex tasks such as question answering and arithmetic reasoning. Developers use prompt engineering to design robust and effective prompting techniques that interface with LLMs and other tools. + +This comprehensive guide covers the theory and practical aspects of prompt engineering and how to leverage the best prompting techniques to interact and build with LLMs. + +All examples are tested with `gpt-3.5-turbo` using the [OpenAI's Playground](https://platform.openai.com/playground) unless otherwise specified. The model uses the default configurations, i.e., `temperature=1` and `top_p=1`. The prompts should also work with other models that have similar capabilities as `gpt-3.5-turbo` but the model responses may vary. + + \ No newline at end of file diff --git a/ar-pages/introduction/_meta.ar.json b/ar-pages/introduction/_meta.ar.json new file mode 100644 index 0000000..98f6af2 --- /dev/null +++ b/ar-pages/introduction/_meta.ar.json @@ -0,0 +1,7 @@ +{ + "settings": "إعدادات النماذج اللغوية الكبيرة", + "basics": "أساسيات التلقين", + "elements": "عناصر الأوامر", + "tips": "نصائح عامة لتصميم الأوامر", + "examples": "أمثلة على الأوامر" +} diff --git a/ar-pages/introduction/basics.ar.mdx b/ar-pages/introduction/basics.ar.mdx new file mode 100644 index 0000000..effb162 --- /dev/null +++ b/ar-pages/introduction/basics.ar.mdx @@ -0,0 +1,145 @@ +# Basics of Prompting + +import {Screenshot} from 'components/screenshot' +import INTRO1 from '../../img/introduction/sky.png' +import {Bleed} from 'nextra-theme-docs' + +## Prompting an LLM + +You can achieve a lot with simple prompts, but the quality of results depends on how much information you provide it and how well-crafted the prompt is. A prompt can contain information like the *instruction* or *question* you are passing to the model and include other details such as *context*, *inputs*, or *examples*. You can use these elements to instruct the model more effectively to improve the quality of results. + +Let's get started by going over a basic example of a simple prompt: + +*Prompt* + +```md +The sky is +``` + +*Output:* +```md +blue. +``` + +If you are using the OpenAI Playground or any other LLM playground, you can prompt the model as shown in the following screenshot: + + + +Here is a tutorial on how to get started with the OpenAI Playground: + +