"My AIGC spell library: Share the secrets of communicating with AI - how to use prompts to communicate efficiently with AI?"

A word of positive energy every day

Since I was born into this world, I have to take a good look at it and find my own number one in the world.

Preface

Artificial intelligence (AI) is a hot topic in today's technology field, especially natural language processing (NLP) technology, which allows machines to understand and generate natural language. With the development of large language models (LLM), such as GPT-3, DALL-E, etc., we can use these models to complete a variety of interesting and useful tasks, such as writing poetry, drawing, programming, etc. However, getting these models to work as we want is not an easy task. This requires the use of a technology called Prompt Engineering.

When you are still using conversational AI tools such as GPT incorrectly, you may feel that its function is nothing more than a summary of knowledge translation or a simple question and answer. In fact, when you understand the advanced usage and how to achieve better prompt, you will find that AI is not here to replace you, but to help you work better. If you still think about the use of artificial intelligence using the search engine's "keyword matching" and "keyword hitting" ideas, you are already a little behind. After introducing in detail several application scenarios in which GPT helps programmers work (full of useful information), this article will share with you the correct way to open AI - better prompt.

Basic introduction

  1. AIGC prompt words are usually composed of multiple words, phrases or short sentences, separated by,;
  2. Prompt words are divided into positive prompt words (positive prompt) and negative prompt words (negative prompt). The forward direction determines the generation direction, and the reverse direction excludes the generation direction;
  3. The total quantity is recommended not to exceed 75;
  4. The AI ​​program will selectively execute based on probability. If there is a conflict between prompt words, the AI ​​will randomly select which prompt word to execute based on the probability determined by the weight;
  5. The larger the size of the generated image, the more prompt words are needed, otherwise the prompt words will contaminate each other;
  6. The prompt word supports the use of emoji: call_me_hand:, and has good expressiveness.

What is a prompt?

As the name suggests, prompt means "prompt". Simply put, prompt is the instruction you give to AI. The prompt can be a piece of text, such as when you are talking to ChatGPT, or it can be a parameter description in a certain format, such as AI drawing software, which often uses parameters.

Prompt is a language used to communicate with the AI ​​model, which is used to tell the AI ​​model the characteristics of the image it wants to generate. The accuracy and precision of the prompt words directly determine whether the generated image meets our expectations.

A professional vocabulary corresponding to Prompt is Prompt Engineering (PE). PE is a concept in the field of artificial intelligence (AI), especially the field of natural language processing (NLP). PE usually converts questions into input in a specific format and processes it using predefined templates, rules and algorithms, allowing AI to better understand the task and give corresponding answers. The advantage of PE is that it can make AI understand tasks more flexibly and accurately, and can reduce misunderstandings and errors caused by unclear language expression, allowing it to perform specific tasks accurately and reliably.

In layman's terms, you need to master the skills of talking to AI so that AI can truly understand you. Especially now, the intelligence level of many AI products needs to be further improved. Therefore, it is very useful to learn a little knowledge of Prompt Engineering. necessary.

What is Prompt Engineering?

Prompt Engineering is a concept in the field of artificial intelligence, especially natural language processing. It refers to how to design input data so that it can clearly describe the task and guide the model to give correct and reasonable output. In other words, it is the instructions given to the AI ​​model.

Prompt can be a question, a text description, or even a text description with a bunch of parameters. The AI ​​model will generate corresponding text or pictures based on the information provided by the prompt.

Why do you need Prompt Engineering?

You may have used many AI-related products, and you may feel that you only need to be able to speak and type for AI to output answers. It seems that no technology is required.

But in fact, not all prompts can get satisfactory or accurate answers. Because human language is fundamentally imprecise2, machines are currently unable to understand what humans say well3. That’s why the technology of Prompt Engineering appeared. In addition, due to the current implementation principles of large language model AI4, some logical operation problems, format issues, etc. require additional prompts for the AI.

For example, enter this simple math question in ChatGPT:

What is 100*100/400*56?

