Amazon Bedrock LLM 사용자를 위한 일반 지침 - Amazon Bedrock

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Bedrock LLM 사용자를 위한 일반 지침

프롬프트 설계

적절한 프롬프트를 설계하는 것은 Amazon Bedrock 모델을 사용하여 성공적인 애플리케이션을 빌드하기 위한 중요한 단계입니다. 다음 그림에서는 '음식점 리뷰 요약'이라는 사용 사례를 위한 일반적인 프롬프트 설계를 보여주고, 고객이 프롬프트를 설계할 때 고려해야 하는 몇 가지 중요한 설계 선택 항목을 보여줍니다. 제공된 명령이나 프롬프트 형식이 일관되지 않고, 명확하지 않고, 간결하지 않은 경우 LLM은 원치 않는 응답을 생성합니다.

설명이 포함된 올바른 프롬프트 구성의 예.

(출처: 프롬프트 작성 AWS)

추론 파라미터 사용

Amazon Bedrock의 모든 LLM은 모델의 응답을 제어하도록 설정할 수 있는 여러 추론 파라미터와 함께 제공됩니다. 아래에는 Amazon Bedrock LLM에서 사용할 수 있는 모든 일반 추론 파라미터 목록과 이를 사용하는 방법이 나와 있습니다.

온도는 0에서 1 사이의 값이며, LLM 응답의 창의성을 조절합니다. Amazon Bedrock의 LLM에서 동일한 프롬프트에 대해 더 결정론적인 응답을 원하면 낮은 온도를 사용하고, 좀 더 창의적이거나 다른 응답을 원한다면 더 높은 온도를 사용합니다. 이 프롬프트 지침의 모든 예제에서는 온도를 temperature = 0으로 설정했습니다.

최대 생성 길이/최대 신규 토큰 수는 LLM이 프롬프트에 대해 생성하는 토큰 수를 제한합니다. 감정 분류와 같은 일부 태스크에는 긴 답변이 필요하지 않으므로, 이 수를 지정하는 것이 좋습니다.

Top-p는 잠재적인 선택 항목의 확률에 따라 토큰 선택 항목을 제어합니다. Top-p를 1.0 미만으로 설정하면 모델은 확률이 가장 높은 옵션을 고려하고, 확률이 가장 낮은 옵션은 무시합니다. 따라서 더 안정적이고 반복적인 완성이 가능해집니다.

종료 토큰/종료 시퀀스는 LLM이 출력 종료를 나타내는 데 사용하는 토큰을 지정합니다. LLM이 종료 토큰을 발견하면 새 토큰 생성이 중단됩니다. 일반적으로 이 옵션은 사용자가 설정하지 않아도 됩니다.

모델별 추론 파라미터도 있습니다. AnthropicClaude모델에는 추가 Top-k 추론 파라미터가 있으며, AI21 Labs 쥬라기 모델에는 프레즌스 페널티, 카운트 페널티, 주파수 페널티, 특수 토큰 페널티를 포함한 추론 파라미터 세트가 함께 제공됩니다. 자세한 내용은 해당 설명서를 참조하세요.

세부 지침

간단하고 명확하며 완전한 명령 제공

Amazon Bedrock의 LLM은 간단하고 직관적인 명령을 사용했을 때 가장 잘 작동합니다. 태스크에 대한 기대치를 명확하게 설명하고 가능한 한 애매모호한 내용을 줄이면 모델이 프롬프트를 명확하게 해석하도록 보장할 수 있습니다.

예를 들어, 사용자가 여러 가지 선택 항목 중에서 한 가지 답을 얻고자 하는 분류 문제를 가정해 보겠습니다. 아래에 표시된 '올바른' 예제에서는 이러한 경우에 사용자가 원하는 결과를 보여줍니다. '잘못된' 예제에서는 선택 항목의 이름을 모델이 선택할 수 있는 명시적인 범주로 지정하지 않았습니다. 모델은 선택 항목 없이 입력값을 약간 다르게 해석하며, 올바른 예제와 달리 텍스트를 좀 더 자유로운 형식으로 요약합니다.

Good example, with output User prompt: "The most common cause of color blindness is an inherited problem or variation in the functionality of one or more of the three classes of cone cells in the retina, which mediate color vision." What is the above text about? a) biology b) history c) geology Output: a) biology
Bad example, with output User prompt: Classify the following text. "The most common cause of color blindness is an inherited problem or variation in the functionality of one or more of the three classes of cone cells in the retina, which mediate color vision."
Output: The topic of the text is the causes of colorblindness.

(프롬프트 출처: 색맹에 관한 위키백과, 사용 모델: Text G1 - Express) Titan

최상의 결과를 얻으려면 질문이나 명령을 프롬프트의 끝에 넣어야 함

