้กน็›ฎๆ–‡ไปถๅคน

ๆ–‡ไปถ
wehub-resource-sync e06fe8e8c6
Secret Leaks / trufflehog (push) Failing after 1s
Build documentation / build (push) Failing after 1s
Build documentation / build_other_lang (push) Failing after 0s
CodeQL Security Analysis / CodeQL Analysis (push) Failing after 0s
PR CI / pr-ci (push) Failing after 1s
Slow tests on important models (on Push - A10) / Get all modified files (push) Failing after 1s
Slow tests on important models (on Push - A10) / Model CI (push) Has been skipped
Self-hosted runner (benchmark) / Benchmark (aws-g5-4xlarge-cache) (push) Has been cancelled
New model PR merged notification / Notify new model (push) Has been cancelled
Update Transformers metadata / build_and_package (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:57:37 +08:00

23 KiB

๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ(LLM) ํ”„๋กฌํ”„ํŒ… ๊ฐ€์ด๋“œ llm-prompting-guide

open-in-colab

Falcon, LLaMA ๋“ฑ์˜ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์€ ์‚ฌ์ „ ํ›ˆ๋ จ๋œ ํŠธ๋žœ์Šคํฌ๋จธ ๋ชจ๋ธ๋กœ, ์ดˆ๊ธฐ์—๋Š” ์ฃผ์–ด์ง„ ์ž…๋ ฅ ํ…์ŠคํŠธ์— ๋Œ€ํ•ด ๋‹ค์Œ ํ† ํฐ์„ ์˜ˆ์ธกํ•˜๋„๋ก ํ›ˆ๋ จ๋ฉ๋‹ˆ๋‹ค. ์ด๋“ค์€ ๋ณดํ†ต ์ˆ˜์‹ญ์–ต ๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ์žฅ๊ธฐ๊ฐ„์— ๊ฑธ์ณ ์ˆ˜์กฐ ๊ฐœ์˜ ํ† ํฐ์œผ๋กœ ํ›ˆ๋ จ๋ฉ๋‹ˆ๋‹ค. ๊ทธ ๊ฒฐ๊ณผ, ์ด ๋ชจ๋ธ๋“ค์€ ๋งค์šฐ ๊ฐ•๋ ฅํ•˜๊ณ  ๋‹ค์žฌ๋‹ค๋Šฅํ•ด์ ธ์„œ, ์ž์—ฐ์–ด ํ”„๋กฌํ”„ํŠธ๋กœ ๋ชจ๋ธ์— ์ง€์‹œํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—…์„ ์ฆ‰์‹œ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ตœ์ ์˜ ์ถœ๋ ฅ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ์ด๋Ÿฌํ•œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์„ค๊ณ„ํ•˜๋Š” ๊ฒƒ์„ ํ”ํžˆ "ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง"์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง์€ ์ƒ๋‹นํ•œ ์‹คํ—˜์ด ํ•„์š”ํ•œ ๋ฐ˜๋ณต์ ์ธ ๊ณผ์ •์ž…๋‹ˆ๋‹ค. ์ž์—ฐ์–ด๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ณด๋‹ค ํ›จ์”ฌ ์œ ์—ฐํ•˜๊ณ  ํ‘œํ˜„๋ ฅ์ด ํ’๋ถ€ํ•˜์ง€๋งŒ, ๋™์‹œ์— ๋ชจํ˜ธ์„ฑ์„ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ์ž์—ฐ์–ด ํ”„๋กฌํ”„ํŠธ๋Š” ๋ณ€ํ™”์— ๋งค์šฐ ๋ฏผ๊ฐํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กฌํ”„ํŠธ์˜ ์‚ฌ์†Œํ•œ ์ˆ˜์ •๋งŒ์œผ๋กœ๋„ ์™„์ „ํžˆ ๋‹ค๋ฅธ ์ถœ๋ ฅ์ด ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  ๊ฒฝ์šฐ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ •ํ™•ํ•œ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๊ณต์‹์€ ์—†์ง€๋งŒ, ์—ฐ๊ตฌ์ž๋“ค์€ ๋” ์ผ๊ด€๋˜๊ฒŒ ์ตœ์ ์˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ชจ๋ฒ” ์‚ฌ๋ก€๋ฅผ ๊ฐœ๋ฐœํ–ˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ฐ€์ด๋“œ์—์„œ๋Š” ๋” ๋‚˜์€ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ๋‹ค์–‘ํ•œ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—…์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๋ชจ๋ฒ” ์‚ฌ๋ก€๋ฅผ ๋‹ค๋ฃน๋‹ˆ๋‹ค:

ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง์€ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ ์ถœ๋ ฅ ์ตœ์ ํ™” ๊ณผ์ •์˜ ์ผ๋ถ€์ผ ๋ฟ์ž…๋‹ˆ๋‹ค. ๋˜ ๋‹ค๋ฅธ ์ค‘์š”ํ•œ ๊ตฌ์„ฑ ์š”์†Œ๋Š” ์ตœ์ ์˜ ํ…์ŠคํŠธ ์ƒ์„ฑ ์ „๋žต์„ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•™์Šต ๊ฐ€๋Šฅํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ ๋„ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์ด ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋ฆฌ ๋•Œ ๊ฐ๊ฐ์˜ ํ›„์† ํ† ํฐ์„ ์„ ํƒํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ…์ŠคํŠธ ์ƒ์„ฑ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์กฐ์ •ํ•จ์œผ๋กœ์จ ์ƒ์„ฑ๋œ ํ…์ŠคํŠธ์˜ ๋ฐ˜๋ณต์„ ์ค„์ด๊ณ  ๋” ์ผ๊ด€๋˜๊ณ  ์‚ฌ๋žŒ์ด ๋งํ•˜๋Š” ๊ฒƒ ๊ฐ™์€ ํ…์ŠคํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ…์ŠคํŠธ ์ƒ์„ฑ ์ „๋žต๊ณผ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์ด ๊ฐ€์ด๋“œ์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜์ง€๋งŒ, ๋‹ค์Œ ๊ฐ€์ด๋“œ์—์„œ ์ด๋Ÿฌํ•œ ์ฃผ์ œ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

ํ”„๋กฌํ”„ํŒ…์˜ ๊ธฐ์ดˆ basics-of-prompting

๋ชจ๋ธ์˜ ์œ ํ˜• types-of-models

ํ˜„๋Œ€์˜ ๋Œ€๋ถ€๋ถ„์˜ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์€ ๋””์ฝ”๋”๋งŒ์„ ์ด์šฉํ•œ ํŠธ๋žœ์Šคํฌ๋จธ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด LLaMA, Llama2, Falcon, GPT2 ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋””์ฝ”๋” ์ „์šฉ ๋ชจ๋ธ๋กœ ์ถ”๋ก ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด text-generation ํŒŒ์ดํ”„๋ผ์ธ์„ ์‚ฌ์šฉํ•˜์„ธ์š”:

>>> from transformers import pipeline
>>> import torch

>>> torch.manual_seed(0) # doctest: +IGNORE_RESULT

>>> generator = pipeline('text-generation', model = 'openai-community/gpt2')
>>> prompt = "Hello, I'm a language model"

>>> generator(prompt, max_length = 30)
[{'generated_text': "Hello, I'm a language model programmer so you can use some of my stuff. But you also need some sort of a C program to run."}]

๊ธฐ๋ณธ ๋ชจ๋ธ vs ์ง€์‹œ/์ฑ„ํŒ… ๋ชจ๋ธ base-vs-instructchat-models

๐Ÿค— Hub์—์„œ ์ตœ๊ทผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋Œ€๋ถ€๋ถ„์˜ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ ์ฒดํฌํฌ์ธํŠธ๋Š” ๊ธฐ๋ณธ ๋ฒ„์ „๊ณผ ์ง€์‹œ(๋˜๋Š” ์ฑ„ํŒ…) ๋‘ ๊ฐ€์ง€ ๋ฒ„์ „์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, tiiuae/falcon-7b์™€ tiiuae/falcon-7b-instruct๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ๋ชจ๋ธ์€ ์ดˆ๊ธฐ ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ํ…์ŠคํŠธ๋ฅผ ์™„์„ฑํ•˜๋Š” ๋ฐ ํƒ์›”ํ•˜์ง€๋งŒ, ์ง€์‹œ๋ฅผ ๋”ฐ๋ผ์•ผ ํ•˜๊ฑฐ๋‚˜ ๋Œ€ํ™”ํ˜• ์‚ฌ์šฉ์ด ํ•„์š”ํ•œ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ์ž‘์—…์—๋Š” ์ด์ƒ์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋•Œ ์ง€์‹œ(์ฑ„ํŒ…) ๋ฒ„์ „์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ฒดํฌํฌ์ธํŠธ๋Š” ์‚ฌ์ „ ํ›ˆ๋ จ๋œ ๊ธฐ๋ณธ ๋ฒ„์ „์„ ์ง€์‹œ์‚ฌํ•ญ๊ณผ ๋Œ€ํ™” ๋ฐ์ดํ„ฐ๋กœ ์ถ”๊ฐ€ ๋ฏธ์„ธ ์กฐ์ •ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ์ด ์ถ”๊ฐ€์ ์ธ ๋ฏธ์„ธ ์กฐ์ •์œผ๋กœ ์ธํ•ด ๋งŽ์€ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—…์— ๋” ์ ํ•ฉํ•œ ์„ ํƒ์ด ๋ฉ๋‹ˆ๋‹ค.

tiiuae/falcon-7b-instruct๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ผ๋ฐ˜์ ์ธ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—…์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ช‡ ๊ฐ€์ง€ ๊ฐ„๋‹จํ•œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—… nlp-tasks

๋จผ์ €, ํ™˜๊ฒฝ์„ ์„ค์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

pip install -q transformers accelerate

๋‹ค์Œ์œผ๋กœ, ์ ์ ˆํ•œ ํŒŒ์ดํ”„๋ผ์ธ("text-generation")์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:

>>> from transformers import pipeline, AutoTokenizer
>>> import torch

>>> torch.manual_seed(0) # doctest: +IGNORE_RESULT
>>> model = "tiiuae/falcon-7b-instruct"

>>> tokenizer = AutoTokenizer.from_pretrained(model)
>>> pipe = pipeline(
...     "text-generation",
...     model=model,
...     tokenizer=tokenizer,
...     dtype=torch.bfloat16,
...     device_map="auto",
... )

Falcon ๋ชจ๋ธ์€ bfloat16 ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜์—ฌ ํ›ˆ๋ จ๋˜์—ˆ์œผ๋ฏ€๋กœ, ๊ฐ™์€ ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ CUDA๊ฐ€ ํ•„์š”ํ•˜๋ฉฐ, ์ตœ์‹  ๊ทธ๋ž˜ํ”ฝ ์นด๋“œ์—์„œ ๊ฐ€์žฅ ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

์ด์ œ ํŒŒ์ดํ”„๋ผ์ธ์„ ํ†ตํ•ด ๋ชจ๋ธ์„ ๋กœ๋“œํ–ˆ์œผ๋‹ˆ, ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ์ž‘์—…์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ ๋ถ„๋ฅ˜ text-classification

ํ…์ŠคํŠธ ๋ถ„๋ฅ˜์˜ ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ํ˜•ํƒœ ์ค‘ ํ•˜๋‚˜๋Š” ๊ฐ์ • ๋ถ„์„์ž…๋‹ˆ๋‹ค. ์ด๋Š” ํ…์ŠคํŠธ ์‹œํ€€์Šค์— "๊ธ์ •์ ", "๋ถ€์ •์ " ๋˜๋Š” "์ค‘๋ฆฝ์ "๊ณผ ๊ฐ™์€ ๋ ˆ์ด๋ธ”์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ํ…์ŠคํŠธ(์˜ํ™” ๋ฆฌ๋ทฐ)๋ฅผ ๋ถ„๋ฅ˜ํ•˜๋„๋ก ๋ชจ๋ธ์— ์ง€์‹œํ•˜๋Š” ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์ง€์‹œ์‚ฌํ•ญ์„ ์ œ๊ณตํ•œ ๋‹ค์Œ, ๋ถ„๋ฅ˜ํ•  ํ…์ŠคํŠธ๋ฅผ ์ง€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ฃผ๋ชฉํ•  ์ ์€ ๋‹จ์ˆœํžˆ ๊ฑฐ๊ธฐ์„œ ๋๋‚ด์ง€ ์•Š๊ณ , ์‘๋‹ต์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์ธ "Sentiment: "์„ ์ถ”๊ฐ€ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค:

>>> torch.manual_seed(0)
>>> prompt = """Classify the text into neutral, negative or positive. 
... Text: This movie is definitely one of my favorite movies of its kind. The interaction between respectable and morally strong characters is an ode to chivalry and the honor code amongst thieves and policemen.
... Sentiment:
... """

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=10,
... )

