This interactive application helps users visualize and understand the effects of key parameters (temperature, top_p, and top_k) on text generation using language models from Hugging Face.
- Interactive Parameter Control: Adjust temperature, top_p, and top_k in real-time
- Model Selection: Use any text generation model from Hugging Face
- Real-Time Text Generation: See how parameter changes affect generated text
- Save & Load Settings: Store your preferred configurations for later use
- Detailed Parameter Explanations: Learn what each parameter does and how it affects generation
- Python 3.10+
- PyTorch
- Transformers
- Gradio
- Requests
-
Clone this repository:
git clone https://github.com/krishna-f22/llm-parameter-visualization.git cd llm-parameter-visualization -
Create a virtual environment using Python 3.10:
python3.10 -m venv .venv
-
Activate the virtual environment:
-
On macOS/Linux:
source .venv/bin/activate -
On Windows:
.venv\Scripts\activate
-
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
-
Open your web browser and navigate to
http://127.0.0.1:7860 -
Enter a model name from Hugging Face, adjust the parameters, and see the generated text change in real-time.
Temperature controls the randomness of the model's predictions.
- Low temperature (e.g., 0.1-0.3): More deterministic and focused outputs. The model will more consistently choose the highest probability tokens.
- Medium temperature (e.g., 0.7-1.0): Balanced between deterministic and creative outputs.
- High temperature (e.g., 1.5-2.0): More random and diverse outputs. The model is more likely to choose lower probability tokens.
Top-p sampling (also called nucleus sampling) sets a probability threshold and only considers tokens whose cumulative probability exceeds this threshold.
- Low top-p (e.g., 0.1-0.3): Only the most likely tokens are considered, resulting in more focused outputs.
- Medium top-p (e.g., 0.5-0.7): Balanced between focused and diverse outputs.
- High top-p (e.g., 0.9-1.0): Most tokens are considered, allowing for more diverse outputs.
Top-k limits the set of tokens the model considers to the k highest probability tokens.
- Low top-k (e.g., 1-10): Very restrictive, considering only the most likely tokens, which increases coherence but limits creativity.
- Medium top-k (e.g., 20-50): Balanced between coherence and creativity.
- High top-k (e.g., 80-100): More tokens are considered, allowing for greater diversity in the output.
- Adjust parameters to your liking
- Click "Save Current Settings" to store them locally
- Use "Export Settings" to download a configuration file
- Click "Browse" in the "Import Settings" section
- Select a previously exported settings file
- Click "Load Imported Settings"
llm-parameter-visualization/
├── app.py # Main application file
├── README.md # This documentation
└── locally_stored_model/ # Directory for saved settings and models
├── settings.json # Saved parameter settings
└── selected_model.txt # Last used model name
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Hugging Face for their amazing transformers library
- Gradio for the interactive UI framework
- F22Labs for their hardware and immense opportunities.