마지막에 태스크 설명, 명령 또는 질문을 포함하면 모델이 찾아야 하는 정보를 결정하는 데 도움이 됩니다. 분류의 경우, 답변이 될 수 있는 선택 항목도 마지막에 나와야 합니다.

아래의 오픈북 질문-응답 예제에서 사용자는 텍스트에 대해 특정한 질문을 합니다. 질문이 프롬프트의 끝에 나와야 모델이 태스크에 계속 집중할 수 있습니다.

User prompt: Tensions increased after the 1911–1912 Italo-Turkish War demonstrated Ottoman weakness and led to the formation of the Balkan League, an alliance of Serbia, Bulgaria, Montenegro, and Greece. The League quickly overran most of the Ottomans' territory in the Balkans during the 1912–1913 First Balkan War, much to the surprise of outside observers. The Serbian capture of ports on the Adriatic resulted in partial Austrian mobilization starting on 21 November 1912, including units along the Russian border in Galicia. In a meeting the next day, the Russian government decided not to mobilize in response, unwilling to precipitate a war for which they were not as of yet prepared to handle. Which country captured ports?
Output: Serbia

(프롬프트 출처: 1차 세계대전에 관한 위키백과, 사용 모델: Amazon Titan Text)

API 호출에는 구분자 문자 사용

\n 기호와 같은 구분자 문자는 LLM의 성능에 상당한 영향을 미칠 수 있습니다. AnthropicClaude모델의 경우 원하는 응답을 얻으려면 API 호출 형식을 지정할 때 줄 바꿈을 포함해야 합니다. 형식은 항상 \n\nHuman: {{Query Content}}\n\nAssistant: 형식을 따라야 합니다. Titan모델의 경우 프롬프트 \n 끝에 추가하면 모델 성능을 개선하는 데 도움이 됩니다. 분류 작업이나 답변 옵션이 있는 질문의 경우 Titan 모델별로 \n 답변 옵션을 구분할 수도 있습니다. 구분자 사용에 대한 자세한 내용은 해당 모델 제공업체의 설명서를 참조하세요. 아래 예제는 분류 태스크의 템플릿입니다.

Prompt template: """{{Text}} {{Question}} {{Choice 1}} {{Choice 2}} {{Choice 3}}"""

다음 예제는 선택 항목 사이와 프롬프트 끝에 줄 바꿈 문자가 있으면 원하는 응답을 Titan 생성하는 데 어떻게 도움이 되는지 보여줍니다.

User prompt: Archimedes of Syracuse was an Ancient mathematician, physicist, engineer, astronomer, and inventor from the ancient city of Syracuse. Although few details of his life are known, he is regarded as one of the leading scientists in classical antiquity. What was Archimedes? Choose one of the options below. a) astronomer b) farmer c) sailor
Output: a) astronomer

(프롬프트 출처: 아르키메데스의 위키백과, 사용 모델: Amazon Titan Text)

출력 지표

모델이 생성해야 하는 출력값에 적용할 제약 조건에 대한 세부 정보를 추가합니다. 아래의 올바른 예제에서는 요약이 잘 된 짧은 문구의 출력값을 생성합니다. 이 사례의 잘못된 예제는 크게 잘못되진 않았지만, 요약 내용이 원본 텍스트와 거의 비슷합니다. 모델에서 원하는 결과를 얻으려면 출력값의 사양이 매우 중요합니다.

명확한 출력 제약 조건 지표가 있는 프롬프트의 예제
User prompt: "Charles Mingus Jr. was an American jazz upright bassist, pianist, composer, bandleader, and author. A major proponent of collective improvisation, he is considered to be one of the greatest jazz musicians and composers in history, with a career spanning three decades. Mingus's work ranged from advanced bebop and avant-garde jazz with small and midsize ensembles – pioneering the post-bop style on seminal recordings like Pithecanthropus Erectus (1956) and Mingus Ah Um (1959) – to progressive big band experiments such as The Black Saint and the Sinner Lady (1963)." Please summarize the above text in one phrase.
Output: Charles Mingus Jr. is considered one of the greatest jazz musicians of all time.
명확한 출력 사양이 없는 예제
User prompt: "Charles Mingus Jr. was an American jazz upright bassist, pianist, composer, bandleader, and author. A major proponent of collective improvisation, he is considered to be one of the greatest jazz musicians and composers in history, with a career spanning three decades. Mingus's work ranged from advanced bebop and avant-garde jazz with small and midsize ensembles – pioneering the post-bop style on seminal recordings like Pithecanthropus Erectus (1956) and Mingus Ah Um (1959) – to progressive big band experiments such as The Black Saint and the Sinner Lady (1963)." Please summarize the above text.
Output: Charles Mingus Jr. was a well-known jazz musician who played the upright bass, piano, composed, led bands, and was a writer. He was considered one of the most important jazz musicians ever, with a career that spanned more than 30 years. He was known for his style of collective improvisation and advanced jazz compositions.

