Why is it that engineering can harness large models?

Exploring key skills in the era of artificial intelligence - Prompt Engineering
Core content:
1. The rise of prompt engineering and industry needs
2. The principle of interaction between prompts and large models
3. Techniques to improve the output quality of large models
Today we are going to focus on a very critical field in the era of big models of artificial intelligence: prompt engineering . There is now a special position called "prompt engineer", which shows how popular this skill is in the industry. Some domestic companies pay prompt engineers almost the same salary as software development engineers, with an annual salary of 200,000 to 300,000 RMB; while overseas, some senior prompt engineers even earn more than 300,000 US dollars. This phenomenon of exceeding the salary of general software development positions has surprised many people. What is the reason why prompt engineers are so popular? To solve this mystery, we must first know what "prompt" is, and then understand what "prompt engineering" is.
1. What is the prompt?
You may ask: When we use big models in our daily lives, aren’t we just “asking questions” and getting “answers”? Where can we see any “prompts”? In fact, if you read OpenAI’s official documents, you will find that the words “question and answer” are almost invisible in the documents. Instead, they are replaced by “prompt” and “completion”, which translates to “prompt” and “completion”. In other words, when we input a question into the big model, we are actually giving the model a “prompt”, and the part of the text it generates is called “completion”.
The reason for this name is closely related to the training principle of large models. Models such as GPT are mostly based on the decoder mechanism in the Transformer architecture, and use autoregressive unsupervised pre-training methods to "memorize" massive amounts of text. Simply put, after the model has been trained on massive amounts of text, it will make probabilistic inferences about the input "prompts" and generate the most likely subsequent texts in sequence - this forms the answers we usually see.
The big model calculates the probability every time it outputs a word (or a token), so the generation speed is relatively slow. It can be seen that "prompts" are the most important communication bridge when we interact with the big model , and it is also the basis for the existence of prompt engineering.
2. What is the prompt project?
I believe that many people were impressed by ChatGPT's amazing performance when they used it for the first time, and even felt that it could "read" people's emotions. However, when they used it again the next day, they often felt that the answers it generated were not as rich as they imagined, and even seemed a bit repetitive and lacked novelty.
This gap may be due to poor instructions . Most people give too brief instructions to large models, such as:
Tip 1: “Give me an outline for this PowerPoint presentation.” Tip 2: “Help me write the background for a patent application.” Tip three: "Generate a journal."
Take [Tip 1] for example. Imagine that you have a secretary named Xiao Li and you want him to help you make a PPT. Your conversation should generally go like this:
??: Xiao Li, please help me write a PPT.
?: Boss, what content does your PPT need and what will it be used for?
??:I will visit customers tomorrow and show them our new products.
?: Do you need a brief introduction or a detailed introduction? Do you need to include other content besides the product?
??: Just give a brief introduction. In addition to the product introduction, include some customer cases.
?: OK, boss, what style of PPT do you need?
??: Something with a more technological feel.
?:Okay, boss.
However, if you think of the big model as your "virtual employee" or secretary, you will find that if you want it to output results that meet your needs, you must first state the needs clearly and in detail. A high-quality prompt usually specifies the task scenario, goals, examples, roles, style, and other information, so that the model can "understand" what you want as much as possible.
Normally, you need to describe the content of your PPT in detail to Xiao Li so that Xiao Li can make a PPT that meets your requirements as accurately as possible. In fact, the above conversation is not detailed enough. As expected, after Xiao Li sends you the first draft, you will make some suggestions and revise it again, sometimes even for multiple rounds.
If we regard the big model as Secretary Xiao Li, then the tips we give him should not be simple sentences, but should describe the requirements as clearly as possible. The more detailed and accurate the requirements description is, the more the output of the big model will meet your requirements. So a good tip contains a lot of information, which helps you and the big model understand each other, so it is complex and standardized, similar to how people get along with each other. Only by understanding each other can we cooperate happily and efficiently.
Therefore, prompt engineering is an emerging discipline that studies how to design the best prompts to enable language models to complete specific tasks more efficiently. It not only includes the writing and iteration of prompts, but also involves how to connect with large models, understand the limitations and potential of large models, and use them to complete various tasks. In other words, if the large model is regarded as a highly intelligent "all-round employee", then prompt engineering is how to train yourself to have the ability to "lead it to do things", which is what we call "AI leadership".
3. What is AI leadership?
Anyone who has managed a team knows that "leadership" is extremely important for a manager. With the development of AI big models, we actually have a "virtual employee" in our hands - it theoretically has a vast amount of knowledge and good understanding, but whether it can achieve outstanding performance depends on how you lead it.
Are you sure you can manage an employee with an IQ of 140+ and who has stored most of the world's public information? Although this question sounds scary, the solution is simple - we need to improve our AI leadership . In the process of dealing with AI, prompts are the only communication medium. Only by mastering the prompting skills can we maximize the potential of this "virtual employee".
4. How to construct good prompts?
To get satisfactory output results, there are usually two ways:
Multi-round interaction : First give relatively simple prompts, and then gradually adjust the model output based on multiple conversations. Get it right the first time : Get the context, requirements, and specific details across in the first entry.
I prefer the second one because: if you write it all at once, the model will understand the context more directly and clearly. Based on practical experience, you can use the following "little formula" to conceive a good prompt, which mainly includes the following modules:
Task module : Use simple and clear verbs or sentences to express your goals and expected outputs. Context module : Provides sufficient background information to describe clear usage scenarios and requirement boundaries. Example module : Give examples or display formats to let the model know the style or framework required for output. Role module : describes what role the model should "play", such as technical expert, consultant or coach. Format module : specifies the required output format, such as table, email, list, code snippet, word limit, etc. Tone module : Specify the tone or style you want your output to be, casual, fun, or formal and professional?
The priority of these modules is usually: Task > Context > Example > Role > Format > Tone. A high-quality prompt does not necessarily have to include all of them, but at least "Task" and "Context" are essential.
Take a development scenario as an example: If you want the big model to help generate sample code for a user login module, you can write it like this:
❝You are a software development engineer. Please use Java language to write a login module and generate related codes.
We specified the role of software development engineer for the model and specified that a login module be written in Java. The following are the results returned by ChatGPT3.5.
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class LoginModule {
private Map<String, String> userDatabase;
public LoginModule () {
// Initialize the user database. In actual applications, you will usually connect to the database.
userDatabase = new HashMap<>();
userDatabase.put( "user1" , "password1" );
userDatabase.put( "user2" , "password2" );
// Add more users...
}
public boolean authenticateUser (String username, String password) {
// In actual applications, this usually connects to the database to verify whether the username and password match
String storedPassword = userDatabase.get(username);
return storedPassword != null && storedPassword.equals(password);
}
public static void main (String[] args) {
LoginModule loginModule = new LoginModule();
Scanner scanner = new Scanner(System.in);
System.out.print( "Please enter your username: " );
String username = scanner.nextLine();
System.out.print( "Please enter your password: " );
String password = scanner.nextLine();
if (loginModule.authenticateUser(username, password)) {
System.out.println( "Login successful!" );
} else {
System.out.println( "Login failed, wrong username or password!" );
}
scanner.close();
}
}
It can be seen that this is not the code we want, because generally what we need is a web page login, and the above result is a console program, so we will modify the prompt.
❝You are a software development engineer. Please use Java language to write a web login module. Please use SpringBoot framework and ReactJS language for the front end. Passwords must be encrypted with MD5. Step 1: The user enters the username and password on the page and clicks Login. Step 2: The server interface receives the request and verifies that the parameters are not empty. Step 3: Verify by querying the database for username and password. Please generate relevant code.
This time we not only specified the roles, but also the generation steps for the tasks, and of course the model output was more detailed.
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping ( "/api" )
public class UserController {
@PostMapping ( "/login" )
public String login (@RequestBody UserLoginRequest request) {
// Step 2: Non-empty verification
if (request.getUsername() == null || request.getPassword() == null ) {
return "Username and password cannot be empty" ;
}
// Step 3: Database verification
if (isValidUser(request.getUsername(), request.getPassword())) {
return "Login successful" ;
} else {
return "Incorrect username or password" ;
}
}
private boolean isValidUser (String username, String password) {
// Here you should call the method to query the database for user information and verify the username and password
// In actual projects, passwords should not be stored as plain text, but should be stored and compared using a hash algorithm
// This is just for demonstration, a safer method should be used in practice
return "admin" .equals(username) && "21232f297a57a5a743894a0e4a801fc3" .equals(md5(password));
}
private String md5 (String input) {
// Here is a simple MD5 encryption example. A more secure encryption method should be used in actual projects.
// Note: MD5 is not a secure encryption algorithm and is only used for demonstration
// In actual projects, more secure hash algorithms should be used, such as BCrypt
// You can use libraries such as Spring Security to securely process passwords
return org.apache.commons.codec.digest.DigestUtils.md5Hex(input);
}
}
UserController is added and the RESTful interface is defined, but the database connection part is still prompted by comments and is not generated. We can continue to optimize the prompts.
❝You are a software development engineer. Please generate a web user login module. The front end uses ReactJS+CSS+HTML for page layout and HTTP request. The back end uses Java+SpringBoot+MyBatis framework and Maven for dependency package management. The password is required to be encrypted with MD5, and the specific database connection code is generated. Please follow the steps below to generate the code. Step 1: The user enters the username and password on the page and clicks Login. Step 2: The front end initiates an HTTP request, the server interface receives the request, and verifies that the parameters are not empty. Step 3: Verify by querying the username and password through the database. Please generate the relevant code.
After we ask this question, we have basically all the necessary codes, including the database connection and the front-end page code. This is a simple example. It should be noted that different big models have different implementation mechanisms and configurations. You need to debug continuously to find the right way to communicate and interact with the big model and finally build the most appropriate prompt.
5. Universal tool: Use prompts to generate prompts
There is a particularly interesting method, which is to let ChatGPT write "prompts" for you, that is, use prompts to generate better prompts . You can try to tell ChatGPT in the conversation:
❝"I want you to be my prompt engineer. Our goal is to work together to hone the most appropriate prompt. You ask me what needs to be done, I answer, and then you give the improved prompt plan and questions that need to be supplemented. We iterate repeatedly until I feel it is done."
View: https://chatgpt.com/share/67d6e2f6-9f70-8001-b4f9-345ec14822e8
The power of this tool lies in that as long as we don’t call a stop, it will keep asking, and the prompts can be adjusted very perfectly. After this step, I took the initiative to call a stop.
Through this kind of self-questioning and self-answering guidance, we can continuously improve the prompts, make the requirements more and more clear, and finally come up with a very perfect prompt solution. This method is particularly powerful. For novices or those who are not yet proficient in requirements description, it can greatly improve efficiency and reduce the repetition when communicating with large models.
6. Words to Software Engineers
Artificial intelligence is evolving at an unimaginable speed. For many software engineers, this means that in the near future, the focus of programming may shift from "writing code" to "writing prompts." In other words, we are very likely to usher in a major change in software development from "code thinking" to "prompt thinking" within five years. The various source codes we store in GitHub or code repositories today may be replaced by various "prompt libraries" in the future.
Currently, the workflow of software developers is:
Analyze requirements Writing Code Testing and Iteration The future “prompt engineers” will likely adopt a similar but distinct model: Analyze requirements Design Tips Although the outputs of iterative large models are essentially solving problems, the implementation method will be completely different from today.