Integrating question answering and text-to-SQL in Portuguese

Marcos Menon José, Marcelo Archanjo José, Denis Deratani Mauá, Fábio Gagliardi Cozman · DOI

Abstract

Deep learning transformers have significantly advanced natural language question answering (QA). However, different query types require distinct computational strategies. This paper proposes a modular architecture that integrates a Neural Question Answering Reasoner for unstructured text with a Natural Language parser for SQL databases. By implementing this system for the Portuguese language using translated biomedical benchmarks, we demonstrate that a transformer-based classifier can route queries to the appropriate module with over 99% accuracy. This validates a specialized, modular approach to multi-modal QA in non-English contexts.

Introduction

The evolution of transformer-based models has revolutionized how machines interact with human language. Despite these gains, a "one-size-fits-all" model often fails to address the nuances of different data sources. Factual questions (e.g., "What is a fistula?") are best handled by reading comprehension models over unstructured text. Conversely, analytical queries involving counts or aggregations (e.g., "How many patients are under 45?") are more efficiently resolved by querying structured relational databases via SQL.

Furthermore, the landscape of QA research is heavily skewed toward English. For languages like Portuguese, there is a notable deficit in both high-quality datasets and integrated systems capable of handling diverse query types. This research addresses these gaps by developing a unified Portuguese QA architecture that intelligently routes queries to specialized engines.

System Architecture

The core of our proposal is a "router" architecture designed to act as a traffic controller for incoming natural language queries. The system consists of three primary components:

  1. The Classifier: Upon receiving a query, the system employs a classifier based on BERTimbau (a Portuguese pre-trained BERT model). This module determines whether the question requires a factual text-based answer or a database-driven SQL response. In testing, BERTimbau significantly outperformed classical methods like Naive Bayes.
  2. Neural QA Reasoner (Factual Branch): If the query is classified as factual, it enters a retriever-reader pipeline. We utilize the BM25 algorithm to retrieve relevant passages from a Portuguese knowledge base. These passages are then processed by PTT5 (Portuguese T5), which generates a natural language answer.
  3. Text-to-SQL (Relational Branch): If the query is classified as a database task, it is sent to mRAT-SQL (multilingual Relation-Aware Transformer SQL). This module, powered by an mT5 backbone, translates the Portuguese question into a structured SQL query to be executed against a relational database.

To manage the high computational demands and library dependencies of these models, the system was implemented across a distributed environment using a shared file system for cross-platform communication.

Dataset Development

To train and evaluate the system in a Portuguese context, we constructed a new closed-domain biomedical benchmark. Since native Portuguese datasets are scarce, we performed automated translation on three prominent English sources:

  • MS MARCO: We extracted a biomedical subset of approximately 31,620 QA pairs, translating questions, contexts, and answers into Portuguese.
  • Spider & MIMICSQL: These were used to provide the relational query data, specifically focusing on medical domains such as hospital management and enzyme interactions.

Results and Performance

The BERTimbau classifier demonstrated exceptional performance in distinguishing between query types. In cross-validation, it achieved a 99.9% F1-score, significantly outperforming the Naive Bayes baseline (98.2%). On specific test sets, routing accuracy remained high:

  • MS MARCO: 99.8%
  • Spider: 98.0%
  • MIMICSQL: 99.6%

In terms of latency, the SQL branch was notably faster, averaging 3.2 seconds per query. The factual branch averaged 7.4 seconds, reflecting the additional overhead of the two-stage retrieval and reading process.

Discussion and Limitations

Our findings suggest that specialization is a superior strategy to generalization in QA systems. By delegating tasks to specialized sub-systems, we achieve higher reliability than a single monolithic model might provide. Additionally, we observed that fine-tuning multilingual models (mT5) on a variety of languages (English, Spanish, French, and Portuguese) actually improved performance on Portuguese-specific tasks compared to training on Portuguese alone.

One limitation of this study is the potential for "dataset artifacts." Because the benchmark was synthesized from distinct sources, the classifier might be identifying structural differences between the source datasets rather than the deep semantic nature of the questions. Future research will focus on developing more "ecologically valid" datasets that better mirror organic user behavior to ensure the robustness of the classification logic.

Summary updated

BibTeX
@inproceedings{jose2022integrating,
  author = {Marcos Menon José and Marcelo Archanjo José and Denis Deratani Mauá and Fábio Gagliardi Cozman},
  title = {{Integrating question answering and text-to-SQL in Portuguese}},
  booktitle = {PROPOR},
  year = {2022},
  doi = {10.1007/978-3-030-98305-5\_26},
}
Figure