>>> for seq in sequences:
...     print(f"Result: {seq['generated_text']}")
Result: Classify the text into neutral, negative or positive. 
Text: This movie is definitely one of my favorite movies of its kind. The interaction between respectable and morally strong characters is an ode to chivalry and the honor code amongst thieves and policemen.
Sentiment:
Positive

๊ฒฐ๊ณผ์ ์œผ๋กœ, ์šฐ๋ฆฌ๊ฐ€ ์ง€์‹œ์‚ฌํ•ญ์—์„œ ์ œ๊ณตํ•œ ๋ชฉ๋ก์—์„œ ์„ ํƒ๋œ ๋ถ„๋ฅ˜ ๋ ˆ์ด๋ธ”์ด ์ •ํ™•ํ•˜๊ฒŒ ํฌํ•จ๋˜์–ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

ํ”„๋กฌํ”„ํŠธ ์™ธ์—๋„ max_new_tokens ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋ชจ๋ธ์ด ์ƒ์„ฑํ•  ํ† ํฐ์˜ ์ˆ˜๋ฅผ ์ œ์–ดํ•˜๋ฉฐ, ํ…์ŠคํŠธ ์ƒ์„ฑ ์ „๋žต ๊ฐ€์ด๋“œ์—์„œ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ํ…์ŠคํŠธ ์ƒ์„ฑ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

