Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities in general knowledge retrieval and reasoning. However, they frequently falter when faced with "time-sensitive" questions—queries requiring precise temporal logic, such as "Who was the CEO of Apple in 2005?" These failures stem from the fact that LLMs are fundamentally probabilistic engines rather than symbolic ones. They often exhibit "number-blindness," struggling to handle sequential or overlapping date intervals accurately.
When an LLM processes a biography containing multiple dates and events, it may hallucinate connections or default to the most frequent association rather than the chronologically correct one. Standard techniques like Chain-of-Thought (CoT) offer some improvement but still rely on the model's internal, often flawed, temporal reasoning. To address this, we introduce QAaP (Question Answering as Programming), a framework that offloads temporal reasoning from the "fuzzy" neural model to a "precise" symbolic script.
The QAaP Framework
The core philosophy of QAaP is to treat the LLM as a high-powered "parser" and "extractor" while delegating the logic of matching and verification to a deterministic programming environment. The process is divided into two primary phases:
1. Representing Information as Code
In this phase, the natural language input is transformed into structured data:
- Parse: The LLM converts the user's question into a Python dictionary containing keys for
subject,relation,object, andtime(represented asdatetimeobjects). - Extract: The model scans external knowledge sources (e.g., Wikipedia) or its own internal parameters to extract relevant facts into a list of structured Python dictionaries.
2. Choosing the Answer via Programming
Once the data is structured, symbolic logic takes over:
- Check: A programmatic step verifies that the extracted facts are explicitly present in the source text, acting as a guardrail against hallucination.
- Match: Instead of a probabilistic guess, the system calculates a temporal alignment score. Borrowing from computer vision, it uses an Intersection over Union (IoU) calculation to measure the overlap between the time window requested in the query and the intervals found in candidate facts. The candidate with the highest score is selected as the answer.
Evaluation and Results
The QAaP framework was evaluated against three major temporal benchmarks: TimeQA (factual questions with time-evolving facts), TempQuestions, and TimeQuestions.
The results demonstrate that QAaP consistently outperforms strong baselines like Chain-of-Thought (CoT) and ReAct. On the challenging TimeQA-Hard subset, QAaP achieved a 14.5% absolute improvement in Exact Match (EM) scores. Similarly, it saw gains of 10.5% on TempQuestions and 8.6% on TimeQuestions, even surpassing some supervised, fine-tuned models. Crucially, QAaP maintained its superiority even when provided with "golden" (perfect) context paragraphs, indicating that the primary bottleneck in temporal QA is the reasoning process itself, not just information retrieval.
Discussion and Future Directions
The success of QAaP highlights a critical insight: LLMs are significantly better at structuring data than reasoning over it. By converting unreliable prose into reliable code, the framework mitigates common LLM pitfalls like date-math errors and information scattering.
However, several challenges remain. The current implementation focuses primarily on explicit temporal constraints (e.g., "in 1995"). Future work is needed to handle implicit time (e.g., "during the Gulf War") and to extend the symbolic matching logic to other domains such as spatial constraints or quantitative reasoning. Additionally, while the use of advanced models like GPT-4 yields high performance, exploring more cost-effective open-source alternatives for the extraction phase remains a priority for widespread adoption.
Summary updated