bhaviktheslider commited on
Commit
4c3d8fa
·
verified ·
1 Parent(s): bba005d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +589 -49
README.md CHANGED
@@ -1,4 +1,5 @@
1
- Model
 
2
  ---
3
 
4
  # MasterControlAIML R1-Qwen2.5-1.5b SFT R1 JSON Unstructured-To-Structured LoRA Model
@@ -24,7 +25,10 @@ This repository provides a fine-tuned Qwen2 model optimized for transforming uns
24
  - [Quick Start](#quick-start)
25
  - [Using Unsloth for Fast Inference](#using-unsloth-for-fast-inference)
26
  - [Using Transformers for Inference](#using-transformers-for-inference)
27
- - [Advanced Example with LangChain Prompt](#advanced-example-with-langchain-prompt)
 
 
 
28
  - [Contributing](#contributing)
29
  - [License](#license)
30
  - [Acknowledgments](#acknowledgments)
@@ -42,7 +46,7 @@ This model is tailored for tasks where mapping unstructured text (e.g., manuals,
42
  - **Efficient Inference:** Utilizes the [Unsloth](https://github.com/unslothai/unsloth) library for fast model inference.
43
  - **Structured Output:** Maps text inputs into a strict JSON schema with hierarchical relationships.
44
  - **Flexible Integration:** Example code snippets show how to use both the Unsloth API and Hugging Face’s Transformers.
45
- - **Advanced Prompting:** Includes an example of using LangChain prompt templates for detailed instruction-driven output.
46
 
47
  ---
48
 
@@ -74,10 +78,9 @@ The Unsloth library allows you to quickly load and run inference with the model.
74
  from unsloth import FastLanguageModel
75
  import torch
76
 
77
- # Specify the model name
78
- MODEL = "MasterControlAIML/DeepSeek-R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured"
79
 
80
- # Load the model and tokenizer
81
  model, tokenizer = FastLanguageModel.from_pretrained(
82
  model_name=MODEL,
83
  max_seq_length=2048,
@@ -85,10 +88,9 @@ model, tokenizer = FastLanguageModel.from_pretrained(
85
  load_in_4bit=False,
86
  )
87
 
88
- # Prepare the model for inference
89
  FastLanguageModel.for_inference(model)
90
 
91
- # Define a prompt template
92
  ALPACA_PROMPT = """
93
  Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
94
  ### Instruction:
@@ -97,13 +99,13 @@ Below is an instruction that describes a task, paired with an input that provide
97
  {}
98
  """
99
 
100
- # Example: Create input and generate output
101
  instruction = "Provide a summary of the Quality Assurance Manual."
102
  prompt = ALPACA_PROMPT.format(instruction, "")
103
  inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
104
  output = model.generate(**inputs, max_new_tokens=2000)
105
 
106
- # Decode and print the generated text
107
  print(tokenizer.batch_decode(output, skip_special_tokens=True)[0])
108
  ```
109
 
@@ -111,13 +113,13 @@ print(tokenizer.batch_decode(output, skip_special_tokens=True)[0])
111
 
112
  ### Using Transformers for Inference
113
 
114
- If you prefer to use Hugging Face's Transformers directly, here’s an alternative example:
115
 
116
  ```python
117
  from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
118
  import torch
119
 
120
- MODEL = "MasterControlAIML/DeepSeek-R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured"
121
 
122
  # Initialize tokenizer and model
123
  tokenizer = AutoTokenizer.from_pretrained(MODEL)
@@ -131,13 +133,11 @@ Below is an instruction that describes a task, paired with an input that provide
131
  {}
132
  """
133
 
134
- # Define your text input
135
- TEXT = ""
136
  prompt = ALPACA_PROMPT.format(TEXT, "")
137
  inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
138
  text_streamer = TextStreamer(tokenizer)
139
 
140
- # Generate output with specific generation parameters
141
  with torch.no_grad():
142
  output_ids = model.generate(
143
  input_ids=inputs["input_ids"],
@@ -150,19 +150,278 @@ with torch.no_grad():
150
  pad_token_id=tokenizer.pad_token_id,
151
  )
152
 
153
- # Print the decoded output
154
  print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
155
  ```
156
 
157
  ---
158
 
159
- ### Advanced Example with LangChain Prompt
 
 
 
 
160
 
161
- For advanced users, the repository includes an example that integrates with LangChain to map hierarchical text data into a JSON schema. This example uses a prompt template to instruct the model on how to generate an output that includes both the JSON object (`<answer>`) and the reasoning behind the mapping decisions (`<think>`).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  ```python
164
  from langchain_core.prompts import PromptTemplate
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  SYSTEM_PROMPT = """
167
  ### Role:
168
  You are an expert data extractor specializing in mapping hierarchical text data into a given JSON Schema.
@@ -194,7 +453,7 @@ You are an expert data extractor specializing in mapping hierarchical text data
194
  4. **Correct Mapping of Attributes:**
195
  - Map key attributes, including `id`, `idc`, `idx`, `level_type`, and `component_type`.
196
  5. **JSON Format Compliance:**
197
- - Escape quotes, replace newlines with `\\n`, avoid trailing commas, and use double quotes exclusively.
198
  6. **Step-by-Step Reasoning:**
199
  - Explain your reasoning within the `<think>` tag.
200
 
@@ -202,39 +461,320 @@ You are an expert data extractor specializing in mapping hierarchical text data
202
  If either the `<think>` or `<answer>` tags is missing, the response will be considered incomplete.
203
  """
204
 
205
- # Create a prompt template with LangChain
206
  system_prompt_template = PromptTemplate(template=SYSTEM_PROMPT, input_variables=["TEXT", "SCHEMA"])
207
 
208
- # Format the prompt with your text and JSON schema
209
- system_prompt_str = system_prompt_template.format(
210
- TEXT="Your detailed text input here...",
211
- SCHEMA="""{
212
- "type": "object",
213
- "properties": {
214
- "id": {"type": "string", "description": "Unique identifier."},
215
- "title": {"type": "string", "description": "Section title."},
216
- "level": {"type": "integer", "description": "Hierarchy level."},
217
- "level_type": {"type": "string", "enum": ["ROOT", "SECTION", "SUBSECTION", "DETAIL_N"], "description": "Hierarchy type."},
218
- "component": {
219
- "type": "array",
220
- "items": {
221
- "type": "object",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  "properties": {
223
- "idc": {"type": "integer", "description": "Component ID."},
224
- "component_type": {"type": "string", "enum": ["PARAGRAPH", "TABLE", "CALCULATION", "CHECKBOX"], "description": "Component type."},
225
- "metadata": {"type": "string", "description": "Additional metadata."},
226
- "properties": {"type": "object"}
227
- },
228
- "required": ["idc", "component_type", "metadata", "properties"]
229
- }
230
- },
231
- "children": {"type": "array", "items": {}}
232
- },
233
- "required": ["id", "title", "level", "level_type", "component", "children"]
234
- }"""
235
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
- # Use the system prompt with your inference code as shown in previous examples.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  ```
239
 
240
  ---
@@ -260,4 +800,4 @@ This project is licensed under the [Apache-2.0 License](LICENSE).
260
 
261
  ---
262
 
263
- Enjoy using the model, and happy coding!
 
1
+ Below is an updated version of the README that now includes detailed sample responses—complete with Chain-of-Thought explanations and corresponding filled schema outputs. These examples illustrate how to structure your prompt, what kind of chain-of-thought reasoning you might provide, and the expected JSON output.
2
+
3
  ---
4
 
5
  # MasterControlAIML R1-Qwen2.5-1.5b SFT R1 JSON Unstructured-To-Structured LoRA Model
 
25
  - [Quick Start](#quick-start)
26
  - [Using Unsloth for Fast Inference](#using-unsloth-for-fast-inference)
27
  - [Using Transformers for Inference](#using-transformers-for-inference)
28
+ - [Prompt & Code Examples](#prompt--code-examples)
29
+ - [Example 1: Basic Alpaca Prompt Template](#example-1-basic-alpaca-prompt-template)
30
+ - [Example 2: Advanced Data Extraction with LangChain](#example-2-advanced-data-extraction-with-langchain)
31
+ - [Sample Responses & Chain-of-Thought Explanations](#sample-responses--chain-of-thought-explanations)
32
  - [Contributing](#contributing)
33
  - [License](#license)
34
  - [Acknowledgments](#acknowledgments)
 
46
  - **Efficient Inference:** Utilizes the [Unsloth](https://github.com/unslothai/unsloth) library for fast model inference.
47
  - **Structured Output:** Maps text inputs into a strict JSON schema with hierarchical relationships.
48
  - **Flexible Integration:** Example code snippets show how to use both the Unsloth API and Hugging Face’s Transformers.
49
+ - **Advanced Prompting:** Detailed examples using the Alpaca prompt template and LangChain prompt templates are provided below.
50
 
51
  ---
52
 
 
78
  from unsloth import FastLanguageModel
79
  import torch
80
 
81
+ MODEL = "MasterControlAIML/R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured-lora"
 
82
 
83
+ # Load model and tokenizer
84
  model, tokenizer = FastLanguageModel.from_pretrained(
85
  model_name=MODEL,
86
  max_seq_length=2048,
 
88
  load_in_4bit=False,
89
  )
90
 
91
+ # Prepare for inference
92
  FastLanguageModel.for_inference(model)
93
 
 
94
  ALPACA_PROMPT = """
95
  Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
96
  ### Instruction:
 
99
  {}
100
  """
101
 
102
+ # Example instruction and prompt
103
  instruction = "Provide a summary of the Quality Assurance Manual."
104
  prompt = ALPACA_PROMPT.format(instruction, "")
105
  inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
106
  output = model.generate(**inputs, max_new_tokens=2000)
107
 
108
+ # Print generated text
109
  print(tokenizer.batch_decode(output, skip_special_tokens=True)[0])
110
  ```
111
 
 
113
 
114
  ### Using Transformers for Inference
115
 
116
+ Alternatively, you can use Hugging Face's Transformers directly:
117
 
118
  ```python
119
  from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
120
  import torch
121
 
122
+ MODEL = "MasterControlAIML/R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured-lora"
123
 
124
  # Initialize tokenizer and model
125
  tokenizer = AutoTokenizer.from_pretrained(MODEL)
 
133
  {}
134
  """
135
 
136
+ TEXT = "Provide a detailed explanation of the QA processes in manufacturing."
 
137
  prompt = ALPACA_PROMPT.format(TEXT, "")
138
  inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
139
  text_streamer = TextStreamer(tokenizer)
140
 
 
141
  with torch.no_grad():
142
  output_ids = model.generate(
143
  input_ids=inputs["input_ids"],
 
150
  pad_token_id=tokenizer.pad_token_id,
151
  )
152
 
 
153
  print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
154
  ```
155
 
156
  ---
157
 
158
+ ## Prompt & Code Examples
159
+
160
+ To guide the model in mapping unstructured text to a JSON schema, you can structure your prompt as follows.
161
+
162
+ ### Example 1: Basic Alpaca Prompt Template
163
 
164
+ #### Code
165
+
166
+ ```python
167
+ # Define the Alpaca prompt template
168
+ ALPACA_PROMPT = """
169
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
170
+ ### Instruction:
171
+ {}
172
+ ### Response:
173
+ {}
174
+ """
175
+
176
+ # Sample text input describing a Quality Assurance Manual
177
+ TEXT = """
178
+ The Quality Assurance Manual for Manufacturing Process serves as a comprehensive guide to ensuring the quality of manufactured products and services. This manual encompasses all avenues of the QA process, including methodologies for testing, established standards, and documentation practices.
179
+
180
+ This document introduces the fundamental principles of quality assurance, emphasizing its role in achieving customer satisfaction across different manufacturing domains. According to the key metrics outlined in the Key Metrics for QA table, the defect rate stands at 0.5%, while the yield rate is 98%. These metrics underscore the importance of strict quality control measures to achieve high levels of product reliability.
181
+
182
+ ---
183
+
184
+ Introduction to Quality Assurance
185
+ This section delves into the core principles of quality assurance, setting the foundation for the detailed methodologies that follow. Quality Assurance (QA) is a critical process that ensures that products and services fully meet customer expectations and industry standards.
186
+
187
+ QA in Manufacturing Processes
188
+ Manufacturing processes require strict adherence to QA procedures to ensure product reliability and safety. In this subsection, we explore QA in specific manufacturing processes, covering essential aspects such as process controls and raw material inspection. The QA Checklist for Manufacturing identifies critical processes that must be controlled, such as Process Controls (checked), but also highlights areas that need further attention, such as Raw Material Inspection (not check).
189
+
190
+ [QA Checklist for Manufacturing]
191
+ | Process Controls | True | Value: Yes |
192
+ | Raw Material Inspection | False | Value: No |
193
+
194
+ Confirming QA procedures are followed is essential to maintaining quality standards in manufacturing. This checklist includes two items: Defects Identified and Corrected and Regular Audits Conducted. For Defects Identified and Corrected, the item is checked, indicating that the relevant procedures are in place. However, Regular Audits Conducted is not checked, suggesting a potential gap in this area.
195
+
196
+ Quality Assurance Standards
197
+ ISO 9001 is a well-known standard for quality management systems, which forms the backbone of many manufacturing QA processes. This subsection discusses the adoption and benefits of ISO 9001. The QA Standards Comparison table provides a side-by-side view of two standards: ISO 9001 and ASQ Certified Quality Manager. ISO 9001 is checked, indicating full compliance, while ASQ Certified Quality Manager is not checked, indicating a need for further certification.
198
+
199
+ These standards, coupled with rigorous testing methodologies and comprehensive documentation, form the pillars of our quality assurance framework. Ensuring that all manufacturing processes comply with these standards not only improves product quality but also enhances customer trust and satisfaction. Achieving and maintaining such standards requires ongoing effort and commitment from all involved parties.
200
+ """
201
+
202
+ # JSON schema defining the expected structure of the output
203
+ SCHEMA = """
204
+ {
205
+ "type": "object",
206
+ "properties": {
207
+ "id": {
208
+ "type": "string",
209
+ "description": "Dot-separated integers representing the unique identifier of each element in the hierarchy."
210
+ },
211
+ "title": {
212
+ "type": "string",
213
+ "description": "Descriptive title for the section or document."
214
+ },
215
+ "level": {
216
+ "type": "integer",
217
+ "description": "Hierarchy level starting from 0 (root)."
218
+ },
219
+ "level_type": {
220
+ "type": "string",
221
+ "enum": ["ROOT", "SECTION", "SUBSECTION", "DETAIL_N"],
222
+ "description": "Type of hierarchy level."
223
+ },
224
+ "component": {
225
+ "type": "array",
226
+ "items": {
227
+ "type": "object",
228
+ "properties": {
229
+ "idc": {
230
+ "type": "integer",
231
+ "description": "Component ID within the element."
232
+ },
233
+ "component_type": {
234
+ "type": "string",
235
+ "enum": ["PARAGRAPH", "TABLE", "CALCULATION", "CHECKBOX"],
236
+ "description": "Type of component (e.g., paragraph, table)."
237
+ },
238
+ "metadata": {
239
+ "type": "string",
240
+ "pattern": "<title>.+</title>|<note>.+</note>|<overview>.+</overview>",
241
+ "description": "Metadata such as title, note, or overview."
242
+ },
243
+ "properties": {
244
+ "type": "object",
245
+ "properties": {
246
+ "variables": {
247
+ "type": "array",
248
+ "items": {
249
+ "type": "object",
250
+ "properties": {
251
+ "idx": {"type": "string"},
252
+ "name": {"type": "string"},
253
+ "value": {},
254
+ "unit": {"type": ["null", "string"]},
255
+ "metrics": {"type": "boolean"},
256
+ "formula": {"type": "boolean"}
257
+ },
258
+ "required": ["idx", "name", "value"]
259
+ }
260
+ },
261
+ "content": {
262
+ "type": ["array"],
263
+ "items": {"type": "string"}
264
+ }
265
+ }
266
+ }
267
+ },
268
+ "required": ["idc", "component_type", "metadata", "properties"]
269
+ }
270
+ },
271
+ "children": {
272
+ "type": "array",
273
+ "items": {}
274
+ }
275
+ },
276
+ "required": ["id", "title", "level", "level_type", "component", "children"]
277
+ }
278
+ """
279
+
280
+ # Now you would use your chosen inference method (e.g., via Unsloth or Transformers)
281
+ # to feed the prompt (ALPACA_PROMPT, TEXT, and SCHEMA) into the model.
282
+ ```
283
+
284
+ ---
285
+
286
+ ### Example 2: Advanced Data Extraction with LangChain
287
+
288
+ #### Code
289
 
290
  ```python
291
  from langchain_core.prompts import PromptTemplate
292
 
293
+ # Sample text input with a slightly different structure
294
+ TEXT1 = """
295
+ Quality Assurance Manual Overview
296
+
297
+ This document provides an introduction to the quality assurance procedures for manufacturing processes.
298
+
299
+ ## Introduction to Manufacturing Processes
300
+
301
+ This section covers the basics of manufacturing processes. It includes definitions and a brief history.
302
+
303
+ | Name | Description |
304
+ |---------------------|---------------------------|
305
+ | Process 1 | Initial process in制造过程。|
306
+
307
+ ### Detailed Process 1
308
+
309
+ This process refines material to meet specific standards.
310
+
311
+ | Parameter | Range |
312
+ |-----------|----------|
313
+ | Temperature | 200-300°C |
314
+
315
+ **Operational Parameters**
316
+
317
+ The operational parameters are critical for the success of this process.
318
+
319
+ | Setting | Class |
320
+ |---------|------------|
321
+ | Critical | High Precision |
322
+ """
323
+
324
+ # A different JSON schema example
325
+ SCHEMA1 = """
326
+ {
327
+ "$schema": "http://json-schema.org/draft-07/schema#",
328
+ "type": "object",
329
+ "properties": {
330
+ "id": {
331
+ "type": "string",
332
+ "description": "Dot-separated integers representing the hierarchical id of the element."
333
+ },
334
+ "title": {
335
+ "type": "string",
336
+ "description": "Descriptive title of the section or component."
337
+ },
338
+ "level": {
339
+ "type": "integer",
340
+ "description": "Hierarchy level starting from 0 for the root."
341
+ },
342
+ "level_type": {
343
+ "type": "string",
344
+ "enum": ["ROOT", "SECTION", "SUBSECTION", "DETAIL_N"],
345
+ "description": "Type of the hierarchal level."
346
+ },
347
+ "component": {
348
+ "type": "array",
349
+ "items": {
350
+ "type": "object",
351
+ "properties": {
352
+ "idc": {
353
+ "type": "integer",
354
+ "description": "Sequential unique component ID."
355
+ },
356
+ "component_type": {
357
+ "type": "string",
358
+ "enum": ["PARAGRAPH", "TABLE", "CALCULATION", "CHECKBOX"],
359
+ "description": "Type of the component."
360
+ },
361
+ "metadata": {
362
+ "type": "string",
363
+ "description": "Additional metadata token (may be <title>, <note>, or <overview>)."
364
+ },
365
+ "properties": {
366
+ "type": "object",
367
+ "properties": {
368
+ "variables": {
369
+ "type": "array",
370
+ "items": {
371
+ "type": "object",
372
+ "properties": {
373
+ "idx": {
374
+ "type": "string",
375
+ "description": "Unique identifier, X.Y (X represents row, Y represents column for Tables, 0 otherwise)."
376
+ },
377
+ "name": {
378
+ "type": "string",
379
+ "description": "Attribute name."
380
+ },
381
+ "value": {
382
+ "type": "string",
383
+ "description": "Attribute value."
384
+ },
385
+ "unit": {
386
+ "type": "string",
387
+ "description": "Optional unit."
388
+ },
389
+ "metrics": {
390
+ "type": "boolean",
391
+ "description": "Flag indicating if variable is a metric."
392
+ },
393
+ "formula": {
394
+ "type": "boolean",
395
+ "description": "Flag indicating if variable has an equation."
396
+ }
397
+ }
398
+ }
399
+ },
400
+ "content": {
401
+ "type": "array",
402
+ "items": {
403
+ "type": "string"
404
+ },
405
+ "description": "Text content (e.g., notes, MCQs, questions, points, etc.)."
406
+ }
407
+ }
408
+ }
409
+ }
410
+ }
411
+ },
412
+ "children": {
413
+ "type": "array",
414
+ "items": {
415
+ "$ref": "#"
416
+ },
417
+ "description": "Nested elements."
418
+ }
419
+ },
420
+ "required": ["id", "title", "level", "level_type", "component", "children"]
421
+ }
422
+ """
423
+
424
+ # LangChain prompt to guide the model
425
  SYSTEM_PROMPT = """
426
  ### Role:
427
  You are an expert data extractor specializing in mapping hierarchical text data into a given JSON Schema.
 
453
  4. **Correct Mapping of Attributes:**
454
  - Map key attributes, including `id`, `idc`, `idx`, `level_type`, and `component_type`.
455
  5. **JSON Format Compliance:**
456
+ - Escape quotes (`\"`), replace newlines with `\\n`, avoid trailing commas, and use double quotes exclusively.
457
  6. **Step-by-Step Reasoning:**
458
  - Explain your reasoning within the `<think>` tag.
459
 
 
461
  If either the `<think>` or `<answer>` tags is missing, the response will be considered incomplete.
462
  """
463
 
464
+ from langchain_core.prompts import PromptTemplate
465
  system_prompt_template = PromptTemplate(template=SYSTEM_PROMPT, input_variables=["TEXT", "SCHEMA"])
466
 
467
+ # Format the prompt with your chosen text and JSON schema
468
+ system_prompt_str = system_prompt_template.format(TEXT=TEXT1, SCHEMA=SCHEMA1)
469
+
470
+ # Now, pass `system_prompt_str` into your model inference pipeline (using Unsloth, Transformers, etc.)
471
+ # to get the output that contains both the reasoning and the mapped JSON object.
472
+ ```
473
+
474
+ ---
475
+
476
+ ## Sample Responses & Chain-of-Thought Explanations
477
+
478
+ Below are two sample outputs that include both a **Chain-of-Thought Explanation** (`<think>`) and the corresponding **Filled JSON Schema** (`<answer>`). These examples show how the model should articulate its reasoning and produce the final mapped schema.
479
+
480
+ ### Sample Response 1
481
+
482
+ ```plaintext
483
+ <think>
484
+ Chain of Thought Explanation:
485
+ To fill out the blank schema based on the Text and make it look exactly like the Filled Schema, I would start by understanding what each part represents.
486
+
487
+ First, looking at the Blank Schema, it has placeholders where actual content should go. The goal here is to replace those placeholders with appropriate data extracted from the Text so that when completed, it matches the Filled Schema perfectly.
488
+
489
+ I notice that both schemas have a similar structure, just with different types of components. My first step would be to identify how each component type maps back to elements in the Text.
490
+
491
+ For example, in the Introduction section under "Key Metrics," there's a table listing two variables: Defect Rate at 0.5% and Yield Rate at 98%. In the Filled Schema, these become entries in the 'variables' array of a Table component. So I'd extract these values from the corresponding parts in the Text and plug them into their respective places in the Blank Schema.
492
+
493
+ Next, moving down to the Subsection titled "QA Checklists," there are checkboxes for Confirmations about defects being identified and corrected versus audits conducted regularly. Looking at the Text again, I see bullet points describing whether particular checks were done—like confirming if defects had been found—and then noting what wasn't confirmed. From this, I can infer that each checkbox corresponds to one of these confirmation statements.
494
+
495
+ Then comes the Detail Section called "Standards Overview." Here, there's another table comparing ISO 9001 and ASQ-Certified QM. In the Text, under QA Standards Comparison, they mention checking both options with clear indicators of true/false states. Therefore, I'd replicate this structure in the Blank Schema by adding these same rows of comparison details.
496
+
497
+ Throughout this entire process, my focus remains on matching each piece of textual information to its correct location within the schema without altering any other parts beyond what's specified. By methodically identifying and populating each placeholder based on the Text's content, the end result should mirror the Filled Schema precisely because every element in the filled version was accounted for during extraction.
498
+ </think>
499
+
500
+ <answer>{
501
+ "id": "0.0",
502
+ "title": "Quality Assurance Manual for Manufacturing Process",
503
+ "level": 0,
504
+ "level_type": "ROOT",
505
+ "component": [
506
+ {
507
+ "idc": 0,
508
+ "component_type": "PARAGRAPH",
509
+ "metadata": "<overview>This manual covers the QA procedures and guidelines for various manufacturing processes.</overview>",
510
  "properties": {
511
+ "variables": [],
512
+ "content": []
513
+ }
514
+ }
515
+ ],
516
+ "children": [
517
+ {
518
+ "id": "1.0",
519
+ "title": "Introduction to Quality Assurance",
520
+ "level": 1,
521
+ "level_type": "SECTION",
522
+ "component": [
523
+ {
524
+ "idc": 0,
525
+ "component_type": "PARAGRAPH",
526
+ "metadata": "",
527
+ "properties": {
528
+ "variables": [],
529
+ "content": [
530
+ "Quality Assurance (QA) involves systematic activities designed to ensure consistent production of reliable and safe products.",
531
+ "It aims to reduce variability in the final product and improve overall efficiency."
532
+ ]
533
+ }
534
+ },
535
+ {
536
+ "idc": 1,
537
+ "component_type": "TABLE",
538
+ "metadata": "",
539
+ "properties": {
540
+ "variables": [
541
+ {
542
+ "idx": "0.0",
543
+ "name": "Metric",
544
+ "value": "Defect Rate",
545
+ "unit": "%",
546
+ "metrics": true,
547
+ "formula": false
548
+ },
549
+ {
550
+ "idx": "0.1",
551
+ "name": "Target",
552
+ "value": 0.5,
553
+ "unit": null,
554
+ "metrics": true,
555
+ "formula": false
556
+ }
557
+ ],
558
+ "content": []
559
+ }
560
+ }
561
+ ],
562
+ "children": [
563
+ {
564
+ "id": "1.1",
565
+ "title": "QA in Manufacturing Processes",
566
+ "level": 2,
567
+ "level_type": "SUBSECTION",
568
+ "component": [
569
+ {
570
+ "idc": 0,
571
+ "component_type": "PARAGRAPH",
572
+ "metadata": "",
573
+ "properties": {
574
+ "variables": [],
575
+ "content": [
576
+ "Manufacturing processes require strict adherence to QA procedures to ensure product reliability and safety."
577
+ ]
578
+ }
579
+ },
580
+ {
581
+ "idc": 1,
582
+ "component_type": "CHECKBOX",
583
+ "metadata": "",
584
+ "properties": {
585
+ "variables": [
586
+ {
587
+ "idx": "0.0",
588
+ "name": "Process Control",
589
+ "value": true,
590
+ "unit": null,
591
+ "metrics": false,
592
+ "formula": false
593
+ },
594
+ {
595
+ "idx": "0.1",
596
+ "name": "Raw Material Inspection",
597
+ "value": false,
598
+ "unit": null,
599
+ "metrics": false,
600
+ "formula": false
601
+ }
602
+ ],
603
+ "content": [
604
+ "Check if the following QA procedures are followed:",
605
+ "\u2713 Process Control \u2713 Raw Material Inspection"
606
+ ]
607
+ }
608
+ }
609
+ ],
610
+ "children": [
611
+ {
612
+ "id": "1.1.1",
613
+ "title": "Standard QA Practices",
614
+ "level": 3,
615
+ "level_type": "DETAIL_N",
616
+ "component": [
617
+ {
618
+ "idc": 0,
619
+ "component_type": "PARAGRAPH",
620
+ "metadata": "",
621
+ "properties": {
622
+ "variables": [],
623
+ "content": [
624
+ "Adherence to ISO 9001 standards helps maintain quality control."
625
+ ]
626
+ }
627
+ },
628
+ {
629
+ "idc": 1,
630
+ "component_type": "TABLE",
631
+ "metadata": "",
632
+ "properties": {
633
+ "variables": [
634
+ {
635
+ "idx": "0.0",
636
+ "name": "Comparison",
637
+ "value": "ISO 9001 vs ASQ-Certified QM",
638
+ "unit": null,
639
+ "metrics": false,
640
+ "formula": false
641
+ }
642
+ ],
643
+ "content": []
644
+ }
645
+ }
646
+ ],
647
+ "children": []
648
+ }
649
+ ]
650
+ }
651
+ ]
652
+ }
653
+ ]
654
+ }</answer>
655
+ ```
656
+
657
+ ---
658
+
659
+ ### Sample Response 2
660
 
661
+ ```plaintext
662
+ <think>
663
+ Chain of Thought Explanation:
664
+
665
+ To fill out the blank schema based on the provided Text and ensure it matches exactly what's in the Filled Schema, we can proceed step by step as follows:
666
+
667
+ 1. **Identify Components**: Recognize that both schemas contain similar structures with varying component types (Table, Paragraph, Checkbox).
668
+
669
+ 2. **Extract Data from Text**:
670
+ - Locate tables containing variables like Defect Rate and Yield Rate in the introduction section.
671
+ - Identify confirmatory statements regarding defect identification and regular audits in sub-sections.
672
+
673
+ 3. **Populate Variables**: Fill the Table component under "Key Metrics" with extracted variable names and values (Defect Rate=0.5%, Yield Rate=98%).
674
+
675
+ 4. **Fill Checkboxes**: Convert bullet points into boolean values for checkboxes; set Confirmations to reflect findings (true for defects found, false for audits missed).
676
+
677
+ 5. **Add Standards Table**: Create a second Table in the Details section comparing ISO 9001 and ASQ-Certified QM, mirroring the original.
678
+
679
+ By meticulously aligning each extracted detail with its designated spot in the Blank Schema, ensuring no additional or omitted data exists, the resulting schema will exactly match the Filled Schema's structure and content.
680
+
681
+ **Cross Verification**: Each action directly corresponds to filling specific fields without deviation. Thus, following this structured approach ensures identical outcomes between the transformed schema and the target Filled Schema.
682
+ </think>
683
+
684
+ <answer>{
685
+ "id": "0.0",
686
+ "title": "Quality Assurance Manual",
687
+ "level": 0,
688
+ "level_type": "ROOT",
689
+ "component": [
690
+ {
691
+ "idc": 0
692
+ },
693
+ {
694
+ "idc": 1
695
+ }
696
+ ],
697
+ "children": [
698
+ {
699
+ "id": "1.0",
700
+ "title": "Introduction to Manufacturing Processes",
701
+ "level": 1,
702
+ "level_type": "SECTION",
703
+ "component": [],
704
+ "children": [
705
+ {
706
+ "id": "1.1",
707
+ "title": "Detailed Process 1",
708
+ "level": 2,
709
+ "level_type": "SUBSECTION",
710
+ "component": [],
711
+ "children": []
712
+ },
713
+ {
714
+ "id": "1.2",
715
+ "title": "Operational Details",
716
+ "level": 2,
717
+ "level_type": "SUBSECTION",
718
+ "component": [
719
+ {
720
+ "idc": 0,
721
+ "component_type": "PARAGRAPH",
722
+ "metadata": "<overview>This section outlines the operational aspects of Process 1.</overview>",
723
+ "properties": {}
724
+ }
725
+ ],
726
+ "children": []
727
+ }
728
+ ]
729
+ },
730
+ {
731
+ "id": "2.0",
732
+ "title": "Advanced Manufacturing Techniques",
733
+ "level": 1,
734
+ "level_type": "SECTION",
735
+ "component": [],
736
+ "children": [
737
+ {
738
+ "id": "2.1",
739
+ "title": "High-Temperature Processing",
740
+ "level": 2,
741
+ "level_type": "SUBSECTION",
742
+ "component": [
743
+ {
744
+ "idc": 0,
745
+ "component_type": "TABLE",
746
+ "metadata": "<title>Table of Specifications</title>",
747
+ "properties": {
748
+ "variables": [
749
+ {
750
+ "idx": "0.0",
751
+ "name": "Parameter",
752
+ "value": "Temperature",
753
+ "unit": "\u00b0C",
754
+ "metrics": true,
755
+ "formula": false
756
+ },
757
+ {
758
+ "idx": "1.0",
759
+ "name": "Range",
760
+ "value": "[200, 300]",
761
+ "unit": null,
762
+ "metrics": false,
763
+ "formula": false
764
+ }
765
+ ],
766
+ "content": [
767
+ "Note: Ensure temperature control within specified range."
768
+ ]
769
+ }
770
+ }
771
+ ],
772
+ "children": []
773
+ }
774
+ ]
775
+ }
776
+ ]
777
+ }</answer>
778
  ```
779
 
780
  ---
 
800
 
801
  ---
802
 
803
+ Enjoy using the model and these examples as a reference for building your own prompt-driven applications! Happy coding!