TL;DR
This research provides a systematic evaluation of Large Language Models (LLMs) on "Natural Language to Visualization" (NL2VIS) tasks using the Vega-Lite grammar. By testing six open-source models across eight prompting strategies, the study reveals that more complex reasoning doesn't necessarily improve performance and that seemingly simple chart types, like pie charts, present significant challenges for current models.
Introduction
Creating effective data visualizations typically requires specialized knowledge of design principles and tools like Matplotlib or the Vega-Lite JSON grammar. While automation has progressed from rule-based systems to deep learning, traditional models often struggle to generalize across diverse datasets. LLMs offer a flexible alternative, yet most research has focused on Python code generation rather than declarative grammars like Vega-Lite. This paper addresses this gap, investigating which prompting strategies—ranging from simple examples to step-by-step reasoning—best enable LLMs to transform natural language queries into valid, accurate visualizations.
Methodology
The researchers performed a comprehensive evaluation by crossing six representative open-source LLMs with eight distinct prompting strategies.
Models Evaluated: * Qwen2-7B, Llama-3-8B, Mistral-7B, Gemma-7b, GLM-4-9B, and DeepSeek-R1-Distill-Llama-8B.
Prompting Strategies: 1. In-Context Learning: Zero-shot and Few-shot. 2. Chain-of-Thought (CoT): Zero-shot-CoT and Plan-and-Solve (PS-Plus-CoT). 3. Rationale Engineering: Auto-CoT, Self-Refine, and Self-Consistency. 4. Problem Decomposition: Least-to-Most.
Evaluation Metrics: * Vis Accuracy: Correctness of the generated chart type. * Validity: Adherence to Vega-Lite JSON grammar. * Legality: Correct use of data attributes to answer the user's query.
Datasets
The study utilizes nvBench, a benchmark with over 7,247 visualization instances. The authors focused on single-table tasks across common chart types (bar, pie, scatter, stacked bar, line, and grouping scatter) to isolate the models' generation capabilities.
Key Insights
The evaluation revealed several counterintuitive findings that challenge standard assumptions in LLM prompting:
- Reasoning vs. Syntax: While Chain-of-Thought (CoT) is often the gold standard for NLP, Few-shot prompting consistently outperformed it here. The primary bottleneck is not the model's reasoning ability but its lack of deep familiarity with Vega-Lite's specific JSON syntax.
- The Difficulty of "Simple" Charts: Models surprisingly struggled with pie charts compared to more complex types like grouped scatter plots. This is likely due to training data bias; most charts in training sets use x/y axes, leading models to incorrectly apply x/y encodings to pie charts (which require "theta" and "color" encodings).
- Planning Pitfalls: Strategies like Plan-and-Solve often underperformed relative to Zero-shot-CoT. The planning phase frequently introduced redundant or ambiguous constraints that distracted the model during code generation.
Key Results
The results highlight a clear hierarchy in both model performance and strategy effectiveness.
- Top Performers: Qwen2 and Llama3 were the most robust models across all tests.
- Strategy Efficacy: Self-Consistency achieved the highest legality scores (averaging 37.06%) by generating multiple outputs and selecting the most frequent data mapping, though it is computationally intensive.
- Efficiency: Few-shot prompting emerged as the most balanced "bang for buck" strategy, providing high accuracy without the complexity of iterative reasoning.
Limitations and Future Work
The researchers noted that the "ceiling" for performance is currently limited by the benchmark itself, as a re-examination of nvBench revealed numerous errors in ground truth labels and queries. Future research should expand to multi-table queries involving complex SQL joins and explore more flexible grammars like D3.js. Additionally, moving toward multi-round conversational interfaces may help resolve the inherent ambiguities in natural language visualization requests.
Summary updated