zodiac2525 commited on
Commit
1f6e36b
·
verified ·
1 Parent(s): f845337

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +190 -144
README.md CHANGED
@@ -6,202 +6,248 @@ tags:
6
  - base_model:adapter:Qwen/Qwen2.5-VL-3B-Instruct
7
  - lora
8
  - transformers
 
9
  ---
10
 
11
- # Model Card for Model ID
12
-
13
- <!-- Provide a quick summary of what the model is/does. -->
14
-
15
 
 
16
 
17
  ## Model Details
18
 
19
  ### Model Description
20
 
21
- <!-- Provide a longer summary of what this model is. -->
22
 
 
23
 
 
 
 
 
 
24
 
25
- - **Developed by:** [More Information Needed]
26
- - **Funded by [optional]:** [More Information Needed]
27
- - **Shared by [optional]:** [More Information Needed]
28
- - **Model type:** [More Information Needed]
29
- - **Language(s) (NLP):** [More Information Needed]
30
- - **License:** [More Information Needed]
31
- - **Finetuned from model [optional]:** [More Information Needed]
32
 
33
- ### Model Sources [optional]
 
34
 
35
- <!-- Provide the basic links for the model. -->
36
 
37
- - **Repository:** [More Information Needed]
38
- - **Paper [optional]:** [More Information Needed]
39
- - **Demo [optional]:** [More Information Needed]
40
 
41
- ## Uses
 
 
 
 
 
42
 
43
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
 
45
  ### Direct Use
46
 
47
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
 
48
 
49
- [More Information Needed]
50
 
51
- ### Downstream Use [optional]
52
-
53
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
-
55
- [More Information Needed]
 
56
 
57
  ### Out-of-Scope Use
58
 
59
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
-
61
- [More Information Needed]
62
-
63
- ## Bias, Risks, and Limitations
64
-
65
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
-
67
- [More Information Needed]
68
-
69
- ### Recommendations
70
-
71
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
-
73
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
 
75
  ## How to Get Started with the Model
76
 
77
- Use the code below to get started with the model.
78
-
79
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  ## Training Details
82
 
83
  ### Training Data
84
 
85
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
-
87
- [More Information Needed]
88
 
89
  ### Training Procedure
90
 
91
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
-
93
- #### Preprocessing [optional]
94
-
95
- [More Information Needed]
96
-
97
-
98
- #### Training Hyperparameters
99
-
100
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
 
102
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
 
103
 
104
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
 
106
- [More Information Needed]
 
 
107
 
108
  ## Evaluation
109
 
110
- <!-- This section describes the evaluation protocols and provides the results. -->
111
-
112
- ### Testing Data, Factors & Metrics
113
-
114
- #### Testing Data
115
-
116
- <!-- This should link to a Dataset Card if possible. -->
117
-
118
- [More Information Needed]
119
-
120
- #### Factors
121
-
122
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
-
124
- [More Information Needed]
125
 
126
- #### Metrics
127
-
128
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
-
130
- [More Information Needed]
131
-
132
- ### Results
133
-
134
- [More Information Needed]
135
-
136
- #### Summary
137
-
138
-
139
-
140
- ## Model Examination [optional]
141
-
142
- <!-- Relevant interpretability work for the model goes here -->
143
-
144
- [More Information Needed]
145
-
146
- ## Environmental Impact
147
-
148
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
-
150
- 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).
151
-
152
- - **Hardware Type:** [More Information Needed]
153
- - **Hours used:** [More Information Needed]
154
- - **Cloud Provider:** [More Information Needed]
155
- - **Compute Region:** [More Information Needed]
156
- - **Carbon Emitted:** [More Information Needed]
157
-
158
- ## Technical Specifications [optional]
159
-
160
- ### Model Architecture and Objective
161
-
162
- [More Information Needed]
163
-
164
- ### Compute Infrastructure
165
-
166
- [More Information Needed]
167
-
168
- #### Hardware
169
-
170
- [More Information Needed]
171
-
172
- #### Software
173
-
174
- [More Information Needed]
175
-
176
- ## Citation [optional]
177
-
178
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
-
180
- **BibTeX:**
181
 
182
- [More Information Needed]
 
 
 
 
183
 
184
- **APA:**
 
 
 
185
 
186
- [More Information Needed]
187
 
188
- ## Glossary [optional]
 
 
 
 
189
 
190
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
191
 
192
- [More Information Needed]
193
 
194
- ## More Information [optional]
 
 
 
195
 
196
- [More Information Needed]
197
 
198
- ## Model Card Authors [optional]
199
 
200
- [More Information Needed]
 
 
 
 
 
 
 
201
 
202
  ## Model Card Contact
203
 
204
- [More Information Needed]
205
- ### Framework versions
206
-
207
- - PEFT 0.16.0
 
6
  - base_model:adapter:Qwen/Qwen2.5-VL-3B-Instruct
