LLM-in-the-loop: Leveraging Large Language Model for Thematic Analysis

Shih-Chieh Dai, Aiping Xiong, Lun-Wei KuEMNLP 2023

Abstract

Thematic analysis (TA) is a foundational qualitative research method that remains notoriously labor-intensive, typically requiring multiple human experts to ensure reliability. This paper introduces a novel LLM-in-the-loop framework that integrates Large Language Models (LLMs) as collaborative "machine coders." By facilitating a structured dialogue between human researchers and GPT-3.5, the framework achieves "almost perfect" inter-annotator agreement while drastically reducing manual workload. Our evaluation across two distinct datasets demonstrates that LLMs can effectively serve as reliable second coders, sometimes even surpassing human-to-human agreement benchmarks.

The Thematic Analysis Bottleneck

Qualitative researchers rely on thematic analysis to identify patterns within open-ended data, such as interview transcripts or survey responses. To mitigate individual bias, the standard protocol involves at least two human coders working independently to develop and iterate upon a shared codebook. However, this process is expensive and difficult to scale. As qualitative datasets grow in size, the requirement for dual human coding becomes a significant barrier to timely research.

The LLM-in-the-loop Framework

To address these challenges, we propose a four-step collaborative framework that treats the LLM not just as a tool, but as a peer coder.

Overview of the four-step LLM-in-the-loop framework for collaborative thematic analysis.
  1. Data Familiarization & Exemplar Generation: A human coder (HC) reviews a subset of the data to create 4–8 "exemplars." These exemplars use a Chain-of-Thought (CoT) format to define concepts and map data quotes to specific codes.
  2. Initial Code Generation: Using these exemplars for In-Context Learning (ICL), the LLM (acting as a Machine Coder, or MC) extracts initial codes from the remaining dataset.
  3. Code Refinement & Codebook Generation: This stage involves an iterative "loop" where the MC suggests themes and the human provides feedback, including deletions or merges with specific rationales.
  4. Theme Identification & Evaluation: Both the human and the LLM apply the final codebook to the entire dataset. Reliability is then assessed using Cohen’s $\kappa$.

Collaborative Code Refinement

A key innovation of this framework is the interactive refinement phase. Unlike traditional automated labeling, the MC evaluates human suggestions and provides its own reasoning, ensuring the final codebook is semantically robust and mutually agreed upon.

Detail of Step 3, showing the iterative interaction between the human researcher and the LLM to refine codes.

Experimental Evaluation

We evaluated the framework using two datasets:

  • Music Shuffle (MS): 35 responses regarding personal music listening experiences.
  • Password Manager (PM): 280 responses regarding the adoption of security tools. Due to context limits, a 100-response sample was used for codebook development.

Experiments utilized GPT-3.5-turbo-16k with a temperature setting of 0 to ensure reproducibility and minimize creative variance.

Key Results and Insights

  • High Reliability: In the Music Shuffle study, human-LLM agreement reached a Cohen’s $\kappa$ of 0.87, categorized as "almost perfect."
  • Surpassing Human Benchmarks: In the Password Manager study, the human-LLM agreement (0.81) exceeded the original human-to-human agreement (0.77) reported by the dataset's authors.
  • Semantic Accuracy: Using embedding models, we confirmed that the generated codes maintained high cosine similarity (~0.88) to established "gold standard" codes.
  • Handling Disagreement: Analysis of disagreements revealed they were rarely due to LLM error, but rather differences in granularity or inherent ambiguity in the source text.

Limitations and Future Work

While promising, the framework faces several hurdles. Privacy remains a primary concern, as qualitative data often contains sensitive information that may not be suitable for third-party APIs. Additionally, the study's reliance on GPT-3.5 suggests a need for further testing with open-source models like Llama 3. Future iterations will also explore formal "tie-breaker" mechanisms for instances where the human and LLM reach a conceptual stalemate.

Summary updated

BibTeX
@inproceedings{dai2023llm,
  author = {Shih-Chieh Dai and Aiping Xiong and Lun-Wei Ku},
  title = {{LLM-in-the-loop: Leveraging Large Language Model for Thematic Analysis}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.669},
}
Figure