Using Large Language Models for Text Annotation in Social Science and Humanities: A Hands-On Python/R Tutorial

Publication date

2025-11-13

Authors

Fang, QixiangORCID 0000-0003-2689-6653ISNI 0000000493063739
Garcia Bernardo, JavierORCID 0000-0002-6119-1790ISNI 0000000485189083
van Kesteren, Erik JanORCID 0000-0003-1548-1663ISNI 000000049252840X

Editors

Advisors

Supervisors

Document Type

/dk/atira/pure/researchoutput/researchoutputtypes/workingpaper/preprint
Open Access logo

License

cc_by

Abstract

Large language models (LLMs) have become an essential tool for social scientists and humanities (SSH) researchers who work with textual data. One particularly valuable use case is automating text annotation, traditionally a time-consuming step in preparing data for empirical analysis. Yet, many SSH researchers face two challenges: getting started with LLMs, and understanding how to evaluate and correct for their limitations. The rapid pace of model development can make LLMs appear inaccessible or intimidating, while even experienced users may overlook how annotation errors can bias results from downstream analyses (e.g., regression estimates, $p$-values), even when accuracy appears high. This tutorial provides a step-by-step, hands-on guide to using LLMs for text annotation in SSH research for both Python and R users. We cover (1) how to choose and access LLM APIs, (2) how to design and run annotation tasks programmatically, (3) how to evaluate annotation quality and iterate on prompts, (4) how to integrate annotations into statistical workflows while accounting for uncertainty, and (5) how to manage cost, efficiency, and reproducibility. Throughout, we provide concrete examples, code snippets, and best-practice checklists to help researchers confidently and transparently incorporate LLM-based annotation into their workflows.

Keywords

Citation

Fang, Q, Garcia-Bernardo, J & van Kesteren, E-J 2025 'Using Large Language Models for Text Annotation in Social Science and Humanities: A Hands-On Python/R Tutorial' OSF. https://doi.org/10.31235/osf.io/v4eq6_v1