๊ฐœ์ฒด๋ช… ์ธ์‹ named-entity-recognition

๊ฐœ์ฒด๋ช… ์ธ์‹(Named Entity Recognition, NER)์€ ํ…์ŠคํŠธ์—์„œ ์ธ๋ฌผ, ์žฅ์†Œ, ์กฐ์ง๊ณผ ๊ฐ™์€ ๋ช…๋ช…๋œ ๊ฐœ์ฒด๋ฅผ ์ฐพ๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค. ํ”„๋กฌํ”„ํŠธ์˜ ์ง€์‹œ์‚ฌํ•ญ์„ ์ˆ˜์ •ํ•˜์—ฌ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์ด ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋„๋ก ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” return_full_text = False๋กœ ์„ค์ •ํ•˜์—ฌ ์ถœ๋ ฅ์— ํ”„๋กฌํ”„ํŠธ๊ฐ€ ํฌํ•จ๋˜์ง€ ์•Š๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:

>>> torch.manual_seed(1) # doctest: +IGNORE_RESULT
>>> prompt = """Return a list of named entities in the text.
... Text: The Golden State Warriors are an American professional basketball team based in San Francisco.
... Named entities:
... """

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=15,
...     return_full_text = False,    
... )

>>> for seq in sequences:
...     print(f"{seq['generated_text']}")
- Golden State Warriors
- San Francisco

๋ณด์‹œ๋‹ค์‹œํ”ผ, ๋ชจ๋ธ์ด ์ฃผ์–ด์ง„ ํ…์ŠคํŠธ์—์„œ ๋‘ ๊ฐœ์˜ ๋ช…๋ช…๋œ ๊ฐœ์ฒด๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์‹๋ณ„ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ฒˆ์—ญ translation

๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์ด ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋˜ ๋‹ค๋ฅธ ์ž‘์—…์€ ๋ฒˆ์—ญ์ž…๋‹ˆ๋‹ค. ์ด ์ž‘์—…์„ ์œ„ํ•ด ์ธ์ฝ”๋”-๋””์ฝ”๋” ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์—ฌ๊ธฐ์„œ๋Š” ์˜ˆ์‹œ์˜ ๋‹จ์ˆœ์„ฑ์„ ์œ„ํ•ด ๊ฝค ์ข‹์€ ์„ฑ๋Šฅ์„ ๋ณด์ด๋Š” Falcon-7b-instruct๋ฅผ ๊ณ„์† ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ•œ ๋ฒˆ, ๋ชจ๋ธ์—๊ฒŒ ์˜์–ด์—์„œ ์ดํƒˆ๋ฆฌ์•„์–ด๋กœ ํ…์ŠคํŠธ๋ฅผ ๋ฒˆ์—ญํ•˜๋„๋ก ์ง€์‹œํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

>>> torch.manual_seed(2) # doctest: +IGNORE_RESULT
>>> prompt = """Translate the English text to Italian.
... Text: Sometimes, I've believed as many as six impossible things before breakfast.
... Translation:
... """

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=20,
...     do_sample=True,
...     top_k=10,
...     return_full_text = False,
... )

>>> for seq in sequences:
...     print(f"{seq['generated_text']}")
A volte, ho creduto a sei impossibili cose prima di colazione.

์—ฌ๊ธฐ์„œ๋Š” ๋ชจ๋ธ์ด ์ถœ๋ ฅ์„ ์ƒ์„ฑํ•  ๋•Œ ์กฐ๊ธˆ ๋” ์œ ์—ฐํ•ด์งˆ ์ˆ˜ ์žˆ๋„๋ก do_sample=True์™€ top_k=10์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ ์š”์•ฝ text-summarization

๋ฒˆ์—ญ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, ํ…์ŠคํŠธ ์š”์•ฝ์€ ์ถœ๋ ฅ์ด ์ž…๋ ฅ์— ํฌ๊ฒŒ ์˜์กดํ•˜๋Š” ๋˜ ๋‹ค๋ฅธ ์ƒ์„ฑ ์ž‘์—…์ด๋ฉฐ, ์ธ์ฝ”๋”-๋””์ฝ”๋” ๊ธฐ๋ฐ˜ ๋ชจ๋ธ์ด ๋” ๋‚˜์€ ์„ ํƒ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋””์ฝ”๋” ๊ธฐ๋ฐ˜์˜ ๋ชจ๋ธ๋„ ์ด ์ž‘์—…์— ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ „์—๋Š” ํ”„๋กฌํ”„ํŠธ์˜ ๋งจ ์ฒ˜์Œ์— ์ง€์‹œ์‚ฌํ•ญ์„ ๋ฐฐ์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ”„๋กฌํ”„ํŠธ์˜ ๋งจ ๋๋„ ์ง€์‹œ์‚ฌํ•ญ์„ ๋„ฃ์„ ์ ์ ˆํ•œ ์œ„์น˜๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ง€์‹œ์‚ฌํ•ญ์„ ์–‘ ๊ทน๋‹จ ์ค‘ ํ•˜๋‚˜์— ๋ฐฐ์น˜ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์Šต๋‹ˆ๋‹ค.

>>> torch.manual_seed(3) # doctest: +IGNORE_RESULT
>>> prompt = """Permaculture is a design process mimicking the diversity, functionality and resilience of natural ecosystems. The principles and practices are drawn from traditional ecological knowledge of indigenous cultures combined with modern scientific understanding and technological innovations. Permaculture design provides a framework helping individuals and communities develop innovative, creative and effective strategies for meeting basic needs while preparing for and mitigating the projected impacts of climate change.
... Write a summary of the above text.
... Summary:
... """

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=30,
...     do_sample=True,
...     top_k=10,
...     return_full_text = False,
... )

>>> for seq in sequences:
...     print(f"{seq['generated_text']}")
Permaculture is an ecological design mimicking natural ecosystems to meet basic needs and prepare for climate change. It is based on traditional knowledge and scientific understanding.

์งˆ์˜ ์‘๋‹ต question-answering

์งˆ์˜ ์‘๋‹ต ์ž‘์—…์„ ์œ„ํ•ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋…ผ๋ฆฌ์  ๊ตฌ์„ฑ์š”์†Œ๋กœ ๊ตฌ์กฐํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€์‹œ์‚ฌํ•ญ, ๋งฅ๋ฝ, ์งˆ๋ฌธ, ๊ทธ๋ฆฌ๊ณ  ๋ชจ๋ธ์ด ๋‹ต๋ณ€ ์ƒ์„ฑ์„ ์‹œ์ž‘ํ•˜๋„๋ก ์œ ๋„ํ•˜๋Š” ์„ ๋„ ๋‹จ์–ด๋‚˜ ๊ตฌ๋ฌธ("Answer:") ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