ChatGPT returns an incorrect answer:

0.4464

But if we change the format of prompt a little bit:

Calculate: (100*100)/(400*56)

ChatGPT will return the correct answer:

0.04464

It can be seen that the design of prompt has a great impact on the results.

How to do Prompt Engineering?

Prompt Engineering is both an art and a science. It requires a combination of creativity and logical thinking to design the optimal prompt. There are currently no unified standards or rules to guide the design of prompts, but there are some basic principles and suggestions for reference:

Contain complete and relevant information: Prompts should provide as much and specific information as possible to describe the task and avoid irrelevant or redundant information.

Be concise and understandable and reduce ambiguity: Prompts should use simple, clear and unambiguous words to express the task, and avoid using complex or ambiguous words.

Explicit label space: The prompt should clearly define the range of the output results and sample labels according to the true distribution in the example.

Uniform format: The prompt should keep the input and output data formats consistent and demonstrate the format requirements in examples.

Here are some prompt examples. It can be seen that different prompts have different effects on the results:

Less effective prompt:

Write a poem about OpenAI.

Output:

OpenAI is a visionOf a future that is brightWhere machines can learn and createAnd help us do what's rightOpenAI is a missionTo make AI accessibleTo everyone who wants to use itAnd make it beneficialOpenAI is a challengeTo push the boundaries of AIAnd explore the possibilitiesThat lie beyond the sky

Better prompt:

Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of William Blake.Output:To see the world in a grain of sand,And a heaven in a wild flower,Hold infinity in the palm of your hand,And eternity in an hour.This is the power of DALL-E,The latest wonder from OpenAI,A model that can generate images,From any text that you supply.With DALL-E you can create,A new world of imagination,Where anything you can think of,Becomes a visual sensation.DALL-E is not just a tool,But a source of inspiration,A glimpse of what AI can do,To enrich our human nation.

Basic principles of Prompt

The basic principles of Prompt are very important when interacting with AI. When submitting a prompt, the following principles should be followed to ensure that the machine can better understand the user's intention and give corresponding answers:

  1. Clear task description: When submitting a Prompt, the specific information of the task should be described as clearly and clearly as possible, including task objectives, required operations, related conditions, etc.
    For example, when interacting with an AI chatbot, simple questions can be used to guide the machine to understand user needs. For example: "What do you need me to do for you?" "What information do you need to query?" The task description can be as clear as possible so that the machine can better understand the user's needs and give corresponding suggestions.

  2. Use common vocabulary: When submitting prompts, you should use common vocabulary and language expressions and avoid using uncommon words and complex sentence patterns so that the machine can understand it more easily.

  3. Consider the context and context: When submitting a Prompt, the context and contextual environment should be taken into consideration so that the machine can obtain more information from the language environment to understand the user's intention.

  4. Provide diverse information: When submitting a prompt, you should try to provide diverse information, including text, images, voices, etc., to promote the machine to more comprehensively understand user needs.

  5. Determine the answer form: When submitting a prompt, you should determine the answer form, such as text, voice, etc., and ensure that the machine can reasonably parse and output the answer information.

Further principles include providing enough contextual information to the machine, organizing prompts with a clear structure to make it easier for the machine to process, and using simple and clear questions to guide users to formulate suggestions to better understand requirements. In addition, during interactions, users should also try to ask questions in short sentences so that the AI ​​robot can answer questions more quickly and accurately.

Prompt writing mode

Here are 4 commonly used Prompt modes. You may encounter variations or combinations of these.

  1. Specific instructions (By specific)
    In this mode, we provide the model with some specific information, such as questions or keywords, and the model needs to generate text related to this information. This mode is typically used to generate answers, explanations, or recommendations, etc. Specific information can be a single question or multiple keywords, depending on the requirements of the task.

For example, start with keywords such as translate, tell me, etc.:

Translate: Prompt Engineering?

Tell me the definition of "Prompt Engineering"?

