Structure-Aware Language Model Pretraining Improves Dense Retrieval on Structured Data

Xinze Li, Zhenghao Liu, Chenyan Xiong, Shi Yu, Yu Gu, Zhiyuan Liu, Ge Yu

Introduction

Dense retrieval has revolutionized information access by mapping queries and documents into a shared high-dimensional embedding space. However, when applied to structured data—such as source code, HTML, or product attribute tables—standard Pretrained Language Models (PLMs) like BERT or T5 often underperform. These models are typically optimized for raw natural language and lack the "structure-awareness" necessary to bridge the gap between a user's informal query and the rigid, formal syntax of structured information.

To address this, the SANTA (Structure Aware DeNse ReTrievAl) framework introduces a specialized pretraining approach designed to help language models understand the underlying logic and semantics of structured data. By aligning structured snippets with natural language descriptions and implementing an entity-focused masking strategy, SANTA achieves state-of-the-art performance in both code and product search.

Methodology

SANTA enhances a base T5 model through two novel structure-aware pretraining tasks:

1. Structured Data Alignment (SDA)

SDA is a contrastive learning task that leverages naturally occurring pairs, such as a code snippet and its docstring, or a product’s technical specifications and its summary. The model is trained to pull the embeddings of matched pairs closer together while pushing unmatched pairs apart. This effectively teaches the model to translate between the "language of structure" and the "language of humans," merging these two distinct modalities into a cohesive embedding space.

2. Masked Entity Prediction (MEP)

Standard pretraining typically masks random words. In contrast, MEP identifies and masks "entities"—critical structural components like variable names, function identifiers, or product attributes (e.g., "Material: Stainless Steel"). By forcing the model to predict these specific anchors from the surrounding context, SANTA learns to prioritize the most informative parts of the structure rather than focusing on boilerplate syntax.

Experimental Results

The researchers evaluated SANTA using large-scale datasets, including CodeSearchNet for programming languages and ESCI for product search.

Performance Benchmarks

  • Code Search: On the CodeSearchNet "Overall" metric, SANTA (utilizing hard negatives) achieved a Mean Reciprocal Rank (MRR) of 75.2, significantly outperforming established baselines like CodeBERT and CodeT5.
  • Product Search: In the ESCI product search task, SANTA achieved an NDCG@100 of 83.15 (Four-Class), surpassing standard T5 and RoBERTa baselines.
  • Zero-Shot Effectiveness: One of the most significant findings was SANTA's zero-shot performance. Without task-specific finetuning, SANTA outperformed several finetuned models, including a 6.8% improvement over CodeT5 on code search tasks.

Key Insights

  • Logic Over Identifiers: Analysis of the model's attention maps revealed that while standard models often fixate on arbitrary variable names, SANTA learns to attend to logical operators (such as if statements or comparison symbols). This suggests the model is learning the functional logic of the code rather than merely memorizing keywords.
  • Mitigating Representation Degeneration: T-SNE visualizations showed that SANTA produces a more uniform and distinguishable embedding distribution. This helps solve the "representation degeneration" problem common in standard PLMs, where embeddings often cluster into a narrow cone, making them less effective for retrieval.
  • Bridging the Modality Gap: The SDA task acts as a critical bridge between structured and unstructured data, which typically reside in different areas of the embedding space. By aligning these modalities, SANTA ensures that natural language queries can accurately locate their structured counterparts.

Conclusion and Future Work

SANTA demonstrates that structure-awareness is a fundamental skill that significantly improves the performance and generalization of dense retrieval models. While the framework currently relies on the availability of alignment signals (like docstrings), its success in zero-shot scenarios highlights its potential for broad application. Future research may explore how these structure-aware embeddings can be utilized in generative tasks, such as automated code generation or summarization, further closing the gap between human intent and structured logic.

Summary updated

BibTeX
@inproceedings{li2023structure,
  author = {Xinze Li and Zhenghao Liu and Chenyan Xiong and Shi Yu and Yu Gu and Zhiyuan Liu and Ge Yu},
  title = {{Structure-Aware Language Model Pretraining Improves Dense Retrieval on Structured Data}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.734},
}
Figure