Skip to content

LogProbs

logprobs is a mode where LLMs return the probability of each token. topLogProbs also returns list list of alternate tokens and their log probabilities. This can be useful for debugging and understanding the model’s behavior.

Logprobs

You can enable logprobs in the following ways:

  • Use the logprobs flag on the run command
Terminal window
npx genaiscript run ... --logprobs
  • add the logprobs flag to the script metadata
script({ logprobs: true, ...})

Colored output

When logprobs is enabled, the cli will color the output based on the probability of each token. Blue color indicates high probability and red color indicates low probability.

Here is an example of logprobs in action when running a poem prompt with gpt-4o.


In  the  whisper  of  trees ,  the  night  softly  speaks ,   
Where  the  moon light  we aves  through  the  shadows  it  seeks .   
Stars  tw inkle  above ,  like  dreams  far  away ,   
Painting  the  night  with  the  dawn ’s  gentle  sway .

Top logprobs

You can enable top-logprobs in the following ways:

  • Use the top-logprobs flag on the run command. It enables logprobs as well.
Terminal window
npx genaiscript run ... --top-logprobs 4
  • add the topLogprobs flag to the script metadata
script({ topLogProbs: 4, ...})

Colored output

When top-logprobs are enabled, the console window is colored with the entropy of the alternate tokens.


In  the  whisper  of  trees ,  the  night  softly  speaks ,   
Where  the  moon light  we aves  through  the  shadows  it  seeks .   
Stars  tw inkle  above ,  like  dreams  far  away ,   
Painting  the  night  with  the  dawn ’s  gentle  sway .

Alternate tokens

The trace contains a rendering of the alternate tokens with colored output based on the logprobs.


In
B
Am
the
whispers
twilight
whisper
hush
quiet
of
ing
’s
the
dawn
leaves
,
at
where
the
a
where
wind
secrets
breeze
unfolds
softly
does
sigh
sings
hum
,
,\
,

Stars
A
Moon
moon
the
stars
moon
stars
silver
light
’s
paints
dances
gently
we
aves
eps
avers
through
dreams
silver
the
shadow
shadows
gentle
sky
shadows
it
and
seeks
keeps
streak
.
,
;

Stars
A
Dream
tw
like
dance
inkle
ink
irl
like
above
gently
in
,
like
like
in
a
dreams
eyes
secrets
in
taking
set
away
and
yet
,
;

Guid
In
Painting
the
silence
night’s
sky
night
darkness
with
in
sky
a
the
their
glow
light
colors
of
’s
’s
gentle
first
early
sway
gray
ray
.
.
.
<|end|>