Detecting uncivil language is crucial for maintaining safe, inclusive, and democratic online spaces. Yet existing classifiers often misinterpret posts containing uncivil cues but expressing civil intents, leading to inflated estimates of harmful incivility online. We introduce LinGO, a linguistic graph optimization framework for large language models (LLMs) that leverages linguistic structures and optimization techniques to classify multi-class intents of incivility that use various direct and indirect expressions. LinGO decomposes language into multi-step linguistic components, identifies targeted steps that cause the most errors, and iteratively optimizes prompt and/or example components for targeted steps. We evaluate it using a dataset collected during the 2022 Brazilian presidential election, encompassing four forms of political incivility: Impoliteness (IMP), Hate Speech and Stereotyping (HSST), Physical Harm and Violent Political Rhetoric (PHAVPR), and Threats to Democratic Institutions and Values (THREAT). Each instance is annotated with six types of civil/uncivil intent. We benchmark LinGO using three cost-efficient LLMs: GPT-5-mini, Gemini 2.5 Flash-Lite, and Claude 3 Haiku, and four optimization techniques: TextGrad, AdalFlow, DSPy, and Retrieval-Augmented Generation (RAG). The results show that, across all models, LinGO consistently improves accuracy and weighted F1 compared with zero-shot, chain-of-thought, direct optimization, and fine-tuning baselines. RAG is the strongest optimization technique and, when paired with Gemini model, achieves the best overall performance. These findings demonstrate that incorporating multi-step linguistic components into LLM instructions and optimize targeted components can help the models explain complex semantic meanings, which can be extended to other complex semantic explanation tasks in the future.
翻译:检测不文明语言对于维护安全、包容和民主的网络空间至关重要。然而,现有的分类器常常误判那些包含不文明线索但表达文明意图的帖子,导致对网络中有害不文明行为的高估。我们提出了LinGO,一种面向大语言模型的语言图优化框架,它利用语言结构和优化技术,对使用各种直接和间接表达方式的不文明言论的多类别意图进行分类。LinGO将语言分解为多步骤的语言组件,识别导致最多错误的目标步骤,并针对目标步骤迭代优化提示和/或示例组件。我们使用在2022年巴西总统选举期间收集的数据集对其进行了评估,该数据集涵盖了四种形式的政治不文明行为:不礼貌、仇恨言论与刻板印象、人身伤害与暴力政治言论,以及对民主制度和价值观的威胁。每个实例都标注了六种文明/不文明意图类型。我们使用三种高性价比的大语言模型对LinGO进行了基准测试:GPT-5-mini、Gemini 2.5 Flash-Lite和Claude 3 Haiku,以及四种优化技术:TextGrad、AdalFlow、DSPy和检索增强生成。结果表明,在所有模型中,与零样本、思维链、直接优化和微调基线相比,LinGO持续提高了准确率和加权F1分数。检索增强生成是最强的优化技术,当与Gemini模型配对时,实现了最佳的整体性能。这些发现表明,将多步骤语言组件纳入大语言模型指令并优化目标组件,可以帮助模型解释复杂的语义含义,未来可扩展到其他复杂的语义解释任务。