[LLM Prompt Engineering For Developers] 세미나 – 서문 이후
18장. General guidelines and best practices
18.1: Introduction
Creating the perfect prompt for an LLM
involves several key factors
that can help you obtain relevant and useful responses from the language model.
Below are some tips for crafting an effective prompt. Please note that we will be using the gpt-3.5-turbo model in the examples below
because it is optimized for interactivity and context-sensitivity.
18.2: Start with an action verb
Instead of using generic phrases like “Can you,” start your prompt with action verbs such as “Create,” “Write,” “Make,” or “Generate.” This helps to give clear instructions to the model. For example: “Create 10 article ideas for my meditation and wellness website.”
18.3: Provide a clear context
Give enough context to your question or problem so that the model can generate
a relevant response. Include relevant details, background information, or specific
requirements.
Provide a clear context
Give enough context to your question or problem so that the model can generate a relevant response. Include relevant details, background information, or specific requirements.
Ask the model to play the role of a specific expert or professional. This helps to tailor the response to your needs.
Where and How Prompt Engineering is Used
Prompt engineering is used in many applications, including:
• Creative writing
• Content generation
• Customer service
• Data analysis
• Academic research
• Language translation
• Natural language interfaces
• Educational applications
• Marketing and advertising
• Virtual assistants and smart devices
• Game development
• Healthcare and medical research
• Story generation and role-playing
• Business intelligence and analytics
• Language tutoring and learning
• Image generation
• And more
Its focus is on creating and optimizing instructions given to a language model, such
as ChatGPT.
To be effective, prompt engineering requires an understanding of the underlying
model, as well as an analysis of the training data to identify potential biases. By
adjusting the instructions and model parameters, prompt engineers can shape the
behavior of AI to more accurately meet user needs and produce more consistent
and reliable results.
자연어로 프로그래밍 한다. llm에서 돌아가는.
llm은 이름 대로 거대 언어 데이터로 훈련된 모델이다. 거대하다는 것은 가진 게 많다는 것. 가진 게 많으니 잘 지시 안내하지 않으면 뱉어낼 게 많다는 것.
These models were trained on large amounts of text data and were able to generate coherent and contextually relevant responses.
A “prompt” refers to a text input that is provided to a language model with the goal of generating a response or output.
The prompt acts like a trigger for the language model. By receiving the prompt, the model uses its knowledge and internal structure to
generate an appropriate response.
Basically, the model, always try to provide a completion to the prompt based on the prompt itself, the context of the conversation, the knowledge it has learned from the training data and the probability of the next word. For each token in the input, the model calculates the probability distribution of what the next token should be. It assigns higher probabilities to tokens that are more likely to follow the context given. The model then generates text by selecting the token with the highest probability as the next word. This process is repeated until the desired length or completion is reached.
To provide a better context, adding another element to the list with the name of a tech brand will help AI understand that the user wants to get a list of tech brands and not fruits.
Prompts can be used in a conversational setting.
Prompts can also include instructions for the model.
GPT learns patterns and structures in text data.
The model is trained on a large dataset of text, such as books, articles, and websites. It learns the statistical relationships between words and the context in which they appear. Using its data the model looks for patterns and tries to predict the most likely word to come next based on the input it has received.
To generate words, the model uses a technique called “probability sampling.” It assigns probabilities to different words based on their likelihood to appear in a given context. The model then selects the word with the highest probability or samples from a distribution of likely words based on parameters like temperature or top-p.
코파일럿은 사용자의 요청에 따라 다양한 대화 스타일을 적용할 수 있습니다. 창의적인, 균형잡힌, 또는 정밀한 스타일을 선택할 때, temperature 설정은 0.7 정도로 유지하는 것이 좋습니다. 이 설정은 적절한 창의성과 정확성을 유지하면서도 너무 무작위한 응답을 피할 수 있도록 도와줍니다.
예를 들어, temperature가 0.6이라면, AI는 상대적으로 안정적이고 예측 가능한 응답을 생성하는 반면, temperature를 0.9로 설정하면 더 창의적이고 예상치 못한 응답을 생성할 수 있습니다. 그러나 너무 높은 temperature는 때때로 덜 관련성 있는 결과를 초래할 수 있으므로, 균형잡힌 스타일을 위해서는 중간 범위의 값을 선택하는 것이 좋습니다.
“top-p” 매개변수, 또는 “nucleus sampling”은 GPT와 같은 텍스트 생성 모델에서 생성된 응답의 다양성을 제어하는 기술입니다. 이 기술은 가장 가능성이 높은 단어들 중에서 선택하면서도, 누적 확률이 특정 임계값을 초과하는 단어들의 부분집합에 대한 선택을 제한합니다. 예를 들어, top-p가 0.1로 설정되면, GPT-3는 다음 토큰에 대해 상위 10%의 확률 질량을 구성하는 토큰만을 고려합니다1.
이 방법은 모델이 더 예측 가능하고 일관된 출력을 생성하는 것과 동시에, 너무 무작위적이거나 관련성이 없는 단어를 배제함으로써, 품질 있는 텍스트를 생성할 수 있도록 돕습니다. top-p 샘플링은 텍스트 생성에서 중요한 역할을 하며, 사용자가 원하는 결과에 따라 적절한 매개변수 값을 설정할 수 있습니다.
실제로 GPT 모델을 사용하여 주어진 문맥에서 단어 시퀀스를 생성할 때, “top-p” 매개변수는 누적 확률이 정의된 임계값에 도달할 때까지 가장 가능성이 높은 단어들을 선택하는 데 사용됩니다. 이 방법으로, 그 지점까지 가장 가능성이 높은 단어들만 고려되며, 선택의 폭을 줄이고 생성된 응답에 다양성을 도입합니다1.
예를 들어, top-p가 0.9로 설정되어 있다면, 모델은 누적 확률이 0.9를 초과할 때까지의 가장 가능성이 높은 단어들을 고려합니다. 이는 모델이 더 일관되고 문맥에 맞는 응답을 생성하도록 돕는 동시에, 너무 예측 가능하거나 반복적인 단어들을 배제함으로써 응답의 품질을 향상시킵니다.
the “top-p” parameter helped generate a more focused response by using only the most probable words, while still maintaining some variety in the generated response. It is recommended not to use top-p together with temperature and choose one or the other.
the insertion mode is used to insert text into an existing document and this is an example of a prompt for the insertion mode:
As the sun set, [insert] with a touch of enchantment. The prompt is incomplete and the model will complete it by generating the missing
part. The result will be a complete sentence that makes sense in the context of the prompt.
As the sun set, [insert] with a touch of enchantment. The prompt is incomplete and the model will complete it by generating the missing
part. The result will be a complete sentence that makes sense in the context of the prompt.
The list of things I should not buy at the grocery store:
1.
If you want to have only 5 items in the list, you can use the “stop” parameter to stop the generation after the 6th item. You should set the “stop” parameter to “6.” (note the dot at the end).
Instructions can be used to perform various operations on the text. For example, you can use instructions to delete, replace or insert text and even to change the formatting of the text or translate it into another language. Input: I have 2 apples and 3 oranges. My friend has 1 apple and 2 orang\ es. User: Format the input as a JSON object
Few-shot learning, sometimes referred to as low-shot learning, is a method that allows models to make accurate predictions with only a few examples, reducing data collection and computation efforts and costs.
“Let’s think step by step” to guide the model’s thinking. The second involves manually creating demonstrations that show a question and its step-by-step reasoning. While the second approach performs better, it relies heavily on crafting these demonstrations by hand.