Downloads · 30 days
124
17% of all-time downloads
markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1
Qwen-3.5-4B-Spatial-SQL-1.1 is a text generation model from markrodrigo. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
This is experimental. Models are for prototyping this general approach of text to spatial SQL.
Downloads · 30 days
124
17% of all-time downloads
All-time downloads
749
Public
Parameters
4.2B
8.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8.4 GB · 100%
From the Hugging Face model README
This is experimental. Models are for prototyping this general approach of text to spatial SQL.
This model, Qwen-3.5-4B-Spatial-SQL-1.1, is a 4B, 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 |
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_new_tokens=512, temperature=0.4, return_full_text=False,)
Build the messages </br> messages = [ </br> {"role": "system", "content": "Write a PostGIS SQL statement for the following."}, </br> {"role": "user", "content": "What is the thousand meter buffer for the following point? : 'Point(-3.78621945 40.4463195)'"}, </br> ]
Apply ChatML Template </br> prompt = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True, enable_thinking=False, )
AREA
<p></p>Message: 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>Message: 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>Message: 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>Message: 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>Message: 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 ~ 262,000
<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/PostGIS_Special_Functions_Index.html#PostGIS_GeographyFunctions
More information needed
Custom synthetic
The following hyperparameters were used during training:
| Training Loss | Step | Validation Loss |
|---|---|---|
| 1.1283 | 10 | 0.8828 |
| 0.7981 | 20 | 0.7432 |
| 0.7351 | 30 | 0.6847 |
| 0.6901 | 40 | 0.6427 |
| 0.6298 | 50 | 0.5980 |
| 0.5857 | 60 | 0.5558 |
| 0.5421 | 70 | 0.5335 |