Instructions to use markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1") model = AutoModelForCausalLM.from_pretrained("markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1
- SGLang
How to use markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1 with Docker Model Runner:
docker model run hf.co/markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1
- Model Information
- Model Input / Output Overview:
- Example Prompting
- Examples
- A Few Known Question Variation Examples
- llama.cpp / Hyperparameter Recommendations For Inference
- Agent Considerations
- Further Reference - link this
- Evaluation data
- Training data
- Training hyperparameters
- Training results
- Framework versions
Model Information
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)
Model Input / Output Overview:
Input: Text plus coordinate prompt injection.
Output: PostGIS spatial SQL
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 |
Example Prompting
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_new_tokens=512, temperature=0.4, return_full_text=False,)
Build the messages
messages = [
{"role": "system", "content": "Write a PostGIS SQL statement for the following."},
{"role": "user", "content": "What is the thousand meter buffer for the following point? : 'Point(-3.78621945 40.4463195)'"},
]
Apply ChatML template
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=False,
)
Examples
AREA
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))'
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;
CENTROID
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))'
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
Message: What is the thousand meter buffer for the following point? : 'Point(-8.7522658 41.3862664)'
Response: SELECT ST_AsText(ST_Buffer(geog, 1000)) as buffer FROM (select 'Point(-8.7522658 41.3862664)' :: geography geog) subquery;
LENGTHMessage: How long is the line? : 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)'
Response: SELECT ST_Length(geog) As length FROM (select 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)' :: geography geog) subquery;
DISTANCEMessage: How far apart is the point and line? : 'Point(-109.87549823 38.60574249)' 'LineString(-109.24324628 38.76349931, -109.4821773 38.6875815)'
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;
A Few Known Question Variation Examples
AREA What is the area for the geometry? What is the area for this polygon? CENTROID What is the centroid for the geometry? What is the center point of the polygon? BUFFER What is the 100 meter buffer for the following point? Buffer the following point a thousand meters. What is the 1000 meter buffer for the following point? LENGTH What is the length of the line? How long is this line? DISTANCE The distance between the polygon and the line is? What is the distance between the points? How far apart are the two lines?llama.cpp / Hyperparameter Recommendations For Inference
max context ~ 262,000
top k ~ 100 temp ~ .4-.5 or lowerAgent Considerations
Agents 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.
Further Reference - link this
https://postgis.net/docs/PostGIS_Special_Functions_Index.html#PostGIS_GeographyFunctions
Evaluation data
More information needed
Training data
Custom synthetic
Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 1e-4
- distributed_type: multi-GPU
- num_devices: 2
- optimizer: Adam 8bit
- lr_scheduler_type: linear
Training results
| 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 |
Framework versions
- transformers 5.14.1
- torch 2.13.0
- peft 0.20.0
- bitsandbytes 0.50.0
- datasets 5.0.1
- tokenizers 0.23.1
- Downloads last month
- -
docker model run hf.co/markrodrigo/Qwen-3.5-4B-Spatial-SQL-1.1