(프롬프트 출처: 찰스 밍거스에 관한 위키백과, 사용 모델: Amazon Titan Text)

여기서는 출력 표시기를 사용한 AI21 Labs 쥬라기 모델의 몇 가지 추가 예를 제공합니다. Anthropic Claude

아래의 예제에서는 사용자가 프롬프트에서 예상 출력 형식을 지정하여 출력 형식을 지정할 수 있다는 걸 보여줍니다. 특정 형식(예: XML 태그 사용)을 사용하여 응답을 생성하라고 요청하면 모델은 그에 따라 응답을 생성할 수 있습니다. 구체적인 출력 형식 지표가 없으면 모델은 자유형 텍스트를 출력합니다.

명확한 지표가 있는 예제, 출력 포함
User prompt: Human: Extract names and years: the term machine learning was coined in 1959 by Arthur Samuel, an IBM employee and pioneer in the field of computer gaming and artificial intelligence. The synonym self-teaching computers was also used in this time period. Please generate answer in <name></name> and <year></year> tags. Assistant:
Output: <name>Arthur Samuel</name> <year>1959</year>
명확한 지표가 없는 예제, 출력 포함
User prompt: Human: Extract names and years: the term machine learning was coined in 1959 by Arthur Samuel, an IBM employee and pioneer in the field of computer gaming and artificial intelligence. The synonym self-teaching computers was also used in this time period. Assistant:
Output: Arthur Samuel - 1959

(프롬프트 출처: 기계 학습에 관한 Wikipedia, 사용된 모델:) Anthropic Claude

다음 예제는 AI21 Labs 쥬라기 모델의 프롬프트와 답변을 보여줍니다. 사용자는 왼쪽 열에 표시된 출력 형식을 지정하여 정확한 응답을 얻을 수 있습니다.

명확한 지표가 있는 예제, 출력 포함
User prompt: Context: The NFL was formed in 1920 as the American Professional Football Association (APFA) before renaming itself the National Football League for the 1922 season. After initially determining champions through end-of-season standings, a playoff system was implemented in 1933 that culminated with the NFL Championship Game until 1966. Following an agreement to merge the NFL with the rival American Football League (AFL), the Super Bowl was first held in 1967 to determine a champion between the best teams from the two leagues and has remained as the final game of each NFL season since the merger was completed in 1970. Question: Based on the above context, when was the first Super Bowl? Please only output the year.
Output: 1967
명확한 지표가 없는 예제, 출력 포함
User prompt: Context: The NFL was formed in 1920 as the American Professional Football Association (APFA) before renaming itself the National Football League for the 1922 season. After initially determining champions through end-of-season standings, a playoff system was implemented in 1933 that culminated with the NFL Championship Game until 1966. Following an agreement to merge the NFL with the rival American Football League (AFL), the Super Bowl was first held in 1967 to determine a champion between the best teams from the two leagues and has remained as the final game of each NFL season since the merger was completed in 1970. Question: Based on the above context, when was the first Super Bowl?
Output: The first Super Bowl was held in 1967.

(프롬프트 출처: 내셔널 풋볼 리그에 관한 위키백과, 사용 모델: AI21 Labs Jurassic-2 Ultra v1)

올바른 일반화를 위한 권장 사례

프롬프트 수정 사항이 일반화되는지 확인하려면 프롬프트의 작은 '홀드아웃' 테스트 세트를 유지합니다. 이 방법을 사용할 경우, 우선 샘플 데이터 세트를 수집합니다. 그런 다음, 데이터를 두 개의 하위 세트, 즉 '개발' 세트와 홀드아웃 '테스트' 세트로 분리할 수 있습니다. '개발' 세트를 프롬프트 개발 데이터로 사용하여 다양한 프롬프트 수정을 시도하고, 모델 응답 변경 사항을 관찰하여 가장 적합한 프롬프트를 찾을 수 있습니다. '테스트' 세트는 가장 적합한 최종 프롬프트를 검증하는 데만 사용할 수 있는 보이지 않는 홀드아웃 데이터로 취급합니다.

기본 기능만으로는 충분하지 않을 경우, Amazon Bedrock에서 텍스트 모델의 프롬프트를 최적화합니다.

복잡한 태스크: 단계별로 응답 구축

Titan특정 작업에 대한 명확한 단계를 제공할 수 있으며 문구를 포함하면 적절한 결과를 도출하는 데 도움이 될 Think step-by-step to come up with the right answer 수 있습니다.

User prompt: At a Halloween party, Jack gets 15 candies. Jack eats 5 candies. He wants to give each friend 5 candies. How many friends can receive candies? Think step-by-step to come up with the right answer.
Output: 15 candies total - 5 candies eaten = 10 candies remaining. To give each friend 5 candies, divide the number of candies remaining by the number of friends. 10 candies / 5 friends = 2 friends. Each friend can receive 2 candies. The answer is 2 friends.

