Spaces:
Running
Running
metadata
title: Prompt Squirrel — Tag Retrieval System
colorFrom: indigo
colorTo: purple
sdk: gradio
sdk_version: 5.43.1
python_version: 3.10.12
app_file: app.py
pinned: false
license: apache-2.0
short_description: Closed-vocabulary tag retrieval from natural language
emoji: 🧠
Prompt Squirrel — Tag Retrieval System
Prompt Squirrel performs semantic search over a fixed image-tag vocabulary, mapping natural-language descriptions to relevant tags via retrieval and ranking.
The interface then allows users to interactively refine these retrieved tags into a final prompt.
System Overview
This project demonstrates a multi-stage retrieval pipeline:
- Query rewriting (LLM)
- Candidate generation (TF-IDF + embeddings)
- Candidate ranking and selection (closed-set LLM)
- Interactive refinement (UI)
Key Properties
- Closed vocabulary (no hallucinated tags)
- Retrieval-first architecture (no direct generation)
- Transparent intermediate stages for inspection and debugging
What This Space Does
- Rewrites free text into retrieval-friendly query phrases (LLM).
- Retrieves candidate tags from a fixed vocabulary using semantic search.
- Ranks and filters candidates via closed-set LLM selection (no invented tags).
- Expands implied concepts and organizes results into editable groups.
- Lets users refine and assemble the final prompt via interactive controls.
How To Use
- Enter an image description in
Enter Prompt. - Click
Run. - Toggle tags in rows to add/remove them.
- Copy the final text from
Suggested Prompt.
Technologies Used
- FastText embeddings for semantic retrieval.
- HNSW indexes for efficient nearest-neighbor search.
- Reduced TF-IDF vectors for context-aware ranking.
- OpenRouter instruction models for rewrite, structural inference, probe inference, and closed-set selection.
Default model:
mistralai/mistral-small-24b-instruct-2501(chosen empirically on internal caption-evident evaluations; configurable). - Gradio for the interactive web UI.
Current Snapshot
Latest relabel-aware rescore on caption-evident n=30:
- Micro precision/recall/F1:
0.554 / 0.750 / 0.638 - Macro precision/recall/F1:
0.564 / 0.764 / 0.633 - Ground-truth scale: 30 images, 440 total tag assignments, 205 unique tags
Latency from local UI timing logs (n=110 runs):
- Median:
8.56s - P75:
12.56s - P90:
18.33s
Documentation And Contracts
- Full architecture and rationale (same source used by the in-app docs accordion): docs/space_overview.md
- Retrieval contract: docs/retrieval_contract.md
- Rewrite contract: docs/rewrite_contract.md
- Closed-set selection contract: docs/stage3_contract.md