markrodrigo commited on
Commit
d9f028d
·
verified ·
1 Parent(s): f02cd17

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +209 -0
README.md CHANGED
@@ -1,3 +1,212 @@
1
  ---
2
  license: llama3.2
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 | Step | Validation Loss |
191
+ |:-------------:|:----:|:---------------:|
192
+ | 0.8115 | 10 | 0.6781 |
193
+ | 0.6433 | 20 | 0.6173 |
194
+ | 0.6182 | 30 | 0.5445 |
195
+ | 0.4994 | 40 | 0.4888 |
196
+ | 0.4911 | 50 | 0.4265 |
197
+ | 0.4791 | 60 | 0.3477 |
198
+ | 0.3605 | 70 | 0.3096 |
199
+ | 0.3493 | 80 | 0.2850 |
200
+ | 0.3344 | 90 | 0.2604 |
201
+ | 0.1718 | 100 | 0.2508 |
202
+
203
+
204
+
205
+
206
+ ### Framework versions
207
+
208
+ - Transformers 4.46.1
209
+ - Pytorch 2.5.1
210
+ - peft 0.13.2
211
+ - Datasets 3.1.0
212
+ - Tokenizers 0.21.0