📖

Temperature(AI) とは?

Temperature(温度)は、AIモデルの出力がランダムか予測可能かを制御するサンプリングのハイパーパラメータです。その仕組み、重要性、設定方法について解説します。

AIにおけるTemperature(温度)とは、モデルが次のトークン、単語、ピクセルを選ぶ際に用いる確率分布の形状を変えることで、出力のランダム性を制御するハイパーパラメータです。これは主に大規模言語モデル(LLM)やその他の生成モデルの文脈で議論され、予測可能性創造性の間のダイヤルの役割を果たします。値を下げると、モデルは毎回最も確率の高い選択肢を選ぶ傾向があります。値を上げると、確率が低い選択肢にも果敢に挑戦するようになります。

Temperatureの仕組み

各トークンを生成する前に、モデルは語彙内のすべての候補に対してロジットと呼ばれる生のスコアを計算します。これらのロジットはsoftmax関数によって確率に変換され、ここでTemperatureが作用します。softmaxを適用する前に、各ロジットをTemperatureの値Tで割ります。

T = 1の場合、分布は変化しません。T < 1の場合、確率はばらつき、既により確率の高いトークンはさらに確率が高くなるため、サンプリングはモデルの「最良の推測」に近い状態を保ちます。T > 1の場合、分布は平坦化され、確率が低いトークンの割合が増えるため、出力はより多様になります。例えば、モデルが次の単語として「the」を60%の確信度、「a」を20%の確信度で考えている場合、Temperature 0.2ではほぼ毎回「the」が出力されますが、Temperature 1.2では約5回に1回の割合で「a」が出力されます。

Temperatureが重要である理由

Temperatureは、再学習なしにモデルの挙動を形づくる最もシンプルかつ強力なレバーのひとつです。低温は、コード生成や事実ベースの質問応答、構造化データ抽出など精度が求められ、ハルシネーションがコストになるタスクで好まれます。高温は、ブレインストーミングやストーリーテリング、対話など、正確さよりも新規性や多様性が重視される場面で有用です。

また、プロンプトエンジニアリングの重要な要素でもあります。OpenAI、Anthropic、Googleが提供するものを含むほとんどのLLM APIでは、top-p(nucleus sampling)やtop-kといった関連設定とともに、Temperatureを調整可能なパラメータとして公開しています。ユーザー体験に直接影響を与えるため、モデルをデモから本番環境に移行する際に開発者が最初に調整する設定のひとつです。

主要なTemperatureの範囲と使いどころ

  • 0.0 — グリーディデコーディング。モデルは常に最も確率の高いトークンを選びます。決定論的で、再現可能なコードや数学に適しています。
  • 0.0〜0.3 — 低めで集中力が高い。翻訳、要約、分類、事実ベースの応答に適しています。
  • 0.4〜0.7 — バランス型。一般的なチャットアシスタントのデフォルト値としてよく使われます。
  • 0.7〜1.0 — やや多様。クリエイティブな文章、マーケティングコピー、アイデア発想に有用です。
  • 1.0以上 — 非常にランダム。出力が支離滅裂になる可能性があり、研究や実験的なアート以外ではほとんど使われません。

Temperatureは決定的な指標ではなく、調整ノブとして捉えるのが最適です。top-ptop-kサンプリングと組み合わせ、特定のタスク、モデル、対象ユーザーに応じて調整してください。同じ値でも用途によって感じ方が大きく異なることがあります。

よくある質問

What is a good temperature value for ChatGPT or other LLMs?
A temperature between 0.2 and 0.7 is a sensible starting point for most tasks. Use the lower end for factual answers, coding, and summarization where consistency matters, and the higher end for brainstorming or creative writing where variety is welcome. Many production systems default to around 0.7 for general conversation.
What is the difference between temperature and top-p in AI?
Temperature rescales the entire probability distribution, making it sharper or flatter before a token is sampled. Top-p (nucleus sampling) instead trims the distribution to the smallest set of tokens whose combined probability exceeds a threshold like 0.9. The two settings are complementary: temperature changes how spread out probabilities are, while top-p changes how many candidates are considered at all.
Does temperature 0 make AI outputs identical every time?
Usually, yes, but not always. Temperature 0 (greedy decoding) makes the model pick the single most probable next token at every step, so on a fixed prompt with no other randomness in the pipeline, the output is reproducible. In practice, parallelism, batching, and floating-point quirks on GPUs can occasionally introduce small variations, which is why some teams still set very low values like 0.01 instead of true zero for strict reproducibility.
Can higher temperature make a model more accurate?
Not in general. Higher temperature increases diversity and creativity but also raises the chance of factual errors and hallucinations. For tasks where accuracy is measured against a known answer, lower temperatures almost always perform better on benchmarks. Higher temperatures can occasionally help on tasks with many valid responses, where exploration unlocks a better answer than the model's first guess.