Text2Chart31: Instruction Tuning for Chart Generation with Automatic Feedback

Fatemeh Pesaran Zadeh, Juyeon Kim, Jin-Hwa Kim, Gunhee Kim

Introduction

While Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, their ability to visualize complex, real-world data remains a significant challenge. Existing models often struggle with the intricate relationships between natural language descriptions, underlying data tables, and the specific Python code required for high-quality rendering. Researchers have introduced Text2Chart31, a novel dataset and reinforcement learning (RL) framework designed to bridge this gap. By utilizing a hierarchical data generation pipeline and automated feedback loops, this approach enables smaller open-source models to outperform industry giants like GPT-4 and Claude 3 in generating complex 3D, volumetric, and gridded charts.

Addressing the Visualization Gap

The authors identify two primary obstacles in current chart generation research:

  1. Dataset Scarcity: Most existing chart datasets, such as PlotQA or ChartQA, are designed for Question Answering (QA) rather than generation. Furthermore, they are heavily skewed toward simple bar, line, and pie charts, rarely covering advanced visualizations like 3D surfaces, vector fields, or irregularly gridded plots.
  2. Training Limitations: Standard Supervised Fine-Tuning (SFT) often fails to capture the logical alignment needed to translate a user's descriptive intent into functional visualization code.

Methodology: Hierarchical Pipeline and RL Feedback

To address these challenges, the researchers developed a two-pronged solution: a sophisticated data generation pipeline and an RL-based tuning strategy.

Hierarchical Data Generation

To build a high-quality dataset without prohibitive human labor, the authors implemented a "chain" of LLM calls. This process begins with generating diverse topics and pairing them with detailed plot descriptions. GPT-4 is then used to write Matplotlib code and synthesize corresponding data tables. A critical component of this pipeline is Cycle-Consistency Verification, an automated sanity check where a model generates a description from the code, and an AI compares it to the original description to ensure logical consistency.

The hierarchical data generation pipeline for Text2Chart31, featuring cycle-consistency and self-evaluation.

RL via Automatic Feedback

Instead of relying on expensive Reinforcement Learning from Human Feedback (RLHF), the framework utilizes two automated reward functions:

  • Preference Reward: The model is rewarded for producing code that is closer to the ground-truth "gold standard" than its previous iterations.
  • Alignment Reward: This leverages cycle consistency. If a description generated back from the model's code matches the original user prompt, the model receives a high reward, reinforcing the link between text and visual output.

The Text2Chart31 Dataset

The resulting dataset, Text2Chart31, contains 11.1K tuples consisting of descriptions, code, data tables, and plots. It covers 31 unique plot types categorized into five groups: Pairwise, Statistical, Gridded, Irregularly Gridded, and 3D/Volumetric. Unlike previous datasets, Text2Chart31 provides a balanced distribution of complex visualization types, specifically targeting "underexplored" plots where general-purpose LLMs typically have the highest failure rates.

Experimental Results

The researchers evaluated their models on three tasks: Description-to-Chart, Raw Data-to-Chart, and Code-to-Description. The results demonstrate that fine-tuned open-source models can achieve state-of-the-art performance.

Performance comparison of various models across different plot categories, showing error ratios and code similarity metrics.

Key findings include:

  • Superior Accuracy: The fine-tuned CLI-13B (Code Llama) model achieved a total error rate of 9.21%, significantly lower than GPT-4-turbo (14.27%) and Claude 3 Opus (14.90%).
  • 3D & Volumetric Mastery: In the most challenging categories, the RL-tuned Llama-3-8B reduced error rates from 34.59% (baseline) to 26.42%, outperforming GPT-4-0613.
  • Human Preference: In head-to-head comparisons, human judges preferred charts from Text2Chart31-tuned models over GPT-3.5-turbo in approximately 43-47% of cases, with many remaining cases resulting in ties.

Conclusion and Future Work

Text2Chart31 demonstrates that specialized instruction tuning and automated feedback can significantly enhance the visualization capabilities of LLMs. While the current work is limited to static Matplotlib 3.8 plots in English, it paves the way for future expansions into interactive libraries like Plotly or D3.js and broader linguistic support. The success of the cycle-consistency reward suggests that self-correcting signals are a powerful tool for aligning LLMs with complex technical tasks.

Summary updated

BibTeX
@inproceedings{zadeh2024text,
  author = {Fatemeh Pesaran Zadeh and Juyeon Kim and Jin-Hwa Kim and Gunhee Kim},
  title = {{Text2Chart31: Instruction Tuning for Chart Generation with Automatic Feedback}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.640},
}
Figure