7
  - lora
8
  - transformers
9
+ - image-to-text
10
  ---
11
 
12
+ # Qwen2.5-VL-Diagrams2SQL
 
 
 
13
 
14
+ A fine-tuned **Qwen2.5-VL-3B-Instruct** model specialized for converting database schema diagrams into structured JSON format. This model dramatically improves upon the base model's ability to understand and extract information from ER diagrams, database schemas, and other structured database documentation.
15
 
16
  ## Model Details
17
 
18
  ### Model Description
19
 
20
+ This model addresses a common pain point in database documentation and migration projects: manually transcribing database schema diagrams is time-consuming and error-prone. While the base Qwen2.5-VL model struggled with structured diagram interpretation (often missing tables, incorrectly identifying relationships, or producing malformed outputs), this fine-tuned version shows significant improvements across all metrics.
21
 
22
+ The model uses **LoRA (Low-Rank Adaptation)** for parameter-efficient fine-tuning, targeting attention layers for optimal performance while maintaining efficiency.
23
 
24
+ - **Developed by:** zodiac2525
25
+ - **Model type:** Vision-Language Model (Fine-tuned)
26
+ - **Language(s):** English
27
+ - **License:** Same as base model (Qwen2.5-VL-3B-Instruct)
28
+ - **Finetuned from model:** [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
29
 
30
+ ### Model Sources
 
 
 
 
 
 
31
 
32
+ - **Repository:** [GitHub Repository](https://github.com/zodiac2525/DB-Diagram-to-JSON-Schema)
33
+ - **Base Model:** [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
34
 
35
+ ## Performance Improvements
36
 
37
+ The fine-tuned model shows significant improvements over the base model:
 
 
38
 
39
+ | Metric | Base Qwen2.5-VL | Fine-tuned Model | Improvement |
40
+ |--------|------------------|------------------|-------------|
41
+ | **Table Detection Accuracy** | 65.2% | 89.7% | **+24.5%** |
42
+ | **Relationship Accuracy** | 58.9% | 84.3% | **+25.4%** |
43
+ | **Overall Schema Score** | 62.1% | 87.0% | **+24.9%** |
44
+ | **JSON Format Compliance** | 78.1% | 96.2% | **+18.1%** |
45
 
46
+ ## Uses
47
 
48
  ### Direct Use
49
 
50
+ This model is designed to:
51
+ - Convert database ER diagrams to structured JSON schemas
52
+ - Extract table structures, column definitions, and relationships from visual diagrams
53
+ - Automate database documentation processes
54
+ - Assist in database migration and reverse engineering tasks
55
 
56
+ ### Supported Diagram Types
57
 
58
+ The model has been trained on diverse schema types including:
59
+ - **E-commerce**: Products, orders, customers, payments
60
+ - **Healthcare**: Patients, appointments, medical records
61
+ - **Education**: Students, courses, grades, enrollment
62
+ - **Finance**: Accounts, transactions, investments
63
+ - **IoT/Social Media**: Users, posts, device data
64
 
65
  ### Out-of-Scope Use
66
 
67
+ - Not suitable for non-database diagrams (flowcharts, network diagrams, etc.)
68
+ - Does not generate actual SQL DDL statements (outputs JSON schema only)
69
+ - Not trained for natural language database queries
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  ## How to Get Started with the Model
72
 
73
+ ### Installation
74
+
75
+ ```bash
76
+ pip install transformers torch pillow
77
+ ```
78
+
79
+ ### Basic Usage
80
+
81
+ ```python
82
+ from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
83
+ from PIL import Image
84
+ import torch
85
+ import json
86
+
87
+ # Load the fine-tuned model
88
+ model_id = "zodiac2525/Qwen2.5-VL-Diagrams2SQL"
89
+ processor = AutoProcessor.from_pretrained(model_id)
90
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
91
+ model_id,
92
+ torch_dtype=torch.bfloat16,
93
+ device_map="auto"
94
+ )
95
+
96
+ # Load your ER diagram
97
+ image = Image.open("path/to/your/diagram.png").convert("RGB")
98
+
99
+ # Prepare the input
100
+ messages = [
101
+ {
102
+ "role": "user",
103
+ "content": [
104
+ {"type": "image", "image": image},
105
+ {"type": "text", "text": "Extract data in JSON format"}
106
+ ]
107
+ }
108
+ ]
109
+
110
+ # Process and generate
111
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
112
+ inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
113
+
114
+ # Generate schema
115
+ with torch.no_grad():
116
+ generated_ids = model.generate(
117
+ **inputs,
118
+ max_new_tokens=1024,
119
+ do_sample=False,
120
+ temperature=0.0
121
+ )
122
+
123
+ # Extract and parse JSON
124
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
125
+ json_start = generated_text.find('{')
126
+ if json_start != -1:
127
+ schema_json = json.loads(generated_text[json_start:])
128
+ print(json.dumps(schema_json, indent=2))
129
+ ```
130
+
131
+ ### Expected Output Format
132
+
133
+ The model outputs JSON schemas in the following structure:
134
+
135
+ ```json
136
+ {
137
+ "tables": [
138
+ {
139
+ "name": "users",
140
+ "columns": [
141
+ {
142
+ "name": "id",
143
+ "type": "INT",
144
+ "constraints": ["PRIMARY KEY", "AUTO_INCREMENT"]
145
+ },
146
+ {
147
+ "name": "email",
148
+ "type": "VARCHAR(255)",
149
+ "constraints": ["UNIQUE", "NOT NULL"]
150
+ }
151
+ ]
152
+ }
153
+ ],
154
+ "relationships": [
155
+ {
156
+ "from_table": "orders",
157
+ "from_column": "user_id",
158
+ "to_table": "users",
159
+ "to_column": "id",
160
+ "relationship_type": "FOREIGN KEY"
161
+ }
162
+ ]
163
+ }
164
+ ```
165
 
166
  ## Training Details
167
 
168
  ### Training Data
169
 
170
+ The model was fine-tuned on a custom dataset of 400+ database schema diagrams with corresponding JSON annotations, covering various domains and complexity levels.
 
 
171
 
172
  ### Training Procedure
173
 
174
+ **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
175
+ - **LoRA Rank:** 16
176
+ - **LoRA Alpha:** 32
177
+ - **Target Modules:** q_proj, v_proj, k_proj, o_proj (attention layers)
 
 
 
 
 
 
178
 
179
+ **Training Hyperparameters:**
180
+ - **Learning Rate:** 1e-4
181
+ - **Batch Size:** 4
182
+ - **Gradient Accumulation Steps:** 8
183
+ - **Max Epochs:** 8
184
+ - **Optimizer:** AdamW
185
+ - **Weight Decay:** 0.01
186
+ - **LR Scheduler:** Cosine
187
+ - **Mixed Precision:** bf16
188
 
189
+ ### Training Infrastructure
190
 
191
+ - **Framework:** PyTorch with Transformers
192
+ - **Experiment Tracking:** Comet ML
193
+ - **Hardware:** GPU-optimized training setup
194
 
195
  ## Evaluation
196
 
197
+ The model was evaluated on a held-out test set using multiple metrics:
198
+ - **Table Detection Accuracy**: Percentage of correctly identified tables
199
+ - **Relationship Accuracy**: Percentage of correctly identified relationships
200
+ - **JSON Format Compliance**: Percentage of valid JSON outputs
201
+ - **Overall Schema Score**: Composite metric combining all aspects
 
 
 
 
 
 
 
 
 
 
202
 
203
+ ## Bias, Risks, and Limitations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
+ **Limitations:**
206
+ - Performance may vary with diagram quality, resolution, and formatting
207
+ - Best results achieved with clear, well-structured diagrams
208
+ - May struggle with hand-drawn or heavily stylized diagrams
209
+ - Limited to database schema diagrams (not general-purpose diagram understanding)
210
 
211
+ **Recommendations:**
212
+ - Use high-quality, clear diagram images for best results
213
+ - Verify generated schemas for critical applications
214
+ - Consider the model as an assistive tool rather than fully automated solution
215
 
216
+ ## Technical Specifications
217
 
218
+ ### Model Architecture
219
+ - **Base Architecture:** Qwen2.5-VL (Vision-Language Model)
220
+ - **Vision Encoder:** Processes input images to visual tokens
221
+ - **Language Model:** Qwen2.5 transformer backbone
222
+ - **Multi-modal Fusion:** Integrates visual and textual representations
223
 
224
+ ### Compute Requirements
225
+ - **Minimum VRAM:** 8GB (for inference)
226
+ - **Recommended:** 16GB+ for optimal performance
227
+ - **CPU Inference:** Supported but slower
228
 
229
+ ## Framework Versions
230
 
231
+ - **PEFT:** 0.16.0
232
+ - **Transformers:** 4.49.0+
233
+ - **PyTorch:** 2.0+
234
+ - **Python:** 3.8+
235
 
236
+ ## Citation
237
 
238
+ If you use this model in your research or applications, please cite:
239
 
240
+ ```bibtex
241
+ @misc{qwen25vl-diagrams2sql,
242
+ title={Qwen2.5-VL-Diagrams2SQL: Fine-tuned Vision-Language Model for Database Schema Extraction},
243
+ author={zodiac2525},
244
+ year={2024},
245
+ howpublished={\url{https://huggingface.co/zodiac2525/Qwen2.5-VL-Diagrams2SQL}}
246
+ }
247
+ ```
248
 
249
  ## Model Card Contact
250
 
251
+ For questions, issues, or collaboration opportunities, please:
252
+ - Open an issue on the GitHub repository
253
+ - Contact via Hugging Face model discussions