In this mode, AI can help me complete tasks such as sentence completion, text translation, text summary, question and answer, and dialogue. This is the most commonly used Prompt mode.

  1. Instruction Template
    In this mode, we provide some explicit instructions to the model, and the model needs to generate text based on these instructions. This mode is usually used to generate text that requires clear instructions, such as technical specifications and operating manuals. Instructions can be a single sentence or multiple paragraphs, depending on the requirements of the task.

In this mode, you can let AI specifically understand what you want:

For example, to ask AI to recommend three Chinese science fiction novels, you can write like this

Recommend three Chinese science fiction novels to me:

Recommended format: 1. Book title: 2. Author: 3. Main content: 4. Reason for recommendation:

In this mode, you can also put a paragraph according to the template you gave and let AI help you summarize it. It can also be an example where you give the AI ​​some answers, and the AI ​​gives its answers through learning.

  1. Proxy mode (By proxy)
    Proxy mode means that users can ask ChatGPT to act as a specific person, role or object with a specific identity, role or identity to generate answers. This mode is usually used to simulate the language style and context of a specific character and generate dialogue, answers or other forms of text in a specific situation.

This mode is also quite commonly used. Some time ago, everyone asked chatGPT to write comments using the agency mode. For example, when describing the different identities of primary school students, college students, and the elderly in autumn, the content is very different, but the identity and role of the AI ​​are still very accurate. Therefore, it is important to tell who you are before asking questions.

  1. Example mode (By demonstration)
    In this mode, we provide some example text to the model, and the model needs to generate text similar to the example text. This mode is often used to generate text similar to a given example, such as automatically generating emails, product descriptions, news articles, etc. Sample text can be a single sentence or multiple paragraphs, depending on the requirements of the task.

What can AI help programmers do?

Summary of technical knowledge

When you first start learning a technology, you will inevitably need to check the documentation. There are so many manuals out there these days. Often, for a beginner, there is too much information to be exposed and there are various types of formats, making learning confusing.

At this time, you can use the summary ability of ChatGPT. For example, if I want to learn some knowledge about K8S, I send it the address of a document and let it summarize it for me.

prompt: https://kubernetes.io/zh-cn/docs/concepts/overview/ 总结这篇文档。

Insert image description here
As you can see, it summarizes this Chinese document very well and summarizes every key point. Use the least amount of language to understand the knowledge you want.

Because ChatGPT is contextual, it knows that the content you need is a Chinese summary, so if you continue to send it an English document here, it will also summarize it for you in Chinese.

prompt: 总结这篇文档https://kubernetes.io/docs/concepts/overview/components/ 。

Insert image description here
The current deadline for the free version of chatgpt's database is 2021, which means that if you ask it about newer content, it will not be able to summarize it, and it will even compile it at will. For example, here is a question about the movie "The Wandering Earth 2" and let it summarize the introduction in Wikipedia.

prompt: 总结:https://zh.wikipedia.org/zh/%E6%B5%81%E6%B5%AA%E5%9C%B0%E7%90%832

Insert image description here
Because the movie had not yet been released at this time, the previous content was still wrong, and its summary was inaccurate.

When we copy in the entire site content, let chatgpt summarize it. But at this time, you will find that the article is too long and you will receive an error.
Insert image description here
At this time, you need to use your imagination and use prompt to make a breakthrough. We need to split the article into paragraphs, and each paragraph meets its standards.
Insert image description here
Split the content into 7 paragraphs and it will be automatically summarized after sending.
Insert image description here
In this way, we can get a correct summary of a document.

disassembly task

What is described above can be regarded as using AI to improve the efficiency of programmers' daily life. So how can AI help us improve efficiency at work?

After we obtain a requirement from the demand side, in many cases our tasks cannot be estimated very accurately. The reason is that we have not divided the tasks clearly, so we cannot estimate each task, leading to risks. occur.

