Large language models (LLMs) are increasingly used by researchers in the social sciences and humanities (SSH) for text analysis, particularly to automate text annotation. However, many researchers still face challenges in adopting LLMs, addressing their limitations, and producing reproducible workflows and results. For example, annotation errors can bias downstream statistical analyses even when apparent accuracy is high. This paper provides a step-by-step methodological guide to using LLMs for text annotation in SSH research, with practical Python and R examples. We explain how LLMs work, how to set up research projects, how to interact with (open-source) LLMs programmatically, how to design and evaluate prompts without overfitting, how to integrate LLM annotations into statistical analyses while accounting for annotation error, and how to manage cost, efficiency, and reproducibility at scale. Throughout, we emphasize intuitive methodological reasoning, concrete examples, and best practices to help researchers incorporate LLM-based annotation into reproducible scientific workflows.
翻译:大型语言模型(LLMs)正日益被社会科学与人文学科(SSH)的研究者用于文本分析,特别是自动化文本标注。然而,许多研究者仍在应对采纳LLMs、解决其局限性以及生成可重复工作流程与结果时面临挑战。例如,即使表观准确率很高,标注误差仍可能使下游统计分析产生偏差。本文为在SSH研究中使用LLMs进行文本标注提供了分步方法论指南,并附有实用的Python和R示例。我们阐释了LLMs的工作原理、如何设定研究项目、如何以编程方式与(开源)LLMs交互、如何设计并评估提示词以避免过拟合、如何在考虑标注误差的情况下将LLM标注整合至统计分析中,以及如何在大规模应用中控制成本、提升效率并确保可重复性。全文强调直观的方法论推理、具体案例与最佳实践,以帮助研究者将基于LLM的标注融入可重复的科学工作流程。