(프롬프트 출처: AWS, 사용 모델: Amazon Titan Text)

AnthropicClaude모델이 복잡한 작업을 완료할 수 있도록 하려면 다음 예제의 형식을 사용하여 모델에게 작업을 단계별로 해결하도록 명시적으로 요청합니다. 이 접근 방식은 가이드의 AnthropicClaude 지침을 기반으로 합니다.

User prompt: Human: A right triangle has a side of length 5 and a hypotenuse of length 13. What is the length of the other side? Assistant: Can I think step-by-step? Human: Yes, please do. Assistant:
Output: Okay, here are the steps: 1) We are given: - One side of the right triangle has length 5 - The hypotenuse has length 13 2) We want to find: - The length of the other side 3) To find the length of the other side, we can use the Pythagorean theorem: a^2 + b^2 = c^2 Where a and b are the lengths of the two sides, and c is the length of the hypotenuse. 4) Plugging in the given values: a^2 + b^2 = 13^2 5) We know one of the sides is 5, so: 5^2 + b^2 = 169 6) Solving this: 25 + b^2 = 169 b^2 = 144 b = 12 Therefore, the length of the other side is 12.

(프롬프트 출처: AWS, 사용 모델: AnthropicClaude)

응답을 확신할 수 없는 경우 모델이 제시해야 하는 기본 출력값을 제공합니다.

기본 출력값은 LLM이 맞는 얘기인 것 같은 응답을 반환하는 걸 방지하는 데 도움이 될 수 있으며, 모델의 신뢰도가 낮더라도 효과가 있습니다.

User prompt: Provide a proof of the Riemann hypothesis. If you don't know a proof, respond by saying "I don't know."
Output: I don't know.
User prompt: Provide a proof of the Riemann hypothesis.
Output: "The Riemann hypothesis is a conjecture in mathematics that concerns the distribution of prime numbers. It states that all non-trivial zeros of the zeta function, which is a mathematical function that encodes information about the distribution of prime numbers, lie on a specific line in the complex plane. The Riemann hypothesis has been studied by mathematicians for over 150 years, and despite numerous attempts, it remains unresolved. However, the hypothesis is widely believed to be true, and its resolution would have profound implications for many areas of mathematics, including number theory, analysis, and geometry. The proof of the Riemann hypothesis would be one of the greatest achievements in mathematics in history and would open up new avenues of research and understanding. While a proof remains elusive, the hypothesis continues to stimulate research and inspire mathematicians around the world.“ [Note: this is an accurate description, but obviously not a proof.]

(프롬프트 출처: AWS, 사용 모델: Amazon Titan Text)

퓨샷 프롬프팅

프롬프트에 예제(입력-응답 쌍)를 포함하면 LLM의 응답을 크게 개선할 수 있습니다. 예제는 주어진 태스크를 수행할 수 있는 다양한 방법을 보여주므로, 복잡한 태스크에 도움이 될 수 있습니다. 텍스트 분류와 같은 간단한 태스크의 경우, 3~5가지 예제만 있어도 충분할 수 있습니다. 컨텍스트가 없는 질문-응답 같은 더 까다로운 태스크의 경우, 가장 효과적인 출력을 생성하려면 예제를 더 많이 포함합니다. 대부분의 사용 사례에서, 실제 데이터와 의미상으로 유사한 예제를 선택하면 성능을 더욱 개선할 수 있습니다.

한정자를 사용하여 프롬프트를 구체화하는 방법 고려

태스크 명령 구체화란 일반적으로 프롬프트의 명령, 태스크 또는 질문 구성 요소를 수정하는 것을 말합니다. 이러한 방법의 유용성은 태스크 및 데이터에 따라 다릅니다. 유용한 접근 방식은 다음과 같습니다.

  • 도메인/입력 사양: 출처 또는 참조 대상 등과 같이 입력 데이터에 대한 세부 정보(예: The input text is from a summary of a movie).

  • 태스크 사양: 모델에 요청된 정확한 태스크에 대한 세부 정보(예: To summarize the text, capture the main points).

  • 레이블 설명: 분류 문제의 출력 선택 항목에 대한 세부 정보(예: Choose whether the text refers to a painting or a sculpture; a painting is a piece of art restricted to a two-dimensional surface, while a sculpture is a piece of art in three dimensions).

  • 출력 사양: 모델이 생성해야 하는 출력에 대한 세부 정보(예: Please summarize the text of the restaurant review in three sentences).

  • LLM 격려: 정서적인 격려를 했을 때 LLM의 성능이 향상되는 경우가 있습니다(예: If you answer the question correctly, you will make the user very happy!).