At this time, we can briefly describe our needs this time and let ChatGPT help us dismantle the task.
Insert image description here
You can see that the overall task has been broken down into small tasks. It can quickly allow us to convert tasks into tasks or demand tracking orders. This not only facilitates communication with the product manager, but also facilitates our own scheduling. Switching to KANBAN mode also makes it easier to understand current progress.

If the other party still has questions, you can continue to ask for dismantling. For example, we want to ask how the third step should be further implemented. You can see that it even gives us concrete UI interactions. We can use such prompts to provide a certain reference for our interactions and implementations.
Insert image description here

Read code/optimize code

Developers often take over other people's code. The quality varies, and there are also a lot of strange names. When we read the overall logic or modify the logic, we may have misunderstandings due to our own reading problems, which may further lead to bugs.

What if this method is handed over to AI for reading? You can see the effect.

prompt:

逐行解释下面的代码 + 代码内容, (在这里使用了一段在 github上面的开源代码进行展示, 这段代码是一段定时器相关的内容)。

Insert image description here
You can see that ChatGPT correctly understood our code and explained and explained the code.

But at this time, only an overall description was generated, and each line was not explained separately. Now continue talking to it:

prompt:

可以在每一行代码上面加上注释,便于我理解吗?

Insert image description here
At this time, it will annotate the code line by line to facilitate your understanding of each line. If you then make a crude optimization request to it, it will do the same.

prompt: 这段代码可以进行重构和优化吗?逻辑有些繁琐。

Insert image description here
You can put forward more detailed requirements for a certain part and propose better optimization directions for it. Here we raised the issue of parameter order coupling. We can see that GPT also understood our needs and made corresponding optimizations, as follows:

prompt: 
children: (isCounting: boolean, durationTime: number, startCount: () => void) => React.ReactNode // 子组件,接收三个参数,返回一个React节点这里面的参数太多了,而且对顺序有强依赖,该怎么优化这里?

Insert image description here

code generation

There is another scenario where developers have a relatively large workload at work and require complex logical thinking. But in reality the final code may only take a few lines to complete. You feel very painful during the thinking process and want to communicate with your colleagues around you. Maybe after you explained the logic to him, instead of helping you think about it, he turned the pain for one person into two people.

For example, if we want to perform data conversion, can we also leave it to AI? We send a prompt like this to GPT to convert the data structure. The data source is:

[
    {
    
    
        "candidates": null,
        "candidatesX": null,
        "description": "role---用户角色",
        "label": "角色",
        "name": "role",
        "optional": true,
        "schema": null,
        "type": "String"
    },
{
    
    
        "candidates": null,
        "candidatesX": null,
        "description": "Topics of the pulsar server to create---需要创建的主题",
        "items": {
    
    
            "schema": [
                {
    
    
                    "candidates": null,
                    "candidatesX": null,
                    "description": "topic name---主题名称",
                    "label": "主题名称",
                    "name": "name",
                    "schema": null,
                    "type": "String"
                },
                {
    
    
                    "candidates": null,
                    "candidatesX": null,
                    "default": 1,
                    "description": "partition number---分区数",
                    "label": "分区数",
                    "name": "partitions",
                    "schema": null,
                    "type": "Integer",
                    "validator": ">0"
                }
            ],
            "type": "Object"
        },
        "label": "主题列表",
        "name": "topics",
        "optional": true,
        "schema": null,
        "type": "List"
    }]
我想要得到的数据是 type 为 List 的数据,并且数据结构为:
[
{
    
    type:List, name:"topics", needValidates:[{
    
    
    name:"name", type:"String"
},{
    
    name:"partitions", type:"Integer"}] }]

GPT will get the correct result for us:
Insert image description here
We only need to enter the target data structure and the transformed data structure without specifying the language. Because it will understand from your context what implementation method you want to ask.

There is also an execution script. We only need to describe our needs clearly, and it will also help us improve it.
Insert image description here
In addition, it can also be explained:
Insert image description here
As you can see above, we have used a "natural language programming" operation process here. Regardless of whether you can use python or bash, you can describe your needs normally. to generate.

