# LogProbs

> Learn how to use logprobs to diagnose the performance of your scripts

`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.

* See [OpenAI Logprobs](https://cookbook.openai.com/examples/using_logprobs)

Note

The `logprobs` feature is not available in all models or providers.

## Logprobs

[Section titled “Logprobs”](#logprobs)

You can enable logprobs in the following ways:

* Use the `logprobs` flag on the run command

```sh
npx genaiscript run ... --logprobs
```

* add the `logprobs` flag to the `script` metadata

```js
script({ logprobs: true, ...})
```

### Colored output

[Section titled “Colored output”](#colored-output)

When `logprobs` is enabled, the [cli](/genaiscript/reference/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

[Section titled “Top logprobs”](#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.

```sh
npx genaiscript run ... --top-logprobs 4
```

* add the `topLogprobs` flag to the `script` metadata

```js
script({ topLogProbs: 4, ...})
```

### Colored output

[Section titled “Colored output”](#colored-output-1)

When `top-logprobs` are enabled, the console window is colored with the [entropy](https://people.math.harvard.edu/~ctm/home/text/others/shannon/entropy/entropy.pdf) 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

[Section titled “Alternate tokens”](#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\|> |

***