# Using SPA from Hugging Face Hub This guide shows you how to use Selective Prompt Anchoring (SPA) directly from the Hugging Face Hub. ## Installation First, install the required packages: ```bash pip install huggingface_hub torch transformers ``` ## Basic Usage Here's a simple example of how to use SPA: ```python from huggingface_hub import hf_hub_download import sys import os # Download the SPA files from the Hub repo_id = "YOUR_USERNAME/selective-prompt-anchoring" # Replace with your username spa_file = hf_hub_download(repo_id=repo_id, filename="spa.py") spa_hf_file = hf_hub_download(repo_id=repo_id, filename="spa_hf.py") # Add the directory containing the files to the Python path sys.path.append(os.path.dirname(spa_file)) # Now you can import from the downloaded files from spa_hf import load_spa_model # Load SPA with just the base model, ignoring any saved configurations spa_model = load_spa_model( model_name=None, # Skip loading from Hub base_model_name="Qwen/Qwen3-0.6B", # Use your preferred base model device_map="auto" # Use "cpu" if you don't have a GPU ) # Use SPA to emphasize specific tokens prompt = "How is the weather today?" anchors = ["today"] output = spa_model.generate_with_spa( prompt=prompt, anchors=anchors, anchoring_strength=3.0, # Adjust strength to control anchor influence max_new_tokens=200 ) print(output) ``` ## Advanced Usage For more advanced usage, including different input formats and parameter settings, check out the [GitHub repository](https://github.com/magic-YuanTian/Selective-Prompt-Anchoring) or the [Documentation](https://huggingface.co/docs/selective-prompt-anchoring).