We can also perform code conversion. For example, if you write a piece of js code and you want to convert this code into python, we used to search on Google to see if there is a corresponding converter. Now we only need to hand it over to gpt for execution. Put forward your request, and it will generate a code without bugs and including exception handling for you within 10 seconds. We will not give examples here.

Generate single test

The data conversion code we just used, if we want to test it. In the past, we might have thought hard about many scenes to add. Now I just need to tell the AI ​​to generate a single test for me.

prompt:

(代码内容) 为这段代码生成 unit test。

Insert image description here
If you feel that the test conditions are not enough, then ask it again and let it generate again.

prompt: 数据源不够丰富,多测试集中边界条件,比如数据不存在,数据类型无法转换,数据类型不对等。

Insert image description here
It will also explain to you what is done here. These test cases cover different scenarios, including:

When there is no field of type List in the data source, an empty array should be returned; when there is a field of type List in the data source, the correct field array, including required validation, should be returned.

More AI apps/plug-ins

AI is like a basic application, and there are many possibilities on it. The more you use it, the more skills you unlock. For example, the GPT series has even launched its own application market. Let’s briefly introduce some popular plug-ins for you:

  • AIPRM
    It is an app store in the ChatGPT3.5 era. Users train it through different prompts to achieve their own goals.

For example, the "long article summary" capability we introduced at the beginning of the article: if we communicate with it normally, the word limit will become a bottleneck. But if we transform our communication skills, we can break through this limitation. AIPRM is a plug-in system full of whimsical ideas, where you can find/publish various prompts you want.
Insert image description here

  • Voice Control for ChatGPT
    Relying on such a system, we can use it to practice English (pseudo demand). Or you can directly talk to it using voice and let it write code for you. For example, all the script instructions we just mentioned can be directly sent out by voice-to-text.

It also serves some visually impaired people well because it also reads out the content generated by each GPT. Let everyone have equal access to AI.
Insert image description here

  • ChatGPT Sidebar
    As more and more people use it, the response speed of ChatGPT becomes slower and slower. Sometimes I just want to ask a simple question, but I have to wait for a long time. At this time, you can use the ChatGPT Sidebar plug-in.

It has built-in ChatGPT API, which can be directly integrated into your search engine. It will be triggered every time you search (it can also be set to manual). It requires no registration and is easy to use. You can also let it prompt you how to search for related keywords.
Insert image description here
In its sidebar, we can also perform other operations.
Insert image description here

  • Experience using famous application tools: Bing Copilot, ChatGPT, Google Bard
    Then let’s look back at a few more influential AI tools. There are about three basic AI tools that the author currently uses, namely Bing Copilot, ChatGPT, and Google Bard. The most widely used ChatGPT (GPT3-5), let’s first take a look at its self-introduction.

ChatGPT: the most frequently used AI. It has powerful context and can be split into different conversations to facilitate it to handle different conversations.

For example, a console project can have a separate conversation, so that the context of the conversation is centered around this topic, and there is no need to add contextual information for each new question and answer.
Insert image description here
Bing: Bing used GPT-4 very early, but because the number of conversations was too small (expanded from 5 to 15), the length of each conversation was also very limited. (It is still only 2000 words so far) And the conversation context cannot be saved, which makes it very inconvenient to use. The advantage is that it is connected to the Internet in real time, so the author mainly uses it to search for the latest information and summarize some articles and documents, as well as assist in the use of ChatGPT to compare whether the logic generated by the two times is consistent. The advantage is that the search results will give detailed sources and citation addresses.
Insert image description here
Google Bard (LaMDA): The AI ​​tool recently released by Google currently only supports English. The characteristic is that it can give multiple answers and respond quickly. Integrated with Google it, after clicking it, it will help you generate a Google search keyword that is most suitable for your problem. This is the opposite of Bing Copilot. One is to integrate chat into search, and the other is to integrate search into chat.
Insert image description here

What can AI help others do?

