생성형 AI LLM의 모델 제어 매개 변수
모델 제어 매개 변수. 생성형 AI 프로그램에 우연성을 첨가하여 좀 더 자연스러운 글을 만들어 낼 수 있는 방법입니다.
생성형 AI 출력에 영향을 주는 구성 매개 변수

아마존 클라우드 서비스와 같은 상용 AI 플랫폼에서 LLM을 사용하는 경우, 별도의 모델 제어 매개 변수 파라미터를 통해 LLM의 자연스러운 동작을 조정할 수 있습니다.
일반적으로 LLM foundation 모델들은 추론 시에 모델의 출력에 영향을 줄 수 있는 구성 매개변수 세트를 제공합니다.
아울러, 모델 제어 매개 변수 파라미터들은 초기 훈련 시 학습되어 결정되는 변수들과는 다릅니다.
대신 이 구성 매개변수는 추론시에 호출됩니다. 그리고 완성본의 최대 토큰 수와 출력의 창의성 등을 제어할 수 있습니다.
이런 구성 매개변수의 대표적인 예는 출력에 사용 되는 최대 토큰 수가 있습니다.
출력 최대 토큰 수는 출력 문장의 길이를 제어 할 수 있습니다. 그리고 이는 모델이 문장을 만기 위해 단어를 선택 하는 최대 횟수를 제한함으로써 구현할 수 있습니다.
물론 최대 토큰 수가 충분히 크다고 하더라도 LLM이 중간에 문장 끝을 계산하여 출력하면 짧은 문장으로 끝날 수도 있습니다.
확률은 생성형 AI 에서 다음 단어(의미)선택에 중요한 역할
생성형 AI에서 사용되는 모델인 트랜스포머의 최종 출력 계층은 소프트맥스라고 부릅니다.

소프트맥스는 모델이 다룰 수 있는 모든 값들과 그 값들이 선택 될 수 있는 확률이 옆에 표시된 표라고 볼 수 있습니다.
대부분의 대형 언어 모델은 기본적으로 이른바 이 확률이 높은 단어(토큰)을 무조건적으로 선택하도록 되어 있습니다.
가장 단순한 다음 단어 예측 방식이며 짧은 문장 생성에 잘 작동할 수 있지만 일방적인 선택으로 단어나 단어의 순서가 반복될 수 있습니다.
자연스럽고 창의적인 텍스트를 생성하고 단어가 반복되지 않게 하려면 다른 제어 방식을 사용해야 합니다.
문장 선택에 변동성을 도입하는 방법-온도

랜덤 샘플링은 변동성을 도입하는 가장 쉬운 방법입니다.
랜덤 샘플링에서는 가장 가능성 높은 단어를 매번 선택하는 대신, 모델이 확률 분포를 사용하여 가중치를 부여해 출력 단어를 무작위로 선택합니다.
예를 들어 이 “사과”라는 단어의 확률 점수는 0.26이고 “배”가 0.70이면 기본 방식은 무조건 “배”가 선택이 됩니다.
그러나 랜덤 샘플링에서는 사과라는 단어가 선택될 확률이 100개의 단어가 나온다면 그중에 26번의 사과라는 단어가 나올 수 있습니다.
따라서 무작위성으로 인하여 같은 단어가 반복 적으로 선택될 가능성을 줄일 수 있습니다.
하지만 설정에 따라 출력이 너무 창의적이어서 생성된 내용이 주제에서 벗어나거나 말이 되지 않는 단어가 선택될 가능성도 있습니다.
모델 출력의 랜덤성을 제어하는 데 사용할 수 있는 대표적인 매개변수로 “온도”가 있습니다.
이 매개변수는 모델이 다음 토큰에 대해 계산하는 확률 분포의 모양에 영향을 줍니다.
대체로 온도가 높을수록 랜덤성이 높아지고, 온도가 낮을수록 랜덤성이 낮아집니다.
온도 값은 모델의 최종 소프트맥스 계층에 적용되는 스케일링 인수로, 다음 토큰의 확률 분포 모양에 영향을 줍니다.
온도 값을 1 미만으로 낮게 설정하면 소프트맥스 계층의 확률 분포 편차가 더 크게 증가되어 더 적은 수의 단어들의 집합에 확률이 집중됩니다.
대신 온도를 1보다 큰 높은 값으로 설정하면 모델이 다음 토큰에 대해 더 넓고 평탄한 확률 분포를 계산합니다.
시험환경
“프롬프트 엔지니어링 예시”의 포스트에서 사용한 프로그램을 연속적으로 사용하여 모델에 변동성을 도입하고 온도를 0.1에서 1.9까지 변화시켜 생성형 AI의 답변을 구해 보았습니다.

