小改动暴露语义相似度度量的致命缺陷,嵌入方法常误判相反语义。
How Small Transformation Expose the Weakness of Semantic Similarity Measures
- 通过可控文本修改测试18种语义度量方法,评估其对语义关系的敏感性。
- 嵌入方法99.9%误将语义相反内容判为相似,部分模型反而把对立义比同义更相近。
- 基于LLM的方法能有效区分不同语义,相似度仅0.00~0.29,优于嵌入法。
本研究考察了多种语义相似度度量方法在软件工程应用中的表现,如代码搜索、API推荐、自动化代码审查和重构工具。尽管大语言模型(LLM)被广泛用于此类评估,但其是否真正理解语义关系仍存疑问。研究测试了18种方法,包括词基方法、嵌入技术、基于LLM的系统及结构感知算法。通过系统化框架对文本和代码施加可控变化,评估各方法对不同语义关系的处理能力。结果显示,常用度量存在严重问题:部分嵌入方法将语义相反内容误判为相似达99.9%,某些基于Transformer的方法甚至将对立意义的相似度高于同义项。嵌入方法表现差主要源于距离计算方式;改用余弦相似度后性能提升24%至66%。相比之下,基于LLM的方法能有效识别语义差异,对真实不同的含义给出0.00至0.29的低相似度评分,而嵌入方法却错误赋予0.82至0.99的高分。
原文摘要 · Abstract (English)
This research examines how well different methods measure semantic similarity, which is important for various software engineering applications such as code search, API recommendations, automated code reviews, and refactoring tools. While large language models are increasingly used for these similarity assessments, questions remain about whether they truly understand semantic relationships or merely recognize surface patterns. The study tested 18 different similarity measurement approaches, including word-based methods, embedding techniques, LLM-based systems, and structure-aware algorithms. The researchers created a systematic testing framework that applies controlled changes to text and code to evaluate how well each method handles different types of semantic relationships. The results revealed significant issues with commonly used metrics. Some embedding-based methods incorrectly identified semantic opposites as similar up to 99.9 percent of the time, while certain transformer-based approaches occasionally rated opposite meanings as more similar than synonymous ones. The study found that embedding methods' poor performance often stemmed from how they calculate distances; switching from Euclidean distance to cosine similarity improved results by 24 to 66 percent. LLM-based approaches performed better at distinguishing semantic differences, producing low similarity scores (0.00 to 0.29) for genuinely different meanings, compared to embedding methods that incorrectly assigned high scores (0.82 to 0.99) to dissimilar content.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。