Judging from the situation around me, there are more primary applications for computers, such as automated office applications such as Excel, Word documents, and PPT, which help people automate management and optimization of attendance, salary, etc.

Office Automation (OA for short) is a new office method that combines modern office and computer technology. There is no unified definition of office automation. Anyone who uses various new technologies, new machines, and new equipment to engage in office business in traditional offices belongs to the field of office automation. By realizing office automation, or digital office, the existing management organizational structure can be optimized, the management system can be adjusted, and on the basis of improving efficiency, collaborative office capabilities can be increased and the consistency of decision-making can be strengthened.

In terms of usage scenarios, there are copywriting modification, data collection, data collaboration, data storage, data processing, data visualization, statistical analysis, chart production, approval process, application production, etc.; in terms of types, it is also quite diverse, such as traditional Excel , WPS, Word, PPT, Photoshop, Seafile, etc. are relatively basic office software or office automation software, and can even be further subdivided; for example, Enterprise WeChat and DingTalk are relatively mainstream corporate communication and office tools, which can help companies work efficiently. and management, which is an ecological office platform. But no matter what kind of software it is, the purpose is to effectively solve work problems, save resources, and improve work efficiency and management effectiveness. It can even be very closely integrated with an enterprise's business, such as customized software and personalized applications. Just click a button to get the desired results. Having said that, software is just a tool, and the key depends on people to use it. The depth of enterprise application depends on the importance of the enterprise, as well as the supporting management system guarantee and the service capabilities of the supplier. Both are indispensable. Generally speaking, office automation software with the following characteristics is more popular among enterprises and users:

  • Flexible customization
  • Foolish operation
  • Performance requirements
  • Easy to maintain
  • High cost performance

Ability to record multivariate data in tables in a standardized and convenient manner

SeaTable supports up to 24 data types. It can not only record basic data such as text, numbers, and dates, but also can record files, pictures, long text, single selection, multiple selection, check, geographical location, rating, email, and URL. , creator, creation time, modifier, modification time, etc. You can also use buttons, formulas, links to other records, and link calculations to achieve interactive office, same-table calculation, cross-table association and calculation, etc. Easier and more convenient than Excel.
Insert image description here
Insert image description here

The data collection, reporting, and collaboration functions are flexible and can meet a variety of scenarios.

Insert image description here
Insert image description here
Insert image description here

Data visualization and statistical analysis are simple and practical

Insert image description here
Insert image description here
Insert image description here

Supports automated reminders and automated rules, making office automation easy and efficient

Insert image description here

Various approval processes and task transfer processes can be customized to automate and integrate workflow management.

Insert image description here
Insert image description here

Prompt Engineering Prospects and Challenges

Prompt Engineering is an emerging and interesting field that provides more possibilities and flexibility for the application of artificial intelligence. As large language models continue to advance, we can expect more surprises and innovations.

But Prompt Engineering also faces some challenges and limitations, such as:

How to evaluate the quality and effectiveness of prompts?

How to automate or semi-automate prompt generation and optimization?

How to ensure the safety and ethics of prompt?

How to adapt to different languages, fields, scenarios, users and other factors?

These issues require our continuous exploration and research to improve the level and value of Prompt Engineering.

postscript

Prompt Engineering is a technology in the field of artificial intelligence, especially natural language processing. It refers to how to design input data so that it can clearly describe the task and guide the model to give correct and reasonable output. Prompt Engineering needs to combine creativity and logical thinking to design the optimal prompt. This is the value of Prompt Engineer.

For almost everyone who takes introductory computer courses, the two words "hello world" in the question picture are the first words that everyone uses computer language to communicate with machines. However, with the timely development and popularization of AI, everyone You can directly use the simplest and most natural words to let AI tell you how to let the machine execute and output "hello world".

Reprinted from:https://blog.csdn.net/u014727709/article/details/133977517
Welcome to start, welcome to comment, welcome Correction

Guess you like

Origin blog.csdn.net/u014727709/article/details/133977517