Auto-Formula: Recommend Formulas in Spreadsheets using Contrastive Learning for Table Representations

Sibei Chen, Yeye He, Weiwei Cui, Ju Fan, Song Ge, Haidong Zhang, Dongmei Zhang, Surajit Chaudhuri · DOI · OpenReview

Abstract

Spreadsheet formula authoring remains a significant barrier for non-programmers. While existing recommendation systems rely on natural language context, they often fail with complex logic or missing headers. This paper introduces Auto-Formula, a system that treats spreadsheet structures as images and employs contrastive learning to identify similar sheets within an organization. By retrieving and adapting existing logic from reference sheets, Auto-Formula achieves over 90% precision, significantly outperforming state-of-the-art large language models like GPT-4 in spreadsheet-specific tasks.

The Spreadsheet Authoring Challenge

Billions of people use spreadsheets daily, yet authoring complex, multi-parameter formulas remains a major "pain point." Most users struggle with syntax and nested functions. Current solutions, such as Google’s SpreadsheetCoder, rely heavily on natural language cues—like identifying a "Total" header to suggest a SUM formula. However, this approach is fragile; it fails when headers are ambiguous, missing, or when the underlying logic is non-trivial.

A target cell in a spreadsheet requiring a formula, illustrating the typical user challenge.

The authors observe that in enterprise environments, users rarely start from scratch. Organizations often possess a wealth of "similar-looking" spreadsheets—such as monthly reports or budget trackers—that share identical computational logic despite having different data. The core challenge lies in automatically identifying these "needle-in-a-haystack" reference sheets and adapting their formulas to a new context.

Auto-Formula: A Visual Approach to Logic

The central innovation of Auto-Formula is treating a spreadsheet as an image where cells function as pixels. This allows the system to leverage visual layout features—colors, fonts, borders, and relative positions—which are often more reliable indicators of logic than text alone.

The system operates through a three-step online pipeline:

  1. (S1) Search reference sheets: Finding sheets with similar structural layouts.
  2. (S2) Search reference formulas: Identifying the specific logic used in those sheets.
  3. (S3) Search parameter cells: Pinpointing the exact cell ranges in the new sheet that correspond to the parameters in the reference formula.

The Dual-Model Architecture

To power this pipeline, the researchers developed a dual-model architecture trained via contrastive learning. This technique, popularized by the FaceNet model for face recognition, uses "triplet loss" to ensure that similar sheets are mapped close together in a high-dimensional vector space, while dissimilar ones are pushed apart.

The Auto-Formula pipeline, showing the offline training phase and the three-step online recommendation process.

The architecture consists of two specialized models:

  • Coarse-grained Model ($M_c$): Utilizes Convolutional Neural Networks (CNNs) to create a "fuzzy" representation of a sheet. CNNs are translation-invariant, allowing the system to recognize similarity even if rows or columns have shifted.
  • Fine-grained Model ($M_f$): Employs fully-connected layers to capture precise cell-level boundaries. This model is critical for step S3, ensuring that formula parameters are mapped to the correct ranges in the target sheet.

To train these models without manual labeling, the authors used weak supervision. They analyzed 160,000 public spreadsheets, assuming that files with rare, identical sheet names were likely "similar sheets" containing related logic.

Performance and Benchmarking

Auto-Formula was evaluated against real-world enterprise data from Cisco, PGE, Texas Instruments, and the Enron Corpus. The results demonstrate a significant leap in recommendation quality:

  • High Precision: The system achieved a precision of over 0.9 for its top-1 recommendation. High precision is essential for user trust in AI assistants.
  • Outperforming GPT-4: Even when GPT-4 was augmented with Retrieval-Augmented Generation (RAG) and Chain-of-Thought prompting, Auto-Formula proved more accurate. GPT-4's best F1 score was approximately 0.46, while Auto-Formula reached over 0.70.
  • Scalability: By representing sheets as dense embeddings, the system uses Approximate Nearest Neighbor (ANN) search, maintaining sub-second latency even when searching through 10,000 reference spreadsheets.

Conclusion and Future Directions

Auto-Formula demonstrates that the visual structure of a table is a powerful signal for computational logic. While the system currently relies on the existence of "similar sheets" (the singleton problem), it sets a new standard for spreadsheet assistance. Future work may involve incorporating formula validation steps to filter out logically impossible suggestions and extending the "similar-sheet" primitive to tasks like automated data cleaning and error detection.

Summary updated

BibTeX
@article{chen2024auto,
  author = {Sibei Chen and Yeye He and Weiwei Cui and Ju Fan and Song Ge and Haidong Zhang and Dongmei Zhang and Surajit Chaudhuri},
  title = {{Auto-Formula: Recommend Formulas in Spreadsheets using Contrastive Learning for Table Representations}},
  journal = {Proc. ACM Manag. Data},
  year = {2024},
  doi = {10.1145/3654925},
}
Figure