shai commited on
Commit
a7056ab
·
1 Parent(s): 18fea53

update readme with examples

Browse files
Files changed (1) hide show
  1. README.md +241 -0
README.md CHANGED
@@ -103,6 +103,247 @@ print(f'User: {question}\nAssistant: {response}')
103
  | DeepSeek-VL-1.3B | 2.0 | 39.6 | 63.8 | 39.9 | 33.8 | 29.8 | 27.6 | 51.5 | 413 | 29.2 |
104
 
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  ## Acknowledgments
108
 
 
103
  | DeepSeek-VL-1.3B | 2.0 | 39.6 | 63.8 | 39.9 | 33.8 | 29.8 | 27.6 | 51.5 | 413 | 29.2 |
104
 
105
 
106
+ ## Prompt Engineering for JSON Extraction
107
+
108
+ ### Overview
109
+
110
+ This guide demonstrates how to create prompts for extracting information and converting it into structured JSON outputs. It starts with basic examples and progresses to more complex JSON structures, including handling data from images of tables and charts. The objective is to help users design effective prompts that can be used in various applications, such as natural language processing, chatbots, or data extraction from visual inputs.
111
+
112
+ ### Table of Contents
113
+
114
+ 1. [Getting Started](#getting-started)
115
+ 2. [Extracting Simple Information](#example-1-extracting-simple-information-from-an-image)
116
+ 3. [Extracting Nested Information](#example-2-extracting-nested-information-from-an-image)
117
+ 4. [Extracting Lists and Arrays](#example-3-extracting-lists-and-arrays-from-an-image)
118
+ 5. [Extracting Tables](#example-4-extracting-table-data-from-an-image)
119
+ 6. [Extracting Charts](#example-5-extracting-chart-data-from-an-image)
120
+ 7. [Best Practices](#best-practices)
121
+
122
+ ---
123
+
124
+ ### Getting Started
125
+
126
+ To get started with JSON extraction from images, it's essential to have a clear understanding of the visual content you want to extract and the structure of the desired JSON output. The following examples will guide you through crafting prompts to achieve this.
127
+
128
+
129
+ #### Example 1: Extracting Simple Information from an Image
130
+
131
+ **Hypothetical Scenario:**
132
+ You have an image of a form that contains basic details like "Name," "Date of Birth," and "Address."
133
+
134
+ **Prompt:**
135
+ ```
136
+ Extract the details from the form image and structure them into JSON format:
137
+ {
138
+ "name": "",
139
+ "date_of_birth": "",
140
+ "address": ""
141
+ }
142
+ ```
143
+
144
+ **Expected Output:**
145
+ ```json
146
+ {
147
+ "name": "John Doe",
148
+ "date_of_birth": "1990-01-01",
149
+ "address": "1234 Elm Street, Springfield"
150
+ }
151
+ ```
152
+
153
+ #### Example 2: Extracting Nested Information from an Image
154
+
155
+ **Hypothetical Scenario:**
156
+ You have an image of a form that contains detailed personal information, including contact details and emergency contacts.
157
+
158
+ **Prompt:**
159
+ ```
160
+ Extract the information from the form and format it as follows:
161
+ {
162
+ "personal_details": {
163
+ "name": "",
164
+ "age": 0,
165
+ "gender": ""
166
+ },
167
+ "contact": {
168
+ "phone": "",
169
+ "email": ""
170
+ },
171
+ "emergency_contact": {
172
+ "name": "",
173
+ "relation": "",
174
+ "phone": ""
175
+ }
176
+ }
177
+ ```
178
+
179
+ **Expected Output:**
180
+ ```json
181
+ {
182
+ "personal_details": {
183
+ "name": "Sarah Connor",
184
+ "age": 35,
185
+ "gender": "Female"
186
+ },
187
+ "contact": {
188
+ "phone": "555-1234",
189
+ "email": "sarah.connor@example.com"
190
+ },
191
+ "emergency_contact": {
192
+ "name": "Kyle Reese",
193
+ "relation": "Friend",
194
+ "phone": "555-5678"
195
+ }
196
+ }
197
+ ```
198
+
199
+
200
+ #### Example 3: Extracting Lists and Arrays from an Image
201
+
202
+ **Hypothetical Scenario:**
203
+ You have an image of a schedule that lists several events, their times, and locations.
204
+
205
+ **Prompt:**
206
+ ```
207
+ Extract the event details from the schedule image and structure them into JSON:
208
+ {
209
+ "events": [
210
+ {
211
+ "name": "",
212
+ "time": "",
213
+ "location": ""
214
+ }
215
+ ]
216
+ }
217
+ ```
218
+
219
+ **Expected Output:**
220
+ ```json
221
+ {
222
+ "events": [
223
+ {
224
+ "name": "Morning Meeting",
225
+ "time": "09:00 AM",
226
+ "location": "Conference Room 1"
227
+ },
228
+ {
229
+ "name": "Lunch Break",
230
+ "time": "12:00 PM",
231
+ "location": "Cafeteria"
232
+ },
233
+ {
234
+ "name": "Project Update",
235
+ "time": "02:00 PM",
236
+ "location": "Conference Room 2"
237
+ }
238
+ ]
239
+ }
240
+ ```
241
+
242
+
243
+ #### Example 4: Extracting Table Data from an Image
244
+
245
+ Images of tables often contain structured data that needs to be parsed and converted to JSON. The following example demonstrates how to handle tabular data extraction.
246
+
247
+ **Hypothetical Scenario:**
248
+ You have an image of a table listing product names, prices, and quantities.
249
+
250
+ **Prompt:**
251
+ ```
252
+ Extract the data from the table image and format it as JSON:
253
+ {
254
+ "products": [
255
+ {
256
+ "product_name": "",
257
+ "price": "",
258
+ "quantity": 0
259
+ }
260
+ ]
261
+ }
262
+ ```
263
+
264
+ **Expected Output:**
265
+ ```json
266
+ {
267
+ "products": [
268
+ {
269
+ "product_name": "Apples",
270
+ "price": "$2",
271
+ "quantity": 10
272
+ },
273
+ {
274
+ "product_name": "Bananas",
275
+ "price": "$1",
276
+ "quantity": 20
277
+ },
278
+ {
279
+ "product_name": "Oranges",
280
+ "price": "$3",
281
+ "quantity": 15
282
+ }
283
+ ]
284
+ }
285
+ ```
286
+
287
+
288
+ #### Example 5: Extracting Chart Data from an Image
289
+
290
+ Charts include metadata and data points that need to be accurately extracted. Here's how to structure prompts to extract chart data from images.
291
+
292
+ **Hypothetical Scenario:**
293
+ You have an image of a bar chart that shows monthly sales figures.
294
+
295
+ **Prompt:**
296
+ ```
297
+ Extract the details of the bar chart from the image, including the title, axis labels, and data points and format it as JSON:
298
+ {
299
+ "chart": {
300
+ "title": "",
301
+ "x_axis": "",
302
+ "y_axis": "",
303
+ "data_points": [
304
+ {
305
+ "label": "",
306
+ "value": 0
307
+ }
308
+ ]
309
+ }
310
+ }
311
+ ```
312
+
313
+ **Expected Output:**
314
+ ```json
315
+ {
316
+ "chart": {
317
+ "title": "Monthly Sales Report",
318
+ "x_axis": "Months",
319
+ "y_axis": "Sales (in $)",
320
+ "data_points": [
321
+ {
322
+ "label": "January",
323
+ "value": 500
324
+ },
325
+ {
326
+ "label": "February",
327
+ "value": 600
328
+ },
329
+ {
330
+ "label": "March",
331
+ "value": 700
332
+ }
333
+ ]
334
+ }
335
+ }
336
+ ```
337
+
338
+ ## Best Practices
339
+
340
+ 1. **Be Explicit**: Clearly define the desired keys and structure in your prompt to avoid ambiguity.
341
+ 2. **Use Examples**: Provide sample outputs so that the system can understand the expected format.
342
+ 3. **Anticipate Variations**: Consider possible variations in the visual data and ensure the prompt can accommodate them.
343
+ 4. **Start Simple**: Begin with simple structures, and progressively increase complexity as needed.
344
+ 5. **Test and Iterate**: Refine your prompts through testing to ensure accuracy and consistency in outputs.
345
+
346
+
347
 
348
  ## Acknowledgments
349