BASELINE HUMAN SUMMARY:
#Person2# arrives late because of traffic jam. #Person1# persuades #Person2# to use public transportations to keep healthy and to protect the environment.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.1):
Person1 is stuck in traffic and got stuck in a traffic jam. He thinks it would be better to take public transport to work. He thinks it would be better for the environment. He thinks biking to work would be better.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.2):
Person1 is stuck in traffic and has to take public transport to work.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.3):
Person2 got stuck in traffic at the Carrefour intersection. He thinks it's better to take public transport to work.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.4):
Person2 got stuck in a traffic jam near the Carrefour intersection. People are trying to find a different route to get home. People are trying to find a different way to get home. People are trying to find a different way to get home. People are trying to find a different way to get home.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.5):
Person1 is stuck in traffic after a terrible traffic jam near the Carrefour intersection. Person2 thinks it's better for the environment and for the environment.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.6):
Person2 was stuck in traffic while driving to work. He will consider taking public transport to work. He will consider taking the subway to work, if it's nicer outside.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.7):
There was a terrible traffic jam near the Carrefour intersection so Person2 decided to choose a different route to get home. They also think biking to work is a good option.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.8):
Taking the subway to work doesn't help the environment, so it's easier for Person2.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 0.9):
The traffic in this city is constantly congested. Public transport system is good for the environment but losing your freedom. Using subway or bike will help. People can take the bus if they want.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.0):
After having a terrible congestion in a traffic jam, the person is considering taking public transport to work. Taking public transport is a good idea, but the person argues that it can be avoided so they start biking to work in spring.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.1):
People go to work by public transport or bus. They are taking public transport as they have less pollution problems in this city.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.2):
There was a terrible traffic jam close the Carrefour Street intersection. Some travelers are planning to switch routes to work which are better for the environment. People say taking public transport to work is a good move. The transport system also offers some advantages, with the advantages also being better.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.3):
People find the traffic on the Carrefour intersection more congested on a fast transit route with an awful congenial street noise. The person think that it would be better if he started taking public transport to work when it's nice to be around like this, since it makes her and the public more conscious. He does, however, suggest biking to work or driving to work. Also suggested are going by train instead of driving to work, which can be healthier to the
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.4):
Driving to work can harm the environment and the environment and people tend to get really bad after every traffic stop near the Carrefour intersection.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.5):
In their conversation with someone yesterday, a friend of the party had decided to go cycling with them. They argued on the topic of reducing fuel costs too far away which would contribute to public transport as most of the people drive by car most of the time now. Their friend also thinks that cycling would help to make less pollutions in urban areas but also to keep it as quiet they may just wish walking on the bike was really interesting the most. The friend advises them not to
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.6):
No traffic in our neighbourhood was possible. #Pedestrians would only have the same chance without a car which contributes to pollution of their city. People drive to work in urban neighbourhoods for too long.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.7):
When you can use a vehicle while driving home during the rush hour then driving to place your phone away should be an option on those days they don't need a car at All. If your car was so far in the queue, you'g got too busy working! Now maybe your bus ticket had little traffic after a long flight; this egregious mishap occurred because you came at it in slow motion on Sunday Night and wanted time on top of you to relax by
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.8):
The car was being stuck in some congested mode.
---------------------------------------------------------------------------------------------------
MODEL GENERATION - FEW SHOT(Temparature = 1.9):
One week later and person from Person 2 has been congested because his car has caused pollution on roads. He thinks bicycle is one of more viable ideas and therefore might skip taking them to their destination on road or ride on the bus. Person1 has proposed biking to go working. Nobody likes to take the bus but wants the ride, and in a way, it works! Then someone gives it a try anyway. People have been biking around for different reasons and is satisfied
위 출력은 시험 코드를 Google Colab의 파이썬 노트북으로 실행 시켰을 때 얻을수 있는 화면입니다.
코드 부분에서 “do_sample” 인자를 “True”로 설정하였기 때문에 실행할때 마다 다른 결과를 얻습니다.
일반적으로 온도 값이 작을 수록 사람이 작성한 원안에 가까운 답을 내는 반면, 온도값이 커질수록 횡설 수설 해지며 일반적인 문장에 가까운 출력을 보여줍니다.
결론
좀 더 사람이 쓴 글에 가깝게 하기 위해서는 동일한 단어의 반복을 피해야 합니다.
생성형 AI LLM프로그램은 이른바 확률 계산기의 역할을 수행하기 때문에 확률이 높은 단어를 선택하는 경향이 있고 이런 단점을 극복하기 위하여 출력에 무작위성을 부여하는 방법을 LLM 모델마다 제공합니다.
이러한 변수들을 “구성 매개 변수” 라고 합니다.
LLM을 사용한 응용프로그램의 성격이 자연스러운 표현을 얻고자 하기 위함이면, 원하는 정확도 내에서 자연스러운 표현을 얻기 위한 구성 매개 변수 값을 조정해야 합니다.
대신, LLM의 출력이 문법적으로 정확해야 하는 경우 (예: 텍스트에 기반한 자동 API 호출), 구성 매개 변수 사용을 포기하고 원래의 greedy한 선택 알고리즘을 사용하는 것이 좋을 듯합니다.
긴 글 읽어 주셔서 감사합니다.
![A logo representing a calm, happy Sweden countryside village with only blue color palette [and has a minimalist and modern style] [incorporating elements of nature] [with a touch of Scandinavian design] [that reflects a sense of community]](https://i0.wp.com/raonstad.com/wp-content/uploads/2024/03/img-rsVXmvlyKd0umO7b2rMmaUnI.png?fit=1024%2C1024&ssl=1)