bhaviktheslider commited on
Commit
2676b9e
·
verified ·
1 Parent(s): 8480e5f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +808 -13
README.md CHANGED
@@ -1,22 +1,817 @@
1
  ---
2
- base_model: MasterControlAIML/DeepSeek-R1-Strategy-Qwen-2.5-1.5b-Unstructured-To-Structured
3
- tags:
4
- - text-generation-inference
5
- - transformers
6
- - unsloth
7
- - qwen2
8
- - trl
9
  license: apache-2.0
10
  language:
11
  - en
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- # Uploaded model
 
 
 
 
15
 
16
- - **Developed by:** bhaviktheslider
17
- - **License:** apache-2.0
18
- - **Finetuned from model :** MasterControlAIML/DeepSeek-R1-Strategy-Qwen-2.5-1.5b-Unstructured-To-Structured
 
19
 
20
- This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
1
  ---
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  language:
4
  - en
5
+ base_model:
6
+ - >-
7
+ MasterControlAIML/DeepSeek-R1-Strategy-Qwen-2.5-1.5b-Unstructured-To-Structured
8
+ tags:
9
+ - DeepSeek
10
+ - R1
11
+ - SFT
12
+ - Qwen
13
+ - JSON
14
+ - Unstructured
15
+ - Structured
16
+ ---
17
+
18
+ # MasterControlAIML R1-Qwen2.5-1.5b SFT R1 JSON Unstructured-To-Structured Model
19
+
20
+ [![Unsloth](https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png)](https://github.com/unslothai/unsloth)
21
+
22
+ This repository provides a fine-tuned Qwen2 model optimized for transforming unstructured text into structured JSON outputs according to a predefined schema. The model is finetuned from the base model **MasterControlAIML/DeepSeek-R1-Strategy-Qwen-2.5-1.5b-Unstructured-To-Structured** and leverages LoRA techniques for efficient adaptation.
23
+
24
+ > **Key Highlights:**
25
+ >
26
+ > - **Developed by:** [bhaviktheslider](https://github.com/bhaviktheslider)
27
+ > - **License:** [Apache-2.0](LICENSE)
28
+ > - **Finetuned from:** `MasterControlAIML/DeepSeek-R1-Strategy-Qwen-2.5-1.5b-Unstructured-To-Structured`
29
+ > - **Accelerated Training:** Achieved 2x faster training using [Unsloth](https://github.com/unslothai/unsloth) and Hugging Face's TRL library.
30
+
31
+ ---
32
+
33
+ ## Table of Contents
34
+
35
+ - [Overview](#overview)
36
+ - [Features](#features)
37
+ - [Installation](#installation)
38
+ - [Quick Start](#quick-start)
39
+ - [Using Unsloth for Fast Inference](#using-unsloth-for-fast-inference)
40
+ - [Using Transformers for Inference](#using-transformers-for-inference)
41
+ - [Prompt & Code Examples](#prompt--code-examples)
42
+ - [Example 1: Basic Alpaca Prompt Template](#example-1-basic-alpaca-prompt-template)
43
+ - [Example 2: Advanced Data Extraction with LangChain](#example-2-advanced-data-extraction-with-langchain)
44
+ - [Sample Responses & Chain-of-Thought Explanations](#sample-responses--chain-of-thought-explanations)
45
+ - [Contributing](#contributing)
46
+ - [License](#license)
47
+ - [Acknowledgments](#acknowledgments)
48
+
49
+ ---
50
+
51
+ ## Overview
52
+
53
+ This model is tailored for tasks where mapping unstructured text (e.g., manuals, QA documents) into a structured JSON format is required. It supports hierarchical data extraction based on a given JSON Schema, ensuring that the generated outputs follow the exact structure and rules defined by the schema.
54
+
55
+ ---
56
+
57
+ ## Features
58
+
59
+ - **Efficient Inference:** Utilizes the [Unsloth](https://github.com/unslothai/unsloth) library for fast model inference.
60
+ - **Structured Output:** Maps text inputs into a strict JSON schema with hierarchical relationships.
61
+ - **Flexible Integration:** Example code snippets show how to use both the Unsloth API and Hugging Face’s Transformers.
62
+ - **Advanced Prompting:** Detailed examples using the Alpaca prompt template and LangChain prompt templates are provided below.
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ ### Prerequisites
69
+
70
+ - **Python:** 3.8+
71
+ - **PyTorch:** (Preferably with CUDA support)
72
+ - **Required Libraries:** `transformers`, `torch`, `unsloth`, `langchain` (for advanced usage)
73
+
74
+ ### Installation Command
75
+
76
+ Install the required Python packages with:
77
+
78
+ ```bash
79
+ pip install torch transformers unsloth langchain
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Quick Start
85
+
86
+ ### Using Unsloth for Fast Inference
87
+
88
+ The Unsloth library allows you to quickly load and run inference with the model. Below is a basic example:
89
+
90
+ ```python
91
+ from unsloth import FastLanguageModel
92
+ import torch
93
+
94
+ MODEL = "MasterControlAIML/DeepSeek-R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured-lora"
95
+
96
+ # Load model and tokenizer
97
+ model, tokenizer = FastLanguageModel.from_pretrained(
98
+ model_name=MODEL,
99
+ max_seq_length=2048,
100
+ dtype=None,
101
+ load_in_4bit=False,
102
+ )
103
+
104
+ # Prepare for inference
105
+ FastLanguageModel.for_inference(model)
106
+
107
+ ALPACA_PROMPT = """
108
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
109
+ ### Instruction:
110
+ {}
111
+ ### Response:
112
+ {}
113
+ """
114
+
115
+ # Example instruction and prompt
116
+ instruction = "" (see examples below)
117
+ prompt = ALPACA_PROMPT.format(instruction, "")
118
+ inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
119
+ output = model.generate(**inputs, max_new_tokens=2000)
120
+
121
+ # Print generated text
122
+ print(tokenizer.batch_decode(output, skip_special_tokens=True)[0])
123
+ ```
124
+
125
+ ---
126
+
127
+ ### Using Transformers for Inference
128
+
129
+ Alternatively, you can use Hugging Face's Transformers directly:
130
+
131
+ ```python
132
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
133
+ import torch
134
+
135
+ MODEL = "MasterControlAIML/DeepSeek-R1-Qwen2.5-1.5b-SFT-R1-JSON-Unstructured-To-Structured-lora"
136
+
137
+ # Initialize tokenizer and model
138
+ tokenizer = AutoTokenizer.from_pretrained(MODEL)
139
+ model = AutoModelForCausalLM.from_pretrained(MODEL, torch_dtype=torch.float16, device_map="auto")
140
+
141
+ ALPACA_PROMPT = """
142
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
143
+ ### Instruction:
144
+ {}
145
+ ### Response:
146
+ {}
147
+ """
148
+
149
+ TEXT = ""(see examples below)
150
+ prompt = ALPACA_PROMPT.format(TEXT, "")
151
+ inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
152
+ text_streamer = TextStreamer(tokenizer)
153
+
154
+ with torch.no_grad():
155
+ output_ids = model.generate(
156
+ input_ids=inputs["input_ids"],
157
+ attention_mask=inputs["attention_mask"],
158
+ max_new_tokens=2000,
159
+ temperature=0.7,
160
+ top_p=0.9,
161
+ repetition_penalty=1.1,
162
+ streamer=text_streamer,
163
+ pad_token_id=tokenizer.pad_token_id,
164
+ )
165
+
166
+ print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Prompt & Code Examples
172
+
173
+ To guide the model in mapping unstructured text to a JSON schema, you can structure your prompt as follows.
174
+
175
+ ### Example 1: Basic Alpaca Prompt Template
176
+
177
+ #### Code
178
+
179
+ ```python
180
+ # Define the Alpaca prompt template
181
+ ALPACA_PROMPT = """
182
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
183
+ ### Instruction:
184
+ {}
185
+ ### Response:
186
+ {}
187
+ """
188
+
189
+ # Sample text input describing a Quality Assurance Manual
190
+ TEXT = """
191
+ 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.
192
+
193
+ 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.
194
+
195
+ ---
196
+
197
+ Introduction to Quality Assurance
198
+ 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.
199
+
200
+ QA in Manufacturing Processes
201
+ 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).
202
+
203
+ [QA Checklist for Manufacturing]
204
+ | Process Controls | True | Value: Yes |
205
+ | Raw Material Inspection | False | Value: No |
206
+
207
+ 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.
208
+
209
+ Quality Assurance Standards
210
+ 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.
211
+
212
+ 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.
213
+ """
214
+
215
+ # JSON schema defining the expected structure of the output
216
+ SCHEMA = """
217
+ {
218
+ "type": "object",
219
+ "properties": {
220
+ "id": {
221
+ "type": "string",
222
+ "description": "Dot-separated integers representing the unique identifier of each element in the hierarchy."
223
+ },
224
+ "title": {
225
+ "type": "string",
226
+ "description": "Descriptive title for the section or document."
227
+ },
228
+ "level": {
229
+ "type": "integer",
230
+ "description": "Hierarchy level starting from 0 (root)."
231
+ },
232
+ "level_type": {
233
+ "type": "string",
234
+ "enum": ["ROOT", "SECTION", "SUBSECTION", "DETAIL_N"],
235
+ "description": "Type of hierarchy level."
236
+ },
237
+ "component": {
238
+ "type": "array",
239
+ "items": {
240
+ "type": "object",
241
+ "properties": {
242
+ "idc": {
243
+ "type": "integer",
244
+ "description": "Component ID within the element."
245
+ },
246
+ "component_type": {
247
+ "type": "string",
248
+ "enum": ["PARAGRAPH", "TABLE", "CALCULATION", "CHECKBOX"],
249
+ "description": "Type of component (e.g., paragraph, table)."
250
+ },
251
+ "metadata": {
252
+ "type": "string",
253
+ "pattern": "<title>.+</title>|<note>.+</note>|<overview>.+</overview>",
254
+ "description": "Metadata such as title, note, or overview."
255
+ },
256
+ "properties": {
257
+ "type": "object",
258
+ "properties": {
259
+ "variables": {
260
+ "type": "array",
261
+ "items": {
262
+ "type": "object",
263
+ "properties": {
264
+ "idx": {"type": "string"},
265
+ "name": {"type": "string"},
266
+ "value": {},
267
+ "unit": {"type": ["null", "string"]},
268
+ "metrics": {"type": "boolean"},
269
+ "formula": {"type": "boolean"}
270
+ },
271
+ "required": ["idx", "name", "value"]
272
+ }
273
+ },
274
+ "content": {
275
+ "type": ["array"],
276
+ "items": {"type": "string"}
277
+ }
278
+ }
279
+ }
280
+ },
281
+ "required": ["idc", "component_type", "metadata", "properties"]
282
+ }
283
+ },
284
+ "children": {
285
+ "type": "array",
286
+ "items": {}
287
+ }
288
+ },
289
+ "required": ["id", "title", "level", "level_type", "component", "children"]
290
+ }
291
+ """
292
+
293
+ # Now you would use your chosen inference method (e.g., via Unsloth or Transformers)
294
+ # to feed the prompt (ALPACA_PROMPT, TEXT, and SCHEMA) into the model.
295
+ ```
296
+
297
+ ---
298
+
299
+ ### Example 2: Advanced Data Extraction with LangChain
300
+
301
+ #### Code
302
+
303
+ ```python
304
+ from langchain_core.prompts import PromptTemplate
305
+
306
+ # Sample text input with a slightly different structure
307
+ TEXT1 = """
308
+ Quality Assurance Manual Overview
309
+
310
+ This document provides an introduction to the quality assurance procedures for manufacturing processes.
311
+
312
+ ## Introduction to Manufacturing Processes
313
+
314
+ This section covers the basics of manufacturing processes. It includes definitions and a brief history.
315
+
316
+ | Name | Description |
317
+ |---------------------|---------------------------|
318
+ | Process 1 | Initial process in制造过程。|
319
+
320
+ ### Detailed Process 1
321
+
322
+ This process refines material to meet specific standards.
323
+
324
+ | Parameter | Range |
325
+ |-----------|----------|
326
+ | Temperature | 200-300°C |
327
+
328
+ **Operational Parameters**
329
+
330
+ The operational parameters are critical for the success of this process.
331
+
332
+ | Setting | Class |
333
+ |---------|------------|
334
+ | Critical | High Precision |
335
+ """
336
+
337
+ # A different JSON schema example
338
+ SCHEMA1 = """
339
+ {
340
+ "$schema": "http://json-schema.org/draft-07/schema#",
341
+ "type": "object",
342
+ "properties": {
343
+ "id": {
344
+ "type": "string",
345
+ "description": "Dot-separated integers representing the hierarchical id of the element."
346
+ },
347
+ "title": {
348
+ "type": "string",
349
+ "description": "Descriptive title of the section or component."
350
+ },
351
+ "level": {
352
+ "type": "integer",
353
+ "description": "Hierarchy level starting from 0 for the root."
354
+ },
355
+ "level_type": {
356
+ "type": "string",
357
+ "enum": ["ROOT", "SECTION", "SUBSECTION", "DETAIL_N"],
358
+ "description": "Type of the hierarchal level."
359
+ },
360
+ "component": {
361
+ "type": "array",
362
+ "items": {
363
+ "type": "object",
364
+ "properties": {
365
+ "idc": {
366
+ "type": "integer",
367
+ "description": "Sequential unique component ID."
368
+ },
369
+ "component_type": {
370
+ "type": "string",
371
+ "enum": ["PARAGRAPH", "TABLE", "CALCULATION", "CHECKBOX"],
372
+ "description": "Type of the component."
373
+ },
374
+ "metadata": {
375
+ "type": "string",
376
+ "description": "Additional metadata token (may be <title>, <note>, or <overview>)."
377
+ },
378
+ "properties": {
379
+ "type": "object",
380
+ "properties": {
381
+ "variables": {
382
+ "type": "array",
383
+ "items": {
384
+ "type": "object",
385
+ "properties": {
386
+ "idx": {
387
+ "type": "string",
388
+ "description": "Unique identifier, X.Y (X represents row, Y represents column for Tables, 0 otherwise)."
389
+ },
390
+ "name": {
391
+ "type": "string",
392
+ "description": "Attribute name."
393
+ },
394
+ "value": {
395
+ "type": "string",
396
+ "description": "Attribute value."
397
+ },
398
+ "unit": {
399
+ "type": "string",
400
+ "description": "Optional unit."
401
+ },
402
+ "metrics": {
403
+ "type": "boolean",
404
+ "description": "Flag indicating if variable is a metric."
405
+ },
406
+ "formula": {
407
+ "type": "boolean",
408
+ "description": "Flag indicating if variable has an equation."
409
+ }
410
+ }
411
+ }
412
+ },
413
+ "content": {
414
+ "type": "array",
415
+ "items": {
416
+ "type": "string"
417
+ },
418
+ "description": "Text content (e.g., notes, MCQs, questions, points, etc.)."
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ },
425
+ "children": {
426
+ "type": "array",
427
+ "items": {
428
+ "$ref": "#"
429
+ },
430
+ "description": "Nested elements."
431
+ }
432
+ },
433
+ "required": ["id", "title", "level", "level_type", "component", "children"]
434
+ }
435
+ """
436
+
437
+ # LangChain prompt to guide the model
438
+ SYSTEM_PROMPT = """
439
+ ### Role:
440
+ You are an expert data extractor specializing in mapping hierarchical text data into a given JSON Schema.
441
+
442
+ ### DATA INPUT:
443
+ - **Text:** ```{TEXT}```
444
+ - **Blank JSON Schema:** ```{SCHEMA}```
445
+
446
+ ### TASK REQUIREMENT:
447
+ 1. Analyze the given text and map all relevant information strictly into the provided JSON Schema.
448
+ 2. Provide your output in **two mandatory sections**:
449
+ - **`<answer>`:** The filled JSON object
450
+ - **`<think>`:** Reasoning for the mapping decisions
451
+
452
+ ### OUTPUT STRUCTURE:
453
+
454
+ `<think> /* Explanation of mapping logic */ </think>`
455
+ `<answer> /* Completed JSON Object */ </answer>`
456
+
457
+
458
+
459
+ ### STRICT RULES FOR GENERATING OUTPUT:
460
+ 1. **Both Tags Required:**
461
+ - Always provide both the `<think>` and `<answer>` sections.
462
+ - If reasoning is minimal, state: "Direct mapping from text to schema."
463
+ 2. **JSON Schema Mapping:**
464
+ - Strictly map the text data to the given JSON Schema without modification or omissions.
465
+ 3. **Hierarchy Preservation:**
466
+ - Maintain proper parent-child relationships and follow the schema's hierarchical structure.
467
+ 4. **Correct Mapping of Attributes:**
468
+ - Map key attributes, including `id`, `idc`, `idx`, `level_type`, and `component_type`.
469
+ 5. **JSON Format Compliance:**
470
+ - Escape quotes (`\"`), replace newlines with `\\n`, avoid trailing commas, and use double quotes exclusively.
471
+ 6. **Step-by-Step Reasoning:**
472
+ - Explain your reasoning within the `<think>` tag.
473
+
474
+ ### IMPORTANT:
475
+ If either the `<think>` or `<answer>` tags is missing, the response will be considered incomplete.
476
+ """
477
+
478
+ from langchain_core.prompts import PromptTemplate
479
+ system_prompt_template = PromptTemplate(template=SYSTEM_PROMPT, input_variables=["TEXT", "SCHEMA"])
480
+
481
+ # Format the prompt with your chosen text and JSON schema
482
+ system_prompt_str = system_prompt_template.format(TEXT=TEXT1, SCHEMA=SCHEMA1)
483
+
484
+ # Now, pass `system_prompt_str` into your model inference pipeline (using Unsloth, Transformers, etc.)
485
+ # to get the output that contains both the reasoning and the mapped JSON object.
486
+ ```
487
+
488
  ---
489
 
490
+ ## Sample Responses & Chain-of-Thought Explanations
491
+
492
+ 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.
493
+
494
+ ### Sample Response 1
495
 
496
+ ```plaintext
497
+ <think>
498
+ Chain of Thought Explanation:
499
+ 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.
500
 
501
+ 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.
502
+
503
+ 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.
504
+
505
+ 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.
506
+
507
+ 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.
508
+
509
+ 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.
510
+
511
+ 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.
512
+ </think>
513
+
514
+ <answer>{
515
+ "id": "0.0",
516
+ "title": "Quality Assurance Manual for Manufacturing Process",
517
+ "level": 0,
518
+ "level_type": "ROOT",
519
+ "component": [
520
+ {
521
+ "idc": 0,
522
+ "component_type": "PARAGRAPH",
523
+ "metadata": "<overview>This manual covers the QA procedures and guidelines for various manufacturing processes.</overview>",
524
+ "properties": {
525
+ "variables": [],
526
+ "content": []
527
+ }
528
+ }
529
+ ],
530
+ "children": [
531
+ {
532
+ "id": "1.0",
533
+ "title": "Introduction to Quality Assurance",
534
+ "level": 1,
535
+ "level_type": "SECTION",
536
+ "component": [
537
+ {
538
+ "idc": 0,
539
+ "component_type": "PARAGRAPH",
540
+ "metadata": "",
541
+ "properties": {
542
+ "variables": [],
543
+ "content": [
544
+ "Quality Assurance (QA) involves systematic activities designed to ensure consistent production of reliable and safe products.",
545
+ "It aims to reduce variability in the final product and improve overall efficiency."
546
+ ]
547
+ }
548
+ },
549
+ {
550
+ "idc": 1,
551
+ "component_type": "TABLE",
552
+ "metadata": "",
553
+ "properties": {
554
+ "variables": [
555
+ {
556
+ "idx": "0.0",
557
+ "name": "Metric",
558
+ "value": "Defect Rate",
559
+ "unit": "%",
560
+ "metrics": true,
561
+ "formula": false
562
+ },
563
+ {
564
+ "idx": "0.1",
565
+ "name": "Target",
566
+ "value": 0.5,
567
+ "unit": null,
568
+ "metrics": true,
569
+ "formula": false
570
+ }
571
+ ],
572
+ "content": []
573
+ }
574
+ }
575
+ ],
576
+ "children": [
577
+ {
578
+ "id": "1.1",
579
+ "title": "QA in Manufacturing Processes",
580
+ "level": 2,
581
+ "level_type": "SUBSECTION",
582
+ "component": [
583
+ {
584
+ "idc": 0,
585
+ "component_type": "PARAGRAPH",
586
+ "metadata": "",
587
+ "properties": {
588
+ "variables": [],
589
+ "content": [
590
+ "Manufacturing processes require strict adherence to QA procedures to ensure product reliability and safety."
591
+ ]
592
+ }
593
+ },
594
+ {
595
+ "idc": 1,
596
+ "component_type": "CHECKBOX",
597
+ "metadata": "",
598
+ "properties": {
599
+ "variables": [
600
+ {
601
+ "idx": "0.0",
602
+ "name": "Process Control",
603
+ "value": true,
604
+ "unit": null,
605
+ "metrics": false,
606
+ "formula": false
607
+ },
608
+ {
609
+ "idx": "0.1",
610
+ "name": "Raw Material Inspection",
611
+ "value": false,
612
+ "unit": null,
613
+ "metrics": false,
614
+ "formula": false
615
+ }
616
+ ],
617
+ "content": [
618
+ "Check if the following QA procedures are followed:",
619
+ "\u2713 Process Control \u2713 Raw Material Inspection"
620
+ ]
621
+ }
622
+ }
623
+ ],
624
+ "children": [
625
+ {
626
+ "id": "1.1.1",
627
+ "title": "Standard QA Practices",
628
+ "level": 3,
629
+ "level_type": "DETAIL_N",
630
+ "component": [
631
+ {
632
+ "idc": 0,
633
+ "component_type": "PARAGRAPH",
634
+ "metadata": "",
635
+ "properties": {
636
+ "variables": [],
637
+ "content": [
638
+ "Adherence to ISO 9001 standards helps maintain quality control."
639
+ ]
640
+ }
641
+ },
642
+ {
643
+ "idc": 1,
644
+ "component_type": "TABLE",
645
+ "metadata": "",
646
+ "properties": {
647
+ "variables": [
648
+ {
649
+ "idx": "0.0",
650
+ "name": "Comparison",
651
+ "value": "ISO 9001 vs ASQ-Certified QM",
652
+ "unit": null,
653
+ "metrics": false,
654
+ "formula": false
655
+ }
656
+ ],
657
+ "content": []
658
+ }
659
+ }
660
+ ],
661
+ "children": []
662
+ }
663
+ ]
664
+ }
665
+ ]
666
+ }
667
+ ]
668
+ }</answer>
669
+ ```
670
+
671
+ ---
672
+
673
+ ### Sample Response 2
674
+
675
+ ```plaintext
676
+ <think>
677
+ Chain of Thought Explanation:
678
+
679
+ 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:
680
+
681
+ 1. **Identify Components**: Recognize that both schemas contain similar structures with varying component types (Table, Paragraph, Checkbox).
682
+
683
+ 2. **Extract Data from Text**:
684
+ - Locate tables containing variables like Defect Rate and Yield Rate in the introduction section.
685
+ - Identify confirmatory statements regarding defect identification and regular audits in sub-sections.
686
+
687
+ 3. **Populate Variables**: Fill the Table component under "Key Metrics" with extracted variable names and values (Defect Rate=0.5%, Yield Rate=98%).
688
+
689
+ 4. **Fill Checkboxes**: Convert bullet points into boolean values for checkboxes; set Confirmations to reflect findings (true for defects found, false for audits missed).
690
+
691
+ 5. **Add Standards Table**: Create a second Table in the Details section comparing ISO 9001 and ASQ-Certified QM, mirroring the original.
692
+
693
+ 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.
694
+
695
+ **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.
696
+ </think>
697
+
698
+ <answer>{
699
+ "id": "0.0",
700
+ "title": "Quality Assurance Manual",
701
+ "level": 0,
702
+ "level_type": "ROOT",
703
+ "component": [
704
+ {
705
+ "idc": 0
706
+ },
707
+ {
708
+ "idc": 1
709
+ }
710
+ ],
711
+ "children": [
712
+ {
713
+ "id": "1.0",
714
+ "title": "Introduction to Manufacturing Processes",
715
+ "level": 1,
716
+ "level_type": "SECTION",
717
+ "component": [],
718
+ "children": [
719
+ {
720
+ "id": "1.1",
721
+ "title": "Detailed Process 1",
722
+ "level": 2,
723
+ "level_type": "SUBSECTION",
724
+ "component": [],
725
+ "children": []
726
+ },
727
+ {
728
+ "id": "1.2",
729
+ "title": "Operational Details",
730
+ "level": 2,
731
+ "level_type": "SUBSECTION",
732
+ "component": [
733
+ {
734
+ "idc": 0,
735
+ "component_type": "PARAGRAPH",
736
+ "metadata": "<overview>This section outlines the operational aspects of Process 1.</overview>",
737
+ "properties": {}
738
+ }
739
+ ],
740
+ "children": []
741
+ }
742
+ ]
743
+ },
744
+ {
745
+ "id": "2.0",
746
+ "title": "Advanced Manufacturing Techniques",
747
+ "level": 1,
748
+ "level_type": "SECTION",
749
+ "component": [],
750
+ "children": [
751
+ {
752
+ "id": "2.1",
753
+ "title": "High-Temperature Processing",
754
+ "level": 2,
755
+ "level_type": "SUBSECTION",
756
+ "component": [
757
+ {
758
+ "idc": 0,
759
+ "component_type": "TABLE",
760
+ "metadata": "<title>Table of Specifications</title>",
761
+ "properties": {
762
+ "variables": [
763
+ {
764
+ "idx": "0.0",
765
+ "name": "Parameter",
766
+ "value": "Temperature",
767
+ "unit": "\u00b0C",
768
+ "metrics": true,
769
+ "formula": false
770
+ },
771
+ {
772
+ "idx": "1.0",
773
+ "name": "Range",
774
+ "value": "[200, 300]",
775
+ "unit": null,
776
+ "metrics": false,
777
+ "formula": false
778
+ }
779
+ ],
780
+ "content": [
781
+ "Note: Ensure temperature control within specified range."
782
+ ]
783
+ }
784
+ }
785
+ ],
786
+ "children": []
787
+ }
788
+ ]
789
+ }
790
+ ]
791
+ }</answer>
792
+ ```
793
+
794
+ ---
795
+
796
+ ## Contributing
797
+
798
+ Contributions, bug reports, and feature requests are welcome! Please open an issue or submit a pull request if you would like to contribute to this project.
799
+
800
+ ---
801
+
802
+ ## License
803
+
804
+ This project is licensed under the [Apache-2.0 License](LICENSE).
805
+
806
+ ---
807
+
808
+ ## Acknowledgments
809
+
810
+ - **Unsloth:** For providing fast model inference capabilities. ([GitHub](https://github.com/unslothai/unsloth))
811
+ - **Hugging Face:** For the [Transformers](https://github.com/huggingface/transformers) and [TRL](https://github.com/huggingface/trl) libraries.
812
+ - **LangChain:** For advanced prompt management and integration.
813
+ - And, of course, thanks to the community and contributors who helped shape this project.
814
+
815
+ ---
816
 
817
+ Enjoy using the model and these examples as a reference for building your own prompt-driven applications! Happy coding!