osanseviero commited on
Commit
320af82
1 Parent(s): b5ec15f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -2,6 +2,18 @@ import numpy as np
2
  import matplotlib.pyplot as plt
3
  import gradio as gr
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def get_initial_distribution(seed=42):
6
  np.random.seed(seed) # For reproducibility
7
  token_probs = np.random.rand(10)
@@ -62,7 +74,9 @@ interface = gr.Interface(
62
  gr.Slider(0.0, 1.0, step=0.01, value=0.9, label="Top-p"),
63
  ],
64
  outputs=gr.Plot(label="Token Probability Distribution"),
65
- live=True
 
 
66
  )
67
 
68
  interface.launch()
 
2
  import matplotlib.pyplot as plt
3
  import gradio as gr
4
 
5
+ description = """## Token Probability Distribution Explorer
6
+
7
+ This interactive tool lets you visualize how different parameters affect the probability distribution of tokens.
8
+
9
+ - **Temperature**: Controls the randomness of predictions. Higher values (e.g., 2.0) make the distribution more uniform, while lower values (e.g., 0.1) make it peakier.
10
+ - **Top-k**: Limits the number of most likely tokens to consider. For example, `top_k=5` means only the top 5 tokens are considered, and others are set to zero probability.
11
+ - **Top-p (nucleus sampling)**: Limits the tokens to those whose cumulative probability mass is below a certain threshold. For instance, `top_p=0.9` means only tokens contributing to the top 90% of probability are considered.
12
+
13
+ Adjust the sliders to see how each parameter influences the token probabilities. All tokens will always have some non-zero probability in the initial distribution.
14
+ To learn more about LLM generation, check out the early release of [Hands-On Generative AI with Transformers and Diffusion Models](https://learning.oreilly.com/library/view/hands-on-generative-ai/9781098149239/).
15
+ """
16
+
17
  def get_initial_distribution(seed=42):
18
  np.random.seed(seed) # For reproducibility
19
  token_probs = np.random.rand(10)
 
74
  gr.Slider(0.0, 1.0, step=0.01, value=0.9, label="Top-p"),
75
  ],
76
  outputs=gr.Plot(label="Token Probability Distribution"),
77
+ live=True,
78
+ title="Explore generation parameters of LLMs",
79
+ description
80
  )
81
 
82
  interface.launch()