File size: 7,215 Bytes
d5c7574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6940c2
d5c7574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a06b71c
d5c7574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3cd22e8
d5c7574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ad0bf5
 
 
 
 
 
 
 
d5c7574
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
license: apache-2.0
language:
- en
base_model:
- Qwen/Qwen2.5-Coder-7B-Instruct
pipeline_tag: text-generation
library_name: transformers
tags:
- chart
- code-generation
- visualization
- matplotlib
- data-visualization
- complexity-aware
datasets:
- opendatalab/ChartVerse-Coder-Data
---

**ChartVerse-Coder** is a complexity-aware chart code generator that can autonomously synthesize diverse, high-complexity chart codes from scratch, developed as part of the **[opendatalab/ChartVerse](https://huggingface.co/collections/opendatalab/chartverse)** project. For more details about our method, datasets, and full model series, please visit our [Project Page](https://chartverse.github.io).

Unlike prior template-based or seed-conditioned approaches, ChartVerse-Coder generates chart code via high-temperature sampling, enabling broad exploration of the long-tail chart distribution and producing diverse, realistic charts with high structural complexity.

## πŸ”₯ Highlights

- **Autonomous Synthesis**: Generates diverse chart codes from scratch without templates or seed charts
- **Complexity-Aware**: Trained with RPE-guided filtering to master high-complexity visualizations
- **High Diversity**: Produces charts spanning 3D plots, hierarchical structures, multi-subplot layouts, and more
- **Iterative Self-Enhancement**: Progressively improves code quality through generation-filtering-retraining loops

## πŸ”¬ Method Overview

### Rollout Posterior Entropy (RPE)

<div align="center">
  <img src="https://raw.githubusercontent.com/chartverse/chartverse.github.io/main/static/images/rpe_illustration.png" width="100%" alt="RPE Illustration">
</div>

We propose **Rollout Posterior Entropy (RPE)** to quantify intrinsic chart complexity via generative stability:

1. **VLM Rollout**: Given a chart, prompt a VLM to generate executable code 8 times with temperature 1.0
2. **Feature Extraction**: Extract CLIP embeddings from reconstructed images and compute Gram matrix
3. **Spectral Entropy**: Calculate entropy from normalized singular values

**Key Insight**: Simple charts yield consistent reconstructions (low RPE), while complex charts result in divergent outcomes (high RPE). We retain only samples with **RPE β‰₯ 0.4**.

### Training Pipeline

<div align="center">
  <img src="https://raw.githubusercontent.com/chartverse/chartverse.github.io/main/static/images/pipeline.png" width="100%" alt="ChartVerse Pipeline">
</div>

**Stage 1: Difficulty-Filtered Cold Start**
- Aggregate charts from existing datasets and filter by RPE β‰₯ 0.4
- Use Claude-4-Sonnet to infer source code for high-complexity charts
- Curate **60K** high-quality seed samples

**Stage 2: Iterative Self-Enhancement**
- Generate 2M raw candidates via high-temperature sampling
- Apply tri-fold filtering:
  - βœ… Valid Execution
  - βœ… High Complexity (RPE β‰₯ 0.4)
  - βœ… Low Similarity to existing data (Cosine Sim ≀ 0.65)
- Retrain coder on expanded dataset
- Repeat for 2 iterations

**Final Output**: Generate **1M** high-complexity chart code samples for downstream QA synthesis.

## πŸ‹οΈ Training Details

- **Base Model**: Qwen2.5-Coder-7B-Instruct
- **Cold Start Data**: 60K high-complexity samples
- **Boost Data**: 200K iteratively filtered samples
- **Training**: Full-parameter fine-tuning with LLaMA-Factory
- **Learning Rate**: 2.0 Γ— 10⁻⁡
- **Batch Size**: 16
- **Context Length**: 4,096 tokens
- **Epochs**: 5
- **Precision**: BF16
  
## πŸ“Š Synthesized Data Quality

### Comparison with Existing Datasets

<div align="center">
  <img src="https://raw.githubusercontent.com/chartverse/chartverse.github.io/main/static/images/chart_cmp.png" width="100%" alt="Dataset Comparison">
</div>

ChartVerse-Coder synthesizes charts with significantly higher complexity and diversity than all existing datasets.

### Synthesized Chart Examples

<div align="center">
  <img src="https://raw.githubusercontent.com/starriver030515/chartverse/main/assets/complex_images.png" width="100%" alt="Complex Chart Examples">
</div>

Our synthesized charts demonstrate exceptional diversity:
- **3D Visualizations**: Surface plots, 3D bar charts, scatter plots
- **Hierarchical Structures**: Treemaps, sunburst charts, dendrograms
- **Statistical Plots**: Violin plots, radar charts, box plots with annotations
- **Multi-Subplot Layouts**: Complex dashboards with mixed chart types
- **Specialized Charts**: Sankey diagrams, chord diagrams, heatmaps with clustering

## πŸš€ Quick Start

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load Model
model_path = "opendatalab/ChartVerse-Coder"
model = AutoModelForCausalLM.from_pretrained(
    model_path, torch_dtype="auto", device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_path)

# System Prompt
prompt = """You are a Python visualization expert. Generate a random Python visualization code focusing on charts, tables, or diagrams.

Requirements:
- Choose any visualization type (chart, table, flowchart, diagram, etc.)
- Create sample data
- Use Python visualization library (matplotlib, graphviz, etc.)
- Make it visually appealing with proper labels, titles, and colors
- Include sufficient visual elements
- Carefully design the layout to avoid any overlapping text or elements
- Adjust figure size, margins, and spacing for optimal clarity
- Make it visually appealing with proper labels, titles, and colors

Output format: Only output the Python visualization code wrapped in ```python```
"""

# Generate Chart Code
messages = [
    {"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to("cuda")

# High-temperature sampling for diversity
outputs = model.generate(
    **inputs,
    max_new_tokens=4096,
    temperature=1.0,
    top_p=0.95,
    top_k=20,
    do_sample=True
)

generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_code)
```

### Execute Generated Code

```python
import re
import matplotlib.pyplot as plt

# Extract code from response
code_match = re.search(r'```python\n(.*?)```', generated_code, re.DOTALL)
if code_match:
    code = code_match.group(1)
    exec(code)  # This will save the figure as 'image.png'
```

## πŸ“– Citation

```bibtex
@misc{liu2026chartversescalingchartreasoning,
      title={ChartVerse: Scaling Chart Reasoning via Reliable Programmatic Synthesis from Scratch}, 
      author={Zheng Liu and Honglin Lin and Chonghan Qin and Xiaoyang Wang and Xin Gao and Yu Li and Mengzhang Cai and Yun Zhu and Zhanping Zhong and Qizhi Pei and Zhuoshi Pan and Xiaoran Shang and Bin Cui and Conghui He and Wentao Zhang and Lijun Wu},
      year={2026},
      eprint={2601.13606},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2601.13606}, 
}
```

## πŸ“„ License

This model is released under the Apache 2.0 License.

## πŸ™ Acknowledgements

- Base model: [Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct)
- Training framework: [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory)
- Code inference: Claude-4-Sonnet for cold start data generation