Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,212 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
-
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
[More Information Needed]
|
| 57 |
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
+
license: llama3.2
|
| 3 |
+
base_model: meta-llama/Meta-Llama-3.2-3B
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
+
- spatial
|
| 10 |
+
- sql
|
| 11 |
+
- GIS
|
| 12 |
+
- PostGIS
|
| 13 |
---
|
| 14 |
|
| 15 |
+
**ENGLISH ONLY - Use 8b models for alternate languages.**
|
| 16 |
|
| 17 |
+
### Model Information
|
| 18 |
|
| 19 |
+
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
|
| 20 |
+
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.
|
| 21 |
|
| 22 |
+
There are five primary geographic functions released in version 1.1.
|
| 23 |
|
| 24 |
+
**Model developer**: Mark Rodrigo
|
| 25 |
|
| 26 |
+
**Github**: https://github.com/mprodrigo/spatialsql
|
| 27 |
|
| 28 |
+
**Model Architecture**: The model is a QLoRA / Supervised Fine Tuning (SFT)
|
| 29 |
|
| 30 |
+
### Model Input / Output Overview:
|
| 31 |
|
| 32 |
+
Input: Text plus coordinate prompt injection.
|
| 33 |
+
</br>
|
| 34 |
+
Output: **PostGIS spatial SQL**
|
| 35 |
+
</br>
|
| 36 |
+
NOTE: Inputs and outputs are in meters and or geographic decimal degrees WGS 84 coordinates.
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
| Function | Question Input | Geo Input | SQL Execution Output |
|
| 39 |
+
|:---------:|:----------------:|:---------:|:-------------------------:|
|
| 40 |
+
| Area | Area question | Polygon | Number - Area sq meters |
|
| 41 |
+
| Centroid | Center question | Polygon | Point |
|
| 42 |
+
| Buffer | Buffer distance | Point | Polygon |
|
| 43 |
+
| Length | Length question | Line | Number - Length in meters |
|
| 44 |
|
| 45 |
+
</br>
|
| 46 |
|
| 47 |
+
| Function | Question Input | Geo Input 1 | Geo Input 2 | SQL Execution Output |
|
| 48 |
+
|:---------:|:----------------:|:-----------------------:|:-----------------------:|:-----------------------------------------------|
|
| 49 |
+
| Distance | Distance question| Point, Line, or Polygon | Point, Line, or Polygon | Number - Distance between geometries in meters |
|
| 50 |
|
| 51 |
+
### Example Prompt / Prompt File
|
| 52 |
|
| 53 |
+
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
| 54 |
+
<p></p>
|
| 55 |
+
You are a helpful assistant. You are an expert at PostGIS and Postgresql and SQL and psql.
|
| 56 |
+
<p></p>
|
| 57 |
+
<|eot_id|><|start_header_id|>user<|end_header_id|>
|
| 58 |
|
| 59 |
+
\### Instruction: Write a PostGIS SQL statement for the following.
|
| 60 |
+
<p></p>
|
| 61 |
|
| 62 |
+
\### Input:
|
| 63 |
|
| 64 |
+
<p></p>
|
| 65 |
+
{input}
|
| 66 |
|
| 67 |
+
<p></p>
|
| 68 |
|
| 69 |
+
\### Response:
|
| 70 |
|
| 71 |
+
<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
| 72 |
|
|
|
|
| 73 |
|
| 74 |
+
### Examples
|
| 75 |
|
|
|
|
| 76 |
|
| 77 |
+
AREA
|
| 78 |
+
<p></p>
|
| 79 |
|
| 80 |
+
\### 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))'
|
| 81 |
+
<p></p>
|
| 82 |
|
| 83 |
+
\### 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;
|
| 84 |
+
<p></p>
|
| 85 |
|
| 86 |
+
CENTROID
|
| 87 |
+
<p></p>
|
| 88 |
|
| 89 |
+
\### 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))'
|
| 90 |
+
<p></p>
|
| 91 |
|
| 92 |
+
\### 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;
|
| 93 |
|
| 94 |
+
BUFFER
|
| 95 |
+
<p></p>
|
| 96 |
|
| 97 |
+
\### Input: What is the thousand meter buffer for the following point? : 'Point(-8.7522658 41.3862664)'
|
| 98 |
+
<p></p>
|
| 99 |
|
| 100 |
+
\### Response: SELECT ST_AsText(ST_Buffer(geog, 1000)) as buffer FROM (select 'Point(-8.7522658 41.3862664)' :: geography geog) subquery;
|
| 101 |
|
| 102 |
+
<p></p>
|
| 103 |
+
LENGTH
|
| 104 |
+
<p></p>
|
| 105 |
|
| 106 |
+
\### Input: How long is the line? : 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)'
|
| 107 |
+
<p></p>
|
| 108 |
|
| 109 |
+
\### Response: SELECT ST_Length(geog) As length FROM (select 'LINESTRING (-3.6976693 40.4263178, -3.6986082 40.4258729)' :: geography geog) subquery;
|
| 110 |
+
<p></p>
|
| 111 |
+
DISTANCE
|
| 112 |
+
<p></p>
|
| 113 |
|
| 114 |
+
\### INPUT: How far apart is the point and line? : 'Point(-109.87549823 38.60574249)' 'LineString(-109.24324628 38.76349931, -109.4821773 38.6875815)'
|
| 115 |
+
<p></p>
|
| 116 |
|
| 117 |
+
\### 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;
|
| 118 |
+
<p></p>
|
| 119 |
|
| 120 |
+
### A Few Known Question Variation Examples
|
| 121 |
|
| 122 |
+
<p></p>
|
| 123 |
+
AREA
|
| 124 |
+
<p></p>
|
| 125 |
+
What is the area for the geometry?
|
| 126 |
+
<p></p>
|
| 127 |
+
What is the area for this polygon?
|
| 128 |
+
<p></p>
|
| 129 |
+
CENTROID
|
| 130 |
+
<p></p>
|
| 131 |
+
What is the centroid for the geometry?
|
| 132 |
+
<p></p>
|
| 133 |
+
What is the center point of the polygon?
|
| 134 |
+
<p></p>
|
| 135 |
+
BUFFER
|
| 136 |
+
<p></p>
|
| 137 |
+
What is the 100 meter buffer for the following point?
|
| 138 |
+
<p></p>
|
| 139 |
+
Buffer the following point a thousand meters.
|
| 140 |
+
<p></p>
|
| 141 |
+
What is the 1000 meter buffer for the following point?
|
| 142 |
+
<p></p>
|
| 143 |
+
LENGTH
|
| 144 |
+
<p></p>
|
| 145 |
+
What is the length of the line?
|
| 146 |
+
<p></p>
|
| 147 |
+
How long is this line?
|
| 148 |
+
<p></p>
|
| 149 |
+
DISTANCE
|
| 150 |
+
<p></p>
|
| 151 |
+
The distance between the polygon and the line is?
|
| 152 |
+
<p></p>
|
| 153 |
+
What is the distance between the points?
|
| 154 |
+
<p></p>
|
| 155 |
+
How far apart are the two lines?
|
| 156 |
|
| 157 |
+
### llama.cpp / Hyperparameter Recommendations For Inference
|
| 158 |
+
max context ~ 8,000 or lower
|
| 159 |
+
<p></p>
|
| 160 |
+
top k ~ 100
|
| 161 |
+
<p></p>
|
| 162 |
+
temp ~ .4-.5 or lower
|
| 163 |
|
| 164 |
+
### Agent Considerations
|
| 165 |
+
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.
|
| 166 |
|
| 167 |
+
### Further Reference - link this
|
| 168 |
+
https://postgis.net/docs/manual-3.3/PostGIS_Special_Functions_Index.html#PostGIS_GeographyFunctions
|
| 169 |
+
|
| 170 |
+
### Evaluation data
|
| 171 |
+
More information needed
|
| 172 |
+
|
| 173 |
+
### Training data
|
| 174 |
+
Custom synthetic
|
| 175 |
+
|
| 176 |
+
### Training hyperparameters
|
| 177 |
+
|
| 178 |
+
The following hyperparameters were used during training:
|
| 179 |
+
- learning_rate: 2e-4
|
| 180 |
+
- train_batch_size: 10
|
| 181 |
+
- eval_batch_size: 3
|
| 182 |
+
- distributed_type: multi-GPU
|
| 183 |
+
- num_devices: 2
|
| 184 |
+
- optimizer: Adam 8bit
|
| 185 |
+
- lr_scheduler_type: linear
|
| 186 |
+
- num_epochs: 5
|
| 187 |
+
|
| 188 |
+
### Training results
|
| 189 |
+
|
| 190 |
+
| Training Loss | Epoch | Step | Validation Loss |
|
| 191 |
+
|:-------------:|:------:|:----:|:---------------:|
|
| 192 |
+
| 1.3788 | 5 | 10 | 1.3543 |
|
| 193 |
+
| 0.8504 | 5 | 20 | 0.8671 |
|
| 194 |
+
| 0.5990 | 5 | 30 | 0.6501 |
|
| 195 |
+
| 0.5836 | 5 | 40 | 0.5885 |
|
| 196 |
+
| 0.5713 | 5 | 50 | 0.5607 |
|
| 197 |
+
| 0.5481 | 5 | 60 | 0.5434 |
|
| 198 |
+
| 0.5221 | 5 | 70 | 0.5342 |
|
| 199 |
+
| 0.4983 | 5 | 80 | 0.5259 |
|
| 200 |
+
| 0.4914 | 5 | 90 | 0.5219 |
|
| 201 |
+
| 0.4754 | 5 | 100 | 0.5205 |
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
### Framework versions
|
| 207 |
+
|
| 208 |
+
- Transformers 4.45.1
|
| 209 |
+
- Pytorch 2.4.1
|
| 210 |
+
- peft 0.13.0
|
| 211 |
+
- Datasets 3.0.1
|
| 212 |
+
- Tokenizers 0.20.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|