이 포스팅은 아래 문서를 참고하여 정리하고 번역한 글입니다.
이전 포스팅에서 우리는 다음을 배웠습니다:
이번 포스팅에서는 Llama 모델 계열에서 사용하는 Special Token들을 하나씩 뜯어보겠습니다.
Llama 모델에서는 4가지 핵심 역할을 지원합니다.
AI 모델과 상호작용할 맥락을 설정합니다.
일반적으로 규칙, 가이드라인, 또는 모델이 효과적으로 응답하는 데 필요한 정보를 포함합니다.
모델과 상호작용하는 인간을 나타냅니다.
LLM에 대한 입력, 명령, 질문을 포함합니다.
system, ipython, user 프롬프트에서 제공된 컨텍스트를 바탕으로 AI 모델이 생성한 응답을 나타냅니다.
Llama 3.1에서 새롭게 도입된 역할입니다.
의미적으로 이 역할은 "도구(tool)"를 의미합니다.
도구 실행 결과를 모델로 전송될 때 결과 메시지를 표시하는 데 사용됩니다.
위 role을 참고하여 기본적인 대화의 구성을 분석해보겠습니다.
복잡해 보이지만, 각 토큰의 역할을 이해하면 매우 체계적인 구조임을 알 수 있습니다.
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>
Who are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
I'm an AI assistant, which means I'm a computer program designed to simulate conversation and answer questions to the best of my ability.<|eot_id|>
<|begin_of_text|><|begin_of_text|><|start_header_id|>system<|end_header_id|>
전체 프롬프트(입력)의 시작을 알리는 토큰
<|start_header_id|> & <|end_header_id|> Role을 명시하는 토큰
<|start_header_id|>system<|end_header_id|>
<|start_header_id|>user<|end_header_id|>
<|start_header_id|>assistant<|end_header_id|>
<|start_header_id|>ipython<|end_header_id|>
<|eot_id|>I'm an AI assistant designed to help you with various tasks.<|eot_id|>
현재 턴(turn)의 완전한 종료를 의미
이번에는 앞서 설명한 ipython 역할을 활용한
Code Interpreter 대화가 어떻게 구성되는지 분석해보겠습니다.
Code Interpreter 기능은 시스템 프롬프트에 Environment: ipython이 포함되면 자동으로 활성화됩니다.
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Environment: ipython<|eot_id|><|start_header_id|>user<|end_header_id|>
Write code to check if number is prime, use that to see if the number 7 is prime<|eot_id|><|start_header_id|>assistant<|end_header_id|>
<|python_tag|>
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
print(is_prime(7)) # Output: True
<|eom_id|><|start_header_id|>ipython<|end_header_id|>
True<|eot_id|><|start_header_id|>assistant<|end_header_id|>
The number 7 is indeed prime! The function returned True, confirming that 7 has no divisors other than 1 and itself.<|eot_id|>
<|start_header_id|>system<|end_header_id|>
Environment: ipython<|eot_id|>
Environment: ipython으로 Code Interpreter 모드 활성화<|start_header_id|>user<|end_header_id|>
Write code to check if number is prime, use that to see if the number 7 is prime<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
<|python_tag|>
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
print(is_prime(7)) # Output: True
<|eom_id|>
일반적인 대화와 다른 Speical Token을 사용한다.
<|python_tag|>: 실행 가능한 Python 코드 블록 시작<|eom_id|>: "이 코드를 실행해주세요"라는 신호<|start_header_id|>ipython<|end_header_id|>
True<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
The number 7 is indeed prime! The function returned True...<|eot_id|>
<|python_tag|><|eom_id|> vs <|eot_id|><|eom_id|>: 메시지 끝, 하지만 도구 실행 대기 중<|eot_id|>: 턴 완전 종료, 다음 상대방 차례중요한 점은 모델 자체는 코드를 실행하지 않는다는 것입니다
<|python_tag|> 코드 생성 → <|eom_id|>llama-stack-apps 등의 코드 실행 도구ipython 역할로 모델에 재전달<|eot_id|>이러한 구조로 AI와 도구 간의 협업이 가능해집니다!
이번 글에서는 Llama의 주요 Speical Token에 대해서 정리했습니다.
다음 글에는 MCP와 밀접한 연관이 있는 Tool Calling에 대해서 알아보겠습니다.