Guide
Cuisine tagging
On this page
Cuisine filters and category pages only work when items carry a cuisine, and many menus don't. This guide tags items with POST /classify, stores the labels, and rolls them up into restaurant tags you can filter on.
- Endpoint
POST /classify- Plans
- Every plan
- Try it
- Run it in the playground
How it works
- Send item names to /classify, up to 512 per request.
- Each item comes back with one cuisine label and a confidence between 0 and 1, in the order you sent them.
- Items the API isn't confident about come back as
"uncertain". Send those to review or leave them untagged. - Store the label and confidence with each item, then roll item labels up into restaurant tags.
The label set
/classify picks one label per item from a fixed set of 19:
It returns one cuisine and a confidence per item. Meal categories appear in /suggest responses. An item from a cuisine outside this set gets the closest of the 19 labels.
Tag a menu
import os
import requests
BASE = "https://dish-embed.latimal.com"
headers = {"X-API-Key": os.environ["LATIMAL_API_KEY"], "Content-Type": "application/json"}
def classify_items(items, batch_size=512):
"""Return one {text, cuisine, confidence} result per item, in input order."""
results = []
for i in range(0, len(items), batch_size):
resp = requests.post(f"{BASE}/classify", headers=headers,
json={"items": items[i:i + batch_size]})
resp.raise_for_status()
results.extend(resp.json()["results"])
return results
menu = [
"Pad Thai",
"Margherita Pizza",
"Bibimbap",
"Chicken Tinga Tacos",
"Croissant",
"Cold Brew Coffee",
]
for r in classify_items(menu):
print(f"{r['text']}: {r['cuisine']}")Example output, labels only:
Pad Thai: Thai
Margherita Pizza: Italian
Bibimbap: Korean
Chicken Tinga Tacos: Mexican
Croissant: Bakery
Cold Brew Coffee: BeveragesHandle uncertain results
"uncertain" means the item fell below the API's confidence threshold. Treat it as "no label" and route the item to review, or leave it out of cuisine filters.
You can also set your own, stricter floor on confidence for items that drive visible filters. Pick it from a labeled sample of your own menus.
REVIEW_BELOW = 0.6 # your choice; tune it on a labeled sample of your menus
tagged, review = [], []
for r in classify_items(menu):
if r["cuisine"] == "uncertain" or r["confidence"] < REVIEW_BELOW:
review.append(r["text"])
else:
tagged.append(r)Roll up to restaurant tags
/classify works per item. A restaurant tag is something you compute from its item labels. One simple rule: tag the restaurant with each label that covers a meaningful share of its tagged items.
Drinks, baked goods and desserts get their own labels (Beverages, Bakery, Desserts), so a pizzeria with a long drinks list could pick up a Beverages tag. Leave those labels out of the roll-up if you only want to tag the food.
from collections import Counter
NON_CUISINE = {"Bakery", "Beverages", "Desserts"}
def restaurant_tags(results, min_share=0.25, skip=NON_CUISINE):
labels = [r["cuisine"] for r in results
if r["cuisine"] != "uncertain" and r["cuisine"] not in skip]
if not labels:
return []
counts = Counter(labels)
return [label for label, n in counts.most_common() if n / len(labels) >= min_share]If you already run POST /report on a menu, its cuisine_breakdown.distribution (when cuisine_breakdown isn't null) is a label-to-count map for that menu. Apply the same skip set and share rule to those counts.
Map labels to your filters
Your app's filters probably don't line up one to one with the 19 labels. Keep a small mapping on your side, so you can change filters later without calling the API again:
FILTERS = {
"Asian": {"Chinese", "Japanese", "Korean", "SE Asian", "Thai", "Vietnamese"},
"European": {"Continental", "European", "Italian"},
"Mediterranean and Middle Eastern": {"Mediterranean", "Middle Eastern"},
"American": {"American"},
"Mexican": {"Mexican"},
"South Asian": {"Mughlai", "North Indian", "South Indian"},
"Sweets and drinks": {"Bakery", "Beverages", "Desserts"},
}
def filters_for(label):
return [name for name, labels in FILTERS.items() if label in labels]When to re-tag
- Menu import or sync: classify new and renamed items only. Keep a map from item text to its stored label, so unchanged items skip the call.
- A new review floor or filter mapping: no new calls. You stored the labels and confidences, so re-run your own rules.
Tips
- Send raw item names. The API strips promo markers, prices and serving sizes before it classifies.
- Classify items, then derive the restaurant tag from them.
- Each item gets one label. A fusion dish gets the label that fits it best.
Limits
- Items: 1 to 512 per request
- 500 characters per item