A
zero‑shot / few‑shot geographic‑entity extractor built on
mistralai/Mistral‑7B‑Instruct‑v0.2.
Instead of fine‑tuning, the model relies on a carefully crafted
system prompt that asks it
to return
only a JSON object listing every location in the user‑supplied sentence.
Quantised to
4‑bit with
bitsandbytes
→ fits in ≈ 6 GB VRAM, so it runs on free Colab GPUs and most consumer cards.
1from transformers import pipeline
2
3extractor = pipeline(
4 "text-generation",
5 model="boods/mistral-location-extractor-4bit",
6 model_kwargs=dict(load_in_4bit=True, torch_dtype="auto"),
7)
8
9sentence = "I spent last summer in Douala and Yaoundé before heading to Paris."
10prompt = (
11 "<s>[INST] You are a precise information‑extraction assistant. "
12 "Identify every geographical location mentioned in the user’s sentence. "
13 'Return ONLY a valid JSON object of the form {"locations": [...]} '
14 "Return an empty list if no location is found. [/INST]\n"
15 f"Sentence: {sentence}\nAnswer:"
16)
17
18print(extractor(prompt, max_new_tokens=96, do_sample=False)[0]["generated_text"])
19# ➜ {"locations": ["Douala", "Yaoundé", "Paris"]}
1<s>[INST] {SYSTEM_INSTRUCTIONS} [/INST]
2Sentence: {user_sentence}
3Answer:
1@misc{mistral_location_extractor,
2 title = {Mistral Location Extractor (4‑bit, prompt‑engineered)},
3 author = {Hugging Face user: boods},
4 year = {2025},
5 url = {https://huggingface.co/boods/mistral-location-extractor-4bit}
6}