A Semantic and Lexical Analysis of LLM-Generated Responses in Comparison with Stack Overflow Answers
Abstract
Large Language Models (LLMs) have become indispensable tools in programming education and professional software development. However, their output quality remains poorly characterized, particularly in terms of the semantic and linguistic quality of the explanatory text. Traditional evaluation metrics such as ROUGE primarily rely on lexical overlap and therefore only partially reflect the semantic adequacy of code explanations. This study proposes a multi-metric evaluation framework integrating semantic embeddings and lexical metrics to assess the quality of explanations generated by LLMs. We conducted experiments on 442 question-answer pairs produced by human experts regarding Python programming language from Stack Overflow, comparing them with GPT-4o-mini outputs. Three embedding models (MiniLM-L6, MPNet-Base, Paraphrase-MiniLM) were employed to compute the measure of semantic similarity by using cosine similarity, and ROUGE metrics (ROUGE-1, ROUGE-2, ROUGE-L) were used for lexical analysis. Results reveal a high semantic alignment (cosine similarity: 0.65–0.75) but substantially lower lexical overlap (ROUGE:0.10–0.32), indicating that LLMs produce semantically sound yet lexically distinct explanations. Pearson correlation analysis reveals weak to moderate correlations (r=0.29–0.47) between semantic and lexical metrics, suggesting that traditional metrics alone are insufficient for a comprehensive evaluation. Statistical testing (paired t-tests, p < 0.001) shows significant differences among embedding models, with MPNet-Base achieving the highest semantic consistency. Our findings underscore the critical need for multidimensional evaluation frameworks in assessing LLM-generated explanations, particularly in technical domains where semantic accuracy is crucial.
Keywords
Ethical Statement
References
- M. Chen et al., ”Evaluating large language models trained on code,” 2021, arXiv:2107.03374.
- P. Vaithilingam, T. Zhang, and E. L. Glassman, ”Expectation vs. experience: Evaluating the usability of code generation tools powered by large language models,” in CHI Conf. Human Factors Comput. Syst. Extended Abstracts, 2022, pp. 1–7, doi: 10.1145/3491101.3519665.
- N. Nguyen and S. Nadi, ”An empirical evaluation of GitHub copilot’s code suggestions,” in Proc. 19th Int. Conf. Mining Softw. Repositories (MSR), 2022, pp. 1–5, doi: 10.1145/3524842.3528470.
- S. Barke, M. B. James, and N. Polikarpova, ”Grounded copilot: How programmers interact with code-generating models” in Proc. ACM Program. Lang., vol. 7, pp. 85–111, 2023.
- OpenAI, ”GPT-4 technical report”, 2023, arXiv:2303.08774.
- R. Anil et al., PaLM 2 technical report, 2023, arXiv:2305.10403.
- S. Kabir, D. N. Udo-Imeh, B. Kou, T. Zhang, ”Is Stack Overflow obsolete? An empirical study of the characteristics of ChatGPT answers to Stack Overflow questions”, 2023, arXiv:2308.02312.
- J. Prather et al., ”The robots are here: Navigating the generative AI revolution in computing education,” in Proc. 2023 Working Group Reports Innov. Technol. Comput. Sci. Educ., 2023, pp. 108–159.
Details
Primary Language
English
Subjects
Natural Language Processing
Journal Section
Research Article
Authors
Yasin Ortakcı
*
0000-0002-0683-2049
Türkiye
Early Pub Date
October 27, 2026
Publication Date
-
Submission Date
February 21, 2026
Acceptance Date
August 22, 2026
Published in Issue
Year 2026 Number: Advanced Online Publication