Gazetteer-Constrained Decoding for Toponym Resolution

Toponym resolution means deciding which real place a place name in text refers to: London in England or London in Ontario, one of dozens of Springfields, or "Reading" as a town rather than a verb. The strongest current systems still assemble three separate parts. A search engine retrieves candidate entries from a gazetteer, which is a database of places such as GeoNames with about 7 million entries. A trained neural model then scores or filters those candidates. A third set of rules handles country and state context. Large language models (LLMs) have broad geographic knowledge, but used on their own they can invent places that do not exist. The common fix is to paste a short retrieved candidate list into the prompt. That caps accuracy at whatever the retriever returned, and it uses up context length quickly for names that have hundreds of homonyms.

We propose to move the gazetteer out of the prompt and into the decoder. For each place mention, we build a prefix tree over the GeoNames entries whose name or alternate name matches the mention, with no top-k cutoff. The tree is ordered from coarse to fine: country, then first-level region, then second-level region, then feature class, then entry ID. During decoding, the model may only produce tokens that continue a real path in this tree. The rest of the output is ordinary JSON, enforced by standard grammar-constrained decoding. A frozen, prompted LLM can then find mentions and resolve them in a single pass. It is guaranteed to output only gazetteer entries that exist. It reaches every homonym at no context cost, and it makes the coarse-to-fine decision that GeoNorm hard-codes as a separate stage. The main claim is that decode-time constraints tied to the database outperform both a candidate list placed in the prompt and filtering after generation. We expect the advantage to be largest where those methods break: mentions with many candidates, mentions the retriever misses, and regions that current systems handle poorly.

Core Claim and Positioning

Grammar-constrained decoding restricts the next token so that output stays within a formal language. Current work in this area is purely syntactic. Stay Within Your Bounds (SWYB) guarantees context-free grammar validity under a token budget. Its authors state that it cannot check whether an identifier actually exists in a database. GCD/P-GCD removes sampling bias from local masking using automata on GPU. GREATGRAMMA aligns subword tokens with grammar terminals. None of these systems constrains output against an external knowledge base. We reuse their machinery, especially GREATGRAMMA's token-to-terminal alignment. The new part is an automaton built per mention from database rows, and a hierarchy order chosen so that each level narrows the next.

On the geographic side, GeoNorm combines search-engine sieves, a BERT reranker with population features, and a two-stage pass that resolves countries and states first. GeoPLACE predicts country, state, and feature class with a masked-language-model cloze prompt, then filters retrieved candidates using those predictions. Both motivate this proposal, since attribute constraints clearly help. Both also depend on a retrieval step whose misses cannot be recovered. GeoPLACE also constrains our design. Its authors chose single-token cloze prediction because free generation invented attribute values. Our constraint removes that failure by construction, because an invented value can never appear in the output. The survey Geoparsing: Solved or Biased? sets our evaluation lens. It shows that neural geoparsers have extreme error distances in underrepresented regions, with median error reaching 16,000 km. It also shows these systems form more cold spots than rule-based parsers. We test whether constraining to the full candidate tree reduces those failures or whether the LLM's prior toward well-known places simply reappears inside the tree.

The link to task fragmentation is practical. RexUIE and GLiNER2 show that one schema-driven model can replace many extraction pipelines. RexUIE blocks illegal type combinations through prompt design, and GLiNER2 uses special structural tokens. Neither system grounds entities in an external database, and neither guarantees validity at the token level. Our system is one prompted model and one decoder for the whole geoparsing task. The only external component is an index lookup that builds the tree.

Research Program

The output schema is a JSON list of records, each containing a mention span, a resolution path, and a "not a place" option. The span field is constrained so that it copies a substring of the input. When a span closes, we look up the span's normalized string in an alias index over GeoNames names and alternate names, with light normalization for case and diacritics. From the matching rows we build a trie over the tokenized path country / admin1 / admin2 / feature class / GeoNames ID. We compose that trie with the JSON grammar mask for the resolution field.

If the lookup returns nothing, the decoder falls back to a fuzzy-match tree, and past that to an "unresolved" value. We measure how often this happens rather than hiding it. When several entries share an identical path, a population prior breaks the tie; this is the popularity signal GeoNorm found useful.

Paths are short and have a fixed depth, so the token-budget failures that SWYB addresses do not arise here. We say so openly and budget only for the JSON wrapper. We will study three variations: zero-shot versus few-shot prompting, the tree order (coarse-to-fine versus ID-first), and whether other resolved mentions in the document may condition later ones. The last is spatial coherence, where places mentioned together tend to be near each other.

Baselines

The naive reference point is the same LLM and prompt with no constraint. Its free-text answer is mapped to the nearest valid GeoNames entry by string match. This measures how much the constraint adds beyond the model's own knowledge.

The strongest existing method is GeoPLACE. It reports accuracy of 0.863 on LGL and 0.947 on TR-News, plus a 30% reduction in mean error distance (GeoPLACE). GeoNorm reports 80.7% on LGL (GeoNorm). We found no exact accuracy on Lacuna for either system on GeoWebNews, and no reported resolution accuracy for GeoCorpora. We will rerun both systems ourselves on identical gold mention sets and the same GeoNames snapshot.

Beating GeoPLACE means higher accuracy on LGL and GeoWebNews at a matched or lower error distance, with no training. We would also accept matching its accuracy while clearly improving error distance in cold-spot regions.

The most important ablation is a multiple-choice prompt baseline, in the style of Young Min Cho and colleagues. It uses the same model, fed the top-k Lucene candidates with their hierarchy paths, for k of 10 and 50. A second ablation is a truncated tree restricted to those same top-k candidates. Comparing the full and truncated trees isolates the effect of candidate recall. Comparing the truncated tree with the multiple-choice prompt isolates the effect of placing candidates in the decoder rather than in the context.

All LLM variants use the same open models that SWYB evaluated (Llama-3.1-8B, Qwen2.5-7B), the same prompts, the same exemplars, and the same number of prompt-tuning trials on a held-out split.

Why not just…?

Why not just give the LLM the retrieved candidates as a multiple-choice list? This is the real threat. On benchmarks where Lucene top-20 recall is near perfect, it may match our method. The full-versus-truncated tree ablation settles the question. If our gains come only from mentions whose gold entry falls outside the top-k, then the contribution is recall at no context cost. If the truncated tree also beats the prompt list, then decoding the hierarchy step by step helps in its own right. If neither holds, we will report that the constraint adds nothing over a good list.

Why not generate attributes freely and filter afterwards, as GeoPLACE does? Filtering after generation cannot recover once the model commits to a wrong or invented country. It then leaves an empty or wrong set of candidates. The unconstrained-then-snapped baseline measures how often this happens, and we will report the share of outputs with an empty intersection.

Why not just prompt a frontier model zero-shot? RexUIE reports zero-shot ChatGPT at 21.76 F1 against RexUIE's 30.62 on CoNLL04, and traces the gap to schema-violating outputs. That is indirect evidence for extraction tasks, not for geography. Where budget allows, we will include a frontier-model run with post-hoc snapping. Our argument is that a constrained 8B model runs locally and can never output a nonexistent entry.

Proposed Experiments

We will evaluate resolution with gold mentions on LGL, GeoWebNews, and TR-News, reporting accuracy and mean and median error distance. We will separately evaluate joint recognition and resolution on those benchmarks and on GeoCorpora, reporting span F1 alongside resolution metrics.

The decisive analysis stratifies results in three ways: by the number of gazetteer homonyms, by whether the gold entry falls inside the retriever's top-k, and by world region, following the spatial statistics of Geoparsing: Solved or Biased?. The central prediction is specific. Our method's advantage over multiple-choice prompting should grow with homonym count, and it should be concentrated in retrieval misses and in regions outside North America and Western Europe.

A negative result would also be informative: the full tree could expose more obscure homonyms and increase popularity-driven errors. To check this, we will record the constrained model's probability at each level of the tree. That tells us whether errors arise at the country step or the fine-grained step, and shows whether the model's geographic prior, and not a lack of candidates, is what causes the regional failures.