L a T e X 2 S olver: a Hierarchical Semantic Parsing of L a T e X Document into Code for an Assistive Optimization Modeling Application (2023)

Abstract: We demonstrate an interactive system to help operations research (OR) practitioners convert the mathematical formulation of optimization problems from TeX document format into the solver modeling language. In practice, a manual translation is cumbersome and time-consuming. Moreover, it requires an in-depth understanding of the problem description and a technical expertise to produce the modeling code. Thus, our proposed system TeX2Solver helps partially automate this conversion and help the users build optimization models more efficiently. In this paper, we describe its interface and the components of the hierarchical parsing system. A video demo walk-through is available online at http://bit.ly/3kuOm3x

## introduction operations research (or) is a useful yet complex framework for optimal decision-making. for instance, or has been used to increase bike-share ridership and efficiency @xcite , or to optimize wastewater collection and treatment @xcite in cities. despite its importance in many fields, the or process is both timeconsuming and knowledge-intensive. first, the problem specifications provided by domain experts must be formulated in mathematical form @xcite . then, the formulation needs to be converted into a model code that optimization solvers can interpret. next, data parameters must be collected and used to instantiate the optimization model. finally, a proper solver needs to be selected to solve the given problem and find an optimal solution. traditionally, the domain expert hires an or expert to handle these strenuous tasks and build the right model for the problem of interest. there are two shortcomings in the above process, which increases the project cost and duration. 1. first, the formulation needs to be written twice. or experts typically write the problem formulation as a latex document containing both natural language (nl) descriptions and math formulas. then, they translate it into code using a solver-specific modeling language. this manual work creates a bottleneck and a mental overhead for the or experts. to address these shortcomings, we introduce la-texsolver, an interactive system that takes as input the problem description of a model in latex and partially automates its translation into modeling code. to the best of our knowledge, this is the first modeling tool that accepts an unstructured and multi-modal latex document as input format. moreover, we introduce a unified symbolic model representation, which decouples the translation procedure into two stages. first, our system combines information extraction methods (i.e., text segmentation, entity recognition, relation extraction) with grammar-based parsing to extract the symbolic model. in the second stage, our system uses the actual data parameters to instantiate the symbolic model and generate the modeling code. finally, our intuitive user interface displays the symbolic model as a graph of the model elements as shown in figure 1 . each node shows the formula and metadata of an element and allows the user to review and edit it before it is turned into modeling code. this added flexibility puts the user in control. past efforts to improve the experience of model builders has centered around creating better modeling languages. while they can enable rapid prototyping @xcite , the modeler still needs to learn these languages and manually convert the mathematical formulation into an equivalent code. to alleviate the technical barriers and make solvers more accessible, alternative input formats have also been proposed such as excel spreadsheets @xcite , web forms @xcite , and natural language (ibm, 2022). in comparison, our system is the first to accept a multi-modal markup document that contains natural language descriptions as well as mathematical equations. ## system overview figure 1 showcases the graphical user interface of our latexsolver web application built using the vue frontend framework @xcite . this interface enables users to upload an optimization problem description in latex, composed of both natural language and mathematical formulas. after going through the parsing process, the input latex document will be transformed into a symbolic model that serves as a united representation of the input optimization problem. as an example shown in the main panel of figure 1 , a symbolic model comprises model elements extracted from the document and each element is categorized as one of {set, parameter, objective, variable, constraint, objective} (listed on top of the interface). all parameters and variables in the symbolic model are represented by symbols rather than actual values. our user interface is designed to display the extracted symbolic model as a graph, in which each node contains the formula and metadata of a model element and dynamic links are used to highlight the relationships between symbolic elements. to enhance user engagement and system flexibility, we allow users to review and edit the displayed model elements. users can click on each model element card to reveal its detailed properties in the right-side panel of the interface, where they can edit the properties as desired. furthermore, users have the ability to add or delete elements as needed. once the user is satisfied with the updated symbolic model, our system will guide the user to upload data values to instantiate the symbolic model and generate the corresponding model code instance for the optimization solver to compute for solutions. the backend workflow of latexsolver is illustrated in figure 2 . the system's pipeline consists of three major stages, namely hierarchical declaration extraction, symbolic model parsing and model code generation. given a problem description in latex as input, the system first segments it into a set of declarations, each of which describes a specific model element and includes declaration entities linked by corresponding relations. this stage employs three neural models that were initially introduced for three nlp tasks: text segmentation and labeling, entity recognition, and relation extraction respectively. in the subsequent stage, the extracted declarations are transformed into a symbolic optimization model using a context-free grammar-based parser, which leverages the metadata obtained in the previous stage as supplementary information. the resulting symbolic model is then passed into a solver api-specified model code instance generator, together with user-specified data values, to generate the model code that is ready to be processed by optimization solvers. ## hierarchical declaration extraction a declaration in this paper is, by definition, a multimodal segment consisting of one or more sentences written in a mixture of text and math content, as exemplified in figure 3 . each declaration typically describes one particular model element, such as an objective, constraint, decision variable, parameter or set. as the first stage of latexsolver, the system takes a latex document as input and extracts declarations from it in a hierarchical manner. specifically, the system first performs documentlevel declaration identification to extract and label all the text segments in the document, each associated with one declaration ( §4.1). next, our system performs entity recognition and entity linking within each extracted declaration segment ( §4.2). ## symbolic model parsing and model code generation this section describes the process of converting the detected entities and their relations into a symbolic model which is eventually generated into modeling code, as shown in figure 6 . the symbolic model and concrete data values, such as sets and parameter values, are passed to the model instance code generator which converts them into code based on the target modeling language or solver api. the generated code consists of the model components and their corresponding data values. by decoupling the symbolic model and data values, we allow the users to evaluate their model and problem more efficiently. they can modify the model to evaluate variants of the model or easily change data values to examine different scenarios of the problem. ## limitations and future works the latexsolver system is a useful tool that partially automates the conversion of a problem description into an optimization model, but some limitations highlight potential areas for improvement. first, it was assumed that each declaration contains all complete information that needs to be parsed into a model element. while our proposed system can handle unstructured text at the declaration-level, it is a more challenging problem if information about one model component is scattered across declarations. we believe that in most cases, the input documents would satisfy this assumption. second, this system requires the latex document input to be accurate and errors may cause issues that cascade through the steps of the system (e.g., an error in segmenting and labeling the declarations may yield errors in the entity recognition and relation extraction tasks). the interactive application addresses this by keeping the human in the loop allowing the user to interact with the detected components and their relations. finally, with the rapid advancements in llms @xcite , domain-specific tools such as la-texsolver could be used in conjunction with general-purpose language models. ## conclusion in this paper, we introduce latexsolver, an interactive system to help operations research practitioners efficiently convert the mathematical formulation of optimization problems from the unstructured and multi-modal latex document format into the solver modeling language. the system follows a two-step process of converting the la-tex document to a symbolic model and then to model code. users can easily review and edit the symbolic model automatically extracted from the latex document with an intuitive interface to ensure the system's reliability.