--- license: llama3 base_model: meta-llama/Meta-Llama-3.2-3B language: - en pipeline_tag: text-generation tags: - code - spatial - sql - GIS - PostGIS --- **EXPERIMENTAL ALPHA**
**CURRENTLY TESTING**
**ENGLISH ONLY**
**MODIFICATIONS INBOUND - NOTES BELOW ON SQL ##RESPONSE TRAINING CHALLENGES** ### Model Information This model, Llama-3.2-3B-Instruct-Spatial-SQL-1.0, 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 four primary geographic functions released in version 1.0. **Model developer**: Mark Rodrigo - Chat to Map interfacing. **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 | ### Example Prompt / Prompt File <|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a helpful assistant. You are an expert at PostGIS and Postgresql and SQL and psql.

<|eot_id|><|start_header_id|>user<|end_header_id|> \### Instruction: Write a PostGIS SQL statement for the following.

\### Input:

{input}

\### Response: <|eot_id|><|start_header_id|>assistant<|end_header_id|> ### Examples **Note 10/6/24 ** - Centroid and Buffer responses are currently returning as WKT. While technically correct, this is not the desired response, and will be addressed.
Reference - https://postgis.net/docs/ST_AsText.html - English and Chinese models, etc. currently require the 8b models and or additional fine-tuning for 3b. AREA

\### 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))'

\### 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

\### 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))'

**actual** \### Response: SELECT ST_Centroid(geog) FROM (select 'Polygon ((-3.6934636 40.4808785, -3.6933352 40.4811486, -3.6930125 40.4810598, -3.693141 40.4807897, -3.6934636 40.4808785))' :: geography as geog) subquery **desired** \### 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

\### Input: What is the thousand meter buffer for the following point? : 'Point(-8.7522658 41.3862664)'

**actual** \### Response: SELECT ST_Buffer(geog, 1000) FROM (select 'Point(-8.7522658 41.3862664)' :: geography as geog) subquery **desired** \### Response: SELECT ST_AsText(ST_Buffer(geog, 1000)) as buffer FROM (select 'Point(-8.7522658 41.3862664)' :: geography geog) subquery;

LENGTH

\### Input: 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;

### Framework versions - Transformers 4.45.1 - Pytorch 2.4.1 - peft 0.13.0 - Datasets 3.0.1 - Tokenizers 0.20.0