>>> torch.manual_seed(4) # doctest: +IGNORE_RESULT
>>> prompt = """Answer the question using the context below.
... Context: Gazpacho is a cold soup and drink made of raw, blended vegetables. Most gazpacho includes stale bread, tomato, cucumbers, onion, bell peppers, garlic, olive oil, wine vinegar, water, and salt. Northern recipes often include cumin and/or pimentรณn (smoked sweet paprika). Traditionally, gazpacho was made by pounding the vegetables in a mortar with a pestle; this more laborious method is still sometimes used as it helps keep the gazpacho cool and avoids the foam and silky consistency of smoothie versions made in blenders or food processors.
... Question: What modern tool is used to make gazpacho?
... Answer:
... """

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=10,
...     do_sample=True,
...     top_k=10,
...     return_full_text = False,
... )

>>> for seq in sequences:
...     print(f"Result: {seq['generated_text']}")
Result: Modern tools often used to make gazpacho include

์ถ”๋ก  reasoning

์ถ”๋ก ์€ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ(LLM)์—๊ฒŒ ๊ฐ€์žฅ ์–ด๋ ค์šด ์ž‘์—… ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ, ์ข‹์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ข…์ข… ์ƒ๊ฐ์˜ ์‚ฌ์Šฌ(Chain-of-thought, CoT)๊ณผ ๊ฐ™์€ ๊ณ ๊ธ‰ ํ”„๋กฌํ”„ํŒ… ๊ธฐ๋ฒ•์„ ์ ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•œ ์‚ฐ์ˆ  ์ž‘์—…์— ๋Œ€ํ•ด ๊ธฐ๋ณธ์ ์ธ ํ”„๋กฌํ”„ํŠธ๋กœ ๋ชจ๋ธ์ด ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์‹œ๋„ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

>>> torch.manual_seed(5) # doctest: +IGNORE_RESULT
>>> prompt = """There are 5 groups of students in the class. Each group has 4 students. How many students are there in the class?"""

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=30,
...     do_sample=True,
...     top_k=10,
...     return_full_text = False,
... )

>>> for seq in sequences:
...     print(f"Result: {seq['generated_text']}")
Result: 
There are a total of 5 groups, so there are 5 x 4=20 students in the class.

์ •ํ™•ํ•œ ๋‹ต๋ณ€์ด ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค! ๋ณต์žก์„ฑ์„ ์กฐ๊ธˆ ๋†’์—ฌ๋ณด๊ณ  ๊ธฐ๋ณธ์ ์ธ ํ”„๋กฌํ”„ํŠธ๋กœ๋„ ์—ฌ์ „ํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

>>> torch.manual_seed(6)
>>> prompt = """I baked 15 muffins. I ate 2 muffins and gave 5 muffins to a neighbor. My partner then bought 6 more muffins and ate 2. How many muffins do we now have?"""

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=10,
...     do_sample=True,
...     top_k=10,
...     return_full_text = False,
... )

>>> for seq in sequences:
...     print(f"Result: {seq['generated_text']}")
Result: 
The total number of muffins now is 21

์ •๋‹ต์€ 12์—ฌ์•ผ ํ•˜๋Š”๋ฐ 21์ด๋ผ๋Š” ์ž˜๋ชป๋œ ๋‹ต๋ณ€์ด ๋‚˜์™”์Šต๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ, ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋„ˆ๋ฌด ๊ธฐ๋ณธ์ ์ด๊ฑฐ๋‚˜ ๋ชจ๋ธ์˜ ํฌ๊ธฐ๊ฐ€ ์ž‘์•„์„œ ์ƒ๊ธด ๋ฌธ์ œ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” Falcon์˜ ๊ฐ€์žฅ ์ž‘์€ ๋ฒ„์ „์„ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ถ”๋ก ์€ ํฐ ๋ชจ๋ธ์—๊ฒŒ๋„ ์–ด๋ ค์šด ์ž‘์—…์ด์ง€๋งŒ, ๋” ํฐ ๋ชจ๋ธ๋“ค์ด ๋” ๋‚˜์€ ์„ฑ๋Šฅ์„ ๋ณด์ผ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค.

๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ ํ”„๋กฌํ”„ํŠธ ์ž‘์„ฑ์˜ ๋ชจ๋ฒ” ์‚ฌ๋ก€ best-practices-of-llm-prompting

์ด ์„น์…˜์—์„œ๋Š” ํ”„๋กฌํ”„ํŠธ ๊ฒฐ๊ณผ๋ฅผ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๋ชจ๋ฒ” ์‚ฌ๋ก€ ๋ชฉ๋ก์„ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค:

  • ์ž‘์—…ํ•  ๋ชจ๋ธ์„ ์„ ํƒํ•  ๋•Œ ์ตœ์‹  ๋ฐ ๊ฐ€์žฅ ๊ฐ•๋ ฅํ•œ ๋ชจ๋ธ์ด ๋” ๋‚˜์€ ์„ฑ๋Šฅ์„ ๋ฐœํœ˜ํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค.
  • ๊ฐ„๋‹จํ•˜๊ณ  ์งง์€ ํ”„๋กฌํ”„ํŠธ๋กœ ์‹œ์ž‘ํ•˜์—ฌ ์ ์ง„์ ์œผ๋กœ ๊ฐœ์„ ํ•ด ๋‚˜๊ฐ€์„ธ์š”.
  • ํ”„๋กฌํ”„ํŠธ์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์ด๋‚˜ ๋งจ ๋์— ์ง€์‹œ์‚ฌํ•ญ์„ ๋ฐฐ์น˜ํ•˜์„ธ์š”. ๋Œ€๊ทœ๋ชจ ์ปจํ…์ŠคํŠธ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ, ๋ชจ๋ธ๋“ค์€ ์–ดํ…์…˜ ๋ณต์žก๋„๊ฐ€ 2์ฐจ์ ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์–‘ํ•œ ์ตœ์ ํ™”๋ฅผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•จ์œผ๋กœ์จ ๋ชจ๋ธ์ด ํ”„๋กฌํ”„ํŠธ์˜ ์ค‘๊ฐ„๋ณด๋‹ค ์‹œ์ž‘์ด๋‚˜ ๋ ๋ถ€๋ถ„์— ๋” ์ฃผ์˜๋ฅผ ๊ธฐ์šธ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ง€์‹œ์‚ฌํ•ญ์„ ์ ์šฉํ•  ํ…์ŠคํŠธ์™€ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ถ„๋ฆฌํ•ด๋ณด์„ธ์š”. (์ด์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ค์Œ ์„น์…˜์—์„œ ๋” ์ž์„ธํžˆ ๋‹ค๋ฃน๋‹ˆ๋‹ค.)
  • ์ž‘์—…๊ณผ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ์— ๋Œ€ํ•ด ๊ตฌ์ฒด์ ์ด๊ณ  ํ’๋ถ€ํ•œ ์„ค๋ช…์„ ์ œ๊ณตํ•˜์„ธ์š”. ํ˜•์‹, ๊ธธ์ด, ์Šคํƒ€์ผ, ์–ธ์–ด ๋“ฑ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ชจํ˜ธํ•œ ์„ค๋ช…๊ณผ ์ง€์‹œ์‚ฌํ•ญ์„ ํ”ผํ•˜์„ธ์š”.
  • "ํ•˜์ง€ ๋ง๋ผ"๋Š” ์ง€์‹œ๋ณด๋‹ค๋Š” "๋ฌด์—‡์„ ํ•ด์•ผ ํ•˜๋Š”์ง€"๋ฅผ ๋งํ•˜๋Š” ์ง€์‹œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
  • ์ฒซ ๋ฒˆ์งธ ๋‹จ์–ด๋ฅผ ์“ฐ๊ฑฐ๋‚˜ ์ฒซ ๋ฒˆ์งธ ๋ฌธ์žฅ์„ ์‹œ์ž‘ํ•˜์—ฌ ์ถœ๋ ฅ์„ ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉํ–ฅ์œผ๋กœ "์œ ๋„"ํ•˜์„ธ์š”.
  • ํ“จ์ƒท(Few-shot) ํ”„๋กฌํ”„ํŒ… ๋ฐ ์ƒ๊ฐ์˜ ์‚ฌ์Šฌ(Chain-of-thought, CoT) ๊ฐ™์€ ๊ณ ๊ธ‰ ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•ด๋ณด์„ธ์š”.
  • ํ”„๋กฌํ”„ํŠธ์˜ ๊ฒฌ๊ณ ์„ฑ์„ ํ‰๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ๋ชจ๋ธ๋กœ๋„ ํ…Œ์ŠคํŠธํ•˜์„ธ์š”.
  • ํ”„๋กฌํ”„ํŠธ์˜ ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•˜๊ณ  ์„ฑ๋Šฅ์„ ์ถ”์ ํ•˜์„ธ์š”.

๊ณ ๊ธ‰ ํ”„๋กฌํ”„ํŠธ ๊ธฐ๋ฒ• advanced-prompting-techniques

ํ“จ์ƒท(Few-shot) ํ”„๋กฌํ”„ํŒ… few-shot-prompting

์œ„ ์„น์…˜์˜ ๊ธฐ๋ณธ ํ”„๋กฌํ”„ํŠธ๋“ค์€ "์ œ๋กœ์ƒท(Zero-shot)" ํ”„๋กฌํ”„ํŠธ์˜ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. ์ด๋Š” ๋ชจ๋ธ์— ์ง€์‹œ์‚ฌํ•ญ๊ณผ ๋งฅ๋ฝ์€ ์ฃผ์–ด์กŒ์ง€๋งŒ, ํ•ด๊ฒฐ์ฑ…์ด ํฌํ•จ๋œ ์˜ˆ์‹œ๋Š” ์ œ๊ณต๋˜์ง€ ์•Š์•˜๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. ์ง€์‹œ ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ๋ฏธ์„ธ ์กฐ์ •๋œ ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Ÿฌํ•œ "์ œ๋กœ์ƒท" ์ž‘์—…์—์„œ ์ข‹์€ ์„ฑ๋Šฅ์„ ๋ณด์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ž‘์—…์ด ๋” ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋ฏธ๋ฌ˜ํ•œ ์ฐจ์ด๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๊ณ , ์•„๋งˆ๋„ ์ง€์‹œ์‚ฌํ•ญ๋งŒ์œผ๋กœ๋Š” ๋ชจ๋ธ์ด ํฌ์ฐฉํ•˜์ง€ ๋ชปํ•˜๋Š” ์ถœ๋ ฅ์— ๋Œ€ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” ํ“จ์ƒท(Few-shot) ํ”„๋กฌํ”„ํŒ…์ด๋ผ๋Š” ๊ธฐ๋ฒ•์„ ์‹œ๋„ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ“จ์ƒท ํ”„๋กฌํ”„ํŒ…์—์„œ๋Š” ํ”„๋กฌํ”„ํŠธ์— ์˜ˆ์‹œ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๋ชจ๋ธ์— ๋” ๋งŽ์€ ๋งฅ๋ฝ์„ ์ฃผ๊ณ  ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. ์ด ์˜ˆ์‹œ๋“ค์€ ๋ชจ๋ธ์ด ์˜ˆ์‹œ์˜ ํŒจํ„ด์„ ๋”ฐ๋ผ ์ถœ๋ ฅ์„ ์ƒ์„ฑํ•˜๋„๋ก ์กฐ๊ฑดํ™”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์€ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:

>>> torch.manual_seed(0) # doctest: +IGNORE_RESULT
>>> prompt = """Text: The first human went into space and orbited the Earth on April 12, 1961.
... Date: 04/12/1961
... Text: The first-ever televised presidential debate in the United States took place on September 28, 1960, between presidential candidates John F. Kennedy and Richard Nixon. 
... Date:"""

>>> sequences = pipe(
...     prompt,
...     max_new_tokens=8,
...     do_sample=True,
...     top_k=10,
... )

>>> for seq in sequences:
...     print(f"Result: {seq['generated_text']}")
Result: Text: The first human went into space and orbited the Earth on April 12, 1961.
Date: 04/12/1961
Text: The first-ever televised presidential debate in the United States took place on September 28, 1960, between presidential candidates John F. Kennedy and Richard Nixon. 
Date: 09/28/1960

์œ„์˜ ์ฝ”๋“œ ์Šค๋‹ˆํŽซ์—์„œ๋Š” ๋ชจ๋ธ์— ์›ํ•˜๋Š” ์ถœ๋ ฅ์„ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ๋‹จ์ผ ์˜ˆ์‹œ๋ฅผ ์‚ฌ์šฉํ–ˆ์œผ๋ฏ€๋กœ, ์ด๋ฅผ "์›์ƒท(One-shot)" ํ”„๋กฌํ”„ํŒ…์ด๋ผ๊ณ  ๋ถ€๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ž‘์—…์˜ ๋ณต์žก์„ฑ์— ๋”ฐ๋ผ ํ•˜๋‚˜ ์ด์ƒ์˜ ์˜ˆ์‹œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ“จ์ƒท ํ”„๋กฌํ”„ํŒ… ๊ธฐ๋ฒ•์˜ ํ•œ๊ณ„:

  • ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์ด ์˜ˆ์‹œ์˜ ํŒจํ„ด์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ด ๊ธฐ๋ฒ•์€ ๋ณต์žกํ•œ ์ถ”๋ก  ์ž‘์—…์—๋Š” ์ž˜ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ํ“จ์ƒท ํ”„๋กฌํ”„ํŒ…์„ ์ ์šฉํ•˜๋ฉด ํ”„๋กฌํ”„ํŠธ์˜ ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค. ํ† ํฐ ์ˆ˜๊ฐ€ ๋งŽ์€ ํ”„๋กฌํ”„ํŠธ๋Š” ๊ณ„์‚ฐ๋Ÿ‰๊ณผ ์ง€์—ฐ ์‹œ๊ฐ„์„ ์ฆ๊ฐ€์‹œํ‚ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ”„๋กฌํ”„ํŠธ ๊ธธ์ด์—๋„ ์ œํ•œ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋•Œ๋กœ๋Š” ์—ฌ๋Ÿฌ ์˜ˆ์‹œ๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ๋ชจ๋ธ์€ ์˜๋„ํ•˜์ง€ ์•Š์€ ํŒจํ„ด์„ ํ•™์Šตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์„ธ ๋ฒˆ์งธ ์˜ํ™” ๋ฆฌ๋ทฐ๊ฐ€ ํ•ญ์ƒ ๋ถ€์ •์ ์ด๋ผ๊ณ  ํ•™์Šตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ƒ๊ฐ์˜ ์‚ฌ์Šฌ(Chain-of-thought, CoT) chain-of-thought

์ƒ๊ฐ์˜ ์‚ฌ์Šฌ(Chain-of-thought, CoT) ํ”„๋กฌํ”„ํŒ…์€ ๋ชจ๋ธ์ด ์ค‘๊ฐ„ ์ถ”๋ก  ๋‹จ๊ณ„๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์œ ๋„ํ•˜๋Š” ๊ธฐ๋ฒ•์œผ๋กœ, ๋ณต์žกํ•œ ์ถ”๋ก  ์ž‘์—…์˜ ๊ฒฐ๊ณผ๋ฅผ ๊ฐœ์„ ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋ธ์ด ์ถ”๋ก  ๋‹จ๊ณ„๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์œ ๋„ํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค:

  • ์งˆ๋ฌธ์— ๋Œ€ํ•œ ์ƒ์„ธํ•œ ๋‹ต๋ณ€์„ ์˜ˆ์‹œ๋กœ ์ œ์‹œํ•˜๋Š” ํ“จ์ƒท ํ”„๋กฌํ”„ํŒ…์„ ํ†ตํ•ด ๋ชจ๋ธ์—๊ฒŒ ๋ฌธ์ œ๋ฅผ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•ด ๋‚˜๊ฐ€๋Š”์ง€ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
  • "๋‹จ๊ณ„๋ณ„๋กœ ์ƒ๊ฐํ•ด ๋ด…์‹œ๋‹ค" ๋˜๋Š” "๊นŠ๊ฒŒ ์ˆจ์„ ์‰ฌ๊ณ  ๋ฌธ์ œ๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ํ•ด๊ฒฐํ•ด ๋ด…์‹œ๋‹ค"์™€ ๊ฐ™์€ ๋ฌธ๊ตฌ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ชจ๋ธ์—๊ฒŒ ์ถ”๋ก ํ•˜๋„๋ก ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค.

reasoning section์˜ ๋จธํ•€ ์˜ˆ์‹œ์— ์ƒ๊ฐ์˜ ์‚ฌ์Šฌ(Chain-of-thought, CoT) ๊ธฐ๋ฒ•์„ ์ ์šฉํ•˜๊ณ  HuggingChat์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” (tiiuae/falcon-180B-chat)๊ณผ ๊ฐ™์€ ๋” ํฐ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋ฉด, ์ถ”๋ก  ๊ฒฐ๊ณผ๊ฐ€ ํฌ๊ฒŒ ๊ฐœ์„ ๋ฉ๋‹ˆ๋‹ค:

๋‹จ๊ณ„๋ณ„๋กœ ์‚ดํŽด๋ด…์‹œ๋‹ค:
1. ์ฒ˜์Œ์— 15๊ฐœ์˜ ๋จธํ•€์ด ์žˆ์Šต๋‹ˆ๋‹ค.
2. 2๊ฐœ์˜ ๋จธํ•€์„ ๋จน์œผ๋ฉด 13๊ฐœ์˜ ๋จธํ•€์ด ๋‚จ์Šต๋‹ˆ๋‹ค.
3. ์ด์›ƒ์—๊ฒŒ 5๊ฐœ์˜ ๋จธํ•€์„ ์ฃผ๋ฉด 8๊ฐœ์˜ ๋จธํ•€์ด ๋‚จ์Šต๋‹ˆ๋‹ค.
4. ํŒŒํŠธ๋„ˆ๊ฐ€ 6๊ฐœ์˜ ๋จธํ•€์„ ๋” ์‚ฌ์˜ค๋ฉด ์ด ๋จธํ•€ ์ˆ˜๋Š” 14๊ฐœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
5. ํŒŒํŠธ๋„ˆ๊ฐ€ 2๊ฐœ์˜ ๋จธํ•€์„ ๋จน์œผ๋ฉด 12๊ฐœ์˜ ๋จธํ•€์ด ๋‚จ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, ํ˜„์žฌ 12๊ฐœ์˜ ๋จธํ•€์ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋กฌํ”„ํŒ… vs ๋ฏธ์„ธ ์กฐ์ • prompting-vs-fine-tuning

ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ตœ์ ํ™”ํ•˜์—ฌ ํ›Œ๋ฅญํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์ง€๋งŒ, ์—ฌ์ „ํžˆ ๋ชจ๋ธ์„ ๋ฏธ์„ธ ์กฐ์ •ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์„์ง€ ๊ณ ๋ฏผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๋” ์ž‘์€ ๋ชจ๋ธ์„ ๋ฏธ์„ธ ์กฐ์ •ํ•˜๋Š” ๊ฒƒ์ด ์„ ํ˜ธ๋˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค์ž…๋‹ˆ๋‹ค:

  • ๋„๋ฉ”์ธ์ด ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ์ด ์‚ฌ์ „ ํ›ˆ๋ จ๋œ ๊ฒƒ๊ณผ ํฌ๊ฒŒ ๋‹ค๋ฅด๊ณ  ๊ด‘๋ฒ”์œ„ํ•œ ํ”„๋กฌํ”„ํŠธ ์ตœ์ ํ™”๋กœ๋„ ์ถฉ๋ถ„ํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ.
  • ์ €์ž์› ์–ธ์–ด์—์„œ ๋ชจ๋ธ์ด ์ž˜ ์ž‘๋™ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.
  • ์—„๊ฒฉํ•œ ๊ทœ์ œ ํ•˜์— ์žˆ๋Š” ๋ฏผ๊ฐํ•œ ๋ฐ์ดํ„ฐ๋กœ ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.
  • ๋น„์šฉ, ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ, ์ธํ”„๋ผ ๋˜๋Š” ๊ธฐํƒ€ ์ œํ•œ์œผ๋กœ ์ธํ•ด ์ž‘์€ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.

์œ„์˜ ๋ชจ๋“  ์˜ˆ์‹œ์—์„œ, ๋ชจ๋ธ์„ ๋ฏธ์„ธ ์กฐ์ •ํ•˜๊ธฐ ์œ„ํ•ด ์ถฉ๋ถ„ํžˆ ํฐ ๋„๋ฉ”์ธ๋ณ„ ๋ฐ์ดํ„ฐ์…‹์„ ์ด๋ฏธ ๊ฐ€์ง€๊ณ  ์žˆ๊ฑฐ๋‚˜ ํ•ฉ๋ฆฌ์ ์ธ ๋น„์šฉ์œผ๋กœ ์‰ฝ๊ฒŒ ์–ป์„ ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋ชจ๋ธ์„ ๋ฏธ์„ธ ์กฐ์ •ํ•  ์ถฉ๋ถ„ํ•œ ์‹œ๊ฐ„๊ณผ ์ž์›์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์œ„์˜ ์˜ˆ์‹œ๋“ค์ด ์—ฌ๋Ÿฌ๋ถ„์˜ ๊ฒฝ์šฐ์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ๊ฒƒ์ด ๋” ์œ ์ตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.