Tools

AI-generated text

Doug Turnbull’s approach: generate candidate tags then map them with vector embeddings

Doug Turnbull proposes a two-step tagging workflow for large tag vocabularies: prompt a language model to invent concise, plausible classifications for content, then use vector embeddings to match those imagined labels to the actual tag set.

Doug Turnbull’s approach: generate candidate tags then map them with vector embeddings

Managing a large set of tags can be difficult when the vocabulary grows beyond what you want to present to a language model at once. In the example discussed, the blog in question contains 1,856 tags — likely too many to list to a single LLM prompt and ask “which of these tags match this content?”.

Doug Turnbull’s approach: hallucinate tags, then map them to the real set

Doug Turnbull offers a simple two-step method: first ask the model to invent short, plausible classification labels for the content without showing it the full existing tag vocabulary. The model returns imagined, compact labels tailored to the content. Then, use vector embeddings to match those imagined labels against your actual tag corpus to find the closest real tags.

Steps in brief:

  1. Prompt the language model to generate concise, never-before-seen category labels for the query or content.
  2. Compute vector embeddings for the model-generated labels and for your existing tags or tagged content.
  3. Find nearest neighbors in vector space — the existing tags closest to the generated labels — and use those as the assigned tags.

Why this works

  • You avoid passing thousands of tags into the prompt, reducing prompt length and costs.
  • The model’s creative label suggestions help surface relevant concepts; embeddings ensure the final result maps back to your controlled tag vocabulary.

Example prompt shape

Turnbull suggests giving the model examples of the form your tags take so it generates more useful outputs. An illustrative prompt includes examples like:

Product classifications might look like:

  • Furniture / Living Room Furniture / Coffee Tables & End Tables / Coffee Tables
  • Décor & Pillows / Decorative Pillows & Blankets / Throw Pillows
  • Furniture / Bedroom Furniture / Dressers & Chests
  • Kitchen & Tabletop / Kitchen Organization / Food Storage & Canisters
  • School Furniture and Supplies / School Furniture / School Chairs & Seating / Stackable Chairs
  • Baby & Kids / Toddler & Kids Bedroom Furniture / Kids Beds

Then provide the specific query (for example, “brown coffee table”) and ask the model to generate classifications for it.

Tags shown in the example

The example query in the source is “brown coffee table”. The small tag list shown alongside the example includes: search, ai, generative-ai, llms, embeddings, doug-turnbull.

When to use this method

  • When your tag vocabulary is large (hundreds or thousands of entries) and impractical to provide to an LLM in full.
  • When you want to keep a controlled, consistent tag set while automating scalable tagging.

Conclusion

Turnbull’s two-step process — generate candidate labels with an LLM, then map them to existing tags via vector embeddings — offers an efficient compromise for large tag collections. It reduces prompt complexity while ensuring the assigned tags remain tied to the actual tag corpus.