Abstract
This study presents a comprehensive empirical investigation into the use of Large Language Models (LLMs) for automating the "Natural Language to Visualization" (NL2Vis) task. By evaluating models on the nvBench benchmark, the researchers demonstrate that LLMs significantly outperform traditional deep-learning baselines, particularly in cross-domain scenarios involving unseen databases. The study identifies that representing structured tables as code (e.g., Python or SQL) is the most effective prompting strategy and that iterative optimization techniques like self-repair further enhance performance.
Introduction
Data visualization is a critical component of data analysis, yet creating effective charts often requires specialized skills. The "Natural Language to Visualization" (NL2Vis) task aims to democratize data insights by allowing users to generate visualizations through plain English queries. However, existing deep-learning approaches struggle with generalization to new domains and the complex mapping between natural language and structured data.
This paper investigates whether LLMs can overcome these hurdles through prompt engineering and in-context learning, focusing on three primary research questions: how to effectively feed data into LLMs (RQ1), how LLMs compare to existing models (RQ2), and whether results can be optimized iteratively (RQ3).
Methods
The researchers utilized nvBench, a large-scale benchmark containing approximately 25,750 NL-visualization pairs across 153 databases. The evaluation focused on both in-domain (seen databases) and cross-domain (unseen databases) performance to test the models' ability to generalize.
Prompt Engineering Strategies
To address RQ1, the study compared various methods for serializing tabular data into prompts. The goal was to find the most efficient way for an LLM to understand a table's schema and content.
Strategies tested included:
- Table Serialization/Summarization: Flattening schemas or using natural language descriptions.
- Table Markup: Using structured formats like JSON, XML, or Markdown.
- Table Programming: Representing tables as SQL
CREATEstatements or Python classes (Table2Code).
Optimization Techniques
For RQ3, the authors explored advanced prompting techniques including Chain-of-Thought (CoT), role-playing (e.g., "acting as a visualization expert"), and self-repair mechanisms where the model is asked to fix its own erroneous outputs.
Key Results and Insights
The empirical study yielded several significant findings:
- Superiority of LLMs: LLMs achieved a 26% improvement in exact accuracy for cross-domain settings compared to previous state-of-the-art models. GPT-4 emerged as the top performer, showing robust few-shot learning capabilities.
- Code as the Optimal Representation: Representing tables as Python code (Table2Code) or SQL schemas was more effective than natural language summaries. This suggests that LLMs leverage their extensive pre-training on code to better understand structural data relationships.
- Schema over Content: The structure of the table (columns and types) is more critical for NL2Vis than the actual row values. Including excessive data often consumes token limits without providing proportional accuracy gains.
- Effective Error Recovery: Self-repair strategies provided a 13.3% accuracy boost, while using GPT-4’s Code-interpreter reached over 50% execution accuracy on previously failed cases.
Discussion and Limitations
While LLMs show great promise, the study notes that benchmarks like nvBench use relatively clean data. Real-world "messy" data remains a challenge. Additionally, the current focus on Visualization Query Language (VQL) as an intermediate step could be expanded to direct generation of more aesthetic specifications like Vega-Lite to capture finer details like color and font.
Conclusion
This exploratory study confirms that LLMs are a powerful tool for NL2Vis, offering superior generalization over specialized deep-learning models. The shift towards "Table Programming" as a prompting paradigm and the success of iterative refinement suggest a future where conversational, automated data visualization is highly accessible to non-experts.
Summary updated