[Paper Review] Understanding Large Language Model Behaviors through Interactive Counterfactual Generation and Analysis
This paper introduces LLM Analyzer, an interactive visualization tool with a novel counterfactual generation algorithm that produces grammatically correct, meaningful textual perturbations at multiple granularities (e.g., phrases, clauses, sentences). The method uses dependency parsing to ensure syntactic completeness and enables users to interactively explore how changes affect LLM outputs, achieving 97.2% grammatical correctness across diverse domains.
Understanding the behavior of large language models (LLMs) is crucial for ensuring their safe and reliable use. However, existing explainable AI (XAI) methods for LLMs primarily rely on word-level explanations, which are often computationally inefficient and misaligned with human reasoning processes. Moreover, these methods often treat explanation as a one-time output, overlooking its inherently interactive and iterative nature. In this paper, we present LLM Analyzer, an interactive visualization system that addresses these limitations by enabling intuitive and efficient exploration of LLM behaviors through counterfactual analysis. Our system features a novel algorithm that generates fluent and semantically meaningful counterfactuals via targeted removal and replacement operations at user-defined levels of granularity. These counterfactuals are used to compute feature attribution scores, which are then integrated with concrete examples in a table-based visualization, supporting dynamic analysis of model behavior. A user study with LLM practitioners and interviews with experts demonstrate the system's usability and effectiveness, emphasizing the importance of involving humans in the explanation process as active participants rather than passive recipients.
Motivation & Objective
- To address the challenge of generating meaningful, readable counterfactuals for analyzing large language model (LLM) behaviors.
- To enable users to perturb text at multiple granularities—such as phrases, clauses, and sentences—for deeper understanding of LLM decision-making.
- To support interactive, user-driven analysis by integrating counterfactuals with feature attributions and dependency structures in a visual interface.
- To connect multiple explanation types (e.g., local perturbations and feature attributions) to improve holistic comprehension of LLMs.
Proposed method
- Leverages dependency parsing to identify semantically meaningful, removable text segments that preserve syntactic structure during counterfactual generation.
- Generates counterfactuals by removing segments and replacing them with user-specified alternatives, ensuring grammatical correctness and semantic coherence.
- Supports multi-granularity perturbation: users can interactively adjust the size of segments to be removed or replaced (e.g., word, phrase, clause, sentence).
- Integrates feature attributions and dependency relationships into a table-based visualization to show how segment changes affect model predictions.
- Employs a rule-based system to validate and preserve sentence completeness after perturbations, ensuring readability and mental comparability.
- Enables batch generation of counterfactuals from a single prototype input, with each variant preserving the original sentence’s grammatical and structural integrity.
Experimental results
Research questions
- RQ1How can we generate counterfactuals for LLMs that are both grammatically correct and semantically meaningful for user comparison?
- RQ2How can users effectively explore LLM behavior through perturbations at multiple granularities (e.g., phrase, clause, sentence) in long-form text?
- RQ3How can interactive visualization tools help users aggregate and interpret counterfactuals to uncover joint influences of multiple text segments on LLM outputs?
- RQ4To what extent do users find counterfactual-based analysis useful and intuitive for understanding LLM behaviors in real-world scenarios?
Key findings
- The proposed counterfactual generation algorithm achieved 97.2% grammatical correctness across 1,000 test samples from medical, legal, finance, education, and news datasets.
- On average, the algorithm generated 46 removal-only counterfactuals per input sentence in under one second, demonstrating high efficiency.
- User studies and expert feedback confirmed that LLM Analyzer supports effective and intuitive exploration of LLM behaviors through interactive counterfactual analysis.
- The tool enables users to group counterfactuals by segment of interest and assess joint influences, revealing complex interactions between text components.
- The integration of dependency structures and feature attributions in the visualization helped users validate findings through concrete, interpretable examples.
- The system demonstrated strong usability in a real-world use case involving clinical decision support, showing its practical value in safety-critical domains.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.