Downloads · 30 days
0
markrodrigo/Llama-3.2-3B-Instruct-Spatial-SQL-1.1-Docs
Llama-3.2-3B-Instruct-Spatial-SQL-1.1-Docs is a text generation model from markrodrigo. Use it when you need the model to write or continue text. The card lists the license as llama3.2.
ENGLISH ONLY - Use 8b models for alternate languages.
Downloads · 30 days
0
Access
Public
Updated Jul 19, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md6.5 KB · 81%
From the Hugging Face model README
ENGLISH ONLY - Use 8b models for alternate languages.
This model, Llama-3.2-3B-Instruct-Spatial-SQL-1.1, is an 3B, narrow use case, text to spatial SQL, lightly fine-tuned model. In general, its primary use case is the Natural Language command adaptation of particular geographic spatial functions as normally defined in pure SQL. Data input should be a combination of an English prefix in the form of a question, and a coordinate prompt injection, likely from an active mapping system application coordinate list. Output is PostGIS spatial SQL.
There are five primary geographic functions released in version 1.1.
Model developer: Mark Rodrigo
Github: https://github.com/mprodrigo/spatialsql
Model Architecture: The model is a QLoRA / Supervised Fine Tuning (SFT)
Input: Text plus coordinate prompt injection. </br> Output: PostGIS spatial SQL </br> NOTE: Inputs and outputs are in meters and or geographic decimal degrees WGS 84 coordinates.
| Function | Question Input | Geo Input | SQL Execution Output |
|---|---|---|---|
| Area | Area question | Polygon | Number - Area sq meters |
| Centroid | Center question | Polygon | Point |
| Buffer | Buffer distance | Point | Polygon |
| Length | Length question | Line | Number - Length in meters |
| Function | Question Input | Geo Input 1 | Geo Input 2 | SQL Execution Output |
|---|---|---|---|---|
| Distance | Distance question | Point, Line, or Polygon | Point, Line, or Polygon | Number - Distance between geometries in meters |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
<p></p> You are a helpful assistant. You are an expert at PostGIS and Postgresql and SQL and psql. <p></p> <|eot_id|><|start_header_id|>user<|end_header_id|>### Instruction: Write a PostGIS SQL statement for the following.
<p></p>### Input:
<p></p> {input} <p></p>### Response:
<|eot_id|><|start_header_id|>assistant<|end_header_id|>
AREA
<p></p>### Input: What is the area for the polygon? : 'Polygon ((-3.7515154 40.3855551, -3.7514972 40.3856581, -3.7507005 40.3855767, -3.7507167 40.3854722, -3.7515154 40.3855551))'
<p></p>### Response: SELECT ST_Area(geog) As area FROM (select 'Polygon ((-3.7515154 40.3855551, -3.7514972 40.3856581, -3.7507005 40.3855767, -3.7507167 40.3854722, -3.7515154 40.3855551))' :: geography geog) subquery;
<p></p>CENTROID
<p></p>### Input: What is the centroid for the polygon? : 'Polygon ((-3.6934636 40.4808785, -3.6933352 40.4811486, -3.6930125 40.4810598, -3.693141 40.4807897, -3.6934636 40.4808785))'
<p></p>### Response: SELECT ST_AsText(ST_Centroid(geog)) As centroid FROM (select 'Polygon ((-3.6934636 40.4808785, -3.6933352 40.4811486, -3.6930125 40.4810598, -3.693141 40.4807897, -3.6934636 40.4808785))' :: geography geog) subquery;
BUFFER
<p></p>### Input: What is the thousand meter buffer for the following point? : 'Point(-8.7522658 41.3862664)'
<p></p>### Response: SELECT ST_AsText(ST_Buffer(geog, 1000)) as buffer FROM (select 'Point(-8.7522658 41.3862664)' :: geography geog) subquery;
<p></p> LENGTH <p></p>### Input: How long is the line? : 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)'
<p></p>### Response: SELECT ST_Length(geog) As length FROM (select 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)' :: geography geog) subquery;
<p></p> DISTANCE <p></p>### INPUT: How far apart is the point and line? : 'Point(-109.87549823 38.60574249)' 'LineString(-109.24324628 38.76349931, -109.4821773 38.6875815)'
<p></p>### Response: SELECT ST_Distance(gg1, gg2) As distance FROM (select 'Point(-109.87549823 38.60574249)' :: geography gg1, 'LineString(-109.24324628 38.76349931, -109.4821773 38.6875815)' :: geography gg2) subquery;
<p></p>max context ~ 8,000 or lower
<p></p> top k ~ 100 <p></p> temp ~ .4-.5 or lowerAgents are being considered as a separate project. Agents would mostly be related to pulling the coordinates from a mapping UI, and executing the SQL from responses against a PostGIS database.
https://postgis.net/docs/manual-3.3/PostGIS_Special_Functions_Index.html#PostGIS_GeographyFunctions
More information needed
Custom synthetic
The following hyperparameters were used during training:
| Training Loss | Step | Validation Loss |
|---|---|---|
| 0.8115 | 10 | 0.6781 |
| 0.6433 | 20 | 0.6173 |
| 0.6182 | 30 | 0.5445 |
| 0.4994 | 40 | 0.4888 |
| 0.4911 | 50 | 0.4265 |
| 0.4791 | 60 | 0.3477 |
| 0.3605 | 70 | 0.3096 |
| 0.3493 | 80 | 0.2850 |
| 0.3344 | 90 | 0.2604 |
| 0.1718 | 100 | 0.2508 |