Encoding Spreadsheets for Large Language Models (2024)

Abstract: Spreadsheets are characterized by their extensive two-dimensional grids, flexible layouts, and varied formatting options, which pose significant challenges for large language models (LLMs). In response, we introduce SheetEncoder, pioneering an efficient encoding method designed to unleash and optimize LLMs’ powerful understanding and reasoning capability on spreadsheets. Initially, we propose a vanilla serialization approach that incorporates cell addresses, values, and formats. However, this approach was limited by LLMs’ token constraints, making it impractical for most applications. To tackle this challenge, three innovative modules are proposed to compress spreadsheets effectively: structural-anchor-based compression, inverse index translation, and data-format-aware aggregation. It significantly improves performance in spreadsheet table detection task, outperforming the vanilla approach by 25.6% in GPT4’s in-context learning setting. Moreover, fine-tuned LLM with SheetEncoder has an average compression ratio of 25×, but achieves a state-of-the-art 78.9% F1 score, surpassing the best existing models by 12.3%, demonstrating that SheetEncoder greatly boosts LLMs’s performance on spreadsheet data.

## introduction spreadsheets are ubiquitous for data management and extensively utilized within platforms like microsoft excel and google sheets. understanding spreadsheet layout and structure @xcite @xcite @xcite @xcite , a longstanding challenge for traditional models and is crucial for effective data analysis, data manipulation, and various real-world applications involving intelligent user interaction with spreadsheet data. recently, the rapid development of large language models (llms) has opened new frontiers in table processing @xcite and reasoning @xcite . however, spreadsheets pose unique challenges for llms due to their expansive grids that usually exceed the token limitations of popular llms, as well as their inherent two-dimensional layouts and structures, which are poorly suited to linear and sequential input. furthermore, llms often struggle with spreadsheet-specific features such as cell addresses and formats, complicating their ability to effectively parse and utilize spreadsheet data, as detailed in appendix a. in this paper, we introduce sheetencoder for llms, a pioneering encoding framework to unleash and maximize the potential of llms for spreadsheet understanding and reasoning. we initially propose a vanilla encoding method to serialize spreadsheets into sequences, augmenting the markdown encoding method by including essential cell addresses and (optional) formats. furthermore, large spreadsheets that exceed the token limits of llms not only limit their processing but also, as observed in prior studies, degrade accuracy performance as the size increases @xcite . to address this challenge, we equip sheetencoder with three portable modules to compress spreadsheet, including: we conducted a comprehensive evaluation of our method on a variety of llms. our experiments show that sheetencoder significantly reduces token usage for spreadsheet encoding by 96%. moreover, sheetencoder has shown exceptional performance in spreadsheet table detection, the foundational task of spreadsheet understanding, surpassing tablesense-cnn by 12.3% @xcite . we also applied sheetencoder to a representative spreadsheet qa task. inspired by the chain of thought (cot) methodology @xcite , we propose chain of spreadsheet encoding (cos) to decompose spreadsheet reasoning into a table detectionmatch-reasoning pipeline. it significantly outperformed existing sota methods for table qa @xcite . our primary contributions are summarized as follows: spreadsheet downstream tasks spreadsheet understanding is enabling for a series of spreadsheet tasks for real world applications, such as table question answering analysis @xcite @xcite @xcite , table extraction @xcite @xcite , formula or code generation @xcite @xcite @xcite , error detection @xcite , etc. in this paper, we choose spreadsheet qa, one of the most demanded spreadsheet analysis tasks. it is an extension of the table qa task in spreadsheet data, with the additional complexity of detecting and matching multiple tables within a spreadsheet. llms' token efficiency related work suggests that the performance of llms degrades significantly with long contexts @xcite . efforts to improve model performance and reduce costs have led to the development of compression techniques for long prompts. some researchers employ information-theory metrics to filter out redundant information @xcite . additionally, specialized models have been proposed to optimize prompt compression @xcite . however, these strategies primarily address natural language prompts and may not suit tabular data, potentially leading to considerable structure and data information loss. dbcopilot @xcite ) enables text-to-sql conversion on large databases through schema routing. however, due to llms' insufficient ability in understanding inherent multi-table layouts and complex table structures that cannot execute queries similar to sql, schema routing is impractical, restricting the broader application of cuttingedge tabular works @xcite @xcite ) on spreadsheet data. ## method we propose a novel spreadsheet encoding framework in a markdown-like style as text. to achieve a more compact and efficient representation, we introduce three independent yet combinable mod-ules: structural-anchor-based extraction, invertedindex translation, and data-format-aware aggregation, which enable efficient data compression and enhance performance on downstream tasks. ## conclusion in this paper, we proposed the sheetencoder, a novel framework representing a significant advancement in the processing and understanding of spreadsheet data by leveraging the capabilities of llms. through a novel efficient encoding method, this framework effectively addresses the challenges posed by the size, diversity, and complexity inherent in spreadsheets. it achieves a substantial reduction in token usage and computational costs, enabling practical applications on large datasets. the fine-tuning of various cutting-edge llms further enhances the performance of spreadsheet understanding. moreover, chain of spreadsheet encoding, the framework's extension to spreadsheet downstream tasks illustrates its broad applicability and potential to bridge spreadsheet data management and analysis with table-based techniques, paving the way for more intelligent and efficient user interactions.