TL;DR
SpreadsheetCoder is a BERT-based model designed to predict spreadsheet formulas by treating the spreadsheet as a semi-structured table rather than a collection of independent rows. By leveraging both tabular data and natural language headers, it achieves a 42.51% top-1 prediction accuracy, significantly outperforming prior "Programming-by-Example" methods and assisting 82% more users in production environments like Google Sheets.
What Problem Does This Paper Address?
Most of us have used features like FlashFill, which uses "Programming-by-Example" (PBE) to guess what you're trying to do based on a few input-output pairs. While powerful, PBE has three major blind spots:
- Row Independence: It assumes each row is an island. In reality, formulas often aggregate data across multiple rows (e.g., a "Total" row) or columns.
- Ignoring Metadata: Spreadsheets are full of rich natural language clues in the form of headers (e.g., "Tax Rate," "Total Price"), which PBE systems typically ignore.
- Rigid Languages: Prior systems often used limited Domain-Specific Languages (DSLs) that couldn't handle the full complexity of real-world spreadsheet functions like
VLOOKUPor rectangular ranges.
The authors tackle the challenge of predicting formulas from semi-structured context, where the "specification" for the formula is implicitly hidden in the surrounding data and headers.
Methods
The authors propose SPREADSHEETCODER, an architecture that treats formula prediction as a translation task from a 2D table to a code string.
- Tabular Context Encoder: Since standard BERT models take linear text, the authors "tile" the spreadsheet. They group rows into bundles (e.g., 3 rows + the header row) and pass them through a BERT encoder. They do this for both rows and columns to capture the 2D relational structure.
- Convolutional Layers: To help the model see beyond the immediate neighborhood of a cell, they add row-wise and column-wise convolution layers on top of the BERT embeddings. This allows the model to aggregate information from more distant parts of the table.
- Two-Stage Decoding: Instead of predicting the whole formula at once, the model uses an LSTM to first generate a formula sketch (the functions and literals, like
SUM(RANGE)) and then predicts the specific cell ranges (likeA1:A10). This "sketch-then-fill" approach makes the learning process much more manageable.
Datasets
The researchers evaluated their model on two primary sources:
- Google Sheets Corpus: A massive, internal dataset of 46,000 publicly shared Google Sheets, resulting in 770,000 training samples. This dataset covers over 100 different spreadsheet operators.
- Enron Corpus: A well-known public dataset of over 17,000 Excel spreadsheets. This served as a benchmark to see how well the model generalizes to different spreadsheet styles and formats.
Key Insights and Ideas
- Headers are High-Signal: One of the most significant findings was that including table headers drastically improves performance. Natural language headers provide semantic context that raw numbers simply cannot.
- 2D Context Matters: Modeling the dependencies between different rows and columns (the "tabular" approach) is far superior to treating rows as independent samples. The model learns that a cell labeled "Total" likely needs a
SUMfunction. - Pre-training is a "Free" Win: Initializing the encoder with BERT weights pre-trained on English text helped the model understand headers better, even though spreadsheet data is very different from standard prose.
- Relative vs. Absolute: The model represents cell references relatively (e.g., "the cell 2 rows up") rather than absolutely (e.g., "B2"). This allows the model to learn patterns that generalize across different sheets regardless of where the table is positioned.
Key Results
- Accuracy: On the Google Sheets dataset, SPREADSHEETCODER achieved 42.51% top-1 accuracy for the full formula. For the formula sketch alone, accuracy jumped to 57.41%.
- Baselines: It crushed the "RobustFill" baseline (a state-of-the-art PBE model), which only managed about 31% accuracy.
- Real-World Impact: When deployed in a pilot for Google Sheets, the model assisted 82% more users in composing formulas compared to the previous rule-based system.
- Generalization: Even on the messy Enron dataset, the model maintained a respectable 29.8% top-1 accuracy, proving it isn't just memorizing Google-specific patterns.
Limitations and Future Work
While a major step forward, SPREADSHEETCODER has some constraints:
- Local Scope: The current model only looks at a "local" neighborhood of 10 rows and 10 columns. It cannot yet predict formulas that reference data in other tabs or entirely different files.
- Formatting Ignored: The model doesn't yet use visual cues like cell colors, borders, or font styles, which often signal table boundaries to human users.
- Computational Cost: Using BERT for every formula prediction is computationally expensive. The authors suggest that improving efficiency to support larger context windows is a key area for future research.
- Ambiguity: In some cases, the tabular context is still too ambiguous to yield a single "correct" formula, suggesting a need for better ways to incorporate user intent.
Summary updated