Bridging the Semantic Gap Between Text and Table: A Case Study on NL2SQL

Lin Long, Xijun Gu, Xinjie Sun, Wentao Ye, Haobo Wang, Sai Wu, Gang Chen, Junbo Zhao

TL;DR

Large Language Models (LLMs) struggle to understand tabular data because the 2D structure of a table doesn't translate well into 1D sequential text. To address this, researchers introduce TNT (Text and Table), a framework that treats tables as a distinct modality. By compressing table columns into rich, structure-aware embeddings rather than just pasting raw text into a prompt, TNT drastically improves the LLM's structural understanding. This approach boosts execution accuracy on Natural Language to SQL (NL2SQL) tasks by up to 14.4% when dealing with ambiguous or anonymized table schemas.

What Problem Does This Paper Address?

If you want an LLM to query a database or answer questions about a spreadsheet, the standard approach is to serialize the table into text (like Markdown or JSON) and stuff it into the prompt. However, this naive text-based representation has three major flaws:

  1. Structural Incompatibility: Tables are 2D grids, while LLMs read 1D sequential text. Serializing a table destroys the implicit row-column relationships.
  2. Redundancy: Dumping hundreds of rows into a prompt eats up the context window and slows down processing.
  3. Bias Toward Metadata: LLMs often "cheat" by relying heavily on column names rather than understanding the actual data. If a real-world table has uncurated, ambiguous, or missing column names (e.g., a column named "Col_1" or "A2"), the LLM's performance plummets because it cannot infer the column's meaning from the data itself.

The authors ask a critical question: How can we give LLMs a genuine, structure-aware understanding of tabular data without drowning them in tokens?

Methods: The TNT Architecture

To solve this, the authors propose TNT, a multimodal framework that treats tabular data similarly to how Vision-Language Models (VLMs) treat images. Instead of forcing the LLM to read raw table text, TNT uses a specialized architecture to "look" at the table and pass high-level summaries to the LLM.

TNT Architecture: A multimodal framework integrating a Table Encoder, Adaptor, and LLM via a hybrid prompt.

The architecture consists of three main components:

  1. Table Encoder: First, a lightweight sentence transformer converts every cell's text into a "cell token." Then, a bi-dimensional attention mechanism processes these tokens—attending first across rows, then across columns. This captures the 2D structure without using positional embeddings, ensuring the model doesn't get confused if rows or columns are shuffled.
  2. Table-Language Adaptor: To save tokens, an adaptor uses cross-attention to aggregate the hundreds of cell embeddings into a few fixed-length column embeddings.
  3. Dynamic Context Integration: During inference, the LLM receives a "hybrid prompt." It gets the text-based schema (column names, data types) but with the rich, compressed column embeddings dynamically inserted into the prompt.

Training Pipeline

TNT is trained in three distinct stages:

  • Column-wise Contrastive Learning: The encoder learns general table structures by looking at two random row samples (snapshots) of the same table. It is trained to make the embeddings of the same column across different snapshots similar, while pushing embeddings of different columns apart.
  • Multi-task Feature Alignment: The encoder and adaptor are trained alongside a frozen LLM on synthetic tasks (like predicting which cell belongs to which column) to align the table embeddings with the LLM's text space.
  • Instruction Tuning: The LLM and adaptor are fine-tuned on specific downstream tasks, like NL2SQL.

Key Insights and Ideas

  • Tables are a Modality: Just as an image patch embedding tells an LLM about visual features, a column embedding can tell an LLM about data distributions and row-column relationships far better than serialized text.
  • Column-Level Abstraction is the Sweet Spot: Compressing data at the column level provides the perfect balance of expressive efficiency. It abstracts away the noise of thousands of individual cells while retaining the core semantic meaning of the dataset.
  • Contrastive Learning Unlocks Data Understanding: By forcing the model to match columns based on different random samples of rows, the Table Encoder learns to identify the underlying distributional signature of a column, rather than memorizing specific cell values.

Key Results

To prove TNT actually understands data and doesn't just read column names, the authors created non-semantic versions of the SPIDER datasets where 80% of the column names are anonymized (e.g., renamed to "A1", "A2").

Performance comparison on semantic vs. non-semantic datasets, showing TNT's robustness to ambiguous column names.
  • Massive Gains on Ambiguous Data: On the non-semantic (anonymized) SPIDER datasets, TNT dominated standard fine-tuned LLMs, achieving up to 16.5% higher Exact Match (EM) and 14.4% higher Execution Accuracy (EX). As shown in the figure above, standard fine-tuning suffers a massive 70.0% performance drop when semantics are removed, whereas TNT only drops by 48.7%, proving it can infer column meaning from data shape and distribution.
  • Strong General Performance: On standard SPIDER benchmarks (where column names are helpful), TNT still consistently outperformed baselines (e.g., hitting 79.0% EX on SPIDER-Test with Llama3-8B, compared to 77.8% for the standard fine-tuned version).
  • Punches Above Its Weight: When combined with standard prompting tricks (like Code Correction), TNT based on an 8-billion parameter model (Llama3-8B) achieved 84.3% EX on Spider-test, approaching the performance of heavy-weight, closed-source models like GPT-4.

Limitations and Future Work

  • Compute Constraints: The experiments were limited to ~7B/8B parameter open-source LLMs. Scaling this up to larger models could yield even better results.
  • Complex Table Structures: The current architecture focuses on standard relational tables. Future work will need to address more complex, hierarchical tables (e.g., tables with merged cells or multi-level headers).
  • Broader Tasks: While the paper focuses heavily on NL2SQL as a case study, the authors suggest extending and evaluating this multimodal approach on a wider variety of structured data tasks, such as NL2Code or general data analysis agents.

Summary updated

BibTeX
@inproceedings{long2025bridging,
  author = {Lin Long and Xijun Gu and Xinjie Sun and Wentao Ye and Haobo Wang and Sai Wu and Gang Chen and Junbo Zhao},
  title = {{Bridging the Semantic Gap Between Text and Table: A Case Study on NL2SQL}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=qmsX2R19p9},
}
Figure