Text Generation
Safetensors
unsloth
gemma4
trl
spatial
humanitarian
tool-calling
lora
offline
edge-ai
raspberry-pi
conversational
Instructions to use tasfuuu19/gemma-4-e2b-spatial-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Desktop
Add detailed model card
Browse files
README.md
CHANGED
|
@@ -1,22 +1,185 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
-
- text-generation-inference
|
| 5 |
-
- transformers
|
| 6 |
- unsloth
|
| 7 |
- gemma4
|
| 8 |
- trl
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- bn
|
| 5 |
+
- es
|
| 6 |
+
- id
|
| 7 |
+
license: apache-2.0
|
| 8 |
+
base_model: google/gemma-4-e2b-it
|
| 9 |
tags:
|
|
|
|
|
|
|
| 10 |
- unsloth
|
| 11 |
- gemma4
|
| 12 |
- trl
|
| 13 |
+
- spatial
|
| 14 |
+
- humanitarian
|
| 15 |
+
- tool-calling
|
| 16 |
+
- lora
|
| 17 |
+
- offline
|
| 18 |
+
- edge-ai
|
| 19 |
+
- raspberry-pi
|
| 20 |
+
pipeline_tag: text-generation
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# gemma-4-e2b-spatial-lora
|
| 24 |
+
|
| 25 |
+
> **Gemma 4 E2B fine-tuned for humanitarian spatial tool calling**
|
| 26 |
+
> Part of [GemmaTerrain](https://huggingface.co/tasfuuu19) — Multimodal GeoAI for the Unconnected
|
| 27 |
+
|
| 28 |
+
[](https://huggingface.co/google/gemma-4-e2b-it)
|
| 29 |
+
[](https://opensource.org/licenses/Apache-2.0)
|
| 30 |
+
[](https://github.com/unslothai/unsloth)
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## Overview
|
| 35 |
+
|
| 36 |
+
This is a **LoRA adapter** for `google/gemma-4-e2b-it`, fine-tuned to output structured JSON tool calls for humanitarian spatial queries. It runs offline on ARM edge hardware (Raspberry Pi 5, Steam Deck) as part of the GemmaTerrain system — no internet, no cloud, no GPU required.
|
| 37 |
+
|
| 38 |
+
Given a natural language query in English, Bangla, Spanish, or Indonesian, the model selects exactly one spatial tool and outputs its arguments as JSON.
|
| 39 |
+
|
| 40 |
+
**Example:**
|
| 41 |
+
|
| 42 |
+
| Input | Output |
|
| 43 |
+
|---|---|
|
| 44 |
+
| `"Find the nearest hospital to Camp 6"` | `{"name": "find_nearest_poi_with_route", "arguments": {"poi_type": "hospital", "lat": 21.2, "lon": 92.16}}` |
|
| 45 |
+
| `"15 minute walking radius from Condado"` | `{"name": "generate_isochrone", "arguments": {"lat": 18.46, "lon": -66.07, "max_minutes": 15}}` |
|
| 46 |
+
| `"Camp 6 er kache hospital kothay?"` | `{"name": "find_nearest_poi_with_route", "arguments": {"poi_type": "hospital", "lat": 21.2, "lon": 92.16}}` |
|
| 47 |
+
| `"Farmacias dentro de 1km de Ocean Park"` | `{"name": "list_pois", "arguments": {"poi_type": "pharmacy", "lat": 18.46, "lon": -66.05, "radius_m": 1000}}` |
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Spatial Tools
|
| 52 |
+
|
| 53 |
+
The model is trained to call exactly one of these 6 tools:
|
| 54 |
+
|
| 55 |
+
| Tool | Use case |
|
| 56 |
+
|---|---|
|
| 57 |
+
| `find_nearest_poi_with_route` | "Nearest hospital to X" — returns closest POI + walking route |
|
| 58 |
+
| `list_pois` | "Clinics within 2km of X" — returns all POIs in radius |
|
| 59 |
+
| `calculate_route` | "Walk from A to B" — returns distance + time |
|
| 60 |
+
| `generate_isochrone` | "15 min walking area from X" — returns reachable boundary |
|
| 61 |
+
| `find_along_route` | "Pharmacies along the way from A to B" |
|
| 62 |
+
| `geocode_place` | "Where is X?" — resolves place name to coordinates |
|
| 63 |
+
|
| 64 |
+
**Supported POI types:** `hospital`, `clinic`, `doctors`, `pharmacy`, `police`, `fire_station`, `shelter`, `school`, `university`, `bank`, `atm`, `supermarket`, `marketplace`, `drinking_water`, `water_point`, `fuel`, `bus_station`, `place_of_worship`
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## Training Details
|
| 69 |
+
|
| 70 |
+
| Parameter | Value |
|
| 71 |
+
|---|---|
|
| 72 |
+
| Base model | `google/gemma-4-e2b-it` |
|
| 73 |
+
| Method | QLoRA (4-bit quantization) |
|
| 74 |
+
| LoRA rank | 16 |
|
| 75 |
+
| LoRA alpha | 32 |
|
| 76 |
+
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj` |
|
| 77 |
+
| Max sequence length | 512 tokens |
|
| 78 |
+
| Training examples | 28 unique × augmented to 5,000 |
|
| 79 |
+
| Epochs | 3 |
|
| 80 |
+
| Batch size | 2 (effective: 8 with grad accumulation) |
|
| 81 |
+
| Learning rate | 2e-4 |
|
| 82 |
+
| Precision | fp16 |
|
| 83 |
+
| Framework | Unsloth + TRL SFTTrainer |
|
| 84 |
+
| Hardware | Kaggle T4 (15GB) |
|
| 85 |
+
| Training time | ~45 minutes |
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## Dataset
|
| 90 |
+
|
| 91 |
+
28 hand-crafted humanitarian spatial query → tool call pairs across **3 real-world locations** and **4 languages**:
|
| 92 |
+
|
| 93 |
+
| Location | Context |
|
| 94 |
+
|---|---|
|
| 95 |
+
| **Cox's Bazar, Bangladesh** | Rohingya refugee camps (Camp 3, 6, 8W, 9, 12, 15) |
|
| 96 |
+
| **San Juan, Puerto Rico** | Post-hurricane disaster response (Condado, Santurce, Miramar) |
|
| 97 |
+
| **Jakarta, Indonesia** | Urban humanitarian operations (Menteng, Gelora, Gambir, Kemang) |
|
| 98 |
+
|
| 99 |
+
**Languages:** English · Bangla (transliterated) · Spanish · Indonesian
|
| 100 |
+
|
| 101 |
+
**Query types:** nearest POI, radius search, route calculation, isochrone, along-route search
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## System Prompt
|
| 106 |
+
|
| 107 |
+
```
|
| 108 |
+
You are Meridian, a humanitarian spatial assistant running offline on edge hardware.
|
| 109 |
+
Select exactly ONE tool. Output only the tool call JSON — no explanation.
|
| 110 |
+
|
| 111 |
+
Valid poi_type values: hospital, clinic, doctors, pharmacy, police, fire_station,
|
| 112 |
+
shelter, school, university, bank, atm, supermarket, marketplace, drinking_water,
|
| 113 |
+
water_point, fuel, bus_station, place_of_worship
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Usage
|
| 119 |
+
|
| 120 |
+
### With Unsloth (recommended)
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
from unsloth import FastModel
|
| 124 |
+
|
| 125 |
+
model, tokenizer = FastModel.from_pretrained(
|
| 126 |
+
model_name="tasfuuu19/gemma-4-e2b-spatial-lora",
|
| 127 |
+
max_seq_length=512,
|
| 128 |
+
load_in_4bit=True,
|
| 129 |
+
)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
### With Transformers
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
from peft import PeftModel
|
| 136 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 137 |
+
|
| 138 |
+
base = AutoModelForCausalLM.from_pretrained("google/gemma-4-e2b-it", load_in_4bit=True)
|
| 139 |
+
model = PeftModel.from_pretrained(base, "tasfuuu19/gemma-4-e2b-spatial-lora")
|
| 140 |
+
tokenizer = AutoTokenizer.from_pretrained("tasfuuu19/gemma-4-e2b-spatial-lora")
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### Inference example
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
messages = [
|
| 147 |
+
{"role": "system", "content": "You are Meridian, a humanitarian spatial assistant..."},
|
| 148 |
+
{"role": "user", "content": "Find the nearest hospital to Camp 6"},
|
| 149 |
+
]
|
| 150 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 151 |
+
inputs = tokenizer(text, return_tensors="pt").to("cuda")
|
| 152 |
+
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
|
| 153 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 154 |
+
# {"name": "find_nearest_poi_with_route", "arguments": {"poi_type": "hospital", "lat": 21.2, "lon": 92.16}}
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
---
|
| 158 |
|
| 159 |
+
## GemmaTerrain System
|
| 160 |
+
|
| 161 |
+
This adapter is the **E2B component** of the GemmaTerrain dual-model routing system:
|
| 162 |
+
|
| 163 |
+
```
|
| 164 |
+
Query → Geocode Layer → Cactus Router → Gemma 4 E2B (this model) → Spatial Tool → Result
|
| 165 |
+
↘ Gemma 4 E4B (complex/multimodal queries)
|
| 166 |
+
```
|
| 167 |
|
| 168 |
+
The router sends queries to E2B for simple spatial lookups (nearest, list, route, isochrone) and to E4B for multimodal or complex multi-hop reasoning. Battery level is also a routing signal — below 20%, all queries go to E2B.
|
| 169 |
+
|
| 170 |
+
The spatial backend uses **NetworKit** (Dijkstra routing) + **DuckDB** (spatial queries) on OpenStreetMap data, running fully offline.
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## Limitations
|
| 175 |
+
|
| 176 |
+
- Training set is small (28 unique examples) — generalization relies heavily on the base model
|
| 177 |
+
- Coordinates in training data are fixed to 3 locations; novel locations require geocoding pre-processing
|
| 178 |
+
- Walking speed hardcoded at 5 km/h (83.33 m/min)
|
| 179 |
+
- Not suitable for driving or cycling routing
|
| 180 |
+
|
| 181 |
+
---
|
| 182 |
|
| 183 |
+
## License
|
| 184 |
|
| 185 |
+
Apache 2.0 — same as the base Gemma 4 model.
|