Chelsea707 commited on
Commit
7c2fc11
·
verified ·
1 Parent(s): 8cb9d99

Add Batch 0f0d878a-1a4a-4290-a9c5-be5e7acfed7a data

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +64 -0
  2. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_content_list.json +0 -0
  3. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_model.json +0 -0
  4. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_origin.pdf +3 -0
  5. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/full.md +416 -0
  6. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/images.zip +3 -0
  7. 2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/layout.json +0 -0
  8. 2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_content_list.json +0 -0
  9. 2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_model.json +0 -0
  10. 2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_origin.pdf +3 -0
  11. 2025/Classifying Unreliable Narrators with Large Language Models/full.md +0 -0
  12. 2025/Classifying Unreliable Narrators with Large Language Models/images.zip +3 -0
  13. 2025/Classifying Unreliable Narrators with Large Language Models/layout.json +0 -0
  14. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_content_list.json +0 -0
  15. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_model.json +0 -0
  16. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_origin.pdf +3 -0
  17. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/full.md +618 -0
  18. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/images.zip +3 -0
  19. 2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/layout.json +0 -0
  20. 2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_content_list.json +0 -0
  21. 2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_model.json +0 -0
  22. 2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_origin.pdf +3 -0
  23. 2025/CoAM_ Corpus of All-Type Multiword Expressions/full.md +476 -0
  24. 2025/CoAM_ Corpus of All-Type Multiword Expressions/images.zip +3 -0
  25. 2025/CoAM_ Corpus of All-Type Multiword Expressions/layout.json +0 -0
  26. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_content_list.json +0 -0
  27. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_model.json +0 -0
  28. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_origin.pdf +3 -0
  29. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/full.md +380 -0
  30. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/images.zip +3 -0
  31. 2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/layout.json +0 -0
  32. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_content_list.json +0 -0
  33. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_model.json +0 -0
  34. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_origin.pdf +3 -0
  35. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/full.md +540 -0
  36. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/images.zip +3 -0
  37. 2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/layout.json +0 -0
  38. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_content_list.json +0 -0
  39. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_model.json +0 -0
  40. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_origin.pdf +3 -0
  41. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/full.md +511 -0
  42. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/images.zip +3 -0
  43. 2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/layout.json +0 -0
  44. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_content_list.json +0 -0
  45. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_model.json +0 -0
  46. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_origin.pdf +3 -0
  47. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/full.md +0 -0
  48. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/images.zip +3 -0
  49. 2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/layout.json +0 -0
  50. 2025/CoRe-MMRAG_ Cross-Source Knowledge Reconciliation for Multimodal RAG/4d6bd5e4-e4fd-4ed2-a6b9-effaad773b5a_content_list.json +0 -0
.gitattributes CHANGED
@@ -1717,3 +1717,67 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
1717
  2025/Circuit[[:space:]]Stability[[:space:]]Characterizes[[:space:]]Language[[:space:]]Model[[:space:]]Generalization/5f754489-a22e-45ab-b212-701f2fa00977_origin.pdf filter=lfs diff=lfs merge=lfs -text
1718
  2025/CiteEval_[[:space:]]Principle-Driven[[:space:]]Citation[[:space:]]Evaluation[[:space:]]for[[:space:]]Source[[:space:]]Attribution/19b6fd86-c2e8-472c-97d7-d6634e8f328a_origin.pdf filter=lfs diff=lfs merge=lfs -text
1719
  2025/CityNavAgent_[[:space:]]Aerial[[:space:]]Vision-and-Language[[:space:]]Navigation[[:space:]]with[[:space:]]Hierarchical[[:space:]]Semantic[[:space:]]Planning[[:space:]]and[[:space:]]Global[[:space:]]Memory/bdd8193e-1f9a-4b9b-8ac6-494089d4594e_origin.pdf filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1717
  2025/Circuit[[:space:]]Stability[[:space:]]Characterizes[[:space:]]Language[[:space:]]Model[[:space:]]Generalization/5f754489-a22e-45ab-b212-701f2fa00977_origin.pdf filter=lfs diff=lfs merge=lfs -text
1718
  2025/CiteEval_[[:space:]]Principle-Driven[[:space:]]Citation[[:space:]]Evaluation[[:space:]]for[[:space:]]Source[[:space:]]Attribution/19b6fd86-c2e8-472c-97d7-d6634e8f328a_origin.pdf filter=lfs diff=lfs merge=lfs -text
1719
  2025/CityNavAgent_[[:space:]]Aerial[[:space:]]Vision-and-Language[[:space:]]Navigation[[:space:]]with[[:space:]]Hierarchical[[:space:]]Semantic[[:space:]]Planning[[:space:]]and[[:space:]]Global[[:space:]]Memory/bdd8193e-1f9a-4b9b-8ac6-494089d4594e_origin.pdf filter=lfs diff=lfs merge=lfs -text
1720
+ 2025/Class[[:space:]]Distillation[[:space:]]with[[:space:]]Mahalanobis[[:space:]]Contrast_[[:space:]]An[[:space:]]Efficient[[:space:]]Training[[:space:]]Paradigm[[:space:]]for[[:space:]]Pragmatic[[:space:]]Language[[:space:]]Understanding[[:space:]]Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_origin.pdf filter=lfs diff=lfs merge=lfs -text
1721
+ 2025/Classifying[[:space:]]Unreliable[[:space:]]Narrators[[:space:]]with[[:space:]]Large[[:space:]]Language[[:space:]]Models/f069e84b-73e1-45f3-8102-243e3651ec32_origin.pdf filter=lfs diff=lfs merge=lfs -text
1722
+ 2025/ClusterAttn_[[:space:]]KV[[:space:]]Cache[[:space:]]Compression[[:space:]]under[[:space:]]Intrinsic[[:space:]]Attention[[:space:]]Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_origin.pdf filter=lfs diff=lfs merge=lfs -text
1723
+ 2025/CoAM_[[:space:]]Corpus[[:space:]]of[[:space:]]All-Type[[:space:]]Multiword[[:space:]]Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_origin.pdf filter=lfs diff=lfs merge=lfs -text
1724
+ 2025/CoCoLex_[[:space:]]Confidence-guided[[:space:]]Copy-based[[:space:]]Decoding[[:space:]]for[[:space:]]Grounded[[:space:]]Legal[[:space:]]Text[[:space:]]Generation/57318655-108b-49de-8446-70e3b2ba431f_origin.pdf filter=lfs diff=lfs merge=lfs -text
1725
+ 2025/CoE_[[:space:]]A[[:space:]]Clue[[:space:]]of[[:space:]]Emotion[[:space:]]Framework[[:space:]]for[[:space:]]Emotion[[:space:]]Recognition[[:space:]]in[[:space:]]Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_origin.pdf filter=lfs diff=lfs merge=lfs -text
1726
+ 2025/CoIR_[[:space:]]A[[:space:]]Comprehensive[[:space:]]Benchmark[[:space:]]for[[:space:]]Code[[:space:]]Information[[:space:]]Retrieval[[:space:]]Models/63817457-5e2b-4907-88ff-c95a00015592_origin.pdf filter=lfs diff=lfs merge=lfs -text
1727
+ 2025/CoMet_[[:space:]]Metaphor-Driven[[:space:]]Covert[[:space:]]Communication[[:space:]]for[[:space:]]Multi-Agent[[:space:]]Language[[:space:]]Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_origin.pdf filter=lfs diff=lfs merge=lfs -text
1728
+ 2025/CoRe-MMRAG_[[:space:]]Cross-Source[[:space:]]Knowledge[[:space:]]Reconciliation[[:space:]]for[[:space:]]Multimodal[[:space:]]RAG/4d6bd5e4-e4fd-4ed2-a6b9-effaad773b5a_origin.pdf filter=lfs diff=lfs merge=lfs -text
1729
+ 2025/CoT-ICL[[:space:]]Lab_[[:space:]]A[[:space:]]Synthetic[[:space:]]Framework[[:space:]]for[[:space:]]Studying[[:space:]]Chain-of-Thought[[:space:]]Learning[[:space:]]from[[:space:]]In-Context[[:space:]]Demonstrations/c1736ea4-a8b9-410a-85c0-eaaa17793be9_origin.pdf filter=lfs diff=lfs merge=lfs -text
1730
+ 2025/CoT-Valve_[[:space:]]Length-Compressible[[:space:]]Chain-of-Thought[[:space:]]Tuning/b2157abc-bbea-41d1-ad63-24d5c7472d50_origin.pdf filter=lfs diff=lfs merge=lfs -text
1731
+ 2025/CoT-based[[:space:]]Synthesizer_[[:space:]]Enhancing[[:space:]]LLM[[:space:]]Performance[[:space:]]through[[:space:]]Answer[[:space:]]Synthesis/426c6516-11a0-4f4e-8c42-b9ad7c5108c4_origin.pdf filter=lfs diff=lfs merge=lfs -text
1732
+ 2025/CoachMe_[[:space:]]Decoding[[:space:]]Sport[[:space:]]Elements[[:space:]]with[[:space:]]a[[:space:]]Reference-Based[[:space:]]Coaching[[:space:]]Instruction[[:space:]]Generation[[:space:]]Model/fe3431e5-c708-4d8e-906f-8d5febb96c55_origin.pdf filter=lfs diff=lfs merge=lfs -text
1733
+ 2025/Code-Switching[[:space:]]Red-Teaming_[[:space:]]LLM[[:space:]]Evaluation[[:space:]]for[[:space:]]Safety[[:space:]]and[[:space:]]Multilingual[[:space:]]Understanding/8c9cd6cf-119c-4d3f-8fca-682a270ca147_origin.pdf filter=lfs diff=lfs merge=lfs -text
1734
+ 2025/CodeDPO_[[:space:]]Aligning[[:space:]]Code[[:space:]]Models[[:space:]]with[[:space:]]Self[[:space:]]Generated[[:space:]]and[[:space:]]Verified[[:space:]]Source[[:space:]]Code/e2bb166a-c91d-4839-ab09-7252c49f01e4_origin.pdf filter=lfs diff=lfs merge=lfs -text
1735
+ 2025/CodeTool_[[:space:]]Enhancing[[:space:]]Programmatic[[:space:]]Tool[[:space:]]Invocation[[:space:]]of[[:space:]]LLMs[[:space:]]via[[:space:]]Process[[:space:]]Supervision/ca1257f7-146e-42b9-90eb-345c026736db_origin.pdf filter=lfs diff=lfs merge=lfs -text
1736
+ 2025/CogniBench_[[:space:]]A[[:space:]]Legal-inspired[[:space:]]Framework[[:space:]]and[[:space:]]Dataset[[:space:]]for[[:space:]]Assessing[[:space:]]Cognitive[[:space:]]Faithfulness[[:space:]]of[[:space:]]Large[[:space:]]Language[[:space:]]Models/ba634675-df83-4f8b-bbee-4b391b7a6e6e_origin.pdf filter=lfs diff=lfs merge=lfs -text
1737
+ 2025/Collapse[[:space:]]of[[:space:]]Dense[[:space:]]Retrievers_[[:space:]]Short,[[:space:]]Early,[[:space:]]and[[:space:]]Literal[[:space:]]Biases[[:space:]]Outranking[[:space:]]Factual[[:space:]]Evidence/e4bbcaf6-42bb-4dbd-ac48-bc023aed0acd_origin.pdf filter=lfs diff=lfs merge=lfs -text
1738
+ 2025/Colloquial[[:space:]]Singaporean[[:space:]]English[[:space:]]Style[[:space:]]Transfer[[:space:]]with[[:space:]]Fine-Grained[[:space:]]Explainable[[:space:]]Control/7301f047-7aa3-4de0-8534-d8c265a85a5d_origin.pdf filter=lfs diff=lfs merge=lfs -text
1739
+ 2025/Com2[[:space:]]_[[:space:]]A[[:space:]]Causal-Guided[[:space:]]Benchmark[[:space:]]for[[:space:]]Exploring[[:space:]]Complex[[:space:]]Commonsense[[:space:]]Reasoning[[:space:]]in[[:space:]]Large[[:space:]]Language[[:space:]]Models/c5f47fb4-6b1b-4570-9136-47a9067817c9_origin.pdf filter=lfs diff=lfs merge=lfs -text
1740
+ 2025/Commonsense[[:space:]]Reasoning[[:space:]]in[[:space:]]Arab[[:space:]]Culture/0b03b8ce-5b62-4403-8771-f4d790db4043_origin.pdf filter=lfs diff=lfs merge=lfs -text
1741
+ 2025/Comparing[[:space:]]LLM-generated[[:space:]]and[[:space:]]human-authored[[:space:]]news[[:space:]]text[[:space:]]using[[:space:]]formal[[:space:]]syntactic[[:space:]]theory/5f98d5cd-66be-46b9-9367-403f50f7657c_origin.pdf filter=lfs diff=lfs merge=lfs -text
1742
+ 2025/Comparing[[:space:]]Moral[[:space:]]Values[[:space:]]in[[:space:]]Western[[:space:]]English-speaking[[:space:]]societies[[:space:]]and[[:space:]]LLMs[[:space:]]with[[:space:]]Word[[:space:]]Associations/36f43a91-32eb-45e3-9326-1ff905eec6f0_origin.pdf filter=lfs diff=lfs merge=lfs -text
1743
+ 2025/Comparison-based[[:space:]]Active[[:space:]]Preference[[:space:]]Learning[[:space:]]for[[:space:]]Multi-dimensional[[:space:]]Personalization/cde2fde9-bc2b-4483-8b61-74125209efb3_origin.pdf filter=lfs diff=lfs merge=lfs -text
1744
+ 2025/CompileAgent_[[:space:]]Automated[[:space:]]Real-World[[:space:]]Repo-Level[[:space:]]Compilation[[:space:]]with[[:space:]]Tool-Integrated[[:space:]]LLM-based[[:space:]]Agent[[:space:]]System/7f68c1e2-e8e6-4aa1-bb39-53f4fa9f4001_origin.pdf filter=lfs diff=lfs merge=lfs -text
1745
+ 2025/Completing[[:space:]]A[[:space:]]Systematic[[:space:]]Review[[:space:]]in[[:space:]]Hours[[:space:]]instead[[:space:]]of[[:space:]]Months[[:space:]]with[[:space:]]Interactive[[:space:]]AI[[:space:]]Agents/eec09aff-e3c9-41fe-8ae8-f2bc1cd7854c_origin.pdf filter=lfs diff=lfs merge=lfs -text
1746
+ 2025/Computation[[:space:]]Mechanism[[:space:]]Behind[[:space:]]LLM[[:space:]]Position[[:space:]]Generalization/6f5f62fb-6a90-4ac6-b4ec-27bd1f3bd7fa_origin.pdf filter=lfs diff=lfs merge=lfs -text
1747
+ 2025/Con[[:space:]]Instruction_[[:space:]]Universal[[:space:]]Jailbreaking[[:space:]]of[[:space:]]Multimodal[[:space:]]Large[[:space:]]Language[[:space:]]Models[[:space:]]via[[:space:]]Non-Textual[[:space:]]Modalities/18429446-982a-42c5-b3e2-f38cfca1dbad_origin.pdf filter=lfs diff=lfs merge=lfs -text
1748
+ 2025/ConLoan_[[:space:]]A[[:space:]]Contrastive[[:space:]]Multilingual[[:space:]]Dataset[[:space:]]for[[:space:]]Evaluating[[:space:]]Loanwords/f29fedfa-80bf-4c39-8416-8250d1215093_origin.pdf filter=lfs diff=lfs merge=lfs -text
1749
+ 2025/ConSim_[[:space:]]Measuring[[:space:]]Concept-Based[[:space:]]Explanations’[[:space:]]Effectiveness[[:space:]]with[[:space:]]Automated[[:space:]]Simulatability/f2d22654-549d-4d9b-90e1-ffc47a8aea19_origin.pdf filter=lfs diff=lfs merge=lfs -text
1750
+ 2025/ConceptCarve_[[:space:]]Dynamic[[:space:]]Realization[[:space:]]of[[:space:]]Evidence/f68ee969-d4d2-4202-b946-4b76059505c3_origin.pdf filter=lfs diff=lfs merge=lfs -text
1751
+ 2025/Conditional[[:space:]]Dichotomy[[:space:]]Quantification[[:space:]]via[[:space:]]Geometric[[:space:]]Embedding/6b30b146-da90-49d2-93d0-5e5cd9198eed_origin.pdf filter=lfs diff=lfs merge=lfs -text
1752
+ 2025/Condor_[[:space:]]Enhance[[:space:]]LLM[[:space:]]Alignment[[:space:]]with[[:space:]]Knowledge-Driven[[:space:]]Data[[:space:]]Synthesis[[:space:]]and[[:space:]]Refinement/8a9e839e-f01b-46fd-8b84-7f40ae070ef4_origin.pdf filter=lfs diff=lfs merge=lfs -text
1753
+ 2025/Confidence[[:space:]]v.s.[[:space:]]Critique_[[:space:]]A[[:space:]]Decomposition[[:space:]]of[[:space:]]Self-Correction[[:space:]]Capability[[:space:]]for[[:space:]]LLMs/bf70c05a-062d-409c-b3c0-435d5fc58483_origin.pdf filter=lfs diff=lfs merge=lfs -text
1754
+ 2025/Conformity[[:space:]]in[[:space:]]Large[[:space:]]Language[[:space:]]Models/78c82249-682f-4b89-8505-dd137e7bd87f_origin.pdf filter=lfs diff=lfs merge=lfs -text
1755
+ 2025/ConsistencyChecker_[[:space:]]Tree-based[[:space:]]Evaluation[[:space:]]of[[:space:]]LLM[[:space:]]Generalization[[:space:]]Capabilities/da528703-9f3e-4766-bb30-bb62d347aa76_origin.pdf filter=lfs diff=lfs merge=lfs -text
1756
+ 2025/Consistent[[:space:]]Client[[:space:]]Simulation[[:space:]]for[[:space:]]Motivational[[:space:]]Interviewing-based[[:space:]]Counseling/df650987-6b43-4ab1-9da0-ffd859aeb905_origin.pdf filter=lfs diff=lfs merge=lfs -text
1757
+ 2025/Conspiracy[[:space:]]Theories[[:space:]]and[[:space:]]Where[[:space:]]to[[:space:]]Find[[:space:]]Them[[:space:]]on[[:space:]]TikTok/bb2b4d6e-70c7-4056-82df-524c23c5a0e4_origin.pdf filter=lfs diff=lfs merge=lfs -text
1758
+ 2025/Context-Aware[[:space:]]Sentiment[[:space:]]Forecasting[[:space:]]via[[:space:]]LLM-based[[:space:]]Multi-Perspective[[:space:]]Role-Playing[[:space:]]Agents/9ca1281e-5af3-49da-a828-8aec35b7061e_origin.pdf filter=lfs diff=lfs merge=lfs -text
1759
+ 2025/Contextual[[:space:]]Experience[[:space:]]Replay[[:space:]]for[[:space:]]Self-Improvement[[:space:]]of[[:space:]]Language[[:space:]]Agents/58c93196-6866-484e-96a2-bf261b3c9fdf_origin.pdf filter=lfs diff=lfs merge=lfs -text
1760
+ 2025/Continual[[:space:]]Gradient[[:space:]]Low-Rank[[:space:]]Projection[[:space:]]Fine-Tuning[[:space:]]for[[:space:]]LLMs/2b04b906-c3c8-47fb-81b8-5d585b5c32fb_origin.pdf filter=lfs diff=lfs merge=lfs -text
1761
+ 2025/Contrastive[[:space:]]Learning[[:space:]]on[[:space:]]LLM[[:space:]]Back[[:space:]]Generation[[:space:]]Treebank[[:space:]]for[[:space:]]Cross-domain[[:space:]]Constituency[[:space:]]Parsing/31338127-13ec-4110-b845-01d0a29782d2_origin.pdf filter=lfs diff=lfs merge=lfs -text
1762
+ 2025/Contrastive[[:space:]]Perplexity[[:space:]]for[[:space:]]Controlled[[:space:]]Generation_[[:space:]]An[[:space:]]Application[[:space:]]in[[:space:]]Detoxifying[[:space:]]Large[[:space:]]Language[[:space:]]Models/3f4d0126-cb69-4b99-8ad6-93ef0d818bce_origin.pdf filter=lfs diff=lfs merge=lfs -text
1763
+ 2025/Contrastive[[:space:]]Prompting[[:space:]]Enhances[[:space:]]Sentence[[:space:]]Embeddings[[:space:]]in[[:space:]]LLMs[[:space:]]through[[:space:]]Inference-Time[[:space:]]Steering/7135ff6f-f425-4b0e-bf1a-631fb32c90ef_origin.pdf filter=lfs diff=lfs merge=lfs -text
1764
+ 2025/ControlSpeech_[[:space:]]Towards[[:space:]]Simultaneous[[:space:]]and[[:space:]]Independent[[:space:]]Zero-shot[[:space:]]Speaker[[:space:]]Cloning[[:space:]]and[[:space:]]Zero-shot[[:space:]]Language[[:space:]]Style[[:space:]]Control/069192ac-84d8-4151-a05f-fec11e6e234b_origin.pdf filter=lfs diff=lfs merge=lfs -text
1765
+ 2025/Controllable[[:space:]]Style[[:space:]]Arithmetic[[:space:]]with[[:space:]]Language[[:space:]]Models/8461c354-5836-4699-8f22-f9508f08b33f_origin.pdf filter=lfs diff=lfs merge=lfs -text
1766
+ 2025/Controllable[[:space:]]and[[:space:]]Reliable[[:space:]]Knowledge-Intensive[[:space:]]Task-Oriented[[:space:]]Conversational[[:space:]]Agents[[:space:]]with[[:space:]]Declarative[[:space:]]Genie[[:space:]]Worksheets/481bc112-3cae-45d7-8cfe-cd6678b63039_origin.pdf filter=lfs diff=lfs merge=lfs -text
1767
+ 2025/Controlled[[:space:]]Low-Rank[[:space:]]Adaptation[[:space:]]with[[:space:]]Subspace[[:space:]]Regularization[[:space:]]for[[:space:]]Continued[[:space:]]Training[[:space:]]on[[:space:]]Large[[:space:]]Language[[:space:]]Models/f3e47e1e-f1f2-492d-bb1e-6265891f6e68_origin.pdf filter=lfs diff=lfs merge=lfs -text
1768
+ 2025/Cool-Fusion_[[:space:]]Fuse[[:space:]]Large[[:space:]]Language[[:space:]]Models[[:space:]]without[[:space:]]Training/ad6ce6c5-45fb-4455-8438-31e1a1deb42c_origin.pdf filter=lfs diff=lfs merge=lfs -text
1769
+ 2025/Cooperative[[:space:]]or[[:space:]]Competitive_[[:space:]]Understanding[[:space:]]the[[:space:]]Interaction[[:space:]]between[[:space:]]Attention[[:space:]]Heads[[:space:]]From[[:space:]]A[[:space:]]Game[[:space:]]Theory[[:space:]]Perspective/e34ddbbb-e7d2-4eff-af91-71244317c12c_origin.pdf filter=lfs diff=lfs merge=lfs -text
1770
+ 2025/Coordinating[[:space:]]Chaos_[[:space:]]A[[:space:]]Structured[[:space:]]Review[[:space:]]of[[:space:]]Linguistic[[:space:]]Coordination[[:space:]]Methodologies/79618a7f-f739-4f42-aff7-2bc1cbfb02f7_origin.pdf filter=lfs diff=lfs merge=lfs -text
1771
+ 2025/CoreEval_[[:space:]]Automatically[[:space:]]Building[[:space:]]Contamination-Resilient[[:space:]]Datasets[[:space:]]with[[:space:]]Real-World[[:space:]]Knowledge[[:space:]]toward[[:space:]]Reliable[[:space:]]LLM[[:space:]]Evaluation/94c78caa-8ccd-408d-9ba5-86e8b6f7445d_origin.pdf filter=lfs diff=lfs merge=lfs -text
1772
+ 2025/Counterspeech[[:space:]]the[[:space:]]ultimate[[:space:]]shield![[:space:]]Multi-Conditioned[[:space:]]Counterspeech[[:space:]]Generation[[:space:]]through[[:space:]]Attributed[[:space:]]Prefix[[:space:]]Learning/789942f8-9e93-49d0-b2c8-012bc19ed56a_origin.pdf filter=lfs diff=lfs merge=lfs -text
1773
+ 2025/Crab_[[:space:]]A[[:space:]]Novel[[:space:]]Configurable[[:space:]]Role-Playing[[:space:]]LLM[[:space:]]with[[:space:]]Assessing[[:space:]]Benchmark/35abe981-2724-4f19-992b-a062573a8df5_origin.pdf filter=lfs diff=lfs merge=lfs -text
1774
+ 2025/Cracking[[:space:]]Factual[[:space:]]Knowledge_[[:space:]]A[[:space:]]Comprehensive[[:space:]]Analysis[[:space:]]of[[:space:]]Degenerate[[:space:]]Knowledge[[:space:]]Neurons[[:space:]]in[[:space:]]Large[[:space:]]Language[[:space:]]Models/5e5e56cf-baf3-4956-a74b-1f2b0013e336_origin.pdf filter=lfs diff=lfs merge=lfs -text
1775
+ 2025/Cracking[[:space:]]the[[:space:]]Code[[:space:]]of[[:space:]]Hallucination[[:space:]]in[[:space:]]LVLMs[[:space:]]with[[:space:]]Vision-aware[[:space:]]Head[[:space:]]Divergence/e83c120a-703a-4cc8-b52a-1281dc26bd69_origin.pdf filter=lfs diff=lfs merge=lfs -text
1776
+ 2025/CrafText[[:space:]]Benchmark_[[:space:]]Advancing[[:space:]]Instruction[[:space:]]Following[[:space:]]in[[:space:]]Complex[[:space:]]Multimodal[[:space:]]Open-Ended[[:space:]]World/893aad9b-a71c-42ff-8324-9950fc6f4a85_origin.pdf filter=lfs diff=lfs merge=lfs -text
1777
+ 2025/Cramming[[:space:]]1568[[:space:]]Tokens[[:space:]]into[[:space:]]a[[:space:]]Single[[:space:]]Vector[[:space:]]and[[:space:]]Back[[:space:]]Again_[[:space:]]Exploring[[:space:]]the[[:space:]]Limits[[:space:]]of[[:space:]]Embedding[[:space:]]Space[[:space:]]Capacity/e49c8c18-92ce-4dc7-a6d1-984f3fcafffb_origin.pdf filter=lfs diff=lfs merge=lfs -text
1778
+ 2025/CrisisTS_[[:space:]]Coupling[[:space:]]Social[[:space:]]Media[[:space:]]Textual[[:space:]]Data[[:space:]]and[[:space:]]Meteorological[[:space:]]Time[[:space:]]Series[[:space:]]for[[:space:]]Urgency[[:space:]]Classification/b1e3a415-e0b3-499d-b2fa-b29cb25984f7_origin.pdf filter=lfs diff=lfs merge=lfs -text
1779
+ 2025/CritiQ_[[:space:]]Mining[[:space:]]Data[[:space:]]Quality[[:space:]]Criteria[[:space:]]from[[:space:]]Human[[:space:]]Preferences/c5b499e2-306c-4465-984f-9130075924e2_origin.pdf filter=lfs diff=lfs merge=lfs -text
1780
+ 2025/Croppable[[:space:]]Knowledge[[:space:]]Graph[[:space:]]Embedding/889ebc2a-7451-49ce-857f-34d33a611aee_origin.pdf filter=lfs diff=lfs merge=lfs -text
1781
+ 2025/Cross-Lingual[[:space:]]Auto[[:space:]]Evaluation[[:space:]]for[[:space:]]Assessing[[:space:]]Multilingual[[:space:]]LLMs/4e5b64b6-ff18-4bb2-bedd-1b247a221685_origin.pdf filter=lfs diff=lfs merge=lfs -text
1782
+ 2025/Cross-Lingual[[:space:]]Generalization[[:space:]]and[[:space:]]Compression_[[:space:]]From[[:space:]]Language-Specific[[:space:]]to[[:space:]]Shared[[:space:]]Neurons/c0295439-301a-4825-81a9-1a5756405fc2_origin.pdf filter=lfs diff=lfs merge=lfs -text
1783
+ 2025/Cross-Lingual[[:space:]]Optimization[[:space:]]for[[:space:]]Language[[:space:]]Transfer[[:space:]]in[[:space:]]Large[[:space:]]Language[[:space:]]Models/d1b83d6c-ba24-4ef8-84b8-0cbd2b21c7f1_origin.pdf filter=lfs diff=lfs merge=lfs -text
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/c2b7fdc5-4fd8-4040-8fd6-886fac52ff3c_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:392b81fc354e36d2c98119b97f21e79cfa569fa9dc7fbe0bc640f30d8566dbc2
3
+ size 5795426
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/full.md ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class Distillation with Mahalanobis Contrast: An Efficient Training Paradigm for Pragmatic Language Understanding Tasks
2
+
3
+ Chenlu Wang Weimin Lyu Ritwik Banerjee
4
+
5
+ Department of Computer Science Stony Brook University, New York, USA
6
+
7
+ # Abstract
8
+
9
+ Detecting deviant language such as sexism, or nuanced language such as metaphors or sarcasm, is crucial for enhancing the safety, clarity, and interpretation of online social discourse. While existing classifiers deliver strong results on these tasks, they often come with significant computational cost and high data demands. In this work, we propose Class Distillation (ClaD), a novel training paradigm that targets the core challenge: distilling a small, well-defined target class from a highly diverse and heterogeneous background. $^{1}$ ClaD integrates two key innovations: (i) a loss function informed by the structural properties of class distributions, based on Mahalanobis distance, and (ii) an interpretable decision algorithm optimized for class separation. Across three benchmark detection tasks – sexism, metaphor, and sarcasm – ClaD outperforms competitive baselines, and even with smaller language models and orders of magnitude fewer parameters, achieves performance comparable to several large language models (LLMs). These results demonstrate ClaD as an efficient tool for pragmatic language understanding tasks that require gleaning a small target class from a larger heterogeneous background.
10
+
11
+ # 1 Introduction
12
+
13
+ The widespread adoption of social media and the polarized nature of online discourse have amplified the need for improved communication dynamics, fostering research aimed at promoting safety and mutual respect. Critically, a part of this effort involves detecting complex linguistic phenomena such as figurative speech – like sarcasm and metaphor (Riloff et al., 2013; Oraby et al., 2016; Ghosh et al., 2020; Ge et al., 2023) – as well as harmful language patterns like aggressive rhetoric or sexism (Safi Samghabadi et al., 2020; Samory
14
+
15
+ ![](images/1a53cede772bb4d6d63f5e63f76c975b6a4f67b1eb5f98abe76bc6cdfb278190.jpg)
16
+ Figure 1: The minority target class representing deviant language (●) versus a highly diverse and heterogeneous non-target class of everything else (●). This t-SNE (van der Maaten and Hinton, 2008) visualization (where lighter shades indicate instances located further away in 3-D) displays a representative sample from the "Call me sexist but ..." corpus (Samory et al., 2021).
17
+
18
+ et al., 2021). These tasks present significant urgency and challenges due to the nuances of figurative speech and the variability of deviant language.
19
+
20
+ Most prior research (see §6) has approached these tasks as traditional binary classification problems, utilizing ground truth labels provided in various datasets. Despite varying degrees of success, this formulation has overlooked a crucial commonality: the objective is to isolate a minority target class, characterized more by its pragmatic function in natural language than its semantics, from the much larger and incredibly diverse negative class encompassing everything else. The complexities arising from the somewhat nebulous dichotomy,[2] alongside the diverse and heterogeneous nature of the predominant non-target class, can be gleaned
21
+
22
+ <table><tr><td rowspan="5">Figurative</td><td colspan="6">f1) My alarm clock makes sure I love every Monday morning! ♂</td></tr><tr><td colspan="6">f2) My alarm clock makes sure that I dread every Monday morning! ●</td></tr><tr><td colspan="6">f3) My alarm clock always wakes me up on Monday mornings. ●</td></tr><tr><td colspan="6">f4) A white carpet is a great choice when you have messy kids.My alarm clock always wakes me up on Monday mornings. ●</td></tr><tr><td colspan="6">f5) A white carpet is an engaging choice when you have messy kids, if you take extra care.My alarm clock always wakes me up on Monday mornings. ●</td></tr><tr><td></td><td colspan="6">f1 0.47 f2 f1 0.91 f3 f2 0.62 f3 f4 0.78 f5</td></tr><tr><td rowspan="2">Deviant</td><td colspan="6">d1) A female astronaut, because they need sandwiches up there. ●</td></tr><tr><td colspan="6">d2) An astronaut needs sandwiches up there. ●</td></tr><tr><td></td><td></td><td colspan="5">d1 0.76 d2</td></tr></table>
23
+
24
+ Table 1: Instances of figurative $(f_{i},$ sarcasm detection) and deviant $(d_{i},$ sexism detection) language. Similarity scores are based on the stsb-roberta-large cross-encoder model fine-tuned on the STS benchmark introduced by Cer et al. (2017). These scores reveal a deeper problem: a target class instance $(\mathbb{O})$ may be highly dissimilar to several non-target instances $(\bullet)$ while also being very similar to other non-target instances.
25
+
26
+ from Figure 1. In this context, accurate binary classification proves challenging due to the immense linguistic diversity encompassed within the non-target category. $^{3}$ The model must be adept at learning a complex decision boundary without succumbing to overfitting on the training corpus. Thus, the most effective solutions employ sophisticated deep neural models or ensemble methods, which (a) demand large amounts of training data, (b) require significant resources for training and inference, (c) lack interpretability, and (d) depend on careful regularization and hyperparameter tuning.
27
+
28
+ Since the target class has a well-defined function in terms of natural language pragmatics, we conjecture that a detailed study of the target and non-target class distributions will reveal structural differences that can be leveraged to design a model training paradigm better suited for class distillation (ClaD, discussed in §2), and therefore, superior in terms of (a) inferring test instances of the target class, (b) the demands it places on computational resources during training, and (c) interpretability. We test this conjecture on multiple tasks and bench
29
+
30
+ mark datasets (§3), starting with statistical analyses to glean the structural properties and distributional differences between the target and non-target classes (§3.1). With these insights, we develop novel contrastive loss functions derived from Mahalanobis (1936) distance (§4.1), which leverage intra-class covariance to contrast the target class against the diverse and heterogeneous collection of negative samples. We then introduce an interpretable decision algorithm based on the normalized squared Mahalanobis distance (§4.2) to identify target instances.
31
+
32
+ Our results (§5) demonstrate superior inference and resource efficiency across all tasks. We raise two vital questions in §5.2, investigating how small language models with ClaD, given limited task-specific training, compares to LLMs in low-resource transfer learning. We also examine the extent to which increasing LLM size improves performance with identical training data. Recent findings, such as those from DeepSeek (Liu et al., 2024; Guo et al., 2025), underscore the need for such emphasis on economical training and efficient inference. Further, we present ablation experiments to discern (1) the impact of our decision algorithm, (2) the effect of our novel loss function, and (3) whether traditional one-class classification is comparable to ClaD with Mahalanobis contrast.
33
+
34
+ # 2 ClaD: A Whiteboard Discussion
35
+
36
+ Class Distillation (ClaD) is a specialized training paradigm for binary classification, emphasizing the separation of a distinct category from a diverse and often disproportionately larger non-target background. Non-target instances frequently include expressions that are semantically similar to the target class, while also encompassing elements with no syntactic, semantic, or pragmatic resemblance to each other. This dual challenge leads to significant ambiguity and overlap, making accurate classification particularly difficult.
37
+
38
+ The predicament is not specific to a single task, as Table 1 shows with instances from figurative (sar-casm) and deviant (sexism) language use. These examples highlight the limitations of relying solely on simple prompting with large language models for effective inference, as decisions are easily confounded by the diversity of the non-target class. Further, we show in §5.3 that applying straightforward semantic similarity measures fails to capture the nuanced characteristics defining the target class.
39
+
40
+ Drawing insight from Figure 1, the target instances are not uniformly distributed across the feature space; rather, they appear to form a structured subset that can be viewed as a manifold within a higher-dimensional space. To better understand the shape and properties of this manifold, we analyze the structural and distributional characteristics of the target and non-target classes, providing foundational insights into the class geometries and informing novel loss function formulations (§4.1) and ClaD's decision algorithm (§4.2).
41
+
42
+ A visual approach to unveiling the distributional characteristics is relegated to Appendix A, while our systematic analysis of the datasets and target class' geometric properties is presented next.
43
+
44
+ # 3 Tasks and Datasets
45
+
46
+ We concentrate on three tasks for our analyses and experiments: two types of figurative language (sar-casm and metaphors) and one form of deviant language (sexism), utilizing a dedicated benchmark corpus for each to illustrate that the patterns we uncover and the class distillation paradigm we propose are broadly applicable across such tasks.
47
+
48
+ 1. Sarcasm Headlines (SH) is a curated dataset comprising professionally crafted headlines from The Onion and HuffPost (Misra and Arora, 2019, 2023). Notably free of spelling errors and informal language, it offers high-quality labels and self-contained headlines. Compared to social media datasets, it is a clean and reliable resource that precludes concerns about spurious data correlations arising from viral social media trends (Gururangan et al., 2018; Bender et al., 2021).
49
+ 2. Trope Finder (TroFi) (Birke and Sarkar, 2006) is built to distinguish between literal and non-literal verb usage. It leverages the '88-'89 Wall Street Journal (WSJ) Corpus and enhances it with WordNet, databases of idioms and metaphors, and tags from advanced taggers. TroFi improves metaphor detection by minimizing unverified literal uses and addressing the scarcity of non-literal instances.
50
+ 3. Call Me Sexist But ... (CMSB) is an innovative corpus designed to detect sexism, comprising tweets that explicitly use the titular phrase to voice potential sexism (Samory et al., 2021). It is enhanced with synthetic adversarial modifications to challenge machine learning models.
51
+
52
+ <table><tr><td>Model</td><td>Class</td><td colspan="4">Empirical normality test statistics</td></tr><tr><td></td><td></td><td>HZ</td><td colspan="3">Anderson-Darling</td></tr><tr><td></td><td></td><td></td><td>d1</td><td>d2</td><td>d3</td></tr><tr><td colspan="6">Task + Corpus: Metaphor detection on TroFi</td></tr><tr><td rowspan="2">BERT</td><td>Metaphor</td><td>5.14</td><td>1.53</td><td>2.59</td><td>1.96</td></tr><tr><td>Other</td><td>5.93</td><td>1.83</td><td>1.71</td><td>3.40</td></tr><tr><td rowspan="2">SimCSE</td><td>Metaphor</td><td>4.32</td><td>2.83</td><td>2.11</td><td>0.70</td></tr><tr><td>Other</td><td>5.19</td><td>2.94</td><td>2.79</td><td>1.54</td></tr><tr><td colspan="6">Task + Corpus: Sarcasm detection on Sarcasm Headlines</td></tr><tr><td rowspan="2">BERT</td><td>Sarcasm</td><td>29.94</td><td>13.67</td><td>10.14</td><td>24.99</td></tr><tr><td>Other</td><td>33.24</td><td>13.87</td><td>23.95</td><td>5.76</td></tr><tr><td rowspan="2">SimCSE</td><td>Sarcasm</td><td>21.49</td><td>19.00</td><td>16.38</td><td>23.68</td></tr><tr><td>Other</td><td>24.82</td><td>12.21</td><td>32.65</td><td>42.99</td></tr><tr><td colspan="6">Task + Corpus: Sexism detection on Call Me Sexist But</td></tr><tr><td rowspan="2">BERT</td><td>Sexism</td><td>7.48</td><td>0.97</td><td>1.79</td><td>9.27</td></tr><tr><td>Other</td><td>34.08</td><td>6.70</td><td>40.34</td><td>23.96</td></tr><tr><td rowspan="2">SimCSE</td><td>Sexism</td><td>6.38</td><td>2.34</td><td>2.99</td><td>2.08</td></tr><tr><td>Other</td><td>21.21</td><td>17.07</td><td>1.77</td><td>9.11</td></tr></table>
53
+
54
+ Table 2: Empirical results on how well the target and non-target classes fit (a) multivariate normality, using the Henze-Zirkler (HZ) statistic, and (b) univariate normality on the three t-SNE dimensions $d_{1}, d_{2}, d_{3}$ , using the Anderson-Darling statistic. For both tests, larger numbers indicate greater deviation from normality.
55
+
56
+ # 3.1 Statistical Tests of Normality
57
+
58
+ To systematically analyze the geometric properties of target class representations, we evaluate the normality of the embedding distributions in reduced dimensionality space. Specifically, we apply the HZ (Henze and Zirkler, 1990) test to assess multivariate normality across three t-SNE dimensions for BERT and SimCSE, examining three pragmatic language detection tasks: metaphor, sarcasm, and sexism. We complement this with AD (Anderson and Darling, 1952) tests to evaluate univariate normality along individual dimensions. The results (Table 2) offer a rigorous statistical characterization of the manifold structure, beyond the Q-Q plot inspections shown in Appendix A.
59
+
60
+ The HZ tests consistently show lower values for target data (metaphor, sarcasm, and sexism) compared to non-target data, indicating that target data are closer to a multivariate normal distribution
61
+
62
+ compared to their non-target counterparts. This is further supported by the results of the AD tests along each dimension. Reduced deviation from the theoretical distribution suggests that the target data exhibits a more homogeneous manifold structure. In contrast, the non-target data manifests greater diversity and complexity. Thus, in line with the argument presented earlier with illustrative examples (§ 2), it is indeed less likely that they possess discernible common traits beyond their opposition to the target class. Hence, we hypothesize that a loss function ought to be designed primarily around the target class. The consistency and regularity of the target class' distribution provide a more reliable foundation for learning stable predictors, in contrast to the somewhat more chaotic diversity observed in the distribution of the non-target class.
63
+
64
+ # 4 Training and Inference
65
+
66
+ Mahalanobis (1936) distance is ideal for data approximating a multivariate normal distribution, as it accounts for the manifold structure of the target class, rendering the distance measure scale-invariant. By incorporating the variance and correlations among variables, it accurately reflects the underlying distribution of the data and thereby improves discrimination in detecting non-target instances by robust identification of outliers, reducing false positives. Accordingly, we explore Mahalanobis distance in formulating the loss function.
67
+
68
+ # 4.1 Mahalanobis Loss
69
+
70
+ Let $\mathcal{X} = \{x_i\}, \mathcal{Y} = \{y_j\}$ denote $n$ target and $m$ non-target training samples (resp.). Further, let $f: \mathcal{X} \cup \mathcal{Y} \mapsto \mathbb{R}^d$ denote a representation function mapping these instances to $d$ dimensions. For a given instance $x \in \mathcal{X}$ , we randomly select $x^+ \in \mathcal{X} \setminus \{x\}$ , and $y^- \in \mathcal{Y}$ . These random selections are employed to learn a representation that minimizes (maximizes) the similarity between $x$ and $y^-(x^+)$ . We achieve this with Mahalanobis loss:
71
+
72
+ $$
73
+ \mathcal {L} _ {\mathrm {M A H}} = \frac {1}{| \mathcal {X} |} \sum_ {x \in \mathcal {X}} \frac {\operatorname {s i m} _ {\mathrm {M A H}} \left(x , y ^ {-}\right)}{\operatorname {s i m} _ {\mathrm {M A H}} \left(x , x ^ {+}\right) + \operatorname {s i m} _ {\mathrm {M A H}} \left(x , y ^ {-}\right)} \tag {1}
74
+ $$
75
+
76
+ where $\mathrm{sim}_{\mathrm{MAH}}(x,y)$ is defined using the covariance matrix $\Sigma$ of the set $\{f(x_i)\}$
77
+
78
+ $$
79
+ \begin{array}{l} \operatorname {s i m} _ {\mathrm {M A H}} (x, y) = \\ \exp \left\{- \frac {\left(f (x) - f (y)\right) ^ {T} \Sigma^ {- 1} (f (x) - f (y))}{d} \right\}. \\ \end{array}
80
+ $$
81
+
82
+ Algorithm 1 Mahalanobis $\beta$ -decision algorithm
83
+ Require: New instance $X = X^{*}$ $X_{n + 1} \gets X^{*}$ $\hat{\mu} \gets \frac{1}{n + 1} \sum_{i = 1}^{n + 1} X_i$
84
+ Compute $\hat{\Sigma}$ as the sample covariance matrix of $X_1, \ldots, X_{n + 1}$ $d_{n + 1}^2 (\hat{\mu}, \hat{\Sigma}) \gets (X_{n + 1} - \hat{\mu})^T \hat{\Sigma}^{-1} (X_{n + 1} - \hat{\mu})$ $T \gets \frac{n + 1}{n^2} d_{n + 1}^2 (\hat{\mu}, \hat{\Sigma})$
85
+ Compute the critical value $v_\beta$ for $\mathrm{Beta}\left(\frac{d}{2}, \frac{n - d}{2}\right)$
86
+ if $T < v_\beta$ then
87
+ $X \gets 1$ $\triangleright$ Target class
88
+ else
89
+ $X \gets 0$ $\triangleright$ Non-target class
90
+ end if
91
+
92
+ Alternatively, Mahalanobis mean loss uses the mean $\mu$ of $\{f(x_i)\}$ :
93
+
94
+ $$
95
+ \begin{array}{l} \mathcal {L} _ {\mathrm {M A H}, \mu} = - \frac {1}{| \mathcal {X} |} \sum_ {(x, y ^ {-}) \in \mathcal {X}} \left[ \log \left(\operatorname {s i m} _ {\mathrm {M A H}} (\mu , x)\right) \right. \tag {2} \\ \left. + \log \left(1 - \operatorname {s i m} _ {\mathrm {M A H}} \left(\mu , y ^ {-}\right)\right) \right]. \\ \end{array}
96
+ $$
97
+
98
+ It maximizes the similarity between a target instance $x$ and the mean representation of the target class (making the class more compact), and minimizes the similarity between a negative example $y^{-}$ and the mean (increasing inter-class margin).
99
+
100
+ # 4.2 Inference and Decision Algorithm
101
+
102
+ The inference task is, fundamentally, identical to that of any supervised binary classifier: ascertain if a test instance belongs to the target class. Given representations $\{\mathbf{x}_1,\mathbf{x}_2,\dots ,\mathbf{x}_n\}$ with sample mean $\hat{\mu}$ and covariance matrix $\Sigma$ adhering to a multivariate normal distribution, the squared Mahalanobis distance for a specific observation $\mathbf{x}_i$ is given by
103
+
104
+ $$
105
+ d _ {i} ^ {2} (\hat {\mu}, \Sigma) = \left(\mathbf {x} _ {i} - \hat {\mu}\right) ^ {T} \Sigma^ {- 1} \left(\mathbf {x} _ {i} - \hat {\mu}\right), \tag {3}
106
+ $$
107
+
108
+ which follows the Beta distribution (Wilks, 1962; Ververidis and Kotropoulos, 2008):
109
+
110
+ $$
111
+ \frac {n}{(n - 1) ^ {2}} d _ {i} ^ {2} (\hat {\mu}, \Sigma) \sim \operatorname {B e t a} \left(\frac {d}{2}, \frac {n - d - 1}{2}\right) \tag {4}
112
+ $$
113
+
114
+ This insight informs the design of the Mahalanobis $\beta$ -decision algorithm (Algorithm 1), to test an instance for class membership by comparing its normalized squared Mahalanobis distance to critical values of the corresponding Beta distribution.
115
+
116
+ # 5 Experiments and Results
117
+
118
+ We empirically evaluate $^{6}$ ClaD across two challenging categories of language understanding tasks:
119
+
120
+ ![](images/7fed3bd3e827cf383cbb29dc9e0ae6a01ee73f63669d93f462a193ddb623b98c.jpg)
121
+ (a) Figurative language: sarcasm detection using the Sarcasm Headlines (SH) corpus (Misra and Arora, 2023).
122
+
123
+ ![](images/b92d8c3339068063164c545b5b2787b4da36275f9677175069dd1c09ee5f2955.jpg)
124
+
125
+ ![](images/b3b1b89109466fb69ab20933927e3be30242cb4ee909bd1c1308c3ac6875af91.jpg)
126
+
127
+ ![](images/321f5d7fc89c4f88252cb13a1bbf22bfcc21dab590a3bc58fe8c355211c86bb0.jpg)
128
+
129
+ ![](images/a71d1566c0220a7217c7275061f1203f004f57439740d7c9f30d8b7e471c2432.jpg)
130
+ (b) Figurative language: metaphor detection using the Trope Finder (TroFi) corpus (Birke and Sarkar, 2006).
131
+
132
+ ![](images/d92437a34852ab498a271a498b56ab660df2604ad583042134b97e6aeab98184.jpg)
133
+
134
+ ![](images/6ba7ae5958d958f0559f4ef2588f1151471209b93d8d300820838178d52038a1.jpg)
135
+
136
+ ![](images/28f5ae564820bd56e11f112b8f4c90a0c3d16997016189a4dd089e910a5165cd.jpg)
137
+
138
+ ![](images/421a61284ea9c3fcf8ca94c860def03d17743d50f234469296193dea292cbc5b.jpg)
139
+ (c) Deviant language: sexism detection using the Call me sexist but ... (CMSB) corpus (Samory et al., 2021).
140
+
141
+ ![](images/8547aae874dd35148529bfc8a43fab50605a44acc419ce9728483381e6709496.jpg)
142
+ Figure 2: Comparison of ClaD across three detection tasks (from top to bottom) – (a) sarcasm, (b) metaphors, and (c) sexism – against four transfer learning baseline results where Transformer-based models are fine-tuned on task-specific data: (from left to right) ALBERT, DistilBERT, SimCSE, and XLNet.
143
+
144
+ ![](images/99ce198283d68faed49985ee13dc964cdef01c295ac2301c15fe43f9787e4018.jpg)
145
+
146
+ ![](images/92c2d73ff6ee39f9c2a68b7f472f40a3582acf9849800d3ea6a79fff927fb7a6.jpg)
147
+
148
+ detecting figurative (metaphor and sarcasm) and harmful (sexism) language. ClaD leverages the Mahalanobis mean loss, $\mathcal{L}_{\mathrm{MAH},\mu}$ (Eq. 2), to fine-tune pretrained embeddings, followed by inference with the Mahalanobis $\beta$ -decision algorithm (Alg. 1).
149
+
150
+ ClaD is benchmarked against two modern language model paradigms: (a) specialized encoder(-decoder) architectures optimized for language understanding: SimCSE (Gao et al., 2021), ALBERT (Lan et al., 2020), DistilBERT (Sanh et al., 2019), and XLNet (Yang et al., 2019), and (b) large language models (LLMs), primarily decoder-only architectures distinguished by their scale. We evaluate all models on 80/10/10 splits for train/dev/test, primarily focusing on the false positive rate (FPR) and $F_{1}$ score for the target class.
151
+
152
+ # 5.1 Comparison with Encoder-based Models
153
+
154
+ Figure 2 illustrates ClaD's distinctive advantage: achieving performance competitive with or superior to these established models in just one training epoch. In contrast, transfer learning with these models typically requires 3-5 epochs to attain similar metrics across all three tasks. ClaD's rapid convergence yields substantial computational savings without compromising detection quality. For instance, in sarcasm detection, ClaD achieves a lower FPR after one epoch than most baselines do after five. Similar patterns emerge across all tasks and metrics, where ClaD's single-epoch training matches or outperforms multi-epoch training of the transfer-learning baseline models. The results suggest that ClaD's geometric approach enables efficient adaptation to task-specific features, a finding further supported by our ablation study (§5.3).
155
+
156
+ ![](images/e3932976b7b1930e04c02d7ce193b7f8a71140d204e99d4183972e7018df3c3f.jpg)
157
+ (a) Figurative language: sarcasm
158
+
159
+ ![](images/6d91e2db1a7ed4903b177d6f7218e18ddf1d04fef3ead2b033d3f216ec15015f.jpg)
160
+ (b) Figurative language: metaphors
161
+ Figure 3: Comparison of 5-shot evaluation of a suite of nine large language models (left to right): Llama2, Llama3, Phi2, Phi3, Mistral-7B, Falcon, Qwen2, GPT-2, and OPT, against ClaD's single-epoch training (rightmost).
162
+
163
+ ![](images/cbee9ed5fa73aac2b8ccb870945cebb2010ea8c18c7de77242b4e3e38e40cd4e.jpg)
164
+ (c) Deviant language: sexism
165
+
166
+ # 5.2 Comparison with Large Language Models
167
+
168
+ Next, we evaluate ClaD against a suite of recent large language models (LLMs): OPT, GPT, Phi, Llama, Mistral, Qwen, and Falcon. As ClaD is a training paradigm, and not a model, these evaluations are geared to answer two research questions:
169
+
170
+ Q1. Is limited task-specific ClaD-training with small language models better than low-resource transfer-learning with LLMs?
171
+ Q2. With identical training data, how much larger are the LLMs (if any) that outperform ClaD-training with small language models?
172
+
173
+ Against all LLMs in zero-shot (Appendix C) and few-shot scenarios (discussed next), ClaD demonstrates consistently superior performance.
174
+
175
+ Few-shot Classification: As shown in Figure 3, ClaD retains its substantial advantage over few-shot classification (five instances) with LLMs, which achieve markedly lower $F_{1}$ scores: from $0.0\%$ (GPT-2) to $64.2\%$ (Qwen-2) on $SH$ ; $0.0\%$ (GPT-2) to $72.6\%$ (Falcon) on $TroFi$ , and $0.0\%$ (Falcon) to $25.6\%$ (OPT) on $CMSB$ . Models exhibit distinct characteristics in each task: for example, in metaphor detection, GPT-2, Llama2, and Phi3 completely avoid positive predictions, while Falcon predicts aggressively with perfect recall. The most dramatic changes are seen in deviant language detection, with more models completely avoiding the target class (Falcon, Qwen2, and GPT-2). OPT, on the other hand, exhibits perfect recall. Despite accuracy ranges similar to zero-shot, models show more extreme precision-recall trade-offs, with AUC scores stalled near 0.5 and persistently high FPR.
176
+
177
+ LLMs thus exhibit notable limitations and variability across all tasks, likely stemming from insufficient feature learning in low-resource scenarios (reflected in the AUC stagnation), causing them to fall back on their pretrained biases, particularly for subtle, context-dependent linguistic cues. The er
178
+
179
+ ratic behavior changes between zero- and few-shot settings also suggest unstable optimization paths, possibly due to the large parameter count in these models, stochasticity of gradient updates, and insufficient regularization.
180
+
181
+ Low-resource Training: We extend our analysis to low-resource training (with 100 instances provided to the LLMs) to examine whether this limited increase in data improves decision stability, precision-recall trade-offs, and task adaptation. ClaD's single-epoch training continues to outperform all LLMs in terms of both $F_{1}$ score and FPR, except in metaphor detection. There, although GPT-2, Falcon, and OPT report lower FPRs for the first two epochs, their $F_{1}$ scores are nearly zero as they completely avoid false positives (which comes at the cost of failing to avoid any positives). Figure 4 reveals clear patterns across model scales: while the smaller XLNet-based ClaD achieves superior performance within one epoch, larger models like Llama3 (8B parameters) require multiple epochs to reach their peak performance (e.g., $77.6\%$ $F_{1}$ at epoch 6 for sarcasm detection). Model size significantly impacts learning trajectories: large models (7B-8B parameters) show rapid initial improvements, mid-size models (2B-4B parameters) plateau early with suboptimal performance, and smaller models (124M-350M parameters) struggle to learn effectively. Sexism detection remains the most challenging task, with all LLMs showing conservative labeling of the target class and an inability to learn from limited data. In sarcasm detection, the only task where LLMs perform significantly better than chance, FPR correlates inversely with model size, ranging from $15.4\%$ (Llama3, epoch 8) to $48.1\%$ (GPT-2, epoch 10).
182
+
183
+ Identical Task-specific Training Data: To address our second research question, we compare ClaD's single-epoch training with smaller models
184
+
185
+ ![](images/155abee221fee7a8a5062907c084ea28f2fa03c0b3b2d7afee4e0a1af96bd7ab.jpg)
186
+
187
+ ![](images/e43a2ebd2941a2154d8336d2d455d164439936fbfce722d6d04d863a3c8c2bb8.jpg)
188
+ (a) Figurative language: sarcasm
189
+
190
+ ![](images/af07653ba41e633d5e1d42c87372ac569f501eda9a748c5be9d256ffe4423215.jpg)
191
+
192
+ ![](images/d48522ac5d3584774d4154e3bafa3a1843b329ea872d78aa7a98f4f9ef636a0c.jpg)
193
+ (b) Figurative language: metaphors
194
+
195
+ ![](images/90713215c7175ae4ff099df90a9c3e3500e953f4b24947dd120b0e4f8aec7681.jpg)
196
+
197
+ ![](images/4123c829b17722dd1e2d672a447440de4409fa05896221c7ea360e340ff5654c.jpg)
198
+ (c) Deviant language: sexism
199
+
200
+ ![](images/a6e90989e5f44aaaf73944105ea93516a98cecb9a546054d4b5ed5b209f3d619.jpg)
201
+ Figure 4: Comparison of ClaD across the three detection tasks against nine large language models (LLMs) in a limited data regime. The LLMs are trained on 100 instances over 10 epochs. Results shown for the target class are: (top) the $F_{1}$ scores; and (bottom) the false positive rates (FPR) for the best-performing LLM.
202
+ (a) Figurative language: sarcasm
203
+ Figure 5: Comparison of ClaD across the three detection tasks against LLMs, with identical training data: all models utilize the entire training set for a single epoch. $F_{1}$ scores (top) show ClaD being competitive with most LLMs, and outperforming a few others, while false positive rates (FPR) (bottom) show ClaD remaining superior to the LLMs.
204
+
205
+ ![](images/3530c43f0b1f7df9f46a8198cf4ebe9389af3c13cccdd134e5b342c784487b8b.jpg)
206
+ (b) Figurative language: metaphors
207
+
208
+ ![](images/0435fadc299c92d85434ec9c4fb8538285d23f2f156910e4dd410ca1cd0fa785.jpg)
209
+ (c) Deviant language: sexism
210
+
211
+ against the suite of LLMs (Figure 5).10
212
+
213
+ The relationship between model size and performance varies significantly across tasks. While larger models (7-8B parameters) generally perform well in sarcasm detection ( $F_{1}$ : 0.96-0.97), this advantage diminishes in metaphor detection ( $F_{1}$ : 0.71-0.81) and almost disappears in sexism detection, where many smaller models achieve competitive performance. This suggests that larger models do not consistently translate to better performance across pragmatic language understanding tasks.
214
+
215
+ More often than not, performance improves with increased model size, but with diminishing returns. A striking pattern emerges in the false positive rates, however: while larger models show very low FPR in sarcasm detection $(\sim 0.03)$ , their FPR varies widely in other tasks, sometimes performing worse than smaller models. Particularly interesting is deviant language (sexism) detection, where even the largest models struggle with high FPR. The consistent performance of XLNet-based ClaD, with
216
+
217
+ only 110M params, especially in maintaining lower FPR across tasks while remaining competitive on $F_{1}$ scores, suggests that efficiency derived from a geometric understanding eclipses model size.
218
+
219
+ # 5.3 Ablation Experiments
220
+
221
+ We conduct systematic ablation experiments to evaluate the individual contributions of ClaD's core components: the novel loss function, the decision algorithm, and the Mahalanobis contrast mechanism. We present comparisons using SimCSE as the base model, as it achieved the lowest false positive rate in sarcasm detection.[11] The impact of our novel loss function is evident in Table 3. Compared to standard loss functions in task-specific fine-tuning, $F_{1}$ scores improve by $26.5\%$ , $6\%$ , and $13\%$ for sarcasm, metaphor, and sexism detection, respectively (with corresponding proportionate decreases seen in FPR: $24.6\%$ , $39.1\%$ , and $15.3\%$ ). On the other hand, replacing our $\beta$ -decision algorithm with a 3-layer fully
222
+
223
+ <table><tr><td></td><td>Acc ↑</td><td>Pr ↑</td><td>FPR ↓</td><td>F1 ↑</td></tr><tr><td colspan="5">Sarcasm detection on Sarcasm Headlines</td></tr><tr><td>LMAH + β-decision</td><td>0.896</td><td>0.931</td><td>0.009</td><td>0.885</td></tr><tr><td>LCOSINE + β-decision</td><td>0.492</td><td>0.479</td><td>0.255</td><td>0.620</td></tr><tr><td>LMAH + MLP</td><td>0.521</td><td>0.482</td><td>0.209</td><td>0.300</td></tr><tr><td colspan="5">Metaphor detection on TroFi</td></tr><tr><td>LMAH + β-decision</td><td>0.794</td><td>0.857</td><td>0.167</td><td>0.808</td></tr><tr><td>LCOSINE + β-decision</td><td>0.675</td><td>0.667</td><td>0.558</td><td>0.748</td></tr><tr><td>LMAH + MLP</td><td>0.433</td><td>0.000</td><td>0.000</td><td>0.000</td></tr><tr><td colspan="5">Sexism detection on Call Me Sexist But</td></tr><tr><td>LMAH + β-decision</td><td>0.928</td><td>0.870</td><td>0.012</td><td>0.696</td></tr><tr><td>LCOSINE + β-decision</td><td>0.832</td><td>0.433</td><td>0.165</td><td>0.566</td></tr><tr><td>LMAH + MLP</td><td>0.134</td><td>0.134</td><td>1.000</td><td>0.236</td></tr></table>
224
+
225
+ Table 3: Ablation study comparing ClaD's components: $\mathcal{L}_{\mathrm{MAH}}$ (our Mahalanobis contrast loss), $\mathcal{L}_{\mathrm{COSINE}}$ (the standard cosine similarity loss), and $\beta$ -decision (Algorithm 1). The combination of $\mathcal{L}_{\mathrm{MAH}} + \beta$ -decision achieves superior performance across all metrics, particularly in reducing false positive rates (FPR) while maintaining high $F_{1}$ and target-class precision.
226
+
227
+ connected feed-forward network for classification results in the $F_{1}$ scores dropping by $58.5\%$ , $80.8\%$ , and $46.0\%$ on these tasks, respectively. Finally, we show in Appendix D that traditional one-class classification and anomaly detection methods do not perform well in these pragmatic language tasks where the minority target class requires gleaning from a large heterogeneous non-target majority.
228
+
229
+ # 6 Related Work
230
+
231
+ Extensive research aims to model pragmatic language nuances for respectful communication, advancing the identification of figurative language (Chakrabarty et al., 2022; Saakyan et al., 2022; Wachowiak and Gromann, 2023; Lai and Nissim, 2024) and deviant content (Fortuna and Nunes, 2018; Yin and Zubiaga, 2021; Guest et al., 2021; Bose and Su, 2022). Most leverage BERT-based supervised learning: e.g., BERT-BiLSTM for hate speech (Bose and Su, 2022), dual BERT models for metaphors (Wan et al., 2021), and BERT-LSTM for sarcasm (Kumar and Anand, 2020). Enhancements include syntactic (Wan et al., 2020) or semantic (Zhou et al., 2021) feature integration and multi-task frameworks (Safi Samghabadi et al., 2020). However, generalization remains limited, and ensemble methods (Lemmens et al., 2020; Gregory et al., 2020) trade interpretability for computational cost. Our Class Distillation (ClaD) paradigm addresses these gaps via an interpretable decision
232
+
233
+ algorithm and novel loss function.
234
+
235
+ ClaD shares similarities with one-class classification, which detects anomalies by focusing on the target class. Common methods include one-class SVM (Schölkopf et al., 2001; Noumir et al., 2012), DeepSVDD (Ruff et al., 2018), and adversarial one-class classifiers (Sabokrou et al., 2018), but they often struggle with domain generalization, overfitting, and nuanced data - key challenges in pragmatic language tasks. ClaD, leveraging Mahalanobis contrast, effectively addresses these issues, demonstrated by ablation results in Appendix D.
236
+
237
+ LLMs like GPT-2 (Radford et al., 2019), Phi-2 (Jahaveripi et al., 2023), and OPT (Zhang et al., 2022) excel in text classification but are computationally expensive (Wang et al., 2023). Some, like GPT-3, reportedly struggle with nuanced tasks like metaphor detection (Wachowiak and Gromann, 2023), while others face reasoning limitations and token constraints in in-context learning (Sun et al., 2023). Unlike recent efforts to address these issues, ClaD combines Mahalanobis contrast with smaller models, to efficiently learning task manifolds.
238
+
239
+ # 7 Conclusion
240
+
241
+ This work challenges a fundamental implicit assumption in modern NLP: that scale (in models, pretraining data, or fine-tuning) guarantees superior downstream performance. Through rigorous empirical analysis, we demonstrate that our geometrically grounded training paradigm surpasses state-of-the-art LLMs by significant margins in low-data regimes, achieving superior results in a single epoch where larger models plateau after several. Notably, ClaD matches or exceeds the performance of models nearly two orders of magnitude larger, even with identical task-specific training.
242
+
243
+ Our findings align with broader trends toward efficiency, spurred by DeepSeek's compute-optimal scaling (Liu et al., 2024; Guo et al., 2025), and reveal a novel insight: architectural minimalism, coupled with geometric alignment to task manifolds, can unlock capabilities previously thought to require massive scale. While recent work optimizes how to scale, we demonstrate that whether to scale depends critically on data geometry. ClaD's innovations – manifold-aware training, Mahalanobis contrast, and the decision algorithm – prove that for nuanced language understanding tasks, modeling latent structure trumps brute-force scaling.
244
+
245
+ Our work does not negate scaling, but expands
246
+
247
+ the efficiency frontier, showing that geometric principles can supplant scale and provide a complementary pathway for real-world applications. As AI research increasingly prioritizes efficiency alongside performance – whether through scaling laws, sparsity, or geometric learning – our findings position the geometric understanding of data as a foundational pillar of sustainable NLP.
248
+
249
+ # Limitations
250
+
251
+ While our proposed Class Distillation (ClaD) paradigm demonstrates consistently strong performance and efficiency across sarcasm, metaphor, and sexism detection tasks – outperforming smaller Transformer models with equal training, and LLMs with in limited resource settings – several limitations should be acknowledged. First, although we tested ClaD on diverse tasks encompassing figurative and deviant language, the chosen benchmarks (Sarcasm Headlines, TroFi, and CMSB) may not fully capture the richness of real-world scenarios, and more domain-specific or multilingual tasks could present additional linguistic and cultural nuances not addressed in our current study. Whether our approach can be generalized to specialized domains like legal or clinical tasks also remains to be seen. Second, ClaD relies on the ability of the target class manifold to be modeled as a multivariate normal distribution. While our experiments suggest that training can nudge embeddings closer to a normal manifold, this assumption may not hold universally: certain representations or highly imbalanced corpora may exhibit multimodal or heavy-tailed distributions with substantial deviation from normality, potentially affecting performance. Third, although ClaD's fast convergence leads to significant computational savings compared to multi-epoch fine-tuning, maintaining a dynamically updated covariance matrix in the Mahalanobis distance computation can be memory-intensive for very large datasets. More memory-efficient approximations or low-rank updates can be useful.
252
+
253
+ These limitations may be addressed by exploring alternative distributional assumptions (e.g., Gaussian mixtures) to accommodate more complex embedding spaces, conducting broader evaluations across languages and task domains, and developing lightweight variants of Mahalanobis-based training to reduce the memory overhead. They have the potential to further enhance ClaD's versatility and impact in real-world applications.
254
+
255
+ # Ethics Statement
256
+
257
+ This work adheres to ethical standards in NLP research by ensuring transparency, reproducibility, and fairness in our experiments. Our study does not involve human subjects or sensitive data, and all datasets used are publicly available with appropriate licenses. While our findings highlight efficiency gaps in large-scale language models, we acknowledge that their broader societal impacts, including biases and potential misuse, require further investigation. We encourage responsible deployment of our proposed methods and emphasize the need for continued ethical scrutiny in model development and evaluation.
258
+
259
+ # Acknowledgments
260
+
261
+ This work was supported in part by the U.S. National Science Foundation (NSF) Division of Computer and Network Systems under the award CNS-2335686. The authors thank the anonymous reviewers for their constructive feedback and Biqing Yang and Xinyu Zhang from the Department of Statistics at Ohio State University for inspiring discussions. Computational resources for some parts of this work were provided by the AI Innovation Institute at Stony Brook University.
262
+
263
+ # References
264
+
265
+ Theodore W. Anderson and Donald Darling. 1952. Asymptotic Theory of Certain "Goodness of Fit" Criteria Based on Stochastic Processes. Annals of Mathematical Statistics, 23:193-212.
266
+ Angeliki Athanasiadou. 2024. On the margins of figurative thought and language. *Lingua*, 299:103655.
267
+ Richard Bellman. 1957. Dynamic Programming. Princeton University Press.
268
+ Emily M. Bender, Timnit Gebru, Angelina McMillan-Major, and Shmargaret Shmitchell. 2021. On the Dangers of Stochastic Parrots: Can Language Models Be Too Big? In Proceedings of the 2021 ACM Conference on Fairness, Accountability, and Transparency, FAccT '21, page 610-623, New York, NY, USA. Association for Computing Machinery.
269
+ Julia Birke and Anoop Sarkar. 2006. A Clustering Approach for Nearly Unsupervised Recognition of Non-literal Language. In 11th Conference of the European Chapter of the Association for Computational Linguistics, pages 329-336, Trento, Italy. Association for Computational Linguistics.
270
+ Saugata Bose and Guoxin Su. 2022. Deep one-class hate speech detection model. In Proceedings of the
271
+
272
+ Thirteenth Language Resources and Evaluation Conference, pages 7040-7048.
273
+ Daniel Cer, Mona Diab, Eneko Agirre, Inigo Lopez-Gazpio, and Lucia Specia. 2017. SemEval-2017 Task 1: Semantic Textual Similarity Multilingual and Crosslingual Focused Evaluation. In Proceedings of the 11th International Workshop on Semantic Evaluation (SemEval-2017), pages 1-14. Association for Computational Linguistics.
274
+ Tuhin Chakrabarty, Arkadiy Saakyan, Debanjan Ghosh, and Smaranda Muresan. 2022. FLUTE: Figurative Language Understanding through Textual Explanations. arXiv, 2205.12404v3.
275
+ Raghavendra Chalapathy and Sanjay Chawla. 2019. Deep Learning for Anomaly Detection: A Survey. arXiv, 1901.03407.
276
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4171-4186, Minneapolis, Minnesota. Association for Computational Linguistics.
277
+ Kawin Ethayarajh. 2019. How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), pages 55–65, Hong Kong, China. Association for Computational Linguistics.
278
+ Paula Fortuna and Sérgio Nunes. 2018. A Survey on Automatic Detection of Hate Speech in Text. ACM Computing Surveys, 51(4):1-30.
279
+ Tianyu Gao, Xingcheng Yao, and Danqi Chen. 2021. SimCSE: Simple Contrastive Learning of Sentence Embeddings. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 6894-6910. Association for Computational Linguistics.
280
+ Mengshi Ge, Rui Mao, and Erik Cambria. 2023. A survey on computational metaphor processing techniques: from identification, interpretation, generation to application. Artif. Intell. Rev., 56(2):1829-1895.
281
+ Debanjan Ghosh, Avijit Vajpayee, and Smaranda Muresan. 2020. A Report on the 2020 Sarcasm Detection Shared Task.
282
+ Hunter Gregory, Steven Li, Pouya Mohammadi, Natalie Tarn, Rachel Draelos, and Cynthia Rudin. 2020. A Transformer Approach to Contextual Sarcasm Detection in Twitter. In Proceedings of the Second Workshop on Figurative Language Processing, pages 270-275. Association for Computational Linguistics.
283
+
284
+ Ella Guest, Bertie Vidgen, Alexandros Mittos, Nishanth Sastry, Gareth Tyson, and Helen Margetts. 2021. An Expert Annotated Dataset for the Detection of Online Misogyny. In Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume, pages 1336-1350, Online. Association for Computational Linguistics.
285
+ Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Ruoyu Zhang, Runxin Xu, et al. 2025. DeepSeekR1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. arXiv, 2501.12948.
286
+ Suchin Gururangan, Swabha Swayamdipta, Omer Levy, Roy Schwartz, Samuel Bowman, and Noah A. Smith. 2018. Annotation Artifacts in Natural Language Inference Data. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers), pages 107-112. Association for Computational Linguistics.
287
+ Pengcheng He, Xiaodong Liu, Jianfeng Gao, and Weizhu Chen. 2021. DeBERTa: Decoding-Enhanced BERT With Disentangled Attention. In International Conference on Learning Representations.
288
+ Norbert Henze and Bernd Zirkler. 1990. A class of invariant consistent tests for multivariate normality. Communications in Statistics-theory and Methods, 19:3595-3617.
289
+ Harold Hotelling. 1936. Relations between two sets of variates. Biometrika, 28(3/4):321 - 377.
290
+ Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. 2022. LoRA: Low-Rank Adaptation of Large Language Models. In International Conference on Learning Representations.
291
+ Mojan Javaheripi, Sébastien Bubeck, Marah Abdin, Jyoti Aneja, Sebastien Bubeck, Caio César Teodoro Mendes, Weizhu Chen, Allie Del Giorno, Ronen Eldan, Sivakanth Gopi, et al. 2023. Phi-2: The surprising power of small language models. Microsoft Research Blog.
292
+ Kristina Kasparian. 2013. Hemispheric differences in figurative language processing: Contributions of neuroimaging methods and challenges in reconciling current empirical findings. Journal of Neurolinguistics, 26(1):1-21.
293
+ Roger Kiska. 2012. Hate Speech: A Comparison between the European Court of Human Rights and the United States Supreme Court Jurisprudence. *Regent University Law Review*, 25:107.
294
+ Amardeep Kumar and Vivek Anand. 2020. Transformers on sarcasm detection with context. In Proceedings of the second workshop on figurative language processing, pages 88-92.
295
+
296
+ Huiyuan Lai and Malvina Nissim. 2024. A Survey on Automatic Generation of Figurative Language: From Rule-based Systems to Large Language Models. ACM Comput. Surv., 56(10).
297
+ Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. 2020. ALBERT: A Lite BERT for Self-supervised Learning of Language Representations. In International Conference on Learning Representations (ICLR).
298
+ Jens Lemmens, Ben Burtenshaw, Ehsan Lotfi, Ilia Markov, and Walter Daelemans. 2020. Sarcasm Detection Using an Ensemble Approach. In Proceedings of the Second Workshop on Figurative Language Processing, pages 264-269. Association for Computational Linguistics.
299
+ Aixin Liu, Bei Feng, Bing Xue, Bingxuan Wang, Bochao Wu, Chengda Lu, Chenggang Zhao, et al. 2024. DeepSeek-V3 Technical Report. Technical report, DeepSeek-AI.
300
+ Fei Tony Liu, Kai Ming Ting, and Zhi-Hua Zhou. 2008. Isolation Forest. In 2008 Eighth IEEE International Conference on Data Mining, pages 413-422.
301
+ Fei Tony Liu, Kai Ming Ting, and Zhi-Hua Zhou. 2010. On Detecting Clustered Anomalies Using SCiForest. In Machine Learning and Knowledge Discovery in Databases, pages 274-290, Berlin, Heidelberg. Springer Berlin Heidelberg.
302
+ Prasanta Chandra Mahalanobis. 1936. On the Generalized Distance in Statistics. Proceedings of the National Institute of Sciences of India, 2(1):49-55.
303
+ Rishabh Misra and Prahal Arora. 2019. Sarcasm Detection using Hybrid Neural Network. arXiv, 1908.07414.
304
+ Rishabh Misra and Prahal Arora. 2023. Sarcasm detection using news headlines dataset. AI Open, 4:13-18.
305
+ Zineb Noumir, Paul Honeine, and Cédue Richard. 2012. On simple one-class classification methods. In 2012 IEEE International Symposium on Information Theory Proceedings, pages 2022-2026.
306
+ Shereen Oraby, Vrindavan Harrison, Lena Reed, Ernesto Hernandez, Ellen Riloff, and Marilyn Walker. 2016. Creating and Characterizing a Diverse Corpus of Sarcasm in Dialogue. In Proceedings of the 17th Annual Meeting of the Special Interest Group on Discourse and Dialogue, pages 31-41, Los Angeles. Association for Computational Linguistics.
307
+ Karl Pearson. 1901. On Lines and Planes of Closest Fit to Systems of Points in Space. Philosophical Magazine, 2(11):559 - 572.
308
+ Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever, et al. 2019. Language Models are Unsupervised Multitask Learners. OpenAI Blog, 1(8):9.
309
+
310
+ Nils Reimers and Iryna Gurevych. 2019. SentenceBERT: Sentence Embeddings using Siamese BERT-Networks. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing, pages 3980-3990. Association for Computational Linguistics.
311
+ Ellen Riloff, Ashequl Qadir, Prafulla Survey, Lalindra De Silva, Nathan Gilbert, and Ruihong Huang. 2013. Sarcasm as Contrast between a Positive Sentiment and Negative Situation. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pages 704-714, Seattle, Washington, USA. Association for Computational Linguistics.
312
+ Anna Rogers, Olga Kovaleva, and Anna Rumshisky. 2021. A Primer in BERTology: What We Know About How BERT Works. Transactions of the Association for Computational Linguistics, 8:842-866.
313
+ Michel Rosenfeld. 2002. Hate Speech in Constitutional Jurisprudence: A Comparative Analysis. Cardozo Law Review, 24:1523.
314
+ Lukas Ruff, Nico Gornitz, Lucas Deecke, Shoaib Ahmed Siddiqui, Robert A. Vandermeulen, Alexander Binder, Emmanuel Müller, and Marius Kloft. 2018. Deep One-Class Classification. In Proceedings of the 35th International Conference on Machine Learning, ICML 2018, Stockholm, Sweden, July 10-15, 2018, volume 80 of Proceedings of Machine Learning Research, pages 4390-4399. PMLR.
315
+ Arkadiy Saakyan, Tuhin Chakrabarty, Debanjan Ghosh, and Smaranda Muresan. 2022. A Report on the FigLang 2022 Shared Task on Understanding Figurative Language. In Proceedings of the 3rd Workshop on Figurative Language Processing (FLP), pages 178-183, Abu Dhabi, United Arab Emirates (Hybrid). Association for Computational Linguistics.
316
+ Mohammad Sabokrou, Mohammad Khalooei, Mahmood Fathy, and Ehsan Adeli. 2018. Adversarily Learned One-Class Classifier for Novelty Detection. In 2018 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2018, Salt Lake City, UT, USA, June 18-22, 2018, pages 3379-3388. Computer Vision Foundation / IEEE Computer Society.
317
+ Niloofar Safi Samghabadi, Parth Patwa, Srinivas P. Y. K. L., Prerana Mukherjee, Amitava Das, and Thamar Solorio. 2020. Aggression and Misogyny Detection using BERT: A Multi-Task Approach. In Proceedings of the Second Workshop on Trolling, Aggression and Cyberbullying, pages 126-131, Marseille, France. European Language Resources Association.
318
+ Mattia Samory, Indira Sen, Julian Kohne, Fabian Flock, and Claudia Wagner. 2021. "Call me sexist, but..." : Revisiting Sexism Detection Using Psychological Scales and Adversarial Samples. Proceedings of the International AAAI Conference on Web and Social Media, 15(1):573-584.
319
+
320
+ Victor Sanh, Lysandre Debut, Julien Chaumont, and Thomas Wolf. 2019. DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter. In 5th Workshop on Energy Efficient Machine Learning and Cognitive Computing at NeurIPS 2019.
321
+ Bernhard Scholkopf, John C. Platt, John Shawe-Taylor, Alexander J. Smola, and Robert C. Williamson. 2001. Estimating the support of a high-dimensional distribution. Neural Comput., 13(7):1443-1471.
322
+ Xiaofei Sun, Xiaoya Li, Jiwei Li, Fei Wu, Shangwei Guo, Tianwei Zhang, and Guoyin Wang. 2023. Text classification via large language models. In *Findings of the Association for Computational Linguistics: EMNLP* 2023, Singapore, December 6-10, 2023, pages 8990-9005. Association for Computational Linguistics.
323
+ William Timkey and Marten van Schijndel. 2021. All Bark and No Bite: Rogue Dimensions in Transformer Language Models Obscure Representational Quality. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 4527-4546, Online and Punta Cana, Dominican Republic. Association for Computational Linguistics.
324
+ Laurens van der Maaten and Geoffrey Hinton. 2008. Visualizing Data Using t-SNE. Journal of Machine Learning Research, 9:2579 - 2605.
325
+ Dimitrios Ververidis and Constantine Kotropoulos. 2008. Gaussian mixture modeling by exploiting the mahalanobis distance. IEEE transactions on signal processing, 56(7):2797-2811.
326
+ Lennart Wachowiak and Dagmar Gromann. 2023. Does GPT-3 grasp metaphors? identifying metaphor mappings with generative language models. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1018–1032, Toronto, Canada. Association for Computational Linguistics.
327
+ Hai Wan, Jinxia Lin, Jianfeng Du, Dawei Shen, and Manrong Zhang. 2021. Enhancing Metaphor Detection by Gloss-based Interpretations. In *Findings of the Association for Computational Linguistics: ACLIJCNLP* 2021, pages 1971-1981, Online. Association for Computational Linguistics.
328
+ Mingyu Wan, Kathleen Ahrens, Emmanuele Chersoni, Menghan Jiang, Qi Su, Rong Xiang, and Chu-Ren Huang. 2020. Using conceptual norms for metaphor detection. In Proceedings of the Second Workshop on Figurative Language Processing, pages 104-109.
329
+ Zhiqiang Wang, Yiran Pang, and Yanbin Lin. 2023. Large language models are zero-shot text classifiers. CoRR, abs/2312.01044.
330
+ Samuel S Wilks. 1962. Mathematical statistics. a wiley publication in mathematical statistics john wiley & sons. Inc., New York-London, pages 0173-45805.
331
+
332
+ Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Russ R Salakhutdinov, and Quoc V Le. 2019. XLNet: Generalized Autoregressive Pretraining for Language Understanding. In Advances in Neural Information Processing Systems, volume 32. Curran Associates, Inc.
333
+ Wenjie Yin and Arkaitz Zubiaga. 2021. Towards generalisable hate speech detection: a review on obstacles and solutions. PeerJ Computer Science, 7:e598.
334
+ Susan Zhang, Stephen Roller, Naman Goyal, Mikel Artetxe, Moya Chen, Shuohui Chen, Christopher Dewan, Mona Diab, Xian Li, Xi Victoria Lin, Todor Mihaylov, Myle Ott, Sam Shleifer, Kurt Shuster, Daniel Simig, Punit Singh Koura, Anjali Sridhar, Tianlu Wang, and Luke Zettlemoyer. 2022. OPT: Open Pre-trained Transformer Language Models. arXiv, 2205.01068.
335
+ Xianbing Zhou, Yang Yong, Xiaochao Fan, Ge Ren, Yunfeng Song, Yufeng Diao, Liang Yang, and Hongfei Lin. 2021. Hate speech detection based on sentiment knowledge sharing. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 7158-7166.
336
+
337
+ ![](images/2bda9f102e34241840b4d10cb5aa65b6947818610204ae3300105b8559528e5a.jpg)
338
+ (a) BERT embeddings for the target class, sexism.
339
+
340
+ ![](images/910023ca534ec3f65c8a0d8723ff6335c0b24f10d51c5fa5a5cf864e1b4a9cb8.jpg)
341
+ (b) BERT embeddings for the negative class.
342
+
343
+ ![](images/33a2504abe1b53ccbfffd25107dc4a62a76478663b737527c8a60f58ef284252.jpg)
344
+ (c) SimCSE embeddings for the target class, sexism.
345
+ Figure 6: Q-Q (quantile-quantile) plots to assess the goodness-of-fit of target and non-target classes in the CMSB corpus for sexism detection. Shown here are the first t-SNE dimensions of pretrained BERT-base ( $a$ and $b$ ) and SimCSE ( $c$ and $d$ ) embeddings.
346
+
347
+ ![](images/768261d727a9aabc057cfb16c08d75487bc1f5ef007d871a09abf933bac448e1.jpg)
348
+ (d) SimCSE embeddings for the negative class.
349
+
350
+ # A A Visual Approach to Goodness-of-Fit in Target Class Distributions
351
+
352
+ Our aim is to unveil the distributional properties shared across diverse datasets and tasks, where identifying the minority target class amidst a spectrum of heterogeneous linguistic expressions (with no common pragmatic language function) is paramount. It is well known, however, that there are challenges to such analyses regardless of the manifold structure. As the number of dimensions increase, the volume of space grows exponentially and tests based on density estimation or empirical distance measures can struggle to maintain accuracy due to the increased sparsity and spread of data points.[12] Statistical tests also suffer from reduced power in higher dimensions. Moreover, estimating the covariance matrix becomes problematic in higher dimensions (for instance, due to ill-conditioned or singular matrices).
353
+
354
+ To mitigate these problems, we reduce the number of dimensions using t-SNE (van der Maaten and Hinton, 2008). The Quantile-Quantile (Q
355
+
356
+ Q) plots of the first latent dimension are shown in Figure 6, for visual assessment of adherence to a normal distribution. For the sake of brevity, we present only the Q-Q plots for sexism detection using two language models, BERT (Devlin et al., 2019) and SimCSE (Gao et al., 2021), as similar patterns were observed for the other tasks.
357
+
358
+ # B Configuration
359
+
360
+ Baseline Models: Four baseline models were fine-tuned - SimCSE, ALBERT, XLNet, and DistilBERT - on three datasets using a consistent set of configurations. The models were trained with a per-device batch size of 16 for both training (up to 5 epochs) and evaluation (at the end of each epoch). The learning rate is set to $1 \times 10^{-5}$ for all models, with 50 warm-up steps and a weight decay of 0.01. For tokenization, inputs were padded and truncated to a maximum sequence length of 512. We used the Adam optimizer for parameter updates.
361
+
362
+ Few-shot and Low-resource Experiments: We conducted fine-tuning experiments for the classification models under both few-shot and low-resource scenarios. In the few-shot setting, we used 5 training samples, while in the low-resource setting, we used 100 training samples. Training was conducted up to 10 epochs. We selected a variety of mainstream LLMs: Falcon, GPT-2, Llama2, Llama3, Mistral-7B, OPT, Phi2, Phi3, and Qwen2. These models are loaded via the AutoModelForSequenceClassification module provided by HuggingFace Transformers. To train the models with limited computational resources, we employed 4-bit quantization (e.g., nf4) in conjunction with Low-Rank Adaptation (LoRA) (Hu et al., 2022) for efficient parameter tuning. Specifically, we set the LoRA rank (r) to 16 and the LoRA scaling factor (lora_alpha) to 8 (32 for GPT-2), with a dropout rate (lora_dropout) of 0.05 (0.1 for GPT-2). For optimization, Hugging-Face Trainer was used with its default settings, with cross-entropy loss adopted for binary classification. The learning rate was set to $5 \times 10^{-5}$ , the weight decay set to 0.01, and the batch sizes were 24 for training and 6 for validation (per device).
363
+
364
+ ![](images/95a02076a6c9bf06f2e19bd7320e1440817e09d8f270213e6a512a824c4a5ea4.jpg)
365
+ (a) Figurative language: sarcasm
366
+
367
+ ![](images/8c7de05e6e73c7696ee41a4e95d5a10b7eb68d3c8bb00547974363fb6872c179.jpg)
368
+ (b) Figurative language: metaphors
369
+
370
+ ![](images/0357f4a22c33288f2a074b2be940e83b638033bb613853a18a0e6c412a53efc5.jpg)
371
+ (c) Deviant language: sexism
372
+
373
+ ![](images/83755959bc3c9b3b437b7de247dfeb0d8bfb3a5813de04036721e08d3023d01a.jpg)
374
+ Figure 7: Comparison of zero-shot evaluation of a suite of nine large language models (left to right): Llama2, Llama3, Phi2, Phi3, Mistral-7B, Falcon, Qwen2, GPT-2, and OPT, against ClaD's single-epoch training (rightmost).
375
+
376
+ ![](images/083882c8ce551a498158a491a43c157b5214bf36198bfdf45b19ddbc7a6a926d.jpg)
377
+ (a) Sarcasm detection $(SH)$
378
+
379
+ ![](images/f48c6d08b285d5d95c9c31200bfc5b6e015217f513ceab2f30ef7f90677d57a7.jpg)
380
+
381
+ ![](images/ec4c512ee8e96a099c7984f30a9e19aa90dcf2378abf02e88110f5f89ab710ed.jpg)
382
+ (b) Metaphor detection (TroFi))
383
+
384
+ ![](images/03b1c14e83299bed3395f80bd32cf78e0f5e94daa2958380eb88cc550aa23fa1.jpg)
385
+
386
+ ![](images/ce50543f261f2f65e37dd1c86fb21376ec11d9f3b6bb7667cd0875c4c59426c8.jpg)
387
+ (c) Sexism detection (CMSB)
388
+ Figure 8: Scatter plots of squared Mahalanobis distance for three test datasets before and after training. Red and blue indicate the target and non-target classes, respectively.
389
+
390
+ Zero-shot Experiments: The Transformer library's AutoModelForSequenceClassification API is used. This API automatically adds a linear classification head on top of the model's pooled output, enabling it to be handled as logits for classification tasks. Specifically, for binary classification, the output consists of 2D logits, representing the likelihood of the input belonging to either class. This approach focuses on classification, as opposed to letting a LLM generate its answer (e.g., 1 or $\emptyset$ ) in response. To guide the classification, the following prompt is pretended to every input:
391
+
392
+ Please identify if the following text is an example of <task-word>. Reply with 1 if it exhibits <task-word>, and 0 otherwise: <input sentence>
393
+
394
+ where the placeholder <task-word> is replaced by the specific task of interest (i.e., sarcasm, metaphor, sexism), and <input sentence> is the text being classified. This enables the model to classify the input sentence based on the particular task while maintaining the flexibility to adapt to various tasks by simply changing the task-word.
395
+
396
+ Class Distillation Experiments: We used a sliding window mechanism (window size: $100 \times$ batch size for small datasets, and expanded to $500 \times$ batch size for large datasets, update frequency: batch size) to efficiently update the Mahalanobis distance parameters (mean and covariance matrix) during training by incrementally processing batch data and computing statistics using the latest model-generated embeddings, dynamically adapting the parameters while maintaining computational efficiency. We use batch sizes of 16 for the sarcasm detection and metaphor tasks, and 40 for the sexism detection task.
397
+
398
+ # C Zero-shot classification
399
+
400
+ Converting LLM logits to probabilities via softmax, we observe that ClaD's single-epoch training substantially outperforms zero-shot predictions (shown in Figure 7. While this is perhaps unsurprising, the magnitude of improvement is notable: $F_{1}$ score improvements range from $+27.0\%$ (vs. Falcon) to $+90.9\%$ (vs. GPT-2) on $SH$ , $+10.8\%$ (vs. Qwen2) to $+83.2\%$ (vs. OPT) on TroFi, and $+46.9\%$ (vs. Mistral) to $+74.1\%$ (vs. OPT) on CMSB. In sar
401
+
402
+ <table><tr><td></td><td>Acc</td><td>Pr</td><td>FPR</td><td>F1</td></tr><tr><td colspan="5">Sarcasm detection on Sarcasm Headlines</td></tr><tr><td>Mahalanobis β-decision</td><td>0.580</td><td>0.557</td><td>0.100</td><td>0.547</td></tr><tr><td>One-class SVM</td><td>0.494</td><td>0.465</td><td>0.494</td><td>0.473</td></tr><tr><td>Isolation Forest</td><td>0.472</td><td>0.472</td><td>0.998</td><td>0.641</td></tr><tr><td>Autoencoder</td><td>0.530</td><td>0.517</td><td>0.046</td><td>0.099</td></tr><tr><td colspan="5">Metaphor detection on TroFi</td></tr><tr><td>Mahalanobis β-decision</td><td>0.678</td><td>0.680</td><td>0.500</td><td>0.741</td></tr><tr><td>One-class SVM</td><td>0.614</td><td>0.602</td><td>0.814</td><td>0.734</td></tr><tr><td>Isolation Forest</td><td>0.614</td><td>0.610</td><td>0.737</td><td>0.721</td></tr><tr><td>Autoencoder</td><td>0.578</td><td>0.575</td><td>0.942</td><td>0.724</td></tr><tr><td colspan="5">Sexism detection on Call Me Sexist But</td></tr><tr><td>Mahalanobis β-decision</td><td>0.134</td><td>0.134</td><td>1.000</td><td>0.236</td></tr><tr><td>One-class SVM</td><td>0.602</td><td>0.141</td><td>0.364</td><td>0.206</td></tr><tr><td>Isolation Forest</td><td>0.135</td><td>0.133</td><td>0.996</td><td>0.234</td></tr><tr><td>Autoencoder</td><td>0.827</td><td>0.121</td><td>0.051</td><td>0.066</td></tr></table>
403
+
404
+ Table 4: Comparing Mahalanobis $\beta$ -decision (Algorithm 1) and standard outlier detection methods (One-class SVM, Isolation Forest, and Autoencoder), demonstrating that the former achieves higher $F_{1}$ scores and lower false positive rates (FPR) across most tasks.
405
+
406
+ casm detection, LLMs perform near-randomly (accuracies: 0.47-0.53, AUC ≈ 0.5), with models either aggressively over-predicting (Falcon, Llama2, Llama3: recall ≥ 0.91, but very low precision) or being overly conservative (GPT-2, Phi3: extremely low recall with moderate precision). Metaphor detection shows modest improvements (accuracies: 0.43-0.57, max. AUC: 0.56), though extreme behaviors persist: Falcon, Qwen2 and Mistral favor recall over precision, while Llama2 do the opposite. Sexism detection reveals poor adaptation to class imbalance, with extremely high FPR (≥ 83%) across all LLMs. Some models also exhibit task-specific inconsistencies, such as GPT-2 alternating between conservative and aggressive predictions in sarcasm and metaphor detection, respectively.
407
+
408
+ # D Comparing Anomaly Detection Methods
409
+
410
+ Additionally, Table 4 shows that treating deviant or figurative language merely as "out of the ordinary" is insufficient. We compare our $\beta$ -decision algorithm against traditional anomaly detection methods like isolation forest (IF) (Liu et al., 2008, 2010), autoencoders (Chalapathy and Chawla, 2019), and one-class SVM (Noumir et al., 2012) - all on the same pretrained model - and further demonstrate the necessity of an inference algorithm based on an understanding of the target class manifold. Our
411
+
412
+ novel decision algorithm (Algorithm 1) achieves superior $F_{1}$ scores across all tasks, with one exception: IS performs better on sarcasm detection. However, this happens at the expense of significantly higher FPR and lower target-class precision.
413
+
414
+ # E Mahalanobis Contrast and Separability
415
+
416
+ Training with our Mahalanobis mean loss function, $\mathcal{L}_{\mathrm{MAH},\mu}$ (Equation 2) has a significant impact on classification, evident in the results presented in our ablation experiments subsection 5.3. Here, we add visualizations of class separability, using the squared Mahalanobis distance (Equation 3). Figure 8 presents scatter plots of squared Mahalanobis distance for the three test datasets before and after training, where the target and non-target class instances are shown in red and blue, respectively. It is clearly demonstrated that training with our Mahalanobis loss function leads to a distinct increase in class separability.
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56a2a943018874bb7835c0b55b25800cd70059e5f9839770cccd0287f8a96b10
3
+ size 783162
2025/Class Distillation with Mahalanobis Contrast_ An Efficient Training Paradigm for Pragmatic Language Understanding Tasks/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/Classifying Unreliable Narrators with Large Language Models/f069e84b-73e1-45f3-8102-243e3651ec32_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5aa84a4c2c680e35464054a1db3ce8d7b47ea6f830145c68791e28966603ae4
3
+ size 13003569
2025/Classifying Unreliable Narrators with Large Language Models/full.md ADDED
The diff for this file is too large to render. See raw diff
 
2025/Classifying Unreliable Narrators with Large Language Models/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e50051e342dc5031656705ef564c3379539d6ac7af75efc46eb60ad59501982
3
+ size 1259940
2025/Classifying Unreliable Narrators with Large Language Models/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/a4558acb-b74d-46e4-8030-42e9880522a7_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23c7178d15afcf3c57bf1f85da4f63123aa094788610b2647455a09ae0eb82d9
3
+ size 2021228
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/full.md ADDED
@@ -0,0 +1,618 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ClusterAttn: KV Cache Compression under Intrinsic Attention Clustering
2
+
3
+ Minwei Zhang*, Haifeng Sun*, Jingyu Wang†, Shaolong Li, Wanyi Ning, Qi Qi†, Zirui Zhuang, Jianxin Liao
4
+
5
+ State Key Laboratory of Networking and Switching Technology
6
+
7
+ Beijing University of Posts and Telecommunications
8
+
9
+ {mmwzhang,hfsun,wangjingyu,qiqi8266}@bupt.edu.cn
10
+
11
+ # Abstract
12
+
13
+ Sparse attention can effectively alleviate the significant demands on memory when large language models (LLMs) process long contexts. Existing methods typically apply the same sparse pattern across different attention heads and inputs. However, this uniform approach fails to capture the inherent diversity of attention patterns within LLMs — the intrinsic attention clustering. To address this, we propose ClusterAttn, a training-free sparse attention method that provides an efficient prompt cache compression scheme under intrinsic attention clustering for efficient LLM inference.
14
+
15
+ Our findings show that attention heads consistently focus on specific clusters of the prompt during decoding, a pattern detectable from an observation window at the prompt's end. ClusterAttn adaptively fits these clusters utilizing a density-based attention clustering algorithm, thus compressing the KV cache of the prompt. Evaluations on different models across various benchmarks demonstrate ClusterAttn's superior compression rates and efficiency. By utilizing only 1024 tokens, it can reduce memory usage by $10\% -65\%$ , resulting in a latency reduction of $12\% -23\%$ and a throughput increase of 2.6-4.8 times, all with nearly no accuracy loss. Additionally, ClusterAttn can handle up to 128k context on a single A100-80GB GPU, outperforming existing methods.
16
+
17
+ # 1 Introduction
18
+
19
+ Large Language Models (LLMs) like GPT (Brown et al., 2020; OpenAI, 2023; Ouyang et al., 2022) and LLaMA (Touvron et al., 2023a,b; Meta, 2024) series have significantly advanced natural language processing and artificial general intelligence. These models are trained on large-scale datasets using extensive computational resources (Kaplan et al.,
20
+
21
+ ![](images/d407a85bff2c5f2ef047760af645753a6f840e8830441793baf46af31e852a87.jpg)
22
+
23
+ ![](images/21624fd5e469df598a3b653ba2dab7c4d1cdac961a5cfca58a74af658dac02f9.jpg)
24
+
25
+ ![](images/e604650643a01de977fd6ebf12391ccb78831a010ce3f841113692f956f2859a.jpg)
26
+ Figure 1: The intrinsic attention clustering phenomenon within the prompt exhibited by Mistral 7B across attention heads during the decode phase.
27
+
28
+ ![](images/df0b1ba3fe55330ada7b280aec7b64085d7d9abb11e297788453830e8454230b.jpg)
29
+
30
+ 2020) and massive datasets (Anil et al., 2023), enabling them to generate human-like text and perform complex reasoning. However, efficient deployment is challenging due to the high memory demands of KV cache during inference. For instance, a GPT-3 model with 175 billion parameters requires about 1208 GB of GPU memory to store the KV cache when processing 64 sequences of 4096 tokens, which is 3.45 times the memory needed for model weights. To address this challenge, KV cache compression emerges to reduce memory usage, speed up generation, and lower costs, offering substantial commercial benefits.
31
+
32
+ Previous works proposed sparse attention to improve efficiency but they often lack detailed evaluations for long contexts and primarily focus on optimizing KV cache during decoding. This neglects prompt cache compression, a significant memory bottleneck in real-world applications where inputs are typically larger than responses (OpenAI, 2023; Liu and Mazumder, 2021; Bairi et al., 2024). Ex
33
+
34
+ isting methods also overlook the inherent attention patterns in LLMs that naturally highlight important tokens, a key insight driving our approach — the intrinsic attention clustering.
35
+
36
+ Our analysis explored the intrinsic attention clustering phenomenon during LLM generation, as illustrated in Figure 1. We observed that, for the same prompt, although the attention distributions vary across attention heads, most heads consistently follow a similar clustering pattern. Specifically, tokens with higher attention scores tend to cluster together, and these clusters remain largely stable throughout the decoding process. This intriguing characteristic suggests that by utilizing these clusters within the prompt, we can extract the critical tokens required for subsequent decoding, enabling effective prompt cache compression while maintaining strong performance, as shown in Table 2.
37
+
38
+ In this paper, we propose ClusterAttn, a training-free sparse attention method that provides an effective prompt cache compression scheme for efficient LLM inference. As shown in Figure 2, ClusterAttn identifies intrinsic attention clusters in the prompt before decoding, enabling high-compression, high-accuracy prompt cache reduction. It first performs a full prefetch, then the process involves three steps: (1) aggregating attention importance from context prefix using an observation window to form the clusters, (2) fitting the clusters with a density-based attention clustering algorithm to compress the context prefix, and (3) concatenating the clusters with the observation window as the final compressed KV cache for subsequent decoding.
39
+
40
+ Our contributions are summarized as follows:
41
+
42
+ - We introduce ClusterAttn, a simple yet effective KV cache compression scheme for the prompts. To our knowledge, it's the first method to explore KV compression via intrinsic attention clustering.
43
+ - Our experiments reveal the universality of intrinsic attention clustering and its consistency during generation, guiding the compression of the prompt cache.
44
+ - Inspired by intrinsic attention clustering, we propose an efficient density-based attention clustering algorithm that fits the clusters for compression. With it, we can profile the optimal fit for the clusters for specific models and datasets within hours.
45
+
46
+ We conducted extensive experiments on ClusterAttn, using two large language models, Mistral7B-Instruct-v0.2 (Jiang et al., 2023) and LWM-text-chat-1m (Liu et al., 2024a). Our evaluation of ClusterAttn demonstrated its ability to significantly compress the KV cache while maintaining accuracy comparable to full attention. With only 1024 tokens, ClusterAttn can reduce memory usage by $10\% -65\%$ , resulting in a latency reduction of $12\% -23\%$ and a throughput increase of 2.6-4.8 times, with nearly no accuracy loss. Additionally, it can handle up to 128k context on a single A100-80GB GPU, outperforming existing methods.
47
+
48
+ # 2 Related Work
49
+
50
+ Previous works have proposed several methods to reduce the computational and memory costs of attention mechanisms. Some studies use dynamic sparse attention masks to skip computations during prefetch stage (Pagliardini et al., 2023; Qu et al., 2022; Roy et al., 2021; Wang et al., 2021; Lu et al., 2021; Kitaev et al., 2020), while others discard KV cache based on the input sequence during decoding (Anagnostidis et al., 2023; Sheng et al., 2023; Zhang et al., 2023; Ge et al., 2024; Liu et al., 2023). However, dynamic prefetch often necessitates specific hardware for effective real-time acceleration (Qu et al., 2022; Wang et al., 2021; Lu et al., 2021; Ham et al., 2021, 2020), and dynamic KV cache pruning during decoding may require extensive retraining (Anagnostidis et al., 2023) or extra cumulative attention score calculations (Sheng et al., 2023; Zhang et al., 2023; Liu et al., 2023; Ge et al., 2024).
51
+
52
+ Another research avenue focuses on static sparse attention, where predefined masks are applied consistently across all inputs. This fixed computation flow makes static sparse attention more efficient and better suited for GPUs. In models like BERT (Devlin et al., 2019), various masks have been used (Zaheer et al., 2020; Beltagy et al., 2020; Child et al., 2019; Zhou et al., 2024; Xiao et al., 2024; Han et al., 2024). For generative large language models, fixed-span sliding window masks with global attention on initial tokens are commonly used (Xiao et al., 2024; Han et al., 2024). This local attention pattern allows KV cache outside current span to be discarded, reducing memory usage in long sequences. However, applying static masks uniformly across different attention heads and input lengths may not consider model and data
53
+
54
+ ![](images/73e786d07eba221eed344da05a8c05ad63432aef73d32b00e3950ecfedd12410.jpg)
55
+ Figure 2: Overview of the ClusterAttn on each layer. After a full prefetch, the process involves three steps: (1) aggregating attention importance from context prefix using an observation window to form the clusters, (2) fitting the clusters with a density-based attention clustering algorithm to compress the context prefix, and (3) concatenating the clusters and the observation window to form the KV cache required for subsequent decoding.
56
+
57
+ characteristics, potentially limiting effective context length and leading to suboptimal performance in long sequences.
58
+
59
+ Our method falls within dynamic sparse attention, benefiting from the training-free advantages, it can address the performance limitations encountered by previous methods.
60
+
61
+ # 3 Observation
62
+
63
+ In this section, we introduce the intrinsic clustering patterns that emerge within the attention distribution during decoding. We discuss how these patterns can be leveraged for prompt cache compression. Our findings are based on an analysis of various contexts and the behavior of attention mechanisms in LLMs.
64
+
65
+ # 3.1 Preliminaries
66
+
67
+ To structure our experimental analysis, we introduce the following terminologies:
68
+
69
+ Prompt(prompt): User-provided input composed of context prefix and observation window.
70
+
71
+ Context Prefix (pre): It's part of the prompt, which provides contextual information for current conversation or task.
72
+
73
+ Observation Window (win): It's the final part of the prompt, typically containing the user's query in the task. This window is crucial for analyzing the attention patterns within context prefix.
74
+
75
+ The definitions above are related as follows ( $\mathcal{L}$ denotes the length):
76
+
77
+ $$
78
+ \mathcal {L} _ {\text {p r o m p t}} = \mathcal {L} _ {\text {p r e}} + \mathcal {L} _ {\text {w i n}} \tag {1}
79
+ $$
80
+
81
+ Observation Window Mask $(\mathcal{M}_{win})$ : It's the mask that obscures the attention weights for subsequent softmax function in the observation window.
82
+
83
+ Feature Aggregation: Within the observation window, we perform a column sum of the attention scores for the context prefix, facilitating the observation of intrinsic attention clusters.
84
+
85
+ For each sequence, the feature aggregation process can be expressed through Equation 2 to 5:
86
+
87
+ $$
88
+ \mathcal {W} _ {w i n} = Q [:, - \mathcal {L} _ {w i n}: ] K ^ {T} \tag {2}
89
+ $$
90
+
91
+ $\mathcal{W}_{win}$ denotes the attention weights between the prompt and observation window across all heads.
92
+
93
+ $$
94
+ \mathcal {W} _ {\text {w i n}} ^ {m} = \operatorname {m a s k} \left(\mathcal {W} _ {\text {w i n}} [:,: -, \mathcal {L} _ {\text {w i n}}: ], \mathcal {M} _ {\text {w i n}}\right) \tag {3}
95
+ $$
96
+
97
+ $\mathcal{W}_{win}^{m}$ denotes the attention weights masked by $\mathcal{M}_{win}$ because we only focus on the attention weights of the context prefix.
98
+
99
+ $$
100
+ \mathcal {A} _ {w i n} ^ {m} = \operatorname {s o f t m a x} \left(\mathcal {W} _ {w i n} ^ {m}\right) \tag {4}
101
+ $$
102
+
103
+ $\mathcal{A}_{win}^{m}$ denotes the attention scores after softmax normalization of $\mathcal{W}_{win}^{m}$ .
104
+
105
+ $$
106
+ \mathcal {P} = \sum_ {i = - \mathcal {L} _ {w i n}} ^ {i = \mathcal {L} _ {p r o m p t} - 1} \mathcal {A} _ {w i n} ^ {m} [:, i,: \mathcal {L} _ {p r e} ] \tag {5}
107
+ $$
108
+
109
+ $\mathcal{P}$ denotes the aggregated column sum for the context prefix within the observation window, which reflects the intrinsic attention clustering patterns.
110
+
111
+ Hit Rate: The hit rate quantifies the effectiveness of feature aggregation by measuring the probability that intrinsic attention clusters remain important during subsequent generation. It can be
112
+
113
+ expressed through Equation 6 to 9:
114
+
115
+ $$
116
+ \mathcal {I} _ {w i n} = \left\{ \begin{array}{l l} 1, & \text {i f} \mathcal {P} > \theta \\ 0, & \text {o t h e r w i s e} \end{array} \right. \tag {6}
117
+ $$
118
+
119
+ $$
120
+ \mathcal {I} _ {c u r} = \left\{ \begin{array}{l l} 1, & \text {i f} \mathcal {A} _ {c u r} > \mu \\ 0, & \text {o t h e r w i s e} \end{array} \right. \tag {7}
121
+ $$
122
+
123
+ $\mathcal{A}_{cur}$ denotes the attention scores of the context prefix for the current generated token. The thresholding operation filters $\mathcal{P}$ and $\mathcal{A}_{cur}$ , retaining positions exceeding $\theta$ and $\mu$ , indicating significant attention activations. We used $\theta = 5e - 4$ and $\mu = 5e - 5$ (note that these are relatively large values due to the softmax function over long sequences).
124
+
125
+ $$
126
+ \text {o v e r l a p} = \mathcal {I} _ {\text {w i n}} \wedge \mathcal {I} _ {\text {c u r}} \tag {8}
127
+ $$
128
+
129
+ The overlap between these significant activations quantifies the consistency of the clusters.
130
+
131
+ $$
132
+ \mathcal {H} = \frac {\sum \text {o v e r l a p}}{\sum \mathcal {I} _ {\text {c u r}}} \tag {9}
133
+ $$
134
+
135
+ The hit rate $\mathcal{H}$ is then calculated as the ratio of total overlap to total current significant activations, measuring the attention clusters' effectiveness in emphasizing important contextual features.
136
+
137
+ All our observations were conducted on Mistral-7B-Instruct-v0.2 (Jiang et al., 2023).
138
+
139
+ # 3.2 Clustering Universality Across Contexts
140
+
141
+ We conducted observations on sequences with prompt lengths around $3\mathrm{k}$ from long-document question-answering datasets, including QMSum (Zhong et al., 2021) and OpenReview (An et al., 2024). Before decoding, we used the observation window to aggregate attention features and filtered out positions smaller than $\theta$ . We found that for different prompts, intrinsic attention clustering patterns universally appeared in context prefix across attention heads, as shown in Figure 3.
142
+
143
+ ![](images/43841ce72e0672f78c119e4738426be7b9ecebb72cee05e2a638991c348980c1.jpg)
144
+ Figure 3: Intrinsic attention clusters in attention heads exhibit universality across different prompts before decoding, where tokens with higher attention scores tend to cluster together.
145
+
146
+ ![](images/9acfd447821519723e90ea498d69cc058b1d71ad79bd4a6172db3d3eff10da60.jpg)
147
+
148
+ # 3.3 Clustering Consistency during Generation
149
+
150
+ We then explored whether intrinsic attention clusters retain their significance during subsequent generation. Using samples from Ultrachat (Ding et al., 2023) dataset, we filtered sequences with response lengths over 512 and prompt lengths over 1000. We calculated the average hit rate of the intrinsic attention clusters during the generation of 512 tokens. As shown in Figure 4, the clusters maintain consistency throughout the process, evidenced by the high hit rate.
151
+
152
+ ![](images/5d47d31c1b8b33f64a210cc6b28165aadbfe62509ba45fbe4b2995e3416347f7.jpg)
153
+ Figure 4: The layer-wise average hit rate of intrinsic attention clusters along token generation with input length varies from 1k to 8k.
154
+
155
+ ![](images/0ed065e80e5ff96ce610c8347cd1218b5daa4777baee64c3d5aec629445370fc.jpg)
156
+ Figure 5: The attention score sum of the context prefix with length 2048 across all heads in a layer during generation of 512 tokens. The ridges indicate that the clusters consistently hold higher attention scores during generation.
157
+
158
+ To further validate this, we summed the attention scores of the context prefix across all heads during generation. Figure 5 shows that, although the clusters vary across different heads, they exhibit a high degree of consistency within each head. Since these clusters account for a significant proportion of the attention scores, we heuristically assumed that the context prefix can be greatly compressed
159
+
160
+ based on the intrinsic attention clustering patterns and designed an algorithm that leverages these patterns to dynamically compress the prompt cache.
161
+
162
+ # 4 Method
163
+
164
+ In this section, we introduce ClusterAttn, a simple yet effective method for compressing prompt cache leveraging intrinsic attention clustering after a full prefill, as shown in Figure 2. Compared to full attention, it significantly reduces the KV cache by retaining only the most relevant information, decreasing memory usage and latency while maintaining accuracy and improving throughput.
165
+
166
+ # 4.1 Aggregating Attention Features from the Context Prefix to Form Clusters
167
+
168
+ In Section 3.1, based on the observed phenomena, we proposed using the query of every prompt as the observation window to aggregate attention features from the context prefix and form intrinsic attention clusters. This approach ensures context awareness, laying a foundation for subsequent cluster fitting. In this section, for each sample, we use corresponding $\mathcal{P}$ obtained in Equation 5 as the object for cluster fitting.
169
+
170
+ # 4.2 Density-Based Attention Clustering Algorithm for Compressing Context Prefix
171
+
172
+ After feature aggregation, we need to compress the context prefix based on the clustering patterns. Since the intrinsic attention clusters are formed based on attention scores, and unlike traditional clustering of discrete data, these clusters are composed of continuous tokens, we designed a density-based attention clustering algorithm inspired by DBSCAN (Ester et al., 1996) to fit the intrinsic attention clusters, as shown in Algorithm 1.
173
+
174
+ Given $\mathcal{L}_{pre}$ as the context prefix size, $\mathcal{L}_{cp}$ as the compression size, and $\mathcal{L}_{win}$ as the observation window size, we define blksize and $r$ in Line 2 and 5 respectively, corresponding to the minimal points(minPts) and neighborhood size used in DBSCAN, where num_block and $\theta$ are the hyperparameters to manage the granularity of the clustering. Notably, different from the minimal points required for each cluster in DBSCAN, we use blksize to control the size and range for attention clusters.
175
+
176
+ According to the algorithm, we first perform max pooling on $\mathcal{P}$ based on $blksize$ to obtain the blockwise maximum indices $\mathcal{I}$ within each cluster range. Then, we filter out indices with scores less than
177
+
178
+ Algorithm 1 Density-Based Attention Clustering.
179
+ Input: $K, V, \mathcal{P}, \text{num_block}, \theta, \mathcal{L}_{\text{pre}}, \mathcal{L}_{\text{win}}, \mathcal{L}_{\text{cp}}$
180
+ Output: Compressed Context Prefix KV Cache
181
+ 1: for Attention Head $h$ in LLM do
182
+ 2: $blksize \gets \frac{\mathcal{L}_{pre}}{num_block} \triangleright$ Cluster Range
183
+ 3: $\mathcal{P}_h', \mathcal{I} \gets \text{maxpool}(\mathcal{P}_h, blksize, blksize)$
184
+ 4: $\mathcal{I}_\theta \gets \{i \mid \mathcal{P}_h'[i] \geq \theta\}$
185
+ 5: $r \gets \frac{\mathcal{L}_{cp} - \mathcal{L}_{win}}{2\|\mathcal{I}_\theta\|} \triangleright$ Neighborhood Size
186
+ 6: $\mathcal{I}_G \gets \text{gather}(\mathcal{I}, \mathcal{I}_\theta) + \text{range}(-r, r)$
187
+ 7: $\mathcal{I}_U \gets \text{unique}(\text{clamp}(\mathcal{I}_G, 0, \mathcal{L}_{cp} - \mathcal{L}_{win}))$
188
+ 8: $\mathcal{I}_K \gets \text{topk}(\mathcal{P}_{h}^{\overline{\mathcal{I}_U}}, \mathcal{L}_{cp} - \mathcal{L}_{win} - \| \mathcal{I}_U\|)$
189
+ 9: $\mathcal{I}_F \gets \mathcal{I}_U \cup \mathcal{I}_K \triangleright$ Clusters' Indices
190
+ 10: $\hat{K}_h, \hat{V}_h \gets K_h^{\mathcal{I}_F}, V_h^{\mathcal{I}_F} \triangleright$ Compressed KV
191
+ 11: end for
192
+ 12: return $\{\hat{K}, \hat{V}\}$
193
+
194
+ $\theta$ to obtain $\mathcal{I}_{\theta}$ . The clustering process is defined as Line 6, where the gather operation obtains the cluster centers and $r$ controls the clustering neighborhood. $\mathcal{P}_h^{\overline{\mathcal{I}_U}}$ denotes the remaining attention after excluding the already selected attention clusters. Notably, the unique and topk operations in Line 7 and 8 are intended to eliminate redundant indices while collecting critical elements between cluster gaps. Finally, we obtain the compressed context prefix KV cache $\{\hat{K},\hat{V}\}$ . We use different $\theta$ for threshold filtering depending on the compression size, as shown in Table 1. Thus, the optimal fit for intrinsic attention clusters is primarily determined by num_block, which dictates the granularity of the size and the range of the clusters.
195
+
196
+ <table><tr><td>Compression Size</td><td>1024</td><td>2048</td><td>4096</td></tr><tr><td>θ(theta)</td><td>2e-3</td><td>1e-3</td><td>8e-4</td></tr></table>
197
+
198
+ Table 1: Values of $\theta$ under different compression sizes.
199
+
200
+ To select the most appropriate num_block, we need to profile num_block for each dataset at each compression size. To ensure the consistency and stability of the attention distribution before and after compression, we use the cosine similarity between the attention distribution at the corresponding positions before and after compression during decoding as the metric. Then, we evaluate the optimal fit by measuring the average cosine similarity across all heads for all samples. This is because, although num_block is same for each dataset, the formation of attention clusters for each sample and head is adaptive when performing the algorithm.
201
+
202
+ The final optimization objective is as follows:
203
+
204
+ $$
205
+ \underset {\text {n u m b l o c k}} {\arg \max } \left(\operatorname {a v g} \left[ \sum_ {\text {s a m p l e}} \sum_ {\text {h e a d}} \sum_ {i = 1} ^ {D} \operatorname {c o s s i m} \left(\mathcal {A} _ {f u l l} ^ {i}, \mathcal {A} _ {\mathcal {I} _ {F}} ^ {i}\right) \right]\right) \tag {10}
206
+ $$
207
+
208
+ Here, $\mathcal{A}_{full}^{i}$ and $\mathcal{A}_{\mathcal{L}_F}^i$ denote the attention distribution at the corresponding positions before and after compression when generating the $i^{\mathrm{th}}$ token. $D$ denotes the total number of generated tokens. For each dataset, we select $20\%$ samples and profile the optimal num_block. It should be noted that there is a trade-off with respect to num_block in our experiments and a detailed analysis is lied in Appendix F. We choose the num_block resulting in the highest average similarity as the optimal clustering fit. By applying the corresponding num_block for each dataset, ClusterAttn is able to make tailored cluster selection under fine granularity, allowing for context-aware KV cache compression.
209
+
210
+ # 4.3 Concatenating Clusters with Observation Window as Compressed Prompt Cache
211
+
212
+ After compressing the context prefix with the cluster patterns, the last step is to combine the clusters with the observation window to obtain the final compressed KV cache for the prompt, like in Figure 2. This is because the clusters represent a compression of the context prefix and do not include user's query within the observation window, which is crucial for the model's responses. Additionally, previous studies (Xiao et al., 2024; Zhang et al., 2023; Sun et al., 2024) have demonstrated that recent tokens are vital for the quality of subsequent generations, as they ensure the model's stability and fluency.
213
+
214
+ # 5 Experiments
215
+
216
+ In this section, we evaluated the performance of ClusterAttn across multiple models and various tasks, comparing it with other state-of-the-art baselines to highlight the effectiveness of our proposed method. Below are some experimental settings:
217
+
218
+ Baselines We compared ClusterAttn with the latest sparse attention methods: StreamingLLM (Xiao et al., 2024) and H2O (Zhang et al., 2023), which are all training-free. We followed the configurations from their respective papers. For StreamingLLM, the initial four tokens remain unmasked as attention sinks. For H2O, we ensured the same number of key tokens (heavy hitter tokens) and recent tokens. We adopted the compression sizes of 1024, 2048, and 4096 from their papers
219
+
220
+ and applied them to ClusterAttn. Besides, we used FlashAttn (Dao et al., 2022) as the baseline for full attention since ClusterAttn was implemented on it.
221
+
222
+ Models and Benchmarks We conducted our experiments primarily on two models: LWM-text-chat-1m (Liu et al., 2024a) and Mistral-7B-Instructv0.2 (Jiang et al., 2023). To effectively evaluate the models' handling of different sequence lengths and retrieval capability, we conducted the "Needle in a Haystack" (Gkamradt, 2023) experiment on LWM for ClusterAttn. To comprehensively assess the models' long-context understanding abilities, we performed experiments using LongBench (Bai et al., 2024), which includes 16 sub-tasks.
223
+
224
+ ClusterAttn's Settings Before conducting the experiments, we first selected $20\%$ samples from each dataset required for the experiments. We then performed profiling at compression sizes of 1024, 2048, and 4096 to obtain the optimal num_block for fitting intrinsic attention clusters. During experiments, we directly used the optimal num_block for inference to demonstrate the best performance of our method. Unless otherwise specified, the same num_block was used for each model across each task and length.
225
+
226
+ Further experiments and ablation studies are shown in Appendix. All our experiments were conducted on a single A100 80GB GPU.
227
+
228
+ # 5.1 Evaluation on Intrinsic Attention Clusters Fitting
229
+
230
+ Before testing the performance of ClusterAttn, we first conducted experiments on the Qasper (Dasigi et al., 2021) dataset to evaluate the fitting performance of our density-based attention clustering algorithm on the attention clusters. We compared it with traditional K-means (MacQueen, 1967) and DBSCAN (Ester et al., 1996). To ensure a fair comparison, for prompts with length $3\mathrm{k}$ , we set the number of clusters for K-means to 8, and set miniPts and neighborhood size for DBSCAN to 128 and 64, respectively. For our algorithm, we set $\theta$ , num_block and compression size to 2e-3, 8 and 1024, respectively.
231
+
232
+ Figure 6 shows the clustering performance of different algorithms on a specific head (left) and the average fitting rate across all heads in the LLM (right). The high fitting rate demonstrates the effectiveness of our clustering algorithm, avoiding the inefficiency of K-means in defining correlation
233
+
234
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Method</td><td colspan="3">Single-Document QA</td><td colspan="3">Multi-Document QA</td><td colspan="3">Summarization</td><td colspan="3">Few-shot Learning</td></tr><tr><td>NtrvQA(F1 Score)</td><td>Qasper(F1 Score)</td><td>MF-en(F1 Score)</td><td>HotpotQA(F1 Score)</td><td>2WikiMQA(F1 Score)</td><td>Musique(F1 Score)</td><td>GovReport(Rouge-L)</td><td>QMSum(Rouge-L)</td><td>MultiNews(Rouge-L)</td><td>TREC(Accuracy)</td><td>TriviaQA(F1 Score)</td><td>SAMSum(Rouge-L)</td></tr><tr><td rowspan="6">LWMChat</td><td>Full Attention</td><td>18.20</td><td>25.56</td><td>40.94</td><td>24.57</td><td>19.39</td><td>10.49</td><td>27.97</td><td>24.9</td><td>24.81</td><td>71.0</td><td>60.9</td><td>39.73</td></tr><tr><td>StreamingLLM: 4096</td><td>11.83</td><td>22.45</td><td>18.57</td><td>16.32</td><td>9.15</td><td>7</td><td>18.54</td><td>21.74</td><td>23.93</td><td>67.5</td><td>58.86</td><td>37.69</td></tr><tr><td>H2O: 4096</td><td>13.18</td><td>24.81</td><td>20.02</td><td>16.86</td><td>9.74</td><td>7.2</td><td>25.74</td><td>23.25</td><td>23.82</td><td>71.0</td><td>61.05</td><td>40.32</td></tr><tr><td>ClusterAttn: 1024</td><td>18.04</td><td>23.72</td><td>40.23</td><td>24.6</td><td>19.85</td><td>10.76</td><td>19.8</td><td>24.45</td><td>23.54</td><td>70.0</td><td>61.44</td><td>39.64</td></tr><tr><td>ClusterAttn: 2048</td><td>17.94</td><td>25.01</td><td>41.41</td><td>24.5</td><td>19.39</td><td>11.33</td><td>21.62</td><td>24.21</td><td>24.38</td><td>70.0</td><td>61.14</td><td>39.93</td></tr><tr><td>ClusterAttn: 4096</td><td>17.93</td><td>25.46</td><td>40.78</td><td>24.91</td><td>19.52</td><td>11.28</td><td>25.36</td><td>25.44</td><td>24.61</td><td>70.5</td><td>61.12</td><td>39.65</td></tr><tr><td rowspan="6">Mistral</td><td>Full Attention</td><td>26.82</td><td>33.06</td><td>49.28</td><td>42.77</td><td>27.33</td><td>19.27</td><td>32.85</td><td>24.23</td><td>27.06</td><td>71.0</td><td>86.23</td><td>42.98</td></tr><tr><td>StreamingLLM: 4096</td><td>20.47</td><td>27.64</td><td>45.55</td><td>37.87</td><td>20.74</td><td>12.47</td><td>25.77</td><td>20.86</td><td>23.93</td><td>66.5</td><td>79.85</td><td>39.63</td></tr><tr><td>H2O: 4096</td><td>22.59</td><td>29.07</td><td>47.17</td><td>36.52</td><td>20.61</td><td>16.26</td><td>30.01</td><td>23.8</td><td>26.74</td><td>70.5</td><td>86.18</td><td>42.98</td></tr><tr><td>ClusterAttn: 1024</td><td>25.56</td><td>29.5</td><td>49.25</td><td>40.93</td><td>25.74</td><td>19.45</td><td>25.92</td><td>23.83</td><td>26.13</td><td>69.5</td><td>86.53</td><td>42.10</td></tr><tr><td>ClusterAttn: 2048</td><td>25.88</td><td>32.48</td><td>48.6</td><td>41.72</td><td>27.33</td><td>18.69</td><td>28.84</td><td>24.5</td><td>26.61</td><td>70.0</td><td>86.29</td><td>42.44</td></tr><tr><td>ClusterAttn: 4096</td><td>26.41</td><td>33.37</td><td>49.81</td><td>42.35</td><td>27.96</td><td>18.79</td><td>30.78</td><td>24.23</td><td>27.1</td><td>71.0</td><td>86.26</td><td>43.04</td></tr></table>
235
+
236
+ Table 2: Evaluation of different KV cache compression methods across different LLMs on LongBench.
237
+
238
+ ![](images/56f8c8ae958b280e92079c81be966b648544d3133bbc2b1a0594d7c702284f79.jpg)
239
+ Figure 6: Different algorithms for fitting the intrinsic attention clusters on a specific head (left) and across all heads (right). (IAC denotes the intrinsic attention clusters.)
240
+
241
+ ![](images/b944e352dfadb323c51a2b9f71533bcaa68ca117d8ab173c20d8d9fb9fee67f4.jpg)
242
+
243
+ through mean in long-context scenarios, while being able to capture elements between cluster gaps with greater granularity than DBSCAN.
244
+
245
+ # 5.2 Evaluation on Long Context Understanding
246
+
247
+ We conducted our experiments on LongBench (Bai et al., 2024) for long context understanding ability. For each model, we tested the performance of ClusterAttn at different compression sizes. As shown in Table 2, with only 1024 tokens, the performance drop across 12 different datasets using ClusterAttn is negligible compared to full attention, with some tasks even outperforming it. For LWM model, the average input length is 13,422; for Mistral, it is 13,160. Thus, ClusterAttn achieves an average compression rate of $92\%$ with 1024 tokens, and $68\%$ with 4096 tokens, with negligible accuracy loss. We also compared ClusterAttn with H2O (Zhang et al., 2023) and StreamingLLM (Xiao et al., 2024) on the LongBench datasets to further demonstrate ClusterAttn's performance. To ensure a fair accuracy comparison, we set the compression size of H2O and StreamingLLM to 4096 tokens. As shown in Table 2, ClusterAttn significantly outperforms them. Even with KV cache compressed to 1024 tokens, ClusterAttn on Mistral outperforms H2O with 4096 tokens on 8 out of 12 tasks, and it
248
+
249
+ comprehensively outperforms StreamingLLM.
250
+
251
+ # 5.3 Evaluation on Long Context Retrieval
252
+
253
+ To evaluate the retrieval capability and effective context length of ClusterAttn, we applied it to the LWM model for the "Needle in a Haystack" (Gkamradt, 2023) test. This test requires the model to accurately retrieve a specific sentence ("Needle") hidden in a random position within a long document ("Haystack"). To rigorously assess ClusterAttn's capability, we extended the document length to 128k tokens, which is the maximum sequence length a single A100-80GB GPU can handle when using ClusterAttn with compression size 1024. Results in Figure 7 show that while full attention leads to an out-of-memory error when the sequence length reaches 40k, ClusterAttn can handle a maximum sequence length of 128k with retrieval accuracy still exceeding $90\%$ . This remarkable result highlights ClusterAttn's potential to accurately process details in extremely long input contexts with a 128x compression rate, as well as its immediate effectiveness in saving GPU memory.
254
+
255
+ ![](images/ab523a58c1680bfa90b0399ca58b1ff2b386ba1e4b3fb10a35281bceb0179ce9.jpg)
256
+ Figure 7: Needle-in-a-Haystack test performance of ClusterAttn on a single A100-80GB GPU. The x-axis denotes the length of the sequence (the "haystack"); the y-axis indicates the position that the "needle" (a short sentence) is located within the sequence, from 1k to 128k tokens. For example, $50\%$ indicates that the needle is placed in the middle of the sequence.
257
+
258
+ # 5.4 Coherence Testing
259
+
260
+ To test the impact of ClusterAttn on the coherence of the original model, we constructed a comprehensive and concise test set by extracting $50 \times 4$ data items at each length level from the test sets of four long-context understanding datasets: Qasper (Dasigi et al., 2021), MultiNew (Fabbri et al., 2019), TREC (Hovy et al., 2001; Li and Roth, 2002), and LCC (Mohler et al., 2016). These datasets respectively represent the LLM's capabilities in question answering, summarization, few-shot learning, and code completion. According to LongBench (Bai et al., 2024) standards, these data items are organized as question-answer pairs. The questions and answers are human-written and included in the datasets. Perplexity is calculated only on the answer portions of the data to demonstrate the model's coherence in responding to user requests. Table 3 shows the average perplexity of ClusterAttn, H2O, StreamingLLM, and full attention across different inputs and compression sizes. The table reveals that ClusterAttn consistently exhibits lower perplexity, indicating that our method does not negatively impact the coherence of the generated inference results. On the contrary, by removing redundant information, it can even enhance the coherence of the generated outputs.
261
+
262
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Method</td><td colspan="3">Perplexity</td></tr><tr><td>1024</td><td>2048</td><td>4096</td></tr><tr><td rowspan="4">Mistral</td><td>Full Attention</td><td>3.79</td><td>3.79</td><td>3.79</td></tr><tr><td>H2O</td><td>3.94</td><td>3.90</td><td>3.85</td></tr><tr><td>StreamingLLM</td><td>4.48</td><td>4.27</td><td>4.08</td></tr><tr><td>ClusterAttn</td><td>3.75</td><td>3.82</td><td>3.77</td></tr><tr><td rowspan="4">LWM</td><td>Full Attention</td><td>4.52</td><td>4.52</td><td>4.52</td></tr><tr><td>H2O</td><td>4.63</td><td>4.58</td><td>4.56</td></tr><tr><td>StreamingLLM</td><td>4.79</td><td>4.72</td><td>4.63</td></tr><tr><td>ClusterAttn</td><td>4.49</td><td>4.52</td><td>4.51</td></tr></table>
263
+
264
+ # 5.5 Efficiency
265
+
266
+ In the following experiments, we set the compression size of ClusterAttn and H2O to 1024 tokens to better prove the performance of ClusterAttn. We didn't compare with StreamingLLM here because it performed poorly in previous experiments thus has limited application in real-world scenarios. We used samples of different lengths in "Needle in a Haystack" (Gkamradt, 2023) as the inputs.
267
+
268
+ ![](images/a080feda788fa3529f814d4470f441a083259c5ac21f856c10a120880a2a6c4e.jpg)
269
+ Figure 8: Throughput comparison of FlashAttn (full attention) and ClusterAttn on various batch sizes. Compared to FlashAttn, ClusterAttn improves throughput by 2.6 to 4.8 times.
270
+
271
+ Throughput Improvement We first tested the throughput of the LWM model using ClusterAttn under different batch sizes. The results shown in Figure 8 lead to two main conclusions. First, as the input length increases, the throughput of the ClusterAttn-optimized model remains constant because the KV cache size is nearly fixed during inference, while FlashAttn (Dao, 2024) (full attention) increases exponentially. Second, under same batch size, ClusterAttn-optimized model can decode significantly longer sequences. This demonstrates the effectiveness of ClusterAttn in minimizing memory consumption and enhancing efficiency.
272
+
273
+ Table 3: Average perplexity for four types of tasks across different models and methods.
274
+
275
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Method</td><td colspan="6">Memory (GB)</td></tr><tr><td>4k</td><td>8k</td><td>16k</td><td>32k</td><td>64k</td><td>128k</td></tr><tr><td rowspan="3">Mistral</td><td>FlashAttn</td><td>16.9</td><td>18.8</td><td>22.6</td><td>30.2</td><td>-</td><td>-</td></tr><tr><td>H2O</td><td>21.9</td><td>33.3</td><td>56.7</td><td>72.3</td><td>-</td><td>-</td></tr><tr><td>ClusterAttn</td><td>17.1</td><td>18.3</td><td>21.1</td><td>26.4</td><td>-</td><td>-</td></tr><tr><td rowspan="3">LWM</td><td>FlashAttn</td><td>35.1</td><td>40.7</td><td>51.8</td><td>73.9</td><td>OOM</td><td>OOM</td></tr><tr><td>H2O</td><td>45.7</td><td>58.7</td><td>75.8</td><td>OOM</td><td>OOM</td><td>OOM</td></tr><tr><td>ClusterAttn</td><td>31.7</td><td>32.9</td><td>35.6</td><td>41.5</td><td>51.9</td><td>74.2</td></tr></table>
276
+
277
+ Table 4: Peak memory comparison across different methods and models. With 1024 tokens, ClusterAttn reduces memory usage by $10\% -65\%$ .
278
+
279
+ Peak Memory and Inference Latency We next tested the peak memory usage and inference latency of different methods as sequence length increases, with batch size of 1.
280
+
281
+ Regarding memory usage (Table 4), for Mistral, the maximum sequence length is set to $32\mathrm{k}$ due to its maximum sequence length limit. H2O reaches its memory limit at $32\mathrm{k}$ , consuming two to three
282
+
283
+ ![](images/8be9fcd5d2cf850f1004c4a2b97925e26d2d412ee590291deda75ddf1d7dcffd.jpg)
284
+ Figure 9: Inference latency comparison across different methods and models. With 1024 tokens, ClusterAttn reduces latency by $12\% -23\%$ .
285
+
286
+ times more memory than FlashAttn and ClusterAttn, because it requires complete prefetch and additional overhead for generating dynamic masks. For LWM, with a maximum sequence length of 1 million, H2O encounters OOM issues beyond 16k, FlashAttn faces OOM beyond 32k, while ClusterAttn extends the sequence length to 128k, far exceeding the limits of the other two methods.
287
+
288
+ In terms of inference latency (Figure 9), as the sequence length increases, the latency reduction achieves by ClusterAttn gradually widens the gap with FlashAttn and H2O. When the sequence length reaches $32\mathrm{k}$ , ClusterAttn provides at least a $20\%$ reduction in latency. These outstanding results in both memory usage and latency highlight ClusterAttn's significant potential to reduce inference costs and improve inference quality.
289
+
290
+ # 6 Conclusion
291
+
292
+ We present a sparse attention method for prompt cache compression based on intrinsic attention clustering - ClusterAttn. It's simple, effective, and training-free, leveraging the attention clustering patterns during the decode process. With only 1024 tokens, it can reduce memory usage by $10\% -65\%$ , resulting in a latency reduction of $12\% -23\%$ and a throughput increase of 2.6-4.8 times, with nearly no accuracy loss. Furthermore, it can handle up to 128k context on a single A100-80GB GPU, outperforming existing methods. ClusterAttn effectively alleviates the computational and memory burdens of processing large inputs, offering valuable insights and tools for the community to better manage the challenges of large-scale language modeling.
293
+
294
+ # Ethical Considerations
295
+
296
+ In compliance with ethical considerations, we emphasize that the entirety of our research revolves around open-source datasets, models, and
297
+
298
+ tools. Notably, we exclusively focus on improving model's efficiency and mitigating memory constraints during inference and do not engage in any commercial usage or ethical implications.
299
+
300
+ # Limitations
301
+
302
+ Despite ClusterAttn's advantages, its research scope is primarily limited to the generative aspects of models. This limitation means that if a model inherently struggles with handling long contexts or exhibits poor performance, ClusterAttn cannot extend the model's long-context capabilities. Additionally, ClusterAttn's design does not address the decoding process, which still relies on standard attention or FlashAttn. This limitation restricts its ability to dynamically update the KV cache during decoding, potentially leading to performance bottlenecks if the output sequence is too long.
303
+
304
+ # Acknowledgments
305
+
306
+ This work was supported in part by the National Key R&D Program of China 2024YFE0200800, the National Natural Science Foundation of China under Grants (62101064, 62321001, 62471055, U23B2001, 62171057, 62201072, 62071067), the High-Quality Development Project of the MIIT(2440STCZB2584), the Ministry of Education and China Mobile Joint Fund (MCM20200202, MCM20180101), the Fundamental Research Funds for the Central Universities (2024PTB-004) and the 2024 Education and Teaching Reform Project Funding at Beijing University of Posts and Telecommunications (2024YB17).
307
+
308
+ # References
309
+
310
+ Joshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, and Sumit Sanghai. 2023. GQA: training generalized multi-query transformer models from multi-head checkpoints. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, EMNLP 2023, Singapore, December 6-10, 2023, pages 4895-4901. Association for Computational Linguistics.
311
+ Reza Yazdani Aminabadi, Samyam Rajbhandari, Ammar Ahmad Awan, Cheng Li, Du Li, Elton Zheng, Olatunji Ruwase, Shaden Smith, Minjia Zhang, Jeff Rasley, and Yuxiong He. 2022. Deepspeed-inference: Enabling efficient inference of transformer models at unprecedented scale. In SC22: International Conference for High Performance Computing, Networking, Storage and Analysis, Dallas, TX, USA, November 13-18, 2022, pages 46:1-46:15. IEEE.
312
+
313
+ Chenxin An, Shansan Gong, Ming Zhong, Xingjian Zhao, Mukai Li, Jun Zhang, Lingpeng Kong, and Xipeng Qiu. 2024. L-eval: Instituting standardized evaluation for long context language models. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2024, Bangkok, Thailand, August 11-16, 2024, pages 14388-14411. Association for Computational Linguistics.
314
+ Sotiris Anagnostidis, Dario Pavllo, Luca Biggio, Lorenzo Noci, Aurélien Lucchi, and Thomas Hofmann. 2023. Dynamic context pruning for efficient and interpretable autoregressive transformers. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023.
315
+ Rohan Anil, Sebastian Borgeaud, Yonghui Wu, JeanBaptiste Alayrac, Jiahui Yu, Radu Soricut, Johan Schalkwyk, Andrew M. Dai, Anja Hauth, Katie Millican, David Silver, Slav Petrov, Melvin Johnson, Ioannis Antonoglou, Julian Schrittwieser, Amelia Glaese, Jilin Chen, Emily Pitler, Timothy P. Lillicrap, Angeliki Lazaridou, Orhan Firat, James Molloy, Michael Isard, Paul Ronald Barham, Tom Hennigan, Benjamin Lee, Fabio Viola, Malcolm Reynolds, Yuanzhong Xu, Ryan Doherty, Eli Collins, Clemens Meyer, Eliza Rutherford, Erica Moreira, Kareem Ayoub, Megha Goel, George Tucker, Enrique Piqueras, Maxim Krikun, Iain Barr, Nikolay Savinov, Ivo Danihelka, Becca Roelofs, Anaïs White, Anders Andreassen, Tamara von Glehn, Lakshman Yagati, Mehran Kazemi, Lucas Gonzalez, Misha Khalman, Jakub Sygnowski, and et al. 2023. Gemini: A family of highly capable multimodal models. CoRR, abs/2312.11805.
316
+ Yushi Bai, Xin Lv, Jiajie Zhang, Hongchang Lyu, Jiankai Tang, Zhidian Huang, Zhengxiao Du, Xiao Liu, Aohan Zeng, Lei Hou, Yuxiao Dong, Jie Tang, and Juanzi Li. 2024. Longbench: A bilingual, multitask benchmark for long context understanding. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2024, Bangkok, Thailand, August 11-16, 2024, pages 3119-3137. Association for Computational Linguistics.
317
+ Ramakrishna Bairi, Atharv Sonwane, Aditya Kanade, Vageesh D. C., Arun Iyer, Suresh Parthasarathy, Sriram K. Rajamani, Balasubramanyan Ashok, and Shashank Shet. 2024. Codeplan: Repository-level coding using llms and planning. Proc. ACM Softw. Eng., 1(FSE):675-698.
318
+ Iz Beltagy, Matthew E. Peters, and Arman Cohan. 2020. Longformer: The long-document transformer. CoRR, abs/2004.05150.
319
+ Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss,
320
+
321
+ Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. 2020. Language models are few-shot learners. In Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual.
322
+ Rewon Child, Scott Gray, Alec Radford, and Ilya Sutskever. 2019. Generating long sequences with sparse transformers. CoRR, abs/1904.10509.
323
+ Krzysztof Marcin Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamás Sarlós, Peter Hawkins, Jared Quincy Davis, Afroz Mohiuddin, Lukasz Kaiser, David Benjamin Belanger, Lucy J. Colwell, and Adrian Weller. 2021. Rethinking attention with performers. In 9th International Conference on Learning Representations, ICLR 2021, Virtual Event, Austria, May 3-7, 2021. OpenReview.net.
324
+ Luciano Del Corro, Allie Del Giorno, Sahaj Agarwal, Bin Yu, Ahmed Awadallah, and Subhabrata Mukherjee. 2023. Skipdecode: Autoregressive skip decoding with batching and caching for efficient LLM inference. CoRR, abs/2307.02628.
325
+ Damai Dai, Chengqi Deng, Chenggang Zhao, R. X. Xu, Huazuo Gao, Deli Chen, Jiashi Li, Wangding Zeng, Xingkai Yu, Y. Wu, Zhenda Xie, Y. K. Li, Panpan Huang, Fuli Luo, Chong Ruan, Zhifang Sui, and Wenfeng Liang. 2024. Deepseekmoe: Towards ultimate expert specialization in mixture-of-experts language models. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2024, Bangkok, Thailand, August 11-16, 2024, pages 1280-1297. Association for Computational Linguistics.
326
+ Tri Dao. 2024. Flashattention-2: Faster attention with better parallelism and work partitioning. In The Twelfth International Conference on Learning Representations, ICLR 2024, Vienna, Austria, May 7-11, 2024. OpenReview.net.
327
+ Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. 2022. Flashattention: Fast and memory-efficient exact attention with io-awareness. In Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022.
328
+ Pradeep Dasigi, Kyle Lo, Iz Beltagy, Arman Cohan, Noah A. Smith, and Matt Gardner. 2021. A dataset of information-seeking questions and answers anchored in research papers. In Proceedings of the 2021 Conference of the North American Chapter of
329
+
330
+ the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2021, Online, June 6-11, 2021, pages 4599-4610. Association for Computational Linguistics.
331
+ DeepSeek-AI, Aixin Liu, Bei Feng, Bin Wang, Bingxuan Wang, Bo Liu, Chenggang Zhao, Chengqi Deng, Chong Ruan, Damai Dai, Daya Guo, Dejian Yang, Deli Chen, Dongjie Ji, Erhang Li, Fangyun Lin, Fuli Luo, Guangbo Hao, Guanting Chen, Guowei Li, Hao Zhang, Hanwei Xu, Hao Yang, Haowei Zhang, Honghui Ding, Huajian Xin, Huazuo Gao, Hui Li, Hui Qu, J. L. Cai, Jian Liang, Jianzhong Guo, Ji-aqi Ni, Jiashi Li, Jin Chen, Jingyang Yuan, Junjie Qiu, Junxiao Song, Kai Dong, Kaige Gao, Kang Guan, Lean Wang, Lecong Zhang, Lei Xu, Leyi Xia, Liang Zhao, Liyue Zhang, Meng Li, Miaojun Wang, Mingchuan Zhang, Minghua Zhang, Minghui Tang, Mingming Li, Ning Tian, Panpan Huang, Peiyi Wang, Peng Zhang, Qihao Zhu, Qinyu Chen, Qiushi Du, R. J. Chen, R. L. Jin, Ruiqi Ge, Ruizhe Pan, Runxin Xu, Ruyi Chen, S. S. Li, Shanghai Lu, Shangyan Zhou, Shanhuang Chen, Shaoqing Wu, Shengfeng Ye, Shirong Ma, Shiyu Wang, Shuang Zhou, Shuiying Yu, Shunfeng Zhou, Size Zheng, Tao Wang, Tian Pei, Tian Yuan, Tianyu Sun, W. L. Xiao, Wangding Zeng, Wei An, Wen Liu, Wenfeng Liang, Wenjun Gao, Wentao Zhang, X. Q. Li, Xiangyue Jin, Xi-anzu Wang, Xiao Bi, Xiaodong Liu, Xiaohan Wang, Xiaojin Shen, Xiaokang Chen, Xiaosha Chen, Xiaotao Nie, and Xiaowen Sun. 2024. Deepseek-v2: A strong, economical, and efficient mixture-of-experts language model. CoRR, abs/2405.04434.
332
+ Tim Dettmers, Mike Lewis, Younes Belkada, and Luke Zettlemoyer. 2022. Gpt3.int8(): 8-bit matrix multiplication for transformers at scale. In Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022.
333
+ Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer. 2023. Qlora: Efficient finetuning of quantized llms. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023.
334
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019, Volume 1 (Long and Short Papers), pages 4171-4186. Association for Computational Linguistics.
335
+ Ning Ding, Yulin Chen, Bokai Xu, Yujia Qin, Shengding Hu, Zhiyuan Liu, Maosong Sun, and Bowen Zhou. 2023. Enhancing chat language models by scaling high-quality instructional conversations.
336
+
337
+ In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, EMNLP 2023, Singapore, December 6-10, 2023, pages 3029-3051. Association for Computational Linguistics.
338
+ Martin Ester, Hans-Peter Kriegel, Jörg Sander, and Xiaowei Xu. 1996. A density-based algorithm for discovering clusters in large spatial databases with noise. In Proceedings of the Second International Conference on Knowledge Discovery and Data Mining (KDD-96), Portland, Oregon, USA, pages 226-231. AAAI Press.
339
+ Alexander R. Fabbri, Irene Li, Tianwei She, Suyi Li, and Dragomir R. Radev. 2019. Multi-news: A large-scale multi-document summarization dataset and abstractive hierarchical model. In Proceedings of the 57th Conference of the Association for Computational Linguistics, ACL 2019, Florence, Italy, July 28-August 2, 2019, Volume 1: Long Papers, pages 1074-1084. Association for Computational Linguistics.
340
+ William Fedus, Barret Zoph, and Noam Shazeer. 2022. Switch transformers: Scaling to trillion parameter models with simple and efficient sparsity. J. Mach. Learn. Res., 23:120:1-120:39.
341
+ Suyu Ge, Yunan Zhang, Liyuan Liu, Minjia Zhang, Jiawei Han, and Jianfeng Gao. 2024. Model tells you what to discard: Adaptive KV cache compression for llms. In The Twelfth International Conference on Learning Representations, ICLR 2024, Vienna, Austria, May 7-11, 2024. OpenReview.net.
342
+ Gkamradt. 2023. Llmtest_needleinahaystack: Doing simple retrieval from llm models. [Online; accessed 29-December-2023].
343
+ Bogdan Gliwa, Iwona Mochol, Maciej Biesek, and Aleksander Wawer. 2019. Samsum corpus: A human-annotated dialogue dataset for abstractive summarization. CoRR, abs/1911.12237.
344
+ Albert Gu and Tri Dao. 2023. Mamba: Linear-time sequence modeling with selective state spaces. CoRR, abs/2312.00752.
345
+ Tae Jun Ham, Sungjun Jung, Seonghak Kim, Young H. Oh, Yeonhong Park, Yoonho Song, Jung-Hun Park, Sanghee Lee, Kyoung Park, Jae W. Lee, and Deog-Kyoon Jeong. 2020. A<sup>3</sup>: Accelerating attention mechanisms in neural networks with approximation. In IEEE International Symposium on High Performance Computer Architecture, HPCA 2020, San Diego, CA, USA, February 22-26, 2020, pages 328-341. IEEE.
346
+ Tae Jun Ham, Yejin Lee, Seong Hoon Seo, Soosung Kim, Hyunj Choi, Sung Jun Jung, and Jae W. Lee. 2021. ELSA: hardware-software co-design for efficient, lightweight self-attention mechanism in neural networks. In 48th ACM/IEEE Annual International Symposium on Computer Architecture, ISCA 2021, Virtual Event / Valencia, Spain, June 14-18, 2021, pages 692-705. IEEE.
347
+
348
+ Chi Han, Qifan Wang, Hao Peng, Wenhan Xiong, Yu Chen, Heng Ji, and Sinong Wang. 2024. Lm-infinite: Zero-shot extreme length generalization for large language models. In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers), NAACL 2024, Mexico City, Mexico, June 16-21, 2024, pages 3991-4008. Association for Computational Linguistics.
349
+ Eduard H. Hovy, Laurie Gerber, Ulf Hermjakob, ChinYew Lin, and Deepak Ravichandran. 2001. Toward semantics-based answer pinpointing. In Proceedings of the First International Conference on Human Language Technology Research, HLT 2001, San Diego, California, USA, March 18-21, 2001. Morgan Kaufmann.
350
+ Changho Hwang, Wei Cui, Yifan Xiong, Ziyue Yang, Ze Liu, Han Hu, Zilong Wang, Rafael Salas, Jithin Jose, Prabhat Ram, HoYuen Chau, Peng Cheng, Fan Yang, Mao Yang, and Yongqiang Xiong. 2023. Tutel: Adaptive mixture-of-experts at scale. In Proceedings of the Sixth Conference on Machine Learning and Systems, MLSys 2023, Miami, FL, USA, June 4-8, 2023. mlsys.org.
351
+ Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de Las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, and William El Sayed. 2023. Mistral 7b. CoRR, abs/2310.06825.
352
+ Praneeth Kacham, Vahab Mirrokni, and Peilin Zhong. 2023. Polysketchformer: Fast transformers via sketches for polynomial kernels. CoRR, abs/2310.01655.
353
+ Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B. Brown, Benjamin Chess, Rewon Child, Scott Gray, Alec Radford, Jeffrey Wu, and Dario Amodei. 2020. Scaling laws for neural language models. CoRR, abs/2001.08361.
354
+ Nikita Kitaev, Lukasz Kaiser, and Anselm Levskaya. 2020. Reformer: The efficient transformer. In 8th International Conference on Learning Representations, ICLR 2020, Addis Ababa, Ethiopia, April 26-30, 2020. OpenReview.net.
355
+ Tomás Kocisky, Jonathan Schwarz, Phil Blunsom, Chris Dyer, Karl Moritz Hermann, Gábor Melis, and Edward Grefenstette. 2018. The narrativeqa reading comprehension challenge. Trans. Assoc. Comput. Linguistics, 6:317-328.
356
+ Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph Gonzalez, Hao Zhang, and Ion Stoica. 2023. Efficient memory management for large language model serving with pagedattention. In Proceedings of the 29th Symposium on Operating Systems Principles, SOSP 2023,
357
+
358
+ Koblenz, Germany, October 23-26, 2023, pages 611-626. ACM.
359
+ Juho Lee, Yoonho Lee, Jungtaek Kim, Adam R. Kosiorek, Seungjin Choi, and Yee Whye Teh. 2019. Set transformer: A framework for attention-based permutation-invariant neural networks. In Proceedings of the 36th International Conference on Machine Learning, ICML 2019, 9-15 June 2019, Long Beach, California, USA, volume 97 of Proceedings of Machine Learning Research, pages 3744-3753. PMLR.
360
+ Dmitry Lepikhin, HyoukJoong Lee, Yuanzhong Xu, Dehao Chen, Orhan Firat, Yanping Huang, Maxim Krikun, Noam Shazeer, and Zhifeng Chen. 2021. Gshard: Scaling giant models with conditional computation and automatic sharding. In 9th International Conference on Learning Representations, ICLR 2021, Virtual Event, Austria, May 3-7, 2021. OpenReview.net.
361
+ Dacheng Li, Rulin Shao, Anze Xie, Ying Sheng, Lian-min Zheng, Joseph Gonzalez, Ion Stoica, Xuezhe Ma, and Hao Zhang. 2023a. How long can context length of open-source llms truly promise? In NeurIPS 2023 Workshop on Instruction Tuning and Instruction Following.
362
+ Xin Li and Dan Roth. 2002. Learning question classifiers. In 19th International Conference on Computational Linguistics, COLING 2002, Howard International House and Academia Sinica, Taipei, Taiwan, August 24 - September 1, 2002.
363
+ Yuhong Li, Tianle Cai, Yi Zhang, Deming Chen, and Debadeepta Dey. 2023b. What makes convolutional models great on long sequence modeling? In The Eleventh International Conference on Learning Representations, ICLR 2023, Kigali, Rwanda, May 1-5, 2023. OpenReview.net.
364
+ Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh, Acyr Locatelli, Hanchen Ye, Tianle Cai, Patrick Lewis, and Deming Chen. 2024. Snapkv: LLM knows what you are looking for before generation. In Advances in Neural Information Processing Systems 38: Annual Conference on Neural Information Processing Systems 2024, NeurIPS 2024, Vancouver, BC, Canada, December 10 - 15, 2024.
365
+ Ji Lin, Jiaming Tang, Haotian Tang, Shang Yang, WeiMing Chen, Wei-Chen Wang, Guangxuan Xiao, Xingyu Dang, Chuang Gan, and Song Han. 2024. AWQ: activation-aware weight quantization for ondevice LLM compression and acceleration. In Proceedings of the Seventh Annual Conference on Machine Learning and Systems, MLSys 2024, Santa Clara, CA, USA, May 13-16, 2024. mlsys.org.
366
+ Bing Liu and Sahisnu Mazumder. 2021. Lifelong and continual learning dialogue systems: Learning during conversation. In *Thirty-Fifth AAAI Conference on Artificial Intelligence*, AAAI 2021, Thirty-Third Conference on Innovative Applications of Artificial Intelligence, IAAI 2021, The Eleventh Symposium
367
+
368
+ on Educational Advances in Artificial Intelligence, EAAI 2021, Virtual Event, February 2-9, 2021, pages 15058-15063. AAAI Press.
369
+ Hao Liu, Wilson Yan, Matei Zaharia, and Pieter Abbeel. 2024a. World model on million-length video and language with blockwise ringattention. CoRR, abs/2402.08268.
370
+ Jing Liu, Ruihao Gong, Xiuying Wei, Zhiwei Dong, Jianfei Cai, and Bohan Zhuang. 2024b. QLLM: accurate and efficient low-bitwidth quantization for large language models. In The Twelfth International Conference on Learning Representations, ICLR 2024, Vienna, Austria, May 7-11, 2024. OpenReview.net.
371
+ Zichang Liu, Aditya Desai, Fangshuo Liao, Weitao Wang, Victor Xie, Zhaozhuo Xu, Anastasios Kyrillidis, and Anshumali Shrivastava. 2023. Scissorhands: Exploiting the persistence of importance hypothesis for LLM KV cache compression at test time. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023.
372
+ Liqiang Lu, Yicheng Jin, Hangrui Bi, Zizhang Luo, Peng Li, Tao Wang, and Yun Liang. 2021. Sanger: A co-design framework for enabling sparse attention using reconfigurable architecture. In MICRO '21: 54th Annual IEEE/ACM International Symposium on Microarchitecture, Virtual Event, Greece, October 18-22, 2021, pages 977-991. ACM.
373
+ Xuezhe Ma, Xiang Kong, Sinong Wang, Chunting Zhou, Jonathan May, Hao Ma, and Luke Zettlemoyer. 2021. Luna: Linear unified nested attention. In Advances in Neural Information Processing Systems 34: Annual Conference on Neural Information Processing Systems 2021, NeurIPS 2021, December 6-14, 2021, virtual, pages 2441-2453.
374
+ J. MacQueen. 1967. Some methods for classification and analysis of multivariate observations.
375
+ AI Meta. 2024. Introducing meta llama 3: The most capable openly available llm to date. Meta AI.
376
+ Michael Mohler, Mary Brunson, Bryan Rink, and Marc T. Tomlinson. 2016. Introducing the LCC metaphor datasets. In Proceedings of the Tenth International Conference on Language Resources and Evaluation LREC 2016, Porto Roz, Slovenia, May 23-28, 2016. European Language Resources Association (ELRA).
377
+ OpenAI. 2023. GPT-4 technical report. CoRR, abs/2303.08774.
378
+ Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll L. Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul F. Christiano, Jan Leike, and Ryan Lowe.
379
+
380
+ 2022. Training language models to follow instructions with human feedback. In Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022.
381
+ Matteo Pagliardini, Daniele Paliotta, Martin Jaggi, and François Fleuret. 2023. Faster causal attention over large sequences through sparse flash attention. CoRR, abs/2306.01160.
382
+ Bo Peng, Eric Alcaide, Quentin Anthony, Alon Balalak, Samuel Arcadinho, Stella Biderman, Huanqi Cao, Xin Cheng, Michael Chung, Leon Derczynski, Xingjian Du, Matteo Grella, Kranthi Kiran GV, Xuzheng He, Haowen Hou, Przemyslaw Kazienko, Jan Kocon, Jiaming Kong, Bartlomiej Koptyra, Hayden Lau, Jiaju Lin, Krishna Sri Ipsit Mantri, Ferdinand Mom, Atsushi Saito, Guangyu Song, Xiangru Tang, Johan S. Wind, Stanislaw Wozniak, Zhenyuan Zhang, Qinghua Zhou, Jian Zhu, and Rui-Jie Zhu. 2023. RWKV: reinventing rnns for the transformer era. In Findings of the Association for Computational Linguistics: EMNLP 2023, Singapore, December 6-10, 2023, pages 14048-14077. Association for Computational Linguistics.
383
+ Hao Peng, Nikolaos Pappas, Dani Yogatama, Roy Schwartz, Noah A. Smith, and Lingpeng Kong. 2021. Random feature attention. In 9th International Conference on Learning Representations, ICLR 2021, Virtual Event, Austria, May 3-7, 2021. OpenReview.net.
384
+ Michael Poli, Stefano Massaroli, Eric Nguyen, Daniel Y. Fu, Tri Dao, Stephen Baccus, Yoshua Bengio, Stefano Ermon, and Christopher Ré. 2023. Hyena hierarchy: Towards larger convolutional language models. In International Conference on Machine Learning, ICML 2023, 23-29 July 2023, Honolulu, Hawaii, USA, volume 202 of Proceedings of Machine Learning Research, pages 28043-28078. PMLR.
385
+ Zheng Qu, Liu Liu, Fengbin Tu, Zhaodong Chen, Yufei Ding, and Yuan Xie. 2022. DOTA: detect and omit weak attentions for scalable transformer acceleration. In ASPLOS '22: 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Lausanne, Switzerland, 28 February 2022 - 4 March 2022, pages 14-26. ACM.
386
+ Aurko Roy, Mohammad Saffar, Ashish Vaswani, and David Grangier. 2021. Efficient content-based sparse attention with routing transformers. Trans. Assoc. Comput. Linguistics, 9:53-68.
387
+ Tal Schuster, Adam Fisch, Jai Gupta, Mostafa Dehghani, Dara Bahri, Vinh Tran, Yi Tay, and Donald Metzler. 2022. Confident adaptive language modeling. In Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022.
388
+
389
+ Noam Shazeer. 2019. Fast transformer decoding: One write-head is all you need. CoRR, abs/1911.02150.
390
+ Ying Sheng, Lianmin Zheng, Binhang Yuan, Zhuohan Li, Max Ryabinin, Beidi Chen, Percy Liang, Christopher Ré, Ion Stoica, and Ce Zhang. 2023. Flexgen: High-throughput generative inference of large language models with a single GPU. In International Conference on Machine Learning, ICML 2023, 23-29 July 2023, Honolulu, Hawaii, USA, volume 202 of Proceedings of Machine Learning Research, pages 31094-31116. PMLR.
391
+ Hanshi Sun, Zhuoming Chen, Xinyu Yang, Yuandong Tian, and Beidi Chen. 2024. Triforce: Lossless acceleration of long sequence generation with hierarchical speculative decoding. CoRR, abs/2404.11912.
392
+ Yutao Sun, Li Dong, Shaohan Huang, Shuming Ma, Yuqing Xia, Jilong Xue, Jianyong Wang, and Furu Wei. 2023. Retentive network: A successor to transformer for large language models. CoRR, abs/2307.08621.
393
+ Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothee Lacroix, Baptiste Roziere, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. 2023a. Llama: Open and efficient foundation language models. CoRR, abs/2302.13971.
394
+ Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton-Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurélien Rodriguez, Robert Stojnic, Sergey Edunov, and Thomas Scialom. 2023b. Llama 2: Open foundation and fine-tuned chat models. CoRR, abs/2307.09288.
395
+ Hanrui Wang, Zhekai Zhang, and Song Han. 2021. Spatten: Efficient sparse attention architecture with cascade token and head pruning. In IEEE International Symposium on High-Performance Computer Architecture, HPCA 2021, Seoul, South Korea, February 27 - March 3, 2021, pages 97-110. IEEE.
396
+ Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, and Hao Ma. 2020. Linformer: Self-attention with linear complexity. CoRR, abs/2006.04768.
397
+
398
+ Haoyi Wu and Kewei Tu. 2024. Layer-condensed KV cache for efficient inference of large language models. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2024, Bangkok, Thailand, August 11-16, 2024, pages 11175-11188. Association for Computational Linguistics.
399
+ Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, and Mike Lewis. 2024. Efficient streaming language models with attention sinks. In *The Twelfth International Conference on Learning Representations*, ICLR 2024, Vienna, Austria, May 7-11, 2024. OpenReview.net.
400
+ Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontañón, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. 2020. Big bird: Transformers for longer sequences. In Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual.
401
+ Zhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen, Lianmin Zheng, Ruisi Cai, Zhao Song, Yuandong Tian, Christopher Ré, Clark W. Barrett, Zhangyang Wang, and Beidi Chen. 2023. H2O: heavy-hitter oracle for efficient generative inference of large language models. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023.
402
+ Ming Zhong, Da Yin, Tao Yu, Ahmad Zaidi, Mutethia Mutuma, Rahul Jha, Ahmed Hassan Awadallah, Asli Celikyilmaz, Yang Liu, Xipeng Qiu, and Dragomir R. Radev. 2021. Qmsum: A new benchmark for query-based multi-domain meeting summarization. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, NAACL-HLT 2021, Online, June 6-11, 2021, pages 5905-5921. Association for Computational Linguistics.
403
+ Wangchunshu Zhou, Canwen Xu, Tao Ge, Julian J. McAuley, Ke Xu, and Furu Wei. 2020. BERT loses patience: Fast and robust inference with early exit. In Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual.
404
+ Zixuan Zhou, Xuefei Ning, Ke Hong, Tianyu Fu, Ji-aming Xu, Shiyao Li, Yuming Lou, Luning Wang, Zhihang Yuan, Xiuhong Li, Shengen Yan, Guohao Dai, Xiao-Ping Zhang, Yuhan Dong, and Yu Wang. 2024. A survey on efficient inference for large language models. CoRR, abs/2404.14294.
405
+
406
+ # A Additional Related Work
407
+
408
+ Large Language Models (LLMs) are constrained by considerable computational and memory requirements during inference, particularly in resource-constrained environments. To mitigate these challenges, alone with sparse attention, a variety of efficient inference techniques have been developed.
409
+
410
+ For instance, dynamic inference methods (Zhou et al., 2020; Corro et al., 2023; Schuster et al., 2022; Wu and Tu, 2024), represented by mixture-of-experts (MoE) (Fedus et al., 2022; Lepikhin et al., 2021; Dai et al., 2024; Hwang et al., 2023; DeepSeek-AI et al., 2024), adaptively select specific sub-structures of the model during the inference process based on the input data, significantly improving inference efficiency while keeping model capacity.
411
+
412
+ Techniques like Multi-Query Attention (Ainslie et al., 2023; Shazeer, 2019) and low-rank attentions (DeepSeek-AI et al., 2024; Wang et al., 2020; Ma et al., 2021; Lee et al., 2019) approximate the functionality of traditional attention mechanisms but with more efficient implementations.
413
+
414
+ Quantization (Lin et al., 2024; Dettmers et al., 2023, 2022; Liu et al., 2024b) involves converting the model's weights and activations into a low bit-width format, thereby reducing memory footprint and computational intensity.
415
+
416
+ Alternative mechanisms have also been proposed to replace traditional attention for long-sequence modeling (Gu and Dao, 2023; Peng et al., 2023; Sun et al., 2023; Li et al., 2023b; Kacham et al., 2023; Peng et al., 2021; Choromanski et al., 2021; Wang et al., 2020; Poli et al., 2023). However, these new mechanisms often require weights different from the original transformer, leading to significant retraining costs for large language models.
417
+
418
+ Previous work has also introduced acceleration frameworks for large language models (Aminabadi et al., 2022; Sheng et al., 2023; Kwon et al., 2023) and kernel-level optimizations (Dao et al., 2022; Dao, 2024). These kernel and system optimizations are orthogonal to our work and can be integrated to further enhance efficiency.
419
+
420
+ # B Extended Comparison with SnapKV
421
+
422
+ SnapKV (Li et al., 2024) is also a method for KV cache compression that does not require training. It discovered that each attention head in the model consistently focuses on specific prompt features during generation, and these features can also be
423
+
424
+ obtained through an observation window at the end of the prompt. Based on this observation, SnapKV automatically compresses the KV cache by selecting important KV positions for each attention head.
425
+
426
+ SnapKV is very similar to our findings and solution but differs in terms of observation window and compression algorithm. First, ClusterAttn's observation window uses the user's query at the end of the input prompt as the observation window, whereas SnapKV uses a fixed-length observation window for all prompts. This approach may affect SnapKV's robustness in capturing task-relevant information from the context prefix and its adaptability to different user queries. Second, SnapKV employs a relatively simple pooling method to capture important information from the context prefix, whereas ClusterAttn uses a more fine-grained DBAC(Density-Based Attention Clustering) algorithm. As a result, SnapKV is likely to perform worse after compression compared to ClusterAttn.
427
+
428
+ To comprehensively compare the performance and accuracy of ClusterAttn and SnapKV, we conducted experiments on the LongBench (Bai et al., 2024) dataset using the Mistral (Jiang et al., 2023) and LWM (Liu et al., 2024a) models. According to the LongBench experimental results in Table 5, ClusterAttn performed slightly better overall than SnapKV, but the difference was not significant. We attribute this to the fact that the average length of the LongBench dataset is still not at an ultra-long level, making it difficult to create a clear performance gap when both methods have strong information extraction capabilities.
429
+
430
+ ![](images/1d683e330c0b6de311d1e4735c82b1fd2e2828e9f91780583ff25d67a8d70830.jpg)
431
+ Figure 10: Needle-in-a-Haystack test performance of ClusterAttn on a single A100-80GB GPU. The x-axis denotes the length of the sequence (the "haystack"); the y-axis indicates the position that the "needle" (a short sentence) is located within the sequence, from 1k to 128k tokens. For example, $50\%$ indicates that the needle is placed in the middle of the sequence.
432
+
433
+ Therefore, we conducted a Needle-in-a-haystack (Gkamradt, 2023) experiment on SnapKV using
434
+
435
+ the LWM model (with a compression size of 1024). The experimental results in Figure 10 indicate that although SnapKV maintains good compression ability as sequence length increases, its retrieval accuracy shows a significant decline compared to ClusterAttn. This demonstrates the robustness of ClusterAttn's performance, which benefits from the use of a more fine-grained compression algorithm.
436
+
437
+ # C Extended Results on LLaMA-3
438
+
439
+ We also extended ClusterAttn on LLaMA3-8B-Instruct, we compared full attention, SnapKV (Li et al., 2024), and ClusterAttn on the LongBench (Bai et al., 2024) experiment, with the maximum sequence length in the experiment set to match the model's maximum processing length (8192). The experimental results in Table 6 show that ClusterAttn performed as expected, with both accuracy and efficiency consistent with other models.
440
+
441
+ # D Different Sparse Attention on Preserving Contextual Integrity
442
+
443
+ In large language models (LLMs), information retrieval and generation rely on features with high attention scores, supplemented by using inductive heads to replicate the rest of the context. Therefore, simply selecting top-ranked features may result in retaining only partial details, leading to a loss of information integrity. For instance, this type of compression might cause an LLM to retrieve only the country code of a phone number while fabricating the rest. Our experiments also demonstrate that selecting only the highest-weighted features is insufficient. Such sparse selection can disrupt the contextual integrity of features, reducing accuracy, as shown in Table 7. In contrast, ClusterAttn performs well on all tasks as each cluster represents a continuous segment rather than a sparse selection, preserving the contextual integrity. This approach maintains the stability of attention scores in the compressed KV cache during subsequent decoding, comparable to full attention.
444
+
445
+ # E LongEval
446
+
447
+ To further evaluate the long context retrieval capability of ClusterAttn, we also used a modified version of the LongEval-Lines benchmark (Li et al., 2023a), which includes randomly generated pairs and average scores. Compared to the "Needle in a Haystack" (Gkamradt, 2023) test, LongEval-Lines
448
+
449
+ ![](images/cb52e6016c7e21364b7bcc90408168c78449b83b7ced356962e93147e9240881.jpg)
450
+ Figure 11: Retrieval accuracy tests on LongEval.
451
+
452
+ presents a greater challenge as it involves identifying key-value pairs within a noisy context with similar formatting, whereas the relevant information in the "Needle in a Haystack" test is more distinctly separated from other context. We implemented this task on the Mistral model with a compression size of 1024, applying ClusterAttn, H2O (Zhang et al., 2023), and StreamingLLM (Xiao et al., 2024) respectively. Our findings (Figure 11) indicate that as the sequence length increases, ClusterAttn consistently performs on par with full attention, while H2O and StreamingLLM show poorer results, with H2O even encountering an OOM error when the sequence length exceeds $20\mathrm{k}$ . This demonstrates that preserving intrinsic attention clusters enables accurate extraction of critical information in long contexts, significantly improving retrieval accuracy.
453
+
454
+ # F Ablation Study
455
+
456
+ In Section 4.2, we mentioned our ClusterAttn algorithm. There, two hyperparameters play a crucial role in the cluster fitting process: $\theta$ and num_block. In the following sections, we will analyze the impact of different $\theta$ and num_block on the quality of the intrinsic attention cluster fitting on Mistral-7B-Instruct-v0.2 (Jiang et al., 2023).
457
+
458
+ # F.1 The Impact of Theta Selection on Cluster Fitting
459
+
460
+ We evaluated the selection of $\theta$ for various tasks at different compression sizes by measuring the similarity between attention distributions at the corresponding positions before and after compression during decoding. Based on the attention scores in long contexts, we defined the range of $\theta$ between
461
+
462
+ <table><tr><td rowspan="2">Model</td><td rowspan="2">Method</td><td colspan="3">Single-Document QA</td><td colspan="3">Multi-Document QA</td><td colspan="3">Summarization</td><td colspan="3">Few-shot Learning</td></tr><tr><td>NtrvQA(F1 Score)</td><td>Qasper(F1 Score)</td><td>MF-en(F1 Score)</td><td>HotpotQA(F1 Score)</td><td>2WikiMQA(F1 Score)</td><td>Musique(F1 Score)</td><td>GovReport(Rouge-L)</td><td>QMSum(Rouge-L)</td><td>MultiNews(Rouge-L)</td><td>TREC(Accuracy)</td><td>TriviaQA(F1 Score)</td><td>SAMStum(Rouge-L)</td></tr><tr><td rowspan="7">LWMChat</td><td>Full Attention</td><td>18.20</td><td>25.56</td><td>40.94</td><td>24.57</td><td>19.39</td><td>10.49</td><td>27.97</td><td>24.9</td><td>24.81</td><td>71.0</td><td>60.9</td><td>39.73</td></tr><tr><td>SnapKV: 1024</td><td>18.02</td><td>23.72</td><td>40.22</td><td>24.61</td><td>19.84</td><td>10.74</td><td>19.79</td><td>24.44</td><td>23.51</td><td>70.0</td><td>61.41</td><td>39.62</td></tr><tr><td>SnapKV: 2048</td><td>17.92</td><td>24.99</td><td>41.38</td><td>24.48</td><td>19.38</td><td>11.33</td><td>21.6</td><td>24.22</td><td>24.36</td><td>70.0</td><td>61.11</td><td>39.9</td></tr><tr><td>SnapKV: 4096</td><td>17.90</td><td>25.44</td><td>40.76</td><td>24.90</td><td>19.53</td><td>11.27</td><td>25.34</td><td>25.42</td><td>24.58</td><td>70.5</td><td>61.08</td><td>39.62</td></tr><tr><td>ClusterAttn: 1024</td><td>18.04</td><td>23.72</td><td>40.23</td><td>24.6</td><td>19.85</td><td>10.76</td><td>19.8</td><td>24.45</td><td>23.54</td><td>70.0</td><td>61.44</td><td>39.64</td></tr><tr><td>ClusterAttn: 2048</td><td>17.94</td><td>25.01</td><td>41.41</td><td>24.5</td><td>19.39</td><td>11.33</td><td>21.62</td><td>24.21</td><td>24.38</td><td>70.0</td><td>61.14</td><td>39.93</td></tr><tr><td>ClusterAttn: 4096</td><td>17.93</td><td>25.46</td><td>40.78</td><td>24.91</td><td>19.52</td><td>11.28</td><td>25.36</td><td>25.44</td><td>24.61</td><td>70.5</td><td>61.12</td><td>39.65</td></tr><tr><td rowspan="7">Mistral</td><td>Full Attention</td><td>26.82</td><td>33.06</td><td>49.28</td><td>42.77</td><td>27.33</td><td>19.27</td><td>32.85</td><td>24.23</td><td>27.06</td><td>71.0</td><td>86.23</td><td>42.98</td></tr><tr><td>SnapKV: 1024</td><td>25.54</td><td>29.51</td><td>49.23</td><td>40.91</td><td>25.71</td><td>19.42</td><td>25.88</td><td>23.81</td><td>26.1</td><td>69.5</td><td>86.49</td><td>42.08</td></tr><tr><td>SnapKV: 2048</td><td>25.87</td><td>32.47</td><td>48.58</td><td>41.7</td><td>27.3</td><td>18.68</td><td>28.8</td><td>24.5</td><td>26.59</td><td>70.0</td><td>86.27</td><td>42.45</td></tr><tr><td>SnapKV: 4096</td><td>26.41</td><td>33.36</td><td>49.8</td><td>42.33</td><td>27.94</td><td>18.77</td><td>30.76</td><td>24.2</td><td>27.08</td><td>71.0</td><td>86.23</td><td>43.01</td></tr><tr><td>ClusterAttn: 1024</td><td>25.56</td><td>29.5</td><td>49.25</td><td>40.93</td><td>25.74</td><td>19.45</td><td>25.92</td><td>23.83</td><td>26.13</td><td>69.5</td><td>86.53</td><td>42.10</td></tr><tr><td>ClusterAttn: 2048</td><td>25.88</td><td>32.48</td><td>48.6</td><td>41.72</td><td>27.33</td><td>18.69</td><td>28.84</td><td>24.5</td><td>26.61</td><td>70.0</td><td>86.29</td><td>42.44</td></tr><tr><td>ClusterAttn: 4096</td><td>26.41</td><td>33.37</td><td>49.81</td><td>42.35</td><td>27.96</td><td>18.79</td><td>30.78</td><td>24.23</td><td>27.1</td><td>71.0</td><td>86.26</td><td>43.04</td></tr></table>
463
+
464
+ Table 5: Evaluation of ClusterAttn and SnapKV across different LLMs on LongBench.
465
+
466
+ <table><tr><td rowspan="2">Task</td><td rowspan="2">Attention Method</td><td colspan="3">LLaMA-3-8B-Instruct</td></tr><tr><td>1024</td><td>2048</td><td>4096</td></tr><tr><td rowspan="3">Single QA</td><td>Full Attention</td><td>37.33</td><td>37.33</td><td>37.33</td></tr><tr><td>SnapKV</td><td>36.38</td><td>36.65</td><td>36.87</td></tr><tr><td>ClusterAttn</td><td>36.94</td><td>36.95</td><td>36.93</td></tr><tr><td rowspan="3">Multi QA</td><td>Full Attention</td><td>36.04</td><td>36.04</td><td>36.04</td></tr><tr><td>SnapKV</td><td>35.92</td><td>35.98</td><td>35.96</td></tr><tr><td>ClusterAttn</td><td>36.03</td><td>36.05</td><td>35.99</td></tr><tr><td rowspan="3">Sum</td><td>Full Attention</td><td>26.83</td><td>26.83</td><td>26.83</td></tr><tr><td>SnapKV</td><td>22.58</td><td>23.78</td><td>25.34</td></tr><tr><td>ClusterAttn</td><td>22.54</td><td>24.14</td><td>25.58</td></tr><tr><td rowspan="3">Few-shot</td><td>Full Attention</td><td>69.56</td><td>69.56</td><td>69.56</td></tr><tr><td>SnapKV</td><td>69.34</td><td>69.41</td><td>69.33</td></tr><tr><td>ClusterAttn</td><td>69.68</td><td>69.55</td><td>69.62</td></tr></table>
467
+
468
+ 1e-4 and 8e-2. $\theta$ influences the neighborhood size during the clustering fitting process (such as $\epsilon$ -neighborhood in DBSCAN (Ester et al., 1996)), as shown in Figure 13, as $\theta$ increases, cosine similarity initially rises gradually to the top but rapidly decreases across compression sizes. This is because larger $\theta$ filters out weaker, yet crucial, clusters, leading to poorer fitting quality, while overly small $\theta$ will include irrelevant tokens. Notably, for each compression size, we selected the first $\theta$ where cosine similarity declines, balancing detailed cluster selection and information preservation.
469
+
470
+ # F.2 The Impact of BlockNum Selection on Cluster Fitting
471
+
472
+ To evaluate the impact of num_block on fitting quality, we fixed the corresponding $\theta$ for each compression size and measured the similarity between attention distributions at the corresponding positions before and after compression during decoding across different tasks (Figure 13). We tested
473
+
474
+ Table 6: Average performance of ClusterAttn and SnapKV on various tasks from LongBench. The results show that across three different compression lengths, ClusterAttn outperforms SnapKV in most cases and is comparable to full attention.
475
+
476
+ <table><tr><td rowspan="2">Task</td><td rowspan="2">Attention Method</td><td colspan="3">Mistral-7B-Instruct-v0.2</td></tr><tr><td>1024</td><td>2048</td><td>4096</td></tr><tr><td rowspan="5">PCount</td><td>Full Attention</td><td>2.75</td><td>2.75</td><td>2.75</td></tr><tr><td>H2O</td><td>2.89</td><td>3.18</td><td>3.46</td></tr><tr><td>StreamingLLM</td><td>2.44</td><td>2.57</td><td>2.62</td></tr><tr><td>TopK</td><td>2.73</td><td>2.85</td><td>2.83</td></tr><tr><td>ClusterAttn</td><td>2.98</td><td>3.09</td><td>2.73</td></tr><tr><td rowspan="5">PRe</td><td>Full Attention</td><td>86.98</td><td>86.98</td><td>86.98</td></tr><tr><td>H2O</td><td>85.45</td><td>87.12</td><td>86.38</td></tr><tr><td>StreamingLLM</td><td>78.08</td><td>82.56</td><td>83.77</td></tr><tr><td>TopK</td><td>81.18</td><td>82.47</td><td>81.56</td></tr><tr><td>ClusterAttn</td><td>88.56</td><td>87.43</td><td>86.18</td></tr><tr><td rowspan="5">Lcc</td><td>Full Attention</td><td>55.51</td><td>55.51</td><td>55.51</td></tr><tr><td>H2O</td><td>54.38</td><td>55.47</td><td>53.72</td></tr><tr><td>StreamingLLM</td><td>50.23</td><td>52.24</td><td>53.01</td></tr><tr><td>TopK</td><td>53.38</td><td>53.78</td><td>54.37</td></tr><tr><td>ClusterAttn</td><td>55.65</td><td>55.93</td><td>55.62</td></tr><tr><td rowspan="5">RB-P</td><td>Full Attention</td><td>52.88</td><td>52.88</td><td>52.88</td></tr><tr><td>H2O</td><td>50.74</td><td>52.24</td><td>51.1</td></tr><tr><td>StreamingLLM</td><td>47.32</td><td>49.57</td><td>50.11</td></tr><tr><td>TopK</td><td>51.29</td><td>51.12</td><td>52.45</td></tr><tr><td>ClusterAttn</td><td>51.87</td><td>52.01</td><td>52.65</td></tr></table>
477
+
478
+ Table 7: Performance of different sparse attention on various tasks. PCount and PRe represent retrieval-related tasks, while Lcc and RB-P are related to code completion tasks. These four datasets are from LongBench (Bai et al., 2024). The results show that across three different compression lengths, ClusterAttn significantly outperforms the other three baselines in most cases and is comparable to full attention.
479
+
480
+ num_block values ranging from 1 to 32, ensuring blksize were appropriate for the compression size.
481
+
482
+ Results show that cosine similarity peaks at a specific num_block value for each task. This is because that smaller blksize may overfit to single tokens, limiting generalization, while larger blksize may dilute high-score tokens with low-score ones, resulting in reduced differentiation among clusters. Larger blksize also reduce fitting flexibility, constraining diversity within a fixed compression size. With the optimal num_block, ClusterAttn effectively captures crucial attention clusters, adapting to context variability and enabling context-aware
483
+
484
+ <table><tr><td>Qasper 8</td><td>HotpotQA 8</td><td>GovReport 16</td><td>TREC 10</td></tr><tr><td>NtrvQA 8</td><td>2WikiMQA 10</td><td>QMSum 16</td><td>TriviaQA 10</td></tr><tr><td>MF-en 8</td><td>Musique 24</td><td>MultiNews 18</td><td>SAMSum 10</td></tr><tr><td>PCount 10</td><td>PRe 12</td><td>Lcc 10</td><td>RB-P 16</td></tr><tr><td colspan="4">LongEval 12</td></tr></table>
485
+
486
+ Table 8: The num_block to obtain the optimal cluster fitting for all experiments on Mistral-7B-Instruct-v0.2.
487
+
488
+ <table><tr><td>Qasper 8</td><td>HotpotQA 10</td><td>GovReport 18</td><td>TREC 8</td></tr><tr><td>NtrvQA 10</td><td>2WikiMQA 10</td><td>QMSum 18</td><td>TriviaQA 10</td></tr><tr><td>MF-en 8</td><td>Musique 20</td><td>MultiNews 24</td><td>SAMSum 8</td></tr><tr><td>PCount 10</td><td>PRe 12</td><td>Lcc 10</td><td>RB-P 18</td></tr><tr><td colspan="4">Needle-in-a-Haystack 10</td></tr></table>
489
+
490
+ compression in the KV cache. Table 8 and Table 9 reveal the best num_block to fit the intrinsic attention clusters for all our experiments after profiling. Besides, we also show the profiling time required to obtain the optimal num_block for all tasks in LongBench as in Table 10 and Table 11. It can be seen that ClusterAttn only requires a small number of samples and just a few hours to get the optimal num_block for each dataset, demonstrating the efficiency and practicality of ClusterAttn.
491
+
492
+ # F.3 ClusterAttn v.s. N-gram-based Attention Clustering
493
+
494
+ The intrinsic attention clustering is quite straightforward as a word has been tokenized to n-gram tokens. Thus, pivotal information naturally clusters among these n-gram tokens. To better show the effectiveness of our proposed Density-Based Attention Clustering Algorithm, we conducted the comparison between ClusterAttn and a simple n-gram-based Attention Clustering Algorithm here.
495
+
496
+ To implement the n-gram-based Attention Clustering Algorithm, we first use the observation window for feature aggregation like ClusterAttn. After aggregation, we select important positions based on the prefix attention sum in a descending order
497
+
498
+ Table 9: The num_block to obtain the optimal cluster fitting for all experiments on LWM-text-chat-1m.
499
+
500
+ <table><tr><td>Qasper
501
+ 0.49h,0.5h,0.56h</td><td>HotpotQA
502
+ 0.8h,0.79h,0.78h</td><td>GovReport
503
+ 4.12h,4.13h,4,38h</td><td>TREC
504
+ 0.92h,0.92h,0.95h</td></tr><tr><td>NtrvQA
505
+ 1.42h,1.44h,1.55h</td><td>2WikiMQA
506
+ 0.48h,0.51h,0.52h</td><td>QMSum
507
+ 1.46h,1.55h,2.06h</td><td>TriviaQA
508
+ 0.76h,0.77h,0.84h</td></tr><tr><td>MF-en
509
+ 0.64h,0.68h,0.72h</td><td>Musique
510
+ 0.95h,1.03h,1.01h</td><td>MultiNews
511
+ 4.2h,4.48h,4.64h</td><td>SAMSum
512
+ 0.8h,0.81h,0.93h</td></tr></table>
513
+
514
+ Table 10: The profiling time for all datasets in Long-Bench on Mistral-7B-Instruct-v0.2. From left to right, the compression sizes are 1024, 2048, 4096.
515
+
516
+ <table><tr><td>Qasper
517
+ 0.43h,0.43h,0.45h</td><td>HotpotQA
518
+ 0.77h,0.77h,0.79h</td><td>GovReport
519
+ 4.1h,4.1h,4,4h</td><td>TREC
520
+ 0.34h,0.35h,0.38h</td></tr><tr><td>NtrvQA
521
+ 1.97h,1.98h,2h</td><td>2WikiMQA
522
+ 0.45h,0.46h,0.48h</td><td>QMSum
523
+ 0.97h,1h,1.05h</td><td>TriviaQA
524
+ 0.63h,0.65h,0.66h</td></tr><tr><td>MF-en
525
+ 0.54h,0.54h,0.57h</td><td>Musique
526
+ 0.92h,0.92h,0.94h</td><td>MultiNews
527
+ 1.43h,1.51h,1.46h</td><td>SAMSum
528
+ 0.66h,0.68h,0.68h</td></tr></table>
529
+
530
+ Table 11: The profiling time for all datasets in Long-Bench on LWM-text-chat-1m. From left to right, the compression sizes are 1024, 2048, 4096.
531
+
532
+ and perform n-gram-based attention clustering iteratively until we reach the pre-set compression size. Specifically, we first (1) cluster and retain each position and its surrounding tokens that belong to the same word or phrase. Then, (2) for the current position, retain the n-1 neighboring clusters obtained from step (1) that are adjacent to the already clustered word or phrase, until the total compression length reaches the set compression size.
533
+
534
+ We still chose to compare the n-gram-based attention clustering algorithm and our density-based attention clustering algorithm on LongBench (Bai et al., 2024) using the LWM (Liu et al., 2024a) model, with the compression size set to 1024. From the results in Table 12, the n-gram-based attention clustering algorithm achieved its best performance at 2-gram (although still showing some gap compared to ClusterAttn). Our analysis is as follows:
535
+
536
+ Overall, the n-gram-based attention clustering focuses more on clustering based on the physical proximity of words and phrases, rather than understanding the semantics of the context (an important evaluation criterion for the effectiveness of compression algorithms). This results in clusters that are discrete, lacking semantic continuity, which in turn undermines the integrity of contextual information to some extent, and cannot guarantee the stability of the attention distribution in subsequent generation stages.
537
+
538
+ At the same time, we observed that the overall performance first increased from 1-gram to 2-gram and then decreased. Our understanding of this is that, similar to the effect of num_block on the clustering range in ClusterAttn, the value of n in
539
+
540
+ <table><tr><td rowspan="2">Task</td><td rowspan="2">Attention Method</td><td>LWM</td></tr><tr><td>1024</td></tr><tr><td rowspan="5">Single QA</td><td>1-gram</td><td>25.71</td></tr><tr><td>2-gram</td><td>26.83</td></tr><tr><td>3-gram</td><td>25.1</td></tr><tr><td>4-gram</td><td>23.31</td></tr><tr><td>ClusterAttn</td><td>27.32</td></tr><tr><td rowspan="5">Multi QA</td><td>1-gram</td><td>16.73</td></tr><tr><td>2-gram</td><td>17.97</td></tr><tr><td>3-gram</td><td>16.47</td></tr><tr><td>4-gram</td><td>16.28</td></tr><tr><td>ClusterAttn</td><td>18.40</td></tr><tr><td rowspan="5">Sum</td><td>1-gram</td><td>21.23</td></tr><tr><td>2-gram</td><td>21.59</td></tr><tr><td>3-gram</td><td>21.11</td></tr><tr><td>4-gram</td><td>20.72</td></tr><tr><td>ClusterAttn</td><td>22.59</td></tr><tr><td rowspan="5">Few-shot</td><td>1-gram</td><td>55.77</td></tr><tr><td>2-gram</td><td>56.33</td></tr><tr><td>3-gram</td><td>55.68</td></tr><tr><td>4-gram</td><td>55.17</td></tr><tr><td>ClusterAttn</td><td>57.01</td></tr></table>
541
+
542
+ Table 12: Average performance of ClusterAttn and the n-gram attention clustering algorithm on various tasks from LongBench.
543
+
544
+ n-gram also determines the size of the clustering range. Smaller values of n may result in clusters that are too dispersed, while larger values may include more redundant information, both of which lead to worse generation results after compression.
545
+
546
+ # G Visualization of the BlockNum on Head-level Cluster Fitting
547
+
548
+ Additionally, to prove that the obtained optimal num_block can achieve a relatively suitable cluster fit for each head, we presented the average cosine similarity for different num_block at the same compression size across attention heads. Taking the Qasper (Dasigi et al., 2021) dataset at compression size of 1024 as an example, as is shown in Figure 12, the best fit occurs when num_block equals 8. It can be seen that the overall similarity is higher when num_block is 8 compared to the others, further highlighting our method's capability to refine and apply context-aware compression to the KV cache for each head.
549
+
550
+ # H Visualization of Text Generation
551
+
552
+ We provide visualization of generation examples from narrativeqa (Kocisky et al., 2018), qasper (Dasigi et al., 2021) and samsum (Gliwa et al., 2019) datasets on Mistral-7B-Instruct-v0.2, as shown in Table 13, Table 14 and Table 15. Results are compared between ground truth, ClusterAttn with compression size 1024, 2048, 4096 and the
553
+
554
+ ![](images/13135c4e2bece05298f995f2a487ad20806911fd34f9eb3dc38e70fd35cb9b39.jpg)
555
+
556
+ ![](images/8a55fde536312b9f7db86c5b7c5a42258163dd151275fe205b04f13d836b76a5.jpg)
557
+
558
+ ![](images/ad2180dea0e2bd5aa4959dd6c6a44d71eedfc42c87cd1a4885ed0aaa143e8d37.jpg)
559
+ Figure 12: The average cosine similarity across all heads under different num_block with compression size 1024.
560
+
561
+ full attention.
562
+
563
+ ![](images/2c489ca181638d12b7400c30748adeddbb821e03e2f4b7926244ea4d32181bca.jpg)
564
+
565
+ ![](images/b19653296f33cd0fdcd6c4eabcba47fa996c1c452c8e45441cd23509e2761dcd.jpg)
566
+
567
+ ![](images/3046454f914c0ba041775f150481aff0cda0f8cbbf68e08382a43901bd9571ed.jpg)
568
+
569
+ ![](images/14b87e5fb65d86d9ef07076cff9177909c351d55f3358a5310d0b261fe57909f.jpg)
570
+
571
+ ![](images/4fadb88868016a08835cb83c518e2d80171db339feb64776ddcc8c5e15baedf0.jpg)
572
+
573
+ ![](images/9f4494b61abda0f9b2570eb3415ce3b4c0254a812d83c42886d10d5db9fdbfd1.jpg)
574
+
575
+ ![](images/b9c1ec2acfbf3c519e2fef3f1a6a0334de9067e6617663438418291bf551fb5c.jpg)
576
+
577
+ ![](images/322320e2978cb482c5434372b449c2e4575f79a454fe16557d972cb7b7f5a15f.jpg)
578
+
579
+ ![](images/7eecf3dfcf4c4290ed93d87819f9b302742bd2458a8d6b30d5df049c747bf3d1.jpg)
580
+
581
+ ![](images/4d0d83ad69861b99dd3b82b35cd1abe880b9b14c8f48845bb06b6a3a95710434.jpg)
582
+
583
+ ![](images/ab4b972407f773e088417b2c8b546bacebbe48c624b5e7133112c9ef327b8c99.jpg)
584
+
585
+ ![](images/96b065ba21b145e6628181e9b7a86e97aeb066e2e88f9293f6092d36cb9a50d2.jpg)
586
+
587
+ ![](images/fe98398e08ab27c025d82f5f8341a0faa3ad07bd21b5699410cd47a8a0f3e284.jpg)
588
+
589
+ ![](images/cea6adbdaa69fd69193091afd82378ca7c4c6f9a637008fee625e92e98edd045.jpg)
590
+
591
+ ![](images/1a7c472987a9851921bf8b5da631f6260a44aef535078b6df44e64287cf23c77.jpg)
592
+
593
+ ![](images/91725a6e5b027ec10573bd5b71c47891ac79e2b417364ce12eef8c8b8ae12e29.jpg)
594
+ Figure 13: The average cosine similarity of $\theta$ and num_block under all compression sizes for LongBench.
595
+
596
+ ![](images/3675b4f17aa9fd88ffc0cac83a1f4e7bb402ddc405e5308dffa7008d4d41eb08.jpg)
597
+
598
+ ![](images/d06c8f359bb2fcb55f240ec878fea42bc9076edc426f2d631404287f2d498fa7.jpg)
599
+
600
+ <table><tr><td colspan="2">NarrativeQA</td></tr><tr><td>Context</td><td>You are given a story, which can be either a novel or a movie script, and a question. Answer the question as concisely as you can , using a single phrase if possible. Do not provide any explanation.
601
+ Story: Transcribed from the 1915 Martin Secker edition by David Price, email ccx074@pglaf.org [Picture: Book cover]
602
+ THE COXON FUND BY HENRY JAMES [Picture: Decorative graphic] * * * * * LONDON: MARTIN SECKER NUMBER FIVE JOHN STREET ADELPHI * * * * * This edition first published 1915 The text follows that of the Definitive Edition * * * * * I “They’ve got him for life!” I said to myself that evening on my way back to the station;
603
+ ......
604
+ Now, answer the question based on the story as concisely as you can, using a single phrase if possible. Do not provide any explanation.
605
+ Question: What is Saltram’s living situation?
606
+ Answer:</td></tr><tr><td>Ground Truth</td><td>He is a guest in the home of the Mulvilles.</td></tr><tr><td>ClusterAttn 1024</td><td>Saltram is an inmate at the Mulvilles’ house.</td></tr><tr><td>ClusterAttn 2048</td><td>Saltram is an inmate and doesn’t dress, but he keeps dinner on at the Mulvilles’.</td></tr><tr><td>ClusterAttn 4096</td><td>Saltram is an inmate at the Mulvilles’ and doesn’t dress for dinner.</td></tr><tr><td>Full Attention</td><td>Saltram is an inmate at the Mulvilles’ house.</td></tr></table>
607
+
608
+ Table 13: Visualization of generation examples from narrativeqa dataset on Mistral-7B-Instruct-v0.2. Results are compared between ground truth, ClusterAttn with compression size 1024, 2048, 4096 and the full attention.
609
+
610
+ <table><tr><td colspan="2">Qasper</td></tr><tr><td>Context</td><td>Answer the question based on the given passages. Only give me the answer and do not output any other words.The following are given passages.INTRODUCTION The idea of language identification is to classify a given audio signal into a particular class using a classification algorithm. Commonly language identification task was done using i-vector systems [1]. A very well known approach for language identification proposed by N. Dahek et al. [1] uses the GMM-UBM model to obtain utterance level features called i-vectors.......Answer the question based on the given passages. Only give me the answer and do not output any other words.Question: What is the GhostVLAD approach? Answer:</td></tr><tr><td>Ground Truth</td><td>extension of the NetVLAD, adds Ghost clusters along with the NetVLAD clusters</td></tr><tr><td>ClusterAttn 1024</td><td>The GhostVLAD approach is an extension of the NetVLAD approach for face recognition, which adds Ghost clusters to map any noisy or irrelevant content into ghost clusters and are not included during the feature aggregation stage.</td></tr><tr><td>ClusterAttn 2048</td><td>The GhostVLAD approach is an extension of the NetVLAD approach for face recognition, which adds Ghost clusters to map any noisy or irrelevant content and assigns less weights to them during feature aggregation.</td></tr><tr><td>ClusterAttn 4096</td><td>The GhostVLAD approach is an extension of the NetVLAD approach for face recognition, which adds Ghost clusters to map any noisy or irrelevant content into ghost clusters and are not included during the feature aggregation stage.</td></tr><tr><td>Full Attention</td><td>The GhostVLAD approach is an extension of the NetVLAD approach for face recognition, which adds Ghost clusters to map any noisy or irrelevant content into ghost clusters and are not included during the feature aggregation stage.</td></tr></table>
611
+
612
+ Table 14: Visualization of generation examples from qasper dataset on Mistral-7B-Instruct-v0.2. Results are compared between ground truth, ClusterAttn with compression size 1024, 2048, 4096 and the full attention.
613
+
614
+ <table><tr><td colspan="2">SAMSum</td></tr><tr><td>Context</td><td>Answer the question based on the given passage. Only give me the answer and do not output any other words. The following are some examples.
615
+ Dialogue: Caron: are you getting the last c/s message? Rob: can you? Caron: yes ok Rob: I&#x27;m tied up Caron: that was good.. they wanted referrals for people top drove their food bank vans after they have done one of our courses Rob: I dont understand? Caron: they thought we were a training school and had a list of trained people looking for work Rob: oh??......
616
+ Dialogue: Meg: still at school? Ann: i have extra math classes Meg: so when can i meet you? Ann: i will be home at 7 Summary:</td></tr><tr><td>Ground Truth</td><td>Ann is still at school. She will be home at 7 so she can meet Meg then.</td></tr><tr><td>ClusterAttn 1024</td><td>Meg is asking Ann when she can meet her, Ann tells her she will be home at 7.</td></tr><tr><td>ClusterAttn 2048</td><td>Meg is asking Ann when she can meet her. Ann will be home at 7.</td></tr><tr><td>ClusterAttn 4096</td><td>Meg is asking Ann when she can meet her. Ann will be home at 7.</td></tr><tr><td>Full Attention</td><td>Meg is asking Ann when she can meet her. Ann will be home at 7.</td></tr></table>
617
+
618
+ Table 15: Visualization of generation examples from samsum dataset on Mistral-7B-Instruct-v0.2. Results are compared between ground truth, ClusterAttn with compression size 1024, 2048, 4096 and the full attention.
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:299e0abca838360f095be992b6b441e5ae5cfceafd57a95a7d875ff7991ff074
3
+ size 2002632
2025/ClusterAttn_ KV Cache Compression under Intrinsic Attention Clustering/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoAM_ Corpus of All-Type Multiword Expressions/e1808e4f-b33b-4a27-959d-a5721df232f5_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12b529057d39b3516162b90b198c1989ebec38ca126337acd425a96755437996
3
+ size 617781
2025/CoAM_ Corpus of All-Type Multiword Expressions/full.md ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CoAM: Corpus of All-Type Multiword Expressions
2
+
3
+ Yusuke Ide $^{1}$ Joshua Tanner $^{2}$ Adam Nohejl $^{1}$ Jacob Hoffman $^{2}$ Justin Vasselli $^{1}$ Hidetaka Kamigaito $^{1}$ Taro Watanabe $^{1}$
4
+
5
+ $^{1}$ Nara Institute of Science and Technology $^{2}$ Resolve Research
6
+
7
+ {ide.yusuke.ja6, nohejl.adam(mt3, vasselli.justin Rays.vk4, kamigaito.h, taro}
8
+
9
+ @is.naist.jp, {josh, jake}@rslv.dev
10
+
11
+ # Abstract
12
+
13
+ Multiword expressions (MWEs) refer to idiomatic sequences of multiple words. MWE identification, i.e., detecting MWEs in text, can play a key role in downstream tasks such as machine translation, but existing datasets for the task are inconsistently annotated, limited to a single type of MWE, or limited in size.
14
+
15
+ To enable reliable and comprehensive evaluation, we created CoAM: Corpus of All-Type Multiword Expressions, a dataset of 1.3K sentences constructed through a multi-step process to enhance data quality consisting of human annotation, human review, and automated consistency checking. Additionally, for the first time in a dataset for MWE identification, CoAM's MWEs are tagged with MWE types, such as NOUN and VERB, enabling fine-grained error analysis. Annotations for CoAM were collected using a new interface created with our interface generator, which allows easy and flexible annotation of MWEs in any form. Through experiments using CoAM, we find that a fine-tuned large language model outperforms MWEasWSD, which achieved the state-of-the-art performance on the DiMSUM dataset. Furthermore, analysis using our MWE type tagged data reveals that VERB MWEs are easier than NOUN MWEs to identify across approaches.
16
+
17
+ # 1 Introduction
18
+
19
+ Vocabulary plays a critical role in the comprehension of natural language. While often simplified as a collection of single words, vocabulary also includes idiomatic sequences known as multiword expressions (MWEs) (Baldwin and Kim, 2010), which form an important part of language knowledge (Jackendoff, 1995). We focus specifically on sequences whose meaning or grammatical structure
20
+
21
+ cannot be derived from their constituent words, as they can impede text analysis or comprehension; that is, we exclude transparent collocations. For example, the bold sequences below constitute MWEs.
22
+
23
+ (a) ACL stands for Association for Computational Linguistics.
24
+ (b) He has been under the weather lately.
25
+
26
+ MWE identification (MWEI), the process of automatically tagging MWEs in text (Constant et al., 2017), is valuable for tasks where word-by-word text processing is insufficient, such as machine translation (Li et al., 2024) and lexical complexity assessment (Kochmar et al., 2020). Briakou et al. (2024) investigated step-by-step translation using a large language model (LLM) and demonstrated that identifying MWEs in the initial step improves the translation quality. Additionally, it is possible to build reading assistance systems to automatically gloss text by combining MWEI with definition modeling (Bevilacqua et al., 2020); as Huang et al. (2022) discusses, definition modeling will help laypeople comprehend specialized terminology, which includes many MWEs.
27
+
28
+ Despite the importance of MWEI, existing datasets for the task are inconsistently annotated, limited to a single type of MWE, or limited in size, as described in Section 2. This hinders reliable and comprehensive evaluations of MWEI systems.
29
+
30
+ In this paper, we introduce the Corpus of All-type Multiword expressions (CoAM), a dataset of 1.3K sentences for MWEI. "Types" refer to MWE categories assigned based on the part of speech of the MWE, with "all-type" signifying the inclusion of all such categories of MWEs. To ensure annotation quality, we assigned two annotators and a reviewer to each sentence and checked all annotations for consistency. Additionally, MWEs in the CoAM test set are tagged with their types, such as NOUN and VERB, facilitating fine-grained error analysis of MWEI systems. This enables us to address questions such as: "Are verbal MWEs—
31
+
32
+ the focus of the long-running PARSEME project (Savary et al., 2017)—more difficult to identify compared to other categories of MWEs?"
33
+
34
+ Annotations for CoAM were collected using a checkbox-based annotation interface created using our new interface generator, CAIGen: checkbox-based Annotation Interface Generator. It allows easy and flexible annotation of MWEs in any form, including discontinuous MWEs such as pick... up in pick me up at the station, which are common in English and have historically been a challenge for MWEI systems (Rohanian et al., 2019).
35
+
36
+ Using CoAM, we evaluate two distinct MWEI approaches. The first approach, MWEasWSD (MaW, Tanner and Hoffman, 2023), combines a rule-based pipeline and a trainable bi-encoder model, achieving state-of-the-art performance on the DiMSUM dataset (Schneider et al., 2016). The second is LLM fine-tuning for MWEI, inspired by the effectiveness of similar approaches in the task of named entity recognition (NER, Zhou et al., 2024). We use CoAM to train and evaluate LLMs from the Llama (Dubey et al., 2024) and Qwen (Qwen Team, 2024) model families.
37
+
38
+ The results reveal that a fine-tuned Qwen model with 72B parameters greatly outperforms MaW, demonstrating the effectiveness of LLM finetuning. On the other hand, all approaches suffer from low recall (e.g., $50.7\%$ for Qwen-72B). Further analysis shows that fine-tuned LLMs struggle more with detecting NOUN and CLAUSE MWEs than with detecting VERB MWEs. MWEs not contained in WordNet (Miller, 1995), e.g., real estate, were found particularly difficult to identify, presumably because they are less widely recognized as MWEs.
39
+
40
+ # 2 Related Work
41
+
42
+ Datasets Previous studies have presented several datasets for MWEI and idiom $^3$ identification. The DiMSUM (Schneider et al., 2016) dataset consists of 5,799 sentences annotated with MWEs, including, but not limited to, verbal MWEs, noun MWEs, phatics, and multi-word (MW) proper nouns. Although DiMSUM has been used in multiple MWEI studies, e.g., Kirilin et al. (2016) and Liu et al. (2021), there exist inconsistencies in the annotation, which hinder proper evaluation. Tanner and Hoffman (2023) found that over $80\%$ of the false
43
+
44
+ positives of their system were actually caused by DiMSUM's inconsistent annotation. Next, the PARSEME corpus (Savary et al., 2017; Walsh et al., 2018) is a high-quality dataset for the identification of verbal MWEs. It has been continuously updated, and the latest version (1.3) contains over 455,000 sentences across 26 languages. However, their focus is limited to verbal MWEs. Lastly, ID10M (Tedeschi et al., 2022) is an idiom detection dataset consisting of automatically created training data in 10 languages and a manually curated evaluation benchmark of four languages. Their evaluation dataset was created with the help of professional annotators, but it contains only 200 sentences per language. They used Wiktionary as the source of idioms, and MWEs not in Wiktionary were skipped in the annotation. Additionally, they did not annotate discontinuous idioms. Among non-English datasets for MWE identification, Sequoia Corpus (Candito et al., 2020), a French corpus annotated for MWEs and named entities, stands out for containing 3,440 MWEs.
45
+
46
+ Tagging Schemes ID10M uses the BIO scheme. DiMSUM uses the more flexible 6-tag scheme, which allows discontinuous MWEs, but cannot handle overlapping MWEs (see Appendix D.2 for an example of overlapping MWEs). In contrast, the parseme-tsv format (Savary et al., 2017) accepts MWEs in any form, which leads us to adopt an equivalent data format.
47
+
48
+ Other Tasks Whereas these studies addressed MWE/idiom identification as a sequence tagging task, others worked on a related but different task, idiom usage recognition. It is a binary classification of word sequences in context as idiomatic/figurative or literal. The detection task in Muzny and Zettlemoyer (2013), SemEval-2013 Task 5b (Korkontzelos et al., 2013), SemEval-2022 Task 2 Subtask A (Tayyar Madabushi et al., 2022), and the MAGPIE corpus (Haagsma et al., 2020) are set up for this task. Our task setting is more realistic and challenging than these, requiring systems to identify all MWEs within a given sentence.
49
+
50
+ # 3 Task Formulation
51
+
52
+ We formulate the MWEI task as token-level sequence tagging, where the inputs are tokenized sentences and each token can belong to multiple MWEs. Given the token sequence of each sentence, $x_{1},\ldots ,x_{n}$ , the task is to output a list of
53
+
54
+ MWEs where each MWE is represented as a list of token indices. The $i$ -th MWE in the sentence is represented with $[\mathrm{idx}(t_{i,1}), \mathrm{idx}(t_{i,2}), \ldots]$ where $t_{i,j}$ is the $j$ -th token of the MWE and $\mathrm{idx}(t)$ is $t$ 's index. Our annotation interface allows annotations in this scheme, as illustrated in Figure 1.
55
+
56
+ # 4 Construction of CoAM
57
+
58
+ # 4.1 Data Selection and Preprocessing
59
+
60
+ In selecting the sources of our dataset, we prioritized sources aimed at general audiences so that they are in standard English and mostly free of grammatical errors. We also included both written text and transcribed speech. Consequently, we utilized the following four data sources (see Appendix A.1 for their details). News is news text written by professional writers sourced from EMM NewsBrief, which was introduced by Glavaš and Šajner (2013).<sup>4</sup> Commentary is commentaries on news from the WMT23 Shared Task monolingual training data (Kocmi et al., 2023). TED is a collection of TED talk transcriptions from two sources. (1) NAIST is the dataset by Neubig et al. (2014); (2) IWSLT is the subset of IWSLT 2017 Shared Task (Cettolo et al., 2017). UD is a collection of single sentences sourced from weblogs, reviews, question-answers, newsgroups, and emails in the English Web Treebank. It is part of the Universal Dependencies (Zeman et al., 2018) and the English PARSEME corpus (Walsh et al., 2018). We did not include any sentences from UD in the test set, because UD contains user-generated content with frequent grammatical errors. All the other sources were used both for training and test splits.
61
+
62
+ For all sources, we took the first 10 (or all, when there are less than 10) sentences from each article or talk and presented them in original order. Each sentence was tokenized using spaCy (we use version 3.7.1 and the en_core_web_trf model throughout this paper), with the exception of the UD sentences, which were already tokenized. Note that what we call words are tokens given in this manner.
63
+
64
+ # 4.2 Annotation Guidelines
65
+
66
+ The construction of a reliable dataset requires clear guidelines for annotators in order to minimize mis-annotation. However, we found no such guidelines
67
+
68
+ for all-type MWE annotation, which led us to create new guidelines.
69
+
70
+ We define MWEs as idiomatic sequences that satisfy the following three conditions, based on the definition by the often-cited Baldwin and Kim (2010) and the PARSEME annotation guidelines.
71
+
72
+ (a) It consists of at least two words that are always realized by the same lexemes. This condition means that his in put yourself in his shoes is not part of the MWE, as other words like Michael's can replace it.
73
+ (b) It displays semantic, lexical, or syntactic idiomaticity. Semantic idiomaticity occurs when the meaning of an expression cannot be derived from its constituent words. It is the most important type of idiomaticity because it accounts for the majority of MWEs being classified as idiomatic. See additional discussion on semantic idiomaticity in relation to non-compositionality in Appendix A.2. Note that transparent collocations such as stuck at are not MWEs in our definition because they are not semantically, lexically, or syntactically idiomatic. The meaning or grammatical structure of transparent collocations can be understood by their constituents, and thus they can be processed word-by-word.
74
+ (c) It is not a proper noun, i.e., a specific name of a person, facility, and so on. Previous MWE studies either classified MW proper nouns as MWEs (Schneider et al., 2016) or excluded them as non-idiomatic (Tayyar Madabushi et al., 2022). We opted for the latter, as proper nouns are linked to encyclopedic knowledge rather than lexicographic knowledge (Navigli and Ponzetto, 2012), to which typical MWEs belong to.
75
+
76
+ The full MWE definition is given in Appendix D. The guidelines were updated whenever an issue was found, e.g., an ambiguous description.
77
+
78
+ # 4.3 Annotation Interface
79
+
80
+ For flexible and efficient annotation, we developed a novel annotation interface generator, CAIGen. CAIGen builds a checkbox-based interface in Google Sheets<sup>6</sup>, allowing annotators to perform annotations of MWEs and other kinds of spans simply by checking checkboxes as shown in Figure 1. In the interface generation process, for each sentence, CAIGen first writes the sentence ID, the
81
+
82
+ ![](images/535fcfb3fcf7b3cefacad4d3c05e2a948cca55e719b247b030bcff4f76f4f469.jpg)
83
+ Figure 1: An example sentence presented in our interface by CAIGen. Checks in the checkboxes are instantly reflected in the bordered zone at the upper right, showing which MWEs are currently marked. Note that the number of rows is reduced here for brevity; the actual interfaces we used have nine rows per sentence.
84
+
85
+ <table><tr><td></td><td>Flexible annotation</td><td>Easy collaboration</td><td>Easy-to-use interface</td><td>Customizable interface</td></tr><tr><td>brat</td><td>×</td><td>×</td><td>✓</td><td>×</td></tr><tr><td>FLAT</td><td>✓</td><td>×</td><td>×</td><td>×</td></tr><tr><td>Ours</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr></table>
86
+
87
+ Table 1: Comparison of annotation tools.
88
+
89
+ sentence itself, and a bordered box to show the result of annotations. Then, it arranges each token from left to right, wrapping the line when its length hits a pre-set limit.
90
+
91
+ Its main advantages over other comparable annotation tools are summarized in Table 1. The first tool, brat $^{7}$ (Stenetorp et al., 2012), has been used for annotation of a wide range of tasks such as sentiment analysis (Pontiki et al., 2016) and NER (Tabassum et al., 2020). FLAT $^{8}$ was used for the annotation of the PARSEME corpus (Savary et al., 2017). The advantages of CAIGen over these are as follows. First, the generated interface supports annotations of spans of any form, including discontinuous or overlapping spans (see Appendix D.2 for examples), making it more flexible than the previous tools. Second, CAIGen alleviates researchers' overhead of managing servers and annotator accounts by delegating to Google, while the other tools require either (1) distributing data slices to each annotator and having them run applications locally or (2) running and managing the application on a remote server. Third, CAIGen provides an easy-to-use spreadsheet-based interface, which is simple and familiar to technical and non-technical annotators alike. Lastly, our interface is highly customizable because CAIGen builds it using Google Apps Script, a well-documented programming language based on JavaScript; for example, additional
92
+
93
+ annotations of span types could be easily collected.
94
+
95
+ # 4.4 Annotation
96
+
97
+ The annotation was done by two annotators hired through a company and five authors. The hired annotators comprise one native and one non-native English speaker, both with at least six years of experience as translators. They received feedback from the authors after annotating the first 50 or so sentences to correct misunderstandings about the guidelines. We paid 154 JPY (roughly 1 USD) per sentence as a reward to the company. Meanwhile, the author annotators consist of three native and two non-native speakers, all with a language-related degree and sufficient English proficiency to perform the task. For reliable annotation, we assigned each sentence to two annotators (one hired annotator and one author), ensuring that at least one was a native English speaker, as the task requires a rich English vocabulary.
98
+
99
+ All annotators were instructed to carefully read the guidelines and perform annotation using the checkbox-based interface. In the authors' annotation, we marked unclear sentences to remove them later because it is hard to determine whether a span is an MWE in such sentences.
100
+
101
+ # 4.5 Inter-Annotator Agreement
102
+
103
+ With two annotators being assigned to each sentence, we measured the inter-annotator agreement (IAA) by the MWE-based (exact-match) F1 score. The IAA was found to be only $37.3\%$ , which could be attributed to annotators failing to annotate valid MWEs. We thus suggest that MWE datasets should be constructed with at least two independent annotators to reduce missed MWEs.
104
+
105
+ Nonetheless, it should be noted that this IAA is comparable with other MWEI datasets, and that it does not reflect the quality of CoAM. Our IAA is computed in a strict way, which we chose for its
106
+
107
+ clear interpretability. CoAM's IAA is comparable to those of other datasets when the same, more lenient methods are used. PARSEME 1.1 (Ramisch et al., 2018) computes F1 for exact span matches as we do, but they only report "the highest scores among all possible annotator pairs" (see Table 1, ibid.). The highest score for English PARSEME is $52.9\%$ , similar to the highest score computed in the same way for CoAM: $52.2\%$ . Meanwhile, DiMSUM was annotated by a single annotator, and thus no actual agreement was reported. Although Schneider et al. (2016) estimates DiMSUM's IAA to range from $60\%$ to $75\%$ , this is based on a very small subset (66 sentences) reannotated by the first author and computed as a more lenient F1 score based on partial span matches. Thus, while our reported IAA value is low, we emphasize that our IAA is in line with comparable MWEI datasets. Additionally, we addressed the annotation disagreements through the combination of human review and consistency checking as described below.
108
+
109
+ # 4.6 Review
110
+
111
+ To solve the disagreement between the two annotators and correct any other problematic annotations, two authors—both native English speakers—reviewed all the annotations. We presented them with the annotations in a special interface for reviewing, where the tags given by only one annotator were highlighted, and we asked them to mark inappropriate tags to be deleted and newly found MWEs to be added. When the review was complete, we updated our dataset according to the marks added by reviewers.
112
+
113
+ # 4.7 Consistency Check
114
+
115
+ One of the primary issues with the annotations in the DiMSUM dataset is their inconsistency—that is, a number of MWEs are annotated in one location and not another, despite equivalent constituents and semantics being present in both places. For example, see how give_try is labeled in only one of the sentences in Table 3.
116
+
117
+ In order to quantify this issue in both DiMSUM and CoAM—and to eliminate it from CoAM—we used a partially automated approach to find inconsistencies in both the entirety of CoAM and 1.3K sentences (the size of CoAM) randomly sampled from DiMSUM. We started by initializing an empty set $M$ , then iterated through all given sentences and added all labeled MWEs from them to $M$ . Next, we used a simple rule-based MWEI pipeline, re
118
+
119
+ purposed from Tanner and Hoffman (2023), to find constituent groups in other sentences that could correspond to an MWE in $M$ but were not already labeled. Finally, an author and native speaker of English reviewed each of these candidate constituent groups to see if they are semantically equivalent to already labeled instances of this MWE—that is, to see if they represent an inconsistency.
120
+
121
+ We found 118 instances of inconsistencies like this in the random sample of DiMSUM and 147 in CoAM, reaffirming the difficulty involved in producing consistent MWE annotations. However, we then added the missing labels to all MWEs found in this way, eliminating these inconsistencies from the final CoAM data.
122
+
123
+ # 4.8 MWE Type Tagging
124
+
125
+ To enable fine-grained error analysis, we automatically tagged all the MWEs in CoAM with MWE types. We then manually corrected the tags in the test set, as described below, to enable a precise analysis of the results by MWE types.
126
+
127
+ Inspired by the classification by Schneider et al. (2014b), we group MWEs into five types: NOUN, VERB, MODIFIER/CONNECTIVE (MOD/CONN), CLAUSE, and OTHER. The details are described in Table 2. We automatically tag MWE types in each sentence based on the dependency structure. Dependency parses were provided in the data source for UD and obtained using spaCy for News, Commentary, and TED. For each MWE $m = (w_{1},\ldots ,w_{|m|})$ , we look for its syntactic head, namely, try to find $w^{*}$ that has all the other words in $m$ as its descendants. If $m$ has such $w^{*}$ , we determine its type based on the PoS of $w^{*}$ ; for example, we tag $m$ as VERB when $w^{*}$ is a verb. If $m$ does not have such $w^{*}$ , we tag $m$ as OTHER. For the details, see the algorithm in Appendix A.3.
128
+
129
+ We then manually checked all 384 MWEs in the test set and corrected the errors in them. Two authors who are native English speakers conducted this, identifying and correcting 30 errors. The error rate of automatic tagging was therefore $7.8\%$ . The most common errors were MOD/CONN automatically tagged as VERB (e.g., according to) and OTHER (e.g., not only) constituting $3.3\%$ and $3.1\%$ of the test data, respectively. We expect this to be
130
+
131
+ <table><tr><td>Type</td><td>PoS of Head</td><td>Description</td><td>Example</td></tr><tr><td>NOUN</td><td>NOUN, PRON,
132
+ PROPN</td><td>Noun MWEs or compounds.</td><td>the middle of nowhere, red tape</td></tr><tr><td>VERB</td><td>VERB, AUX</td><td>Verbal MWEs.</td><td>stand for, pick up, be the case</td></tr><tr><td>MOD/
133
+ CONN</td><td>ADJ, ADV, ADP,
134
+ CCONJ, SCONJ</td><td>Adjectival, adverbial, adpositional, or connective
135
+ MWEs.</td><td>under the weather, of course, in
136
+ spite of</td></tr><tr><td>CLAUSE</td><td>VERB, AUX</td><td>MWEs containing (1) a verb or auxiliary verb and (2)
137
+ its nominal subject, such as phatics and proverbs.</td><td>you&#x27;re welcome, the early bird
138
+ gets the worm, when it comes to</td></tr><tr><td>OTHER</td><td>Any</td><td>MWEs whose head is not contained in them or whose
139
+ PoS is none of the PoS above.</td><td>and so on, oh man</td></tr></table>
140
+
141
+ Table 2: MWE types in CoAM. The PoS are denoted with UPOS tags. Underlines denote the head of an MWE.
142
+
143
+ <table><tr><td>Sentence</td><td>Marked</td></tr><tr><td>Having never booked train tickets online before thought I would give it a try and was very surprised at how much I saved.</td><td>✔</td></tr><tr><td>Would recommend giving this a try.</td><td>×</td></tr></table>
144
+
145
+ Table 3: Inconsistent annotation of give_try. Note that the second sentence is reproduced as in DiMSUM, including apparent typos.
146
+
147
+ representative of the errors in the type tags automatically assigned to the training set. Note, however, that we used only the manually corrected tags on the test set for result analysis in Section 6.2.
148
+
149
+ # 4.9 Statistics
150
+
151
+ Table 4 shows dataset statistics. CoAM has more than 1.3K sentences. The MWE density is $6 - 7\%$ in both training and test sets. This proportion is much lower than that of DiMSUM (Schneider et al., 2016)— $13\%$ overall—most likely because DiMSUM includes proper noun phrases in MWEs. Among the five MWE types, VERB and NOUN are the most frequent ones across data sources. See Appendix A.4 for additional analysis regarding MWE continuity.
152
+
153
+ # 5 MWEI Approaches
154
+
155
+ We use CoAM to evaluate the following MWEI approaches.
156
+
157
+ # 5.1 MWEasWSD
158
+
159
+ MWEasWSD (MaW) is an approach that uses (1) an MWE lexicon—WordNet (Miller, 1995)—and a rule-based pipeline to identify MWE candidates and (2) a trainable model to filter MWE candidates (Tanner and Hoffman, 2023). It achieved state-of-the-art performance on the DiMSUM dataset. They published four of their filtering models,
160
+
161
+ among which we use the bi-encoder (BiEnc) and DCA poly-encoder (DCA). Both models are based on BERT (Devlin et al., 2019), specifically bert-base-uncased. They have been trained with SemCor (Miller et al., 1993), and we further finetune each model with the CoAM training set. We also run MaW with the rule-based pipeline only, i.e., without a filtering model.
162
+
163
+ # 5.2 LLM Fine-Tuning
164
+
165
+ Recent studies have shown the effectiveness of LLM fine-tuning for a wide range of tasks, such as NER (Zhou et al., 2024) and grammatical error correction (Kaneko and Okazaki, 2023). Framing their task as sequence transduction, they achieved high performance by providing LLMs with prompts that included instructions on the task.
166
+
167
+ Inspired by their success, we perform LLM finetuning, where the inputs to LLMs are instructions for MWEI (a summary of the annotation guidelines) followed by formatted tokens in a sentence.
168
+
169
+ # 6 Experiments
170
+
171
+ # 6.1 Setup
172
+
173
+ LLM Fine-Tuning We use four instruction-tuned LLMs that are available on Hugging Face Hub: Llama-3.1-8B-Instruct, Llama-3.1-70B-Instruct (Dubey et al., 2024), Qwen-2.5-7B-Instruct, and Qwen-2.5-72B-Instruct (Qwen Team, 2024). We abbreviate them, e.g., to Llama8B, omitting the versions. For efficient training and inference, we use QLoRA (Dettmers et al., 2023), performing 4-bit NormalFloat quantization and double quantization. Other hyperparameters are described in Appendix B.1. The computational budgets are in Appendix C.
174
+
175
+ To find a performant input-output format, we conduct preliminary experiments with three for
176
+
177
+ <table><tr><td rowspan="2"></td><td rowspan="2">Sentences</td><td rowspan="2">Words</td><td rowspan="2">MWEs</td><td rowspan="2">MWE Density (%)</td><td colspan="5">MWE Type Proportion (%)</td></tr><tr><td>NOUN</td><td>VERB</td><td>MOD/CONN</td><td>CLAUSE</td><td>OTHER</td></tr><tr><td>News</td><td>360</td><td>9,328</td><td>230</td><td>5.5</td><td>32.2</td><td>44.3</td><td>23.0</td><td>0.0</td><td>0.4</td></tr><tr><td>Commentary</td><td>357</td><td>9,310</td><td>269</td><td>7.0</td><td>30.5</td><td>29.7</td><td>33.1</td><td>1.5</td><td>5.2</td></tr><tr><td>TED</td><td>299</td><td>6,592</td><td>210</td><td>7.1</td><td>35.2</td><td>38.6</td><td>21.4</td><td>3.8</td><td>1.0</td></tr><tr><td>UD</td><td>285</td><td>5,001</td><td>158</td><td>7.2</td><td>42.4</td><td>39.2</td><td>12.7</td><td>1.3</td><td>4.4</td></tr><tr><td>Train</td><td>780</td><td>16,817</td><td>486</td><td>6.7</td><td>36.2</td><td>38.3</td><td>19.8</td><td>1.4</td><td>4.3</td></tr><tr><td>Test</td><td>521</td><td>13,414</td><td>381</td><td>6.4</td><td>31.8</td><td>36.5</td><td>29.1</td><td>1.8</td><td>0.8</td></tr><tr><td>Total</td><td>1,301</td><td>30,231</td><td>867</td><td>6.6</td><td>34.3</td><td>37.5</td><td>23.9</td><td>1.6</td><td>2.8</td></tr></table>
178
+
179
+ Table 4: Statistics of CoAM. MWE density is the percentage of words in MWEs. The test set comprises part of News, Commentary, and TED, while the training set comprises the rest of the data.
180
+
181
+ <table><tr><td>Role</td><td>Message</td></tr><tr><td>System</td><td>You are a helpful system to identify multiple-word expressions (MWEs).</td></tr><tr><td>User</td><td>Identify all the MWEs in the given sentence, and output their surface forms and the indices of their components.\n\n[mw_defINITION]\n\nEach sentence is given as a string of words delimited by &#x27;\n&#x27;. Respond in TSV format, where the first and second columns contain words and MWE tags, respectively. The MWE tag should be a string of MWE identifiers. When a word belongs to multiple MWEs, the tag should be a concatenation of their numbers delimited by semicolons.\n\nSentence:\nACL\nstands\n</td></tr><tr><td></td><td>:</td></tr></table>
182
+
183
+ Table 5: Example prompt for fine-tuning, based on the tsv_to_tsv format. In our main experiments, [MWEDEFINITION] will be filled with the long MWE definition described in Appendix B.1.
184
+
185
+ mats, adjusting the prompt for each format. These experiments are detailed in Appendix B.1. We find tsv_to_tsv (see Table 5) is the only format the models can comply with and thus adopt it.
186
+
187
+ All prompts contain a placeholder for a definition of MWEs to clarify what sequences should be marked. We report scores using what we refer to as the long definition in Table 6. For scores using a shorter definition, see the ablation study in Appendix B.1.
188
+
189
+ Evaluation Metrics We use MWE-based precision, recall, and F1 score (Savary et al., 2023). See
190
+
191
+ Appendix B.2 for their exact definitions.
192
+
193
+ # 6.2 Results and Analysis
194
+
195
+ In Table 6a, the left three columns show the overall scores. Fine-tuned Qwen-72B achieves the best F1, surpassing the highest F1 by Rule+DCA of MaW. Additionally, fine-tuned Qwen-72B outperforms all MaW systems in precision and recall. This indicates the effectiveness of fine-tuning LLMs for MWEI—particularly LLMs with a large number of parameters. One explanation for this could be that knowledge about MWEs was acquired by LLMs through pre-training, and we can harness this knowledge for MWEI by fine-tuning.
196
+
197
+ Meanwhile, all systems, except for the rule-based one, suffer from low recall. Even the best system, fine-tuned Qwen-72B, achieves a recall of only $52.8\%$ , missing almost half of the gold MWEs.
198
+
199
+ Analysis of Recall Given the low recall across all systems, we conduct further analysis to determine which MWEs the models particularly struggle to identify.
200
+
201
+ Recall by MWE Type in Table 6a shows that CLAUSE and NOUN MWEs tend to be more difficult to identify than MOD/CONN or VERB MWEs across models.
202
+
203
+ In Table 6b, the first two columns analyze how much recall changes depending on whether the MWE is seen or unseen, where an MWE in the test set is considered unseen if the multi-set of lemmas of its constituents was never annotated in the training set. We find that seen MWEs are easier to identify than unseen ones across models and systems, which resembles the results of the PARSEME shared task 1.2 (Ramisch et al., 2020).
204
+
205
+ Recall by Continuity in Table 6b shows that discontinuous MWEs are, across models and systems,
206
+
207
+ <table><tr><td rowspan="2" colspan="2"></td><td rowspan="2">F1</td><td rowspan="2">P</td><td rowspan="2">R</td><td colspan="4">Recall by MWE Type</td></tr><tr><td>NOUN (121)</td><td>VERB (139)</td><td>MOD/CONN (111)</td><td>CLAUSE (7)</td></tr><tr><td rowspan="4">FT</td><td>Llama-8B</td><td>24.9±3.7</td><td>92.0±2.0</td><td>14.4±2.4</td><td>3.3±0.0</td><td>19.4±2.9</td><td>21.6±4.8</td><td>0.0±0.0</td></tr><tr><td>Llama-70B</td><td>38.3±5.2</td><td>69.0±1.7</td><td>26.8±5.1</td><td>19.0±5.2</td><td>39.6±7.5</td><td>21.6±2.7</td><td>0.0±0.0</td></tr><tr><td>Qwen-7B</td><td>48.1±1.0</td><td>60.9±0.8</td><td>39.7±1.0</td><td>28.7±1.3</td><td>52.0±0.8</td><td>39.6±0.9</td><td>0.0±0.0</td></tr><tr><td>Qwen-72B</td><td>57.8±1.8</td><td>63.8±2.2</td><td>52.8±2.1</td><td>42.1±4.4</td><td>59.7±1.4</td><td>57.7±1.8</td><td>28.6±0.0</td></tr><tr><td rowspan="3">MaW</td><td>Rule</td><td>32.4</td><td>27.9</td><td>38.6</td><td>33.1</td><td>45.3</td><td>39.6</td><td>0.0</td></tr><tr><td>Rule+BiEnc</td><td>41.4±0.3</td><td>47.9±0.8</td><td>36.5±0.3</td><td>28.9±0.0</td><td>45.3±0.0</td><td>36.9±0.9</td><td>0.0±0.0</td></tr><tr><td>Rule+DCA</td><td>41.9±0.2</td><td>49.0±0.5</td><td>36.7±0.5</td><td>29.8±0.0</td><td>45.3±0.7</td><td>36.6±1.0</td><td>0.0±0.0</td></tr></table>
208
+
209
+ (a)
210
+
211
+ <table><tr><td rowspan="2" colspan="2"></td><td colspan="2">Recall by Seen/Unseen</td><td colspan="2">Recall by Continuity</td><td colspan="2">Recall by In WN or Not</td></tr><tr><td>Seen (141)</td><td>Unseen (240)</td><td>Continuous (338)</td><td>Discontinuous (43)</td><td>True (161)</td><td>False (220)</td></tr><tr><td rowspan="4">FT</td><td>Llama-8B</td><td>29.6±5.0</td><td>5.6±0.9</td><td>16.0±2.7</td><td>2.3±0.0</td><td>23.4±3.2</td><td>7.9±1.8</td></tr><tr><td>Llama-70B</td><td>37.1±4.5</td><td>20.7±5.4</td><td>29.0±4.9</td><td>9.3±6.2</td><td>43.9±6.3</td><td>14.2±4.1</td></tr><tr><td>Qwen-7B</td><td>47.3±0.4</td><td>35.3±1.3</td><td>43.9±1.1</td><td>7.0±0.0</td><td>53.8±0.9</td><td>29.4±1.1</td></tr><tr><td>Qwen-72B</td><td>61.9±0.8</td><td>47.4±3.8</td><td>57.3±1.8</td><td>17.1±4.8</td><td>62.7±2.8</td><td>45.5±2.8</td></tr><tr><td rowspan="3">MaW</td><td>Rule</td><td>46.8</td><td>33.8</td><td>41.7</td><td>14.0</td><td>91.3</td><td>0.0</td></tr><tr><td>Rule+BiEnc</td><td>45.2±0.4</td><td>31.4±0.2</td><td>39.6±0.3</td><td>11.6±0.0</td><td>86.3±0.6</td><td>0.0±0.0</td></tr><tr><td>Rule+DCA</td><td>44.0±1.2</td><td>32.4±0.2</td><td>40.3±0.5</td><td>7.8±1.3</td><td>86.7±1.3</td><td>0.0±0.0</td></tr></table>
212
+
213
+ (b)
214
+ Table 6: Results by MWEI system and metric/MWE category, as mean percentage scores of three runs with random training seeds. The numbers in parentheses are the MWE counts. $\pm$ denotes standard deviation. The bold font denotes the highest score. Rule stands for the rule-based baseline, and $WN$ for WordNet.
215
+
216
+ <table><tr><td>Result</td><td>MWE</td><td>Context</td><td>Note</td></tr><tr><td>TP</td><td>fire up</td><td>The allegations have fired up the opposition, ...</td><td>VERB in WordNet</td></tr><tr><td>TP</td><td>at least</td><td>... since at least the 1950s.</td><td>MOD/CONN in WordNet</td></tr><tr><td>FN</td><td>in ... hands</td><td>... concentration of power in his own hands.</td><td>MOD/CONN in WordNet</td></tr><tr><td>FN</td><td>real estate</td><td>... park their toxic real estate assets ...</td><td>NOUN not in WordNet</td></tr><tr><td>FN</td><td>you know</td><td>You know, it&#x27;s very old ...</td><td>CLAUSE not in WordNet</td></tr></table>
217
+
218
+ Table 7: Examples of true positives (TPs) and false negatives (FNs), i.e., MWEs identified/missed in all three runs, of fine-tuned Qwen-72B.
219
+
220
+ far more difficult to identify than continuous ones, indicating that discontinuous MWEs remain a key challenge and require further attention.
221
+
222
+ Recall by In WN or Not in Table 6b reveals that MWEs not contained in WordNet are much more difficult to identify than those in WordNet. It is natural that MaW systems cannot identify the MWEs not in WordNet, as their rule-based pipeline cannot detect these candidates, but interestingly we find that fine-tuned LLMs also struggle to identify MWEs not in WordNet. We hypothesize that this is caused by MWEs in WordNet being more widely recognized as MWEs or idioms and that this recognition is reflected in the training data of the LLMs, enhancing their ability to identify these MWEs.
223
+
224
+ Table 7 shows examples of correctly identified MWEs and missed MWEs by fine-tuned Qwen-
225
+
226
+ 72B. VERB MWEs in WordNet like fire up are relatively easy to identify, with a recall of $79.0\%$ achieved by the model. Meanwhile, the discontinuous MWE, in ... hands, was not correctly identified. Additionally, the NOUN MWE real estate was not identified; the aforementioned hypothesis could explain this, as real estate is not in WordNet. Accurately identifying those MWEs could be a challenge for future studies.
227
+
228
+ Ablation Study on LLM Fine-Tuning Given the relatively high performance of fine-tuned Qwen-72B, we investigate how much fine-tuning (FT) contributes to the performance by comparing FT to zero-shot learning (ZSL) and few-shot learning (FSL). In ZSL, we provide the models with the same prompt as FT. In FSL, we sample 5 pairs of
229
+
230
+ <table><tr><td></td><td>Llama-70B</td><td>Qwen-72B</td></tr><tr><td>FT</td><td>38.3±5.2</td><td>57.8±1.8</td></tr><tr><td>FSL</td><td>6.1±0.0</td><td>12.9±0.0</td></tr><tr><td>ZSL</td><td>3.9</td><td>1.4</td></tr></table>
231
+
232
+ Table 8: Ablation results by MWEI method and model, as mean percentage F1 scores of three runs (for FT the randomness arises from training, and for FSL from example selection). $\pm$ denotes standard deviation.
233
+
234
+ input (sentence) and output (gold MWE set) from the training set, convert them into the tsv_to_tsv format, and include them in the prompt as examples. In the sampling process, we ensure that the models have a sufficient number of examples to learn the task and format by repeating random sampling until at least two of the example sentences contain one or more MWEs.
235
+
236
+ Table 8 shows the results. FT greatly outperforms ZSL and FSL, demonstrating the effectiveness of fine-tuning on the CoAM training set.
237
+
238
+ Comparison considering computational efficiency As shown in Table 6a, fine-tuned Qwen-72B outperforms the best MaW system in all of the F1 score, precision, and recall. However, the LLM takes substantial memory and compute, and MaW is more efficient in this regard. MaW's encoder model (bert-base-uncased) has only 110M parameters, taking approximately $2 \times 110\mathrm{M} \times 4 = 880\mathrm{M}$ bytes in total (2 is the number of encoders). 4-bit quantized Qwen-72B takes 72,000M $\times$ 0.5 = 36,000M bytes, taking roughly 40 times more space than MaW. On the other hand, the performance of 4-bit quantized Qwen-7B, which takes roughly 4 times more space, is comparable with Rule+DCA.
239
+
240
+ # 7 Conclusion
241
+
242
+ In this paper, we constructed CoAM, a high-quality dataset of 1.3K sentences for MWEI covering all types of MWEs. Using a combination of human review and automated consistency checking, we addressed consistency issues that have been a problem for previous MWE datasets, enabling more accurate evaluation results for future work in MWEI. We used CoAM to evaluate two MWEI approaches: MaW and LLM fine-tuning. Our largest fine-tuned LLM performed the best, but all systems suffered from low recall. Consequently, we argue that MWEI overall remains a challenging task.
243
+
244
+ # Limitations
245
+
246
+ Dataset Size Because the objective of this work was to maximize dataset quality, we invested heavily in efforts to improve data quality, employing multiple annotators per sentence, manual review, and consistency checking. This focus on quality over quantity resulted in a slightly smaller dataset size (1.3K sentences) compared to some previous works like DiMSUM and PARSEME. However, the evaluation set of CoAM has many more sentences than the gold data of ID10M (Tedeschi et al., 2022), and is large enough for our purpose of reliably evaluating MWEI systems.
247
+
248
+ CAIGen We observed a usability issue with our annotation interface, CAIGen. It requires annotators to use separate table rows for each annotated MWE. Because annotators may forget to use separate rows, which happened in the construction of CoAM, researchers should urge them to confirm their annotations are as intended after finishing each sentence.
249
+
250
+ MWEI Approaches In this study, we experimented with an existing approach, MaW, as well as LLM fine-tuning. Future work could explore other previously proposed methods, such as BERT-based tagging with BIO-like labels, as introduced by Taslimipoor et al. (2020).
251
+
252
+ # Ethical Considerations
253
+
254
+ All sources of CoAM are permitted at minimum for use in research, as described in Appendix A.1. CoAM itself will be released under the condition that the users do not publish the data on the open web to prevent its leakage to the training data of future models. All annotators of CoAM consented to the publication of their annotations. Throughout the dataset construction processes, we found no content harmful to the environment, specific groups of people, or privacy.
255
+
256
+ # Acknowledgments
257
+
258
+ We are grateful for the insightful comments by Yuki Arase, Shohei Higashiyama, and anonymous reviewers. To polish the content of this paper, we used ChatGPT<sup>11</sup> as a writing assistant tool. Financially, this work was supported by JST SPRING Grant Number JPMJSP2140.
259
+
260
+ # References
261
+
262
+ Timothy Baldwin and Su Nam Kim. 2010. Multiword expressions. In Handbook of Natural Language Processing, pages 267-292, Boca Raton. CRC Press.
263
+ Michele Bevilacqua, Marco Maru, and Roberto Navigli. 2020. Generationary or "how we went beyond word sense inventories and learned to gloss". In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 7207-7221, Online. Association for Computational Linguistics.
264
+ Ann Bies, Justin Mott, Colin Warner, and Seth Kulick. 2012. English web treebank. LDC2012T13.
265
+ Eleftheria Briakou, Jiaming Luo, Colin Cherry, and Markus Freitag. 2024. Translating step-by-step: Decomposing the translation process for improved translation quality of long-form texts. In Proceedings of the Ninth Conference on Machine Translation, pages 1301-1317, Miami, Florida, USA. Association for Computational Linguistics.
266
+ Marie Candito, Mathieu Constant, Carlos Ramisch, Agata Savary, Bruno Guillaume, Yannick Parmentier, and Silvio Ricardo Cordeiro. 2020. A french corpus annotated for multiword expressions and named entities. Journal of Language Modelling, 8(2).
267
+ Mauro Cettolo, Marcello Federico, Luisa Bentivogli, Jan Niehues, Sebastian Stüker, Katsuhito Sudoh, Koichiro Yoshino, and Christian Federmann. 2017. Overview of the IWSLT 2017 evaluation campaign. In Proceedings of the 14th International Conference on Spoken Language Translation, pages 2-14, Tokyo, Japan. International Workshop on Spoken Language Translation.
268
+ Mauro Cettolo, Christian Girardi, and Marcello Federico. 2012. Wit3: Web inventory of transcribed and translated talks. In EAMT, pages 261-268.
269
+ Mathieu Constant, Gülşen Eryigit, Johanna Monti, Loneneke Van Der Plas, Carlos Ramisch, Michael Rosner, and Amalia Todirascu. 2017. Multiword expression processing: A survey. Computational Linguistics, 43(4):837-892.
270
+ Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer. 2023. Qlora: Efficient finetuning of quantized llms. In Advances in Neural Information Processing Systems, volume 36, pages 10088-10115. Curran Associates, Inc.
271
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4171-4186, Minneapolis, Minnesota. Association for Computational Linguistics.
272
+
273
+ Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Amy Yang, Angela Fan, et al. 2024. The llama 3 herd of models. Preprint, arXiv:2407.21783.
274
+ Goran Glavaš and Sanja Štajner. 2013. Event-centered simplification of news stories. In Proceedings of the Student Research Workshop associated with RANLP 2013, pages 71-78, Hissar, Bulgaria. INCOMA Ltd. Shoumen, BULGARIA.
275
+ Hessel Haagsma, Johan Bos, and Malvina Nissim. 2020. MAGPIE: A large corpus of potentially idiomatic expressions. In Proceedings of the Twelfth Language Resources and Evaluation Conference, pages 279-287, Marseille, France. European Language Resources Association.
276
+ Jie Huang, Hanyin Shao, Kevin Chen-Chuan Chang, Jinjun Xiong, and Wen-mei Hwu. 2022. Understanding jargon: Combining extraction and generation for definition modeling. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 3994-4004, Abu Dhabi, United Arab Emirates. Association for Computational Linguistics.
277
+ Ray Jackendoff. 1995. The Boundaries of Lexicon. In M. Everaert, E.J. van der Linden, A. Schenk, R. Schreuder, and R. Schreuder, editors, *Idioms: Structural and Psychological Perspectives*, pages 133-166. Erlbaum, NJ.
278
+ Masahiro Kaneko and Naoaki Okazaki. 2023. Reducing sequence length by predicting edit spans with large language models. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 10017-10029, Singapore. Association for Computational Linguistics.
279
+ Angelika Kirilin, Felix Krauss, and Yannick Versley. 2016. ICL-HD at SemEval-2016 task 10: Improving the detection of minimal semantic units and their meanings with an ontology and word embeddings. In Proceedings of the 10th International Workshop on Semantic Evaluation (SemEval-2016), pages 937–945, San Diego, California. Association for Computational Linguistics.
280
+ Ekaterina Kochmar, Sian Gooding, and Matthew Shardlow. 2020. Detecting multiword expression type helps lexical complexity assessment. In Proceedings of the Twelfth Language Resources and Evaluation Conference, pages 4426-4435, Marseille, France. European Language Resources Association.
281
+ Tom Kocmi, Eleftherios Avramidis, Rachel Bawden, Ondrej Bojar, Anton Dvorkovich, Christian Federmann, Mark Fishel, Markus Freitag, Thamme Gowda, Roman Grundkiewicz, Barry Haddow, Philipp Koehn, Benjamin Marie, Christof Monz, Makoto Morishita, Kenton Murray, Makoto Nagata, Toshiaki Nakazawa, Martin Popel, Maja Popovic, and Mariya Shmatova. 2023. Findings of the 2023
282
+
283
+ conference on machine translation (WMT23): LLMs are here but not quite there yet. In Proceedings of the Eighth Conference on Machine Translation, pages 1-42, Singapore. Association for Computational Linguistics.
284
+ Ioannis Korkontzelos, Torsten Zesch, Fabio Massimo Zanzotto, and Chris Biemann. 2013. SemEval-2013 task 5: Evaluating phrasal semantics. In Second Joint Conference on Lexical and Computational Semantics (*SEM), Volume 2: Proceedings of the Seventh International Workshop on Semantic Evaluation (SemEval 2013), pages 39–47, Atlanta, Georgia, USA. Association for Computational Linguistics.
285
+ Shuang Li, Jiangjie Chen, Siyu Yuan, Xinyi Wu, Hao Yang, Shimin Tao, and Yanghua Xiao. 2024. Translate meanings, not just words: Idiomkb's role in optimizing idiomatic translation with language models. In Proceedings of the Thirty-Eighth AAAI Conference on Artificial Intelligence and Thirty-Sixth Conference on Innovative Applications of Artificial Intelligence and Fourteenth Symposium on Educational Advances in Artificial Intelligence, AAAI'24/IAAI'24/EAAI'24. AAAI Press.
286
+ Nelson F. Liu, Daniel Hershcovich, Michael Kranzlein, and Nathan Schneider. 2021. Lexical semantic recognition. In Proceedings of the 17th Workshop on Multiword Expressions (MWE 2021), pages 49-56, Online. Association for Computational Linguistics.
287
+ George A. Miller. 1995. Wordnet: A lexical database for english. Communications of the ACM, 38(1):39-41.
288
+ George A. Miller, Claudia Leacock, Randee Tengi, and Ross T. Bunker. 1993. A semantic concordance. In Human Language Technology: Proceedings of a Workshop Held at Plainsboro, New Jersey, March 21-24, 1993.
289
+ Grace Muzny and Luke Zettlemoyer. 2013. Automatic idiom identification in Wiktionary. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pages 1417-1421, Seattle, Washington, USA. Association for Computational Linguistics.
290
+ Roberto Navigli and Simone Paolo Ponzetto. 2012. Babelnet: The automatic construction, evaluation and application of a wide-coverage multilingual semantic network. Artificial Intelligence, 193:217-250.
291
+ Graham Neubig, Katsuhiro Sudoh, Yusuke Oda, Kevin Duh, Hajime Tsukuda, and Masaaki Nagata. 2014. The NAIST-NTT TED talk treebank. In Proceedings of the 11th International Workshop on Spoken Language Translation: Papers, pages 265–270, Lake Tahoe, California.
292
+ Maria Pontiki, Dimitris Galanis, Haris Papageorgiou, Suresh Manandhar, Ion Androutsopoulos, Núria Bel, and Gülsen Eryiğit. 2016. Semeval-2016 task 5: Aspect based sentiment analysis. In International Workshop on Semantic Evaluation.
293
+
294
+ Qwen Team. 2024. Qwen2.5: A party of foundation models.
295
+ Carlos Ramisch, Silvio Ricardo Cordeiro, Agata Savary, Veronika Vincze, Verginica Barbu Mittelu, Archna Bhatia, Maja Buljan, Marie Candito, Polona Gantar, Voula Giouli, Tunga Güngör, Abdelati Hawwari, Uxoa Iñurrieta, Jolanta Kovalevskaite, Simon Krek, Timm Lichte, Chaya Liebeskind, Johanna Monti, Carla Parra Escartín, Behrang QasemiZadeh, Renata Ramisch, Nathan Schneider, Ivelina Stoyanova, Ashwini Vaidya, and Abigail Walsh. 2018. Edition 1.1 of the PARSEME shared task on automatic identification of verbal multiword expressions. In Proceedings of the Joint Workshop on Linguistic Annotation, Multiword Expressions and Constructions (LAW-MWE-CxG-2018), pages 222-240, Santa Fe, New Mexico, USA. Association for Computational Linguistics.
296
+ Carlos Ramisch, Agata Savary, Bruno Guillaume, Jakub Waszczuk, Marie Candito, Ashwini Vaidya, Verginica Barbu Mititelu, Archna Bhatia, Uxoa Inurrieta, Voula Giouli, Tunga Güngör, Menghan Jiang, Timm Lichte, Chaya Liebeskind, Johanna Monti, Renata Ramisch, Sara Stymne, Abigail Walsh, and Hongzhi Xu. 2020. Edition 1.2 of the PARSEME shared task on semi-supervised identification of verbal multiword expressions. In Proceedings of the Joint Workshop on Multiword Expressions and Electronic Lexicons, pages 107-118, online. Association for Computational Linguistics.
297
+ Omid Rohanian, Shiva Taslimipoor, Samaneh Kouchaki, Le An Ha, and Ruslan Mitkov. 2019. Bridging the gap: Attending to discontinuity in identification of multiword expressions. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 2692-2698, Minneapolis, Minnesota. Association for Computational Linguistics.
298
+ Ivan A. Sag, Timothy Baldwin, Francis Bond, Ann Copestake, and Dan Flickinger. 2002. Multiword expressions: a pain in the neck for nlp.
299
+ Agata Savary, Cherifa Ben Khelil, Carlos Ramisch, Voula Giouli, Verginica Barbu Mititelu, Najet Hadj Mohamed, Cvetana Krstev, Chaya Liebeskind, Hongzhi Xu, Sara Stymne, Tunga Güngör, Thomas Pickard, Bruno Guillaume, Eduard Bejček, Archna Bhatia, Marie Candito, Polona Gantar, Uxoa Inurrieta, Albert Gatt, Jolanta Kovalevskaite, Timm Lichte, Nikola Ljubesić, Johanna Monti, Carla Parra Escartin, Mehrnoush Shamsfard, Ivelina Stoyanova, Veronika Vincze, and Abigail Walsh. 2023. PARSEME corpus release 1.3. In Proceedings of the 19th Workshop on Multiword Expressions (MWE 2023), pages 24-35, Dubrovnik, Croatia. Association for Computational Linguistics.
300
+ Agata Savary, Carlos Ramisch, Silvio Cordeiro, Federico Sangati, Veronika Vincze, Behrang QasemiZadeh, Marie Candito, Fabienne Cap, Voula Giouli, Ivelina Stoyanova, and Antoine Doucet. 2017. The
301
+
302
+ PARSEME shared task on automatic identification of verbal multiword expressions. In Proceedings of the 13th Workshop on Multiword Expressions (MWE 2017), pages 31-47, Valencia, Spain. Association for Computational Linguistics.
303
+ Nathan Schneider, Emily Danchik, Chris Dyer, and Noah A. Smith. 2014a. Discriminative lexical semantic segmentation with gaps: Running the MWE gamut. Transactions of the Association for Computational Linguistics, 2:193-206.
304
+ Nathan Schneider, Dirk Hovy, Anders Johannsen, and Marine Carpuat. 2016. SemEval-2016 task 10: Detecting minimal semantic units and their meanings (DiMSUM). In Proceedings of the 10th International Workshop on Semantic Evaluation (SemEval-2016), pages 546-559, San Diego, California. Association for Computational Linguistics.
305
+ Nathan Schneider, Spencer Onuffer, Nora Kazour, Emily Danchik, Michael T Mordowanec, Henrietta Conrad, and Noah A Smith. 2014b. Comprehensive annotation of multiword expressions in a social web corpus. In Proceedings of the Ninth International Conference on Language Resources and Evaluation, pages 455-461. European Language Resources Association (ELRA).
306
+ Pontus Stenetorp, Sampo Pyysalo, Goran Topić, Tomoko Ohta, Sophia Ananiadou, and Jun'ichi Tsujii. 2012. Brat: a web-based tool for nlp-assisted text annotation. In Proceedings of the Demonstrations at the 13th Conference of the European Chapter of the Association for Computational Linguistics, pages 102-107.
307
+ Jeniya Tabassum, Mounica Maddela, Wei Xu, and Alan Ritter. 2020. Code and named entity recognition in stackoverflow. In Annual Meeting of the Association for Computational Linguistics.
308
+ Joshua Tanner and Jacob Hoffman. 2023. MWE as WSD: Solving multiword expression identification with word sense disambiguation. In Findings of the Association for Computational Linguistics: EMNLP 2023, pages 181-193, Singapore. Association for Computational Linguistics.
309
+ Shiva Taslimipoor, Sara Bahaadini, and Ekaterina Kochmar. 2020. MTLB-STRUCT @parse 2020: Capturing unseen multiword expressions using multitask learning and pre-trained masked language models. In Proceedings of the Joint Workshop on Multiword Expressions and Electronic Lexicons, pages 142-148, online. Association for Computational Linguistics.
310
+ Harish Tayyar Madabushi, Edward Gow-Smith, Marcos Garcia, Carolina Scarton, Marco Idiart, and Aline Villavicencio. 2022. SemEval-2022 task 2: Multilingual idiomaticity detection and sentence embedding. In Proceedings of the 16th International Workshop on Semantic Evaluation (SemEval-2022), pages 107-121, Seattle, United States. Association for Computational Linguistics.
311
+
312
+ Simone Tedeschi, Federico Martelli, and Roberto Navigli. 2022. ID10M: Idiom identification in 10 languages. In Findings of the Association for Computational Linguistics: NAACL 2022, pages 2715-2726, Seattle, United States. Association for Computational Linguistics.
313
+ Abigail Walsh, Claire Bonial, Kristina Geeraert, John P. McCrae, Nathan Schneider, and Clarissa Somers. 2018. Constructing an annotated corpus of verbal MWEs for English. In Proceedings of the Joint Workshop on Linguistic Annotation, Multiword Expressions and Constructions (LAW-MWE-CxG-2018), pages 193–200, Santa Fe, New Mexico, USA. Association for Computational Linguistics.
314
+ Ralph Weischedel, Martha Palmer, Mitchell Marcus, Eduard Hovy, Sameer Pradhan, Lance Ramshaw, Nianwen Xue, Ann Taylor, Jeff Kaufman, Michelle Franchini, Mohammed El-Bachouti, Robert Belvin, and Ann Houston. 2013. Ontonotes release 5.0. LDC2013T19.
315
+ Seid Muhie Yimam, Chris Biemann, Shervin Malmasi, Gustavo Paetzold, Lucia Specia, Sanja Šajner, Anaïs Tack, and Marcos Zampieri. 2018. A report on the complex word identification shared task 2018. In Proceedings of the Thirteenth Workshop on Innovative Use of NLP for Building Educational Applications, pages 66-78, New Orleans, Louisiana. Association for Computational Linguistics.
316
+ Daniel Zeman, Jan Hajic, Martin Popel, Martin Potthast, Milan Straka, Filip Ginter, Joakim Nivre, and Slav Petrov. 2018. CoNLL 2018 shared task: Multilingual parsing from raw text to Universal Dependencies. In Proceedings of the CoNLL 2018 Shared Task: Multilingual Parsing from Raw Text to Universal Dependencies, pages 1-21, Brussels, Belgium. Association for Computational Linguistics.
317
+ Wenxuan Zhou, Sheng Zhang, Yu Gu, Muhao Chen, and Hoifung Poon. 2024. UniversalNER: Targeted distillation from large language models for open named entity recognition. In The Twelfth International Conference on Learning Representations.
318
+
319
+ <table><tr><td>Source</td><td>Paper</td><td>URL</td><td>License</td><td>Note</td></tr><tr><td>News</td><td>Glavaš and Šajner (2013); Yimam et al. (2018)</td><td>https://takelab.fer.hr/data/evsimplify/ https://sites.google.com/view/cwisharedtask2018/datasets</td><td>Creative Commons Attribution-NonCommercial-ShareAlike 3.0</td><td>We used the News_Train data from the CWI Shared Task 2018 datasets.</td></tr><tr><td>Commentary</td><td>Kocmi et al. (2023)</td><td>https://data.statmt.org/news-commentary/v18.1/training-monolingual/</td><td>Can be freely used for research purposes.</td><td>We used the English part of v18.1.</td></tr><tr><td>TED (NAIST-NTT)</td><td>Neubig et al. (2014)</td><td>https://ahcweb01.naist.jp/old/resource/tedtreebank/</td><td>Creative Commons ShareAlike-Attribution-NonCommercial</td><td></td></tr><tr><td>TED (IWSLT)</td><td>Cettolo et al. (2012, 2017)</td><td>https://wit3.fbk.eu/2017-01https://wit3.fbk.eu/2017-01-b</td><td>Creative Commons Attribution-NonCommercial-NoDerivs 3.0</td><td></td></tr><tr><td>UD</td><td>Bies et al. (2012); Walsh et al. (2018)</td><td>https://gitlab.com/parseme/parseme Corpus_en</td><td>Creative Commons ShareAlike 4.0</td><td>We used the portion of PARSEME corpus from the English Web Treebank.</td></tr></table>
320
+
321
+ Table 9: Data sources of CoAM.
322
+
323
+ # A Construction of CoAM
324
+
325
+ # A.1 Data Sources
326
+
327
+ See Table 9.
328
+
329
+ # A.2 Notes on Idiomaticity and (Non-)Compositionality
330
+
331
+ To judge whether a sequence is an MWE, we focus on (semantic) idomaticity instead of non-compositionality, although non-compositionality has been considered an inherent property of MWEs in previous studies, such as Tedeschi et al. (2022). To discuss the difference between the two notions, let us consider the expression spill the beans. It is deemed compositional because it can be analyzed as being made up of spill in a "reveal" sense and the beans in a "secret(s)" sense, resulting in the overall compositional reading of "reveal the secret(s)" (Sag et al., 2002). Meanwhile, the "secret(s)" sense is unique to the expression and cannot be derived from the word beans, making the whole expression semantically idiomatic. We argue that spill the beans should be identified as an MWE because the meaning of beans depends on the whole expression, and that any idiomatic sequences of this kind should be identified even if they are compositional.
332
+
333
+ # A.3 Algorithm for MWE Type Tagging
334
+
335
+ We tag MWEs in CoAM by the algorithm shown in Algorithm 1.
336
+
337
+ # A.4 Statistics Regarding MWE Continuity
338
+
339
+ Discontinuous MWEs are common in English, and previous work has stressed the importance of identifying them (Schneider et al., 2014a; Rohanian et al., 2019). Table 10 shows the ratio of discontinuous MWEs by MWE type. VERB MWEs have the highest proportion of discontinuous expressions, while MOD/CONN, NOUN, and OTHER MWEs reach lower values.
340
+
341
+ Algorithm 1 Algorithm of MWE Type Tagging
342
+ Input: MWE m
343
+ Output: Type t
344
+ 1: for all $w_i \in m$ do
345
+ 2: if $w_i = w^*$ then
346
+ 3: if PoS of $w_i \in \{\text{NOUN}, \text{PRON}, \text{PROP}\}$ then
347
+ 4: if children of $w_i$ include a relative clause modifier that is verb then
348
+ 5: t ← VERB ▷ E.g., ... the price he pays ...
349
+ 6: end if
350
+ 7: t ← NOUN ▷ E.g., ... born in the middle of nowhere ...
351
+ 8: else if PoS of $w_i \in \{\text{VERB}, \text{AUX}\}$ then
352
+ 9: if nominal subject of $w_i \in m$ then
353
+ 10: t ← CLAUSE ▷ E.g., ... when it comes to climate change ...
354
+ 11: else
355
+ 12: t ← VERB ▷ E.g., ... the expression stands for ...
356
+ 13: end if
357
+ 14: else if PoS of $w_i \in \{\text{ADP}, \text{ADJ}, \text{ADV}, \text{CCONJ}, \text{SCONJ}\}$ then
358
+ 15: t ← MOD/CONN ▷ E.g., ... for at least two decades ...
359
+ 16: else
360
+ 17: t ← OTHER (other PoS) ▷ E.g., ... de facto target gauge ...
361
+ 18: end if
362
+ 19: else
363
+ 20: t ← OTHER (head not in MWE) ▷ E.g., ..., and so on ...
364
+ 21: end if
365
+ 22: end for
366
+ 23: return t
367
+
368
+ <table><tr><td>MWE Type</td><td>Discontinuous (%)</td><td>Example</td></tr><tr><td>Noun</td><td>2.0</td><td>... a suicide car bomber and Taliban militants ...</td></tr><tr><td>Verb</td><td>21.8</td><td>... turned four aircraft into cruise missiles ...</td></tr><tr><td>Mod/Conn</td><td>4.8</td><td>... concentration of power in his own hands.</td></tr><tr><td>Clause</td><td>0.0</td><td></td></tr><tr><td>Other</td><td>20.8</td><td>... no more than 2.7%.</td></tr></table>
369
+
370
+ Table 10: Ratio of discontinuous MWEs in CoAM by MWE type.
371
+
372
+ <table><tr><td rowspan="4">LoRA</td><td>r</td><td>64</td></tr><tr><td>α</td><td>16</td></tr><tr><td>Dropout</td><td>0.05</td></tr><tr><td>Target modules</td><td>All linear layers</td></tr><tr><td rowspan="7">Training</td><td>Epoch</td><td>3</td></tr><tr><td>Effective batch size</td><td>32</td></tr><tr><td rowspan="2">Learning rate</td><td>1e-4 for Llama-70B</td></tr><tr><td>2e-4 for other models</td></tr><tr><td>Learning rate scheduler</td><td>constant</td></tr><tr><td>Optimizer</td><td>paged_adamw_8bit (β2=0.999)</td></tr><tr><td>Max grad norm</td><td>0.3</td></tr></table>
373
+
374
+ Table 11: Hyperparameters for fine-tuning. The epoch was determined based on preliminary experiments, while other parameters are based on Dettmers et al. (2023).
375
+
376
+ <table><tr><td>Name</td><td colspan="2">Example (Input → Output)</td></tr><tr><td>dict_to_dict_list</td><td>{1: &#x27;ACL&#x27;, 2: &#x27;stands&#x27;, 3: &#x27;for&#x27;, ...}</td><td>→ [{&#x27;surface&#x27;: &#x27;stands for&#x27;, indices&#x27;: [2, 3]}]</td></tr><tr><td>str_to_str_numberSpan</td><td>ACL stands for Association for Computational Linguists.</td><td>→ ACL &lt;1&gt;stands for&lt;/1&gt; Association for Computational Linguists.</td></tr><tr><td>tsv_to_tsv</td><td>ACL\nstands\nfor\n</td><td>→ ACL\t\nstands\t1\nfor\t1\n</td></tr><tr><td></td><td>:</td><td>:</td></tr></table>
377
+
378
+ Table 12: Input-output formats for fine-tuning. Bold fonts denote the format employed for the main experiments. Suppose the sentence given as the example is ACL stands for Association for Computational Linguistics.
379
+
380
+ # B Experimental Setup
381
+
382
+ # B.1 LLM fine-tuning
383
+
384
+ Hyperparameters Table 11 shows hyperparameters used for training and evaluation. At inference, we perform greedy decoding.
385
+
386
+ Input-Output Format To investigate the optimal input-output format, we perform preliminary experiments. We prepare three input-output formats described in Table 12. All the output formats allow us to represent MWEs in any form, including discontinuous or overlapping MWEs. We train and evaluate Llama-8B and Qwen-7B with CoAM, using each input-output format. We use the hyperparameters described in Table 11 and the long MWE definition (same as the main experiments).
387
+
388
+ As a result, tsv_to_tsv turned out to be the only format the models can comply with. Employing other formats results in the violation of the format despite carefully written instructions. With dict_to_dict_list, the models produce wrong indices in the outputs. With str_to_str_numberSpan, the models delete spaces before punctuations.
389
+
390
+ MWE Definition To validate the efficacy of the long MWE definition, we perform an ablation study
391
+
392
+ comparing the long definition to the short definition. They are both a summary of the full definition described in Appendix D. As shown in Table 13, the long definition has 162 words while the short is further contracted to 57 words. We perform experiments with Llama-8B and Qwen-7B, using the tsv_to_tsv format and the hyperparameters described in Table 11 (same as the main experiments).
393
+
394
+ Table 14 presents the result. For both models, the long definition achieves higher F1 scores than the short by more than 12 points, indicating the effectiveness of a detailed definition.
395
+
396
+ # B.2 Evaluation Metrics
397
+
398
+ We use MWE-based (exact-match) precision, recall, and F1 score (Savary et al., 2023). Let $G$ be the set of gold MWEs and $H$ the set of predicted MWEs (hypothesis),
399
+
400
+ $$
401
+ \operatorname {R e c a l l} = | G \cap H | / | G | \tag {1}
402
+ $$
403
+
404
+ $$
405
+ \text {P r e c i s i o n} = | G \cap H | / | H | \tag {2}
406
+ $$
407
+
408
+ where each MWE is represented with the ID of the sentence and the IDs of its constituent tokens. F1 is the harmonic mean of precision and recall.
409
+
410
+ <table><tr><td>Name</td><td>Content</td></tr><tr><td>Long</td><td>Here, an MWE is defined as a sequence that satisfies the following three conditions.\n1. It consists of multiple words that are always realized by the same lexemes. Such words cannot be replaced without distorting the meaning of the expression or violating language conventions.\n2. It displays semantic, lexical, or syntactic idiomaticity. Semantic idiomaticity occurs when the meaning of an expression cannot be explicitly derived from its components. In other words, a semantically idiomatic takes on a meaning that is unique to that combination of words. Lexical idiomaticity occurs when one or more components of an expression are not used as stand-alone words in standard English. Syntactic idiomaticity occurs when the grammar of an expression cannot be derived directly from that of its components. For example, semantically idiomatic MWEs include &quot;break up&quot;, the lexically idiomatic include &quot;to and fro&quot;, and the syntactically idiomatic include &quot;long time no see&quot;.\n3. It is not a multi-word named entity, i.e., a specific name of a person, facility, etc.</td></tr><tr><td>Short</td><td>Here, an MWE is defined as a sequence that satisfies the following three conditions.\n1. It consists of multiple words that are always realized by the same lexemes.\n2. It is idiomatic, that is, its meaning cannot be explicitly derived from its components.\n3. It is not a multi-word named entity, i.e., a specific name of a person, facility, etc.</td></tr></table>
411
+
412
+ Table 13: MWE definitions to be included in prompts for fine-tuning.
413
+
414
+ <table><tr><td rowspan="2" colspan="2"></td><td rowspan="2">F1</td><td rowspan="2">P</td><td rowspan="2">R(121)</td><td colspan="4">Recall by MWE Type</td></tr><tr><td>Noun(139)</td><td>Verb(111)</td><td>Mod/Conn(7)</td><td>Clause</td></tr><tr><td rowspan="2">Long</td><td>Llama-8B</td><td>24.9±3.7</td><td>92.0±2.0</td><td>14.4±2.4</td><td>3.3±0.0</td><td>19.4±2.9</td><td>21.6±4.8</td><td>0.0±0.0</td></tr><tr><td>Qwen-7B</td><td>48.1±1.0</td><td>60.9±0.8</td><td>39.7±1.0</td><td>28.7±1.3</td><td>52.0±0.8</td><td>39.6±0.9</td><td>0.0±0.0</td></tr><tr><td rowspan="2">Short</td><td>Llama-8B</td><td>21.0±3.1</td><td>89.9±4.7</td><td>11.9±2.0</td><td>3.3±0.0</td><td>16.3±2.3</td><td>16.8±5.0</td><td>0.0±0.0</td></tr><tr><td>Qwen-7B</td><td>36.7±1.3</td><td>65.7±0.7</td><td>25.5±1.3</td><td>15.4±1.7</td><td>32.6±2.2</td><td>29.7±0.0</td><td>0.0±0.0</td></tr></table>
415
+
416
+ Table 14: Ablation results, as mean percentage scores of three runs with random seeds. The numbers in parentheses are the MWE counts. $\pm$ denotes standard deviation.
417
+
418
+ # C Computational Budgets
419
+
420
+ For experiments for MaW (Rule+BiEnc and Rule+DCA), we use a single NVIDIA RTX 2080Ti GPU with 11GB RAM. Each run of training and testing takes around 8 minutes. Consequently, the total GPU hours for MaW are estimated to be 0.8 hours.
421
+
422
+ For LLM fine-tuning, we use NVIDIA RTX 6000 GPU with 48GB RAM for smaller models (Llama-8B and Qwen-7B) and NVIDIA A100 PCIe with 80GB RAM for larger models (Llama-70B and Qwen-72B). Each run of training and testing takes around 66 minutes for the smaller models and 588 minutes for the larger models. Thus, the total GPU hours for fine-tuning experiments of smaller and larger models are estimated to be 6.6 hours and 58.8 hours, respectively.
423
+
424
+ # D Excerpt of Annotation Guidelines
425
+
426
+ # D.1 Definition of MWEs
427
+
428
+ In our definition, MWEs are idiomatic sequences that (a) consist of multiple words, (b) display semantic, lexical, or syntactic idiomaticity, and (c) are not proper nouns.
429
+
430
+ a. An MWE consists of at least two words that are always realized by the same lexemes. $^{12}$ For example, the MWE "break up" is always realized by (1) "break" or its conjugated form such as "broke" and (2) "up". Such words cannot be replaced without distorting the meaning of the expression or violating the language conventions.
431
+ b. An MWE displays semantic, lexical, or syntactic idiomaticity. The semantically idiomatic MWEs include "break up", the lexically idiomatic include "to and fro", and the syntactically idiomatic include "long time no see".
432
+
433
+ - Semantic idiomaticity occurs when the meaning of an expression cannot be derived from its components. That is, you cannot necessarily infer the meaning of the expression even if you know all the senses of its components. In other words, a semantically idiomatic expression takes on a meaning that is unique to that combination of words.
434
+ The inferability differs from one expression to another. The meaning of idiomatic MWEs such as "kick the bucket" cannot be inferred from its components at all. The meaning of institutionalized phrases like "traffic light" is inferable to some degree. Yet "traffic light" is semantically idiomatic because it does not mean any type of light related to traffic but a specific type of light.
435
+ - Lexical idiomaticity occurs when one or more components of an expression are not used as stand-alone words in standard English. Examples include "bide one's time"; "bide" rarely appears by itself in today's standard English.
436
+ - Syntactic idiomaticity occurs when the grammatical structure of an expression cannot be derived directly from that of its components. It constitutes expressions whose grammar seems to go against standard English grammatical conventions. This includes expressions such as "all of a sudden," where "sudden" appears in its archaic noun form.
437
+
438
+ c. An MWE is not a proper noun, such as the name of a specific person, organization, and so forth. In this project, do not annotate proper nouns unless they are part of an MWE (like Pavlov in "Pavlov's dog"). Proper nouns usually start with a capital letter, while exceptions like "iPhone 15" exist. Below is the full list of proper nouns in our definition. $^{13}$
439
+
440
+ <table><tr><td>Type</td><td>Example</td></tr><tr><td>People&#x27;s names</td><td>Shohei Ohtani</td></tr><tr><td>Nationalities or religious or political groups</td><td>African American, Sunni Muslims</td></tr><tr><td>Facilities</td><td>Narita International Airport, Taipei 101</td></tr><tr><td>Organizations</td><td>Procter &amp; Gamble, Kyoto University</td></tr><tr><td>Geopolitical entities (GPE)</td><td>Los Angeles, the United Kingdom</td></tr><tr><td>Non-GPE locations</td><td>Mount Fuji, Amazon River</td></tr><tr><td>Products</td><td>Toyota Prius, Samsung Galaxy</td></tr><tr><td>Named events</td><td>World War II, Olympic Games Tokyo 2020</td></tr><tr><td>Works of art</td><td>Norwegian Wood, Bohemian Rhapsody</td></tr><tr><td>Named legal documents</td><td>The Magna Carta</td></tr><tr><td>Named languages</td><td>Middle English, American Sign Language</td></tr></table>
441
+
442
+ # D.2 Notes
443
+
444
+ # MWEs containing replaceable words
445
+
446
+ MWEs are not necessarily made of continuous words. Some MWEs contain open slots, that is, words that may be replaced with a large or open class of words. In annotation, we do not include open slots in MWEs, as illustrated by the following examples:
447
+
448
+ - You took me by surprise!
449
+ Pick me up at the station.
450
+
451
+ <table><tr><td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td></tr><tr><td>MWE</td><td>Pick</td><td>me</td><td>up</td><td>at</td><td>the</td><td>station</td></tr><tr><td>Pick up</td><td>✓</td><td>□</td><td>✓</td><td>□</td><td>□</td><td>□</td></tr><tr><td></td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr></table>
452
+
453
+ Note that if a word is replaceable with only a very small number of alternatives, we consider it as part of the MWE. For example, we count the following as different MWEs:
454
+
455
+ Their food leaves a lot to be desired.
456
+ - The work leaves much to be desired.
457
+
458
+ <table><tr><td></td><td colspan="2">1</td><td colspan="2">2</td><td colspan="2">3</td><td colspan="2">4</td><td colspan="2">5</td><td colspan="2">6</td><td>7</td></tr><tr><td>MWE</td><td colspan="2">The</td><td colspan="2">work</td><td colspan="2">leaves</td><td colspan="2">much</td><td colspan="2">to</td><td colspan="2">be</td><td>desired</td></tr><tr><td>leaves much to be desired</td><td colspan="2">□</td><td colspan="2">□</td><td colspan="2">✓</td><td colspan="2">✓</td><td colspan="2">✓</td><td colspan="2">✓</td><td>✓</td></tr><tr><td></td><td colspan="2">□</td><td colspan="2">□</td><td colspan="2">□</td><td colspan="2">□</td><td colspan="2">□</td><td colspan="2">□</td><td>□</td></tr></table>
459
+
460
+ # Overlapping MWEs
461
+
462
+ There is a chance that multiple MWEs share the same word. For example, letting in the following sentence belongs to both letting in and letting out.
463
+
464
+ <table><tr><td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr><tr><td>MWE</td><td>They</td><td>were</td><td>letting</td><td>him</td><td>in</td><td>and</td><td>out</td></tr><tr><td>letting in</td><td>□</td><td>□</td><td>☑</td><td>□</td><td>☑</td><td>□</td><td>□</td></tr><tr><td>letting out</td><td>□</td><td>□</td><td>☑</td><td>□</td><td>□</td><td>□</td><td>☑</td></tr><tr><td></td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr></table>
465
+
466
+ # Rearranged MWEs
467
+
468
+ There is a chance that the order of component words in an MWE is different from its canonical form, but we still count such rearranged sequences as MWEs. In the following example, rearrangement happens in the MWE break $\langle \text{one's} \rangle$ heart. As a side note, my here is not annotated because it is replaceable.
469
+
470
+ <table><tr><td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr><tr><td>MWE</td><td>My</td><td>heart</td><td>is</td><td>broken</td><td>.</td></tr><tr><td>heart broken</td><td>□</td><td>✔</td><td>□</td><td>✔</td><td>□</td></tr><tr><td></td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr></table>
471
+
472
+ # Hyphens
473
+
474
+ On our annotation interface, hyphens are treated as words. When you encounter a hyphen in an MWE, mark the hyphen. Meanwhile, note that some hyphenated words, e.g., twenty-one are not MWEs and should not be annotated.
475
+
476
+ <table><tr><td></td><td colspan="2">1</td><td colspan="2">2</td><td colspan="2">3</td><td colspan="2">4</td><td colspan="2">5</td><td colspan="2">6</td><td>7</td></tr><tr><td>MWE</td><td>She</td><td>is</td><td colspan="2">my</td><td colspan="2">next</td><td colspan="2">-</td><td colspan="2">door</td><td colspan="3">neighbor</td></tr><tr><td>next - door</td><td>□</td><td>□</td><td colspan="2">□</td><td>□</td><td>√</td><td></td><td>√</td><td></td><td>√</td><td></td><td colspan="2">□</td></tr><tr><td></td><td>□</td><td>□</td><td colspan="2">□</td><td>□</td><td>□</td><td></td><td>□</td><td></td><td>□</td><td></td><td colspan="2">□</td></tr></table>
2025/CoAM_ Corpus of All-Type Multiword Expressions/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3305b7a124e73ba325ce7e0d5085aa88e3f64d17357a58444feed1e8c424c901
3
+ size 904266
2025/CoAM_ Corpus of All-Type Multiword Expressions/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/57318655-108b-49de-8446-70e3b2ba431f_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0d27f68f7869e4c71ed8ba8ddcb7d748032d70fb1e86750f74639ade6d31dc4
3
+ size 326038
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/full.md ADDED
@@ -0,0 +1,380 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CoCoLex: Confidence-guided Copy-based Decoding for Grounded Legal Text Generation
2
+
3
+ Santosh T.Y.S.S $^{1*}$ , Youssef Tarek Elkhayat $^{1}$ , Oana Ichim $^{2}$ , Pranav Shetty $^{3}$ , Dongsheng Wang $^{3}$ , Zhiqiang Ma $^{3}$ , Armineh Nourbakhsh $^{3}$ , Xiaomo Liu $^{3}$
4
+
5
+ $^{1}$ School of Computation, Information, and Technology, Technical University of Munich, Germany
6
+
7
+ $^{2}$ Graduate Institute of International and Development Studies, Geneva, Switzerland $^{3}$ JPMorgan AI Research
8
+
9
+ # Abstract
10
+
11
+ Due to their ability to process long and complex contexts, LLMs can offer key benefits to the Legal domain, but their adoption has been hindered by their tendency to generate unfaithful, ungrounded, or hallucinatory outputs. While Retrieval-Augmented Generation offers a promising solution by grounding generations in external knowledge, it offers no guarantee that the provided context will be effectively integrated. To address this, context-aware decoding strategies have been proposed to amplify the influence of relevant context, but they usually do not explicitly enforce faithfulness to the context. In this work, we introduce Confidence-guided Copy-based Decoding for Legal Text Generation (CoCoLex)—a decoding strategy that dynamically interpolates the model produced vocabulary distribution with a distribution derived based on copying from the context. CoCoLex encourages direct copying based on models' confidence, ensuring greater fidelity to the source. Experimental results on five legal benchmarks demonstrate that CoCoLex outperforms existing context-aware decoding methods, particularly in long-form generation tasks.
12
+
13
+ # 1 Introduction
14
+
15
+ The legal domain poses unique challenges to document-grounded language generation. Legal documents are often long, structurally complex, and prone to jargon and technical language. Additionally, tasks that are grounded in legal documents such as question answering or analysis often have strict requirements regarding accuracy and faithfulness to sources. In recent years, LLMs have revolutionized the legal domain, transforming areas such as legal education (Choi and Schwarcz, 2023; Jiang et al., 2024), research (Livermore et al.,
16
+
17
+ 2023), compliance checking (Hassani, 2024), and even legal practice (Rodgers et al., 2023).
18
+
19
+ Despite their potential, their adoption is hindered by their tendency to produce hallucinations—text inconsistent with authoritative sources such as case law, statutes, regulations, contracts, and doctrines (Magesh et al., 2024). In law, where strict adherence to authoritative sources is essential, unfaithful outputs can result in inaccurate and even harmful advice (Chitgopkar et al., 2024). These issues stem from the model's inability to fully ground its outputs in verifiable knowledge, leaving them prone to generating plausible-sounding yet non-factual content (El Hamdani et al., 2024; Zmigrod et al., 2024; Santosh et al., 2024d).
20
+
21
+ To address these challenges, Retrieval-Augmented Generation (RAG) has emerged as a promising approach, equipping LLMs with external knowledge chunks to ground their outputs (Lewis et al., 2020; Borgeaud et al., 2022; Guu et al., 2020). However, RAG with regular decoding still struggles to effectively integrate retrieved context (Hagström et al., 2024), leading to outputs that diverge from the provided context—a critical shortcoming in high-stakes legal applications (Magesh et al., 2024). While some methods aim to enhance context grounding through improved pre-training (Guu et al., 2020; Lewis et al., 2020; Borgeaud et al., 2022; Izacard et al., 2023), due to the high cost of pre-training, some studies focus on inference-stage methods, such as decoding strategies for white-box models (Shi et al., 2023; Kim et al., 2024b,a; Zhao et al., 2024) or prompting for black-box models (Zhou et al., 2023; Byerly and Khashabi, 2024; Li et al., 2024). Most of these works prioritize correctness but rarely evaluate whether responses are faithful to the provided context. Therefore, we propose a novel decoding strategy to improve context faithfulness of white-box LLMs for legal text generation.
22
+
23
+ Legal texts often adhere to templatized structures
24
+
25
+ (Ghosh et al., 2023; Nair and Modani, 2023) and verbatim phrases to maintain interpretive precision (Rossi et al., 2021). Inspired by this characteristic, we propose Confidence-guided Copy-based Decoding for Legal Text Generation (CoCoLex), which prioritizes fidelity of the generation by explicitly guiding the model to copy tokens from the context. Specifically, CoCoLex uses a confidence score to dynamically balance copying and generating tokens, interpolating the model's token distribution with a copy-based distribution. Note that despite its conceptual similarity to pointer generator networks (See et al., 2017), CoCoLex is training-free, operating directly on logits during decoding. Its interpolation mechanism draws inspiration from kNN-LM (Khandelwal et al., 2019), which retrieves from external data stores of the pre-training corpus or training examples. Prior works with KNN-LM such as Khandelwal et al. (2019) and Wang et al. (2023) have focused on language modeling and open-ended text generation, CoCoLex enhances faithfulness in context-aware generation, an under-explored area.
26
+
27
+ Our key contributions are given below: (a) We introduce CoCoLex, a novel decoding strategy that enhances the faithfulness of generated text by encouraging copying from the context. (b) Through experiments conducted on five legal text generation datasets using two LLMs, we demonstrate that our method, CoCoLex, not only improves correctness and ensures that generated outputs remain faithful to the source but also maintains fluency and coherence, all without increasing inference overhead, especially in long-form text generation. (c) We present an extension, CoCoLex+, which allows for copying from the entire document rather than being restricted to top-retrieved chunks. This further enhances performance by leveraging a richer and more comprehensive context. (d) We show that our method can be integrated with previous approaches, indicating that its improvements are complementary to other existing methods.
28
+
29
+ # 2 Related Work
30
+
31
+ LLMs and Risks for legal AI. Lawyers are increasingly adopting AI tools to enhance their practice, from drafting contracts to conducting legal research, yielding substantial efficiency gains. As of January 2024, 41 of the top 100 largest U.S. law firms and $35\%$ of a broader sample of 384 firms report using generative AI tools (Henry, 2024; Col
32
+
33
+ lens et al., 2024). In the UK, $14\%$ of lawyers surveyed use these tools weekly or more (Greenhill, 2024). Despite the evident benefits, Legal AI introduces significant ethical challenges, including concerns over client confidentiality, data protection, potential biases, and the critical responsibility of lawyers to supervise and ensure the accuracy of AI-generated outputs (Avery et al., 2023; Harasta et al., 2024; Chitgopkar et al., 2024).
34
+
35
+ Dahl et al. (2024) provide a systematic assessment of LLMs for legal tasks, categorizing hallucination types in their responses, while Magesh et al. (2024) examine RAG-based tools for legal QA. Their findings indicate that although retrieval-augmented models reduce hallucinations compared to general-purpose LLMs, the issue persists. In this work, we propose a novel decoding algorithm within a retrieval-augmented generation framework to mitigate hallucinations. Particularly, our approach enhances the groundedness of model outputs by improving faithfulness to the retrieved context while ensuring relevance to legal queries.
36
+
37
+ Retrieval Augmented Generation. RAG retrieves relevant external information, enabling LLMs to provide factual responses. The retrieval component in RAG can operate at different granularities, such as chunk-level (Guu et al., 2020; Lewis et al., 2020), token-level (Khandelwal et al., 2019; Yogatama et al., 2021), and entity-level (De Jong et al., 2021; Févry et al., 2020). The retrieved information then can be integrated at three possible levels: (a) At the input layer, the retrieved segments can be combined with the input or query, and processed them jointly through the model (Ram et al., 2023; Izacard et al., 2023). (b) Intermediate-layer integration uses semi-parametric modules to incorporate retrieved information into the internal layers of the model (Wu et al., 2022; Borgeaud et al., 2022). (c) Output-layer integration merges the retrieval and generation results after processing (Khandelwal et al., 2019; Santosh et al., 2024c).
38
+
39
+ Existing Retrieval-Augmented Generation (RAG) approaches can be categorized into training-free and training-based methods. Training-based methods involve fine-tuning both the retriever and generator, either independently (Karpukhin et al., 2020; Zhou et al., 2022), sequentially (Borgeaud et al., 2022; Yoran et al., 2023; Lin et al., 2023; Sarto et al., 2022), or jointly (Rubin and Berant, 2024; Izacard et al., 2023), allowing these components to work synergistically. In contrast, training-free methods utilize retrieved
40
+
41
+ knowledge during inference by incorporating it into prompts (Jiang et al., 2023; Khattab et al., 2022; Trivedi et al., 2022). These methods are computationally efficient and therefore we focus on this common variant of RAG, that performs retrieval based on the query and integrates the retrieved context within the input prompt.
42
+
43
+ However, simply augmenting the input with context may not consistently ensure alignment between the generated output and the retrieved context. To address this, decoding-based strategies (Shi et al., 2023; Kim et al., 2024b,a; Zhao et al., 2024) and prompt-based techniques (Zhou et al., 2023; Byerly and Khashabi, 2024; Li et al., 2024) are often employed to guide the model towards generating outputs that remain faithful to the provided context. Existing decoding strategies, such as contrastive decoding (Li et al., 2022), aim to amplify the influence of the retrieved context by adjusting token logits but do not explicitly enforce faithfulness to the source. To overcome this limitation, we propose a novel decoding method that incorporates a token-level copying mechanism from the retrieved context, guided by the model's confidence, in our approach.
44
+
45
+ # 3 CoCoLex
46
+
47
+ Given an input query $x$ and context $c$ , a language model with parameters $\theta$ is prompted to generate a response $\mathbf{y} = \{y_1, y_2, \dots, y_n\}$ of length $n$ . The response is generated autoregressively, with each token $y_t$ sampled from the conditional probability distribution: $y_t \sim p_\theta(y_t \mid c, x, y_{<t})$ . Our decoding strategy, CoCoLex consists of two major components: copy-based decoding, which derives distribution over vocabulary tokens based on copying from context and confidence factor which guides model between copying and generating. We explain these two components below.
48
+
49
+ # 3.1 Copy-based Decoding
50
+
51
+ We hypothesize that while augmenting the query with relevant context improves response quality, it does not always guarantee that the responses are grounded in the provided context. To address this, we introduce a copy mechanism that explicitly directs the model to copy tokens from the context during the decoding process, thereby maintaining contextual fidelity, while ensuring the response remains fluent and relevant to the query.
52
+
53
+ During decoding, we extract and store the hidden
54
+
55
+ state representations of all tokens within the context $c$ from the language model. These representations, denoted as $h_i$ for each token, are stored along with their corresponding next token. Since the hidden states are computed during autoregressive generation, no additional forward passes are required for this storing step. At each decoding step $t$ , the model generates a hidden state vector $h_t$ , which is then compared to the stored context vectors $\{h_i\}$ . The similarity between $h_t$ and each context vector $h_i$ is computed using the Euclidean $L_2$ distance which is subsequently transformed into similarity scores via an exponential decay (See Appendix C for further details):
56
+
57
+ $$
58
+ s _ {t} (i) = \exp (- \operatorname {d i s t} _ {t} (i))
59
+ $$
60
+
61
+ where $\mathrm{dist}_t(i)$ represents the Euclidean distance between $h_t$ and $h_i$ . These similarity scores are aggregated to form a probability distribution over the vocabulary. For each token $v$ in the vocabulary, the probability of selecting $v$ is proportional to the sum of similarity scores associated with the context tokens mapped to $v$ . The probability distribution for the copy mechanism is given by:
62
+
63
+ $$
64
+ p _ {\mathrm {c o p y}} \left(y _ {t} = v \mid c, x\right) = \frac {\sum_ {i \in \operatorname {t o k e n s} (v)} s _ {t} (i)}{\sum_ {v ^ {\prime} \in V} \sum_ {i \in \operatorname {t o k e n s} \left(v ^ {\prime}\right)} s _ {t} (i)},
65
+ $$
66
+
67
+ where $\operatorname{tokens}(v)$ represents the context tokens that map to the token $v$ , and $V$ is the vocabulary.
68
+
69
+ To reduce computational overhead, we limit the aggregation to the top- $k$ most similar context vectors. This approximation is justified because tokens with low similarity scores contribute negligibly to the overall probability distribution. Thus, we compute copy distribution normalizing over the restricted subset of the vocabulary $V_{k}$ , formed by the top- $k$ tokens,
70
+
71
+ $$
72
+ p _ {\mathrm {c o p y}} (y _ {t} = v \mid c, x) \propto \sum_ {i \in \operatorname {t o p -} k \cap \operatorname {t o k e n s} (v)} s _ {t} (i).
73
+ $$
74
+
75
+ # 3.2 Confidence-Guidance
76
+
77
+ Uncertainty serves as a critical metric for determining when to reliably trust the predictions of LLMs. Several prior studies have explored the use of uncertainty to detect hallucinations, highlighting its potential to identify unfaithful content (Vashurin et al., 2024; Fadeeva et al., 2023; Duan et al., 2023; Kadavath et al., 2022; Huang et al., 2023). Advanced LLMs are expected to assign low probabilities to tokens that are likely to introduce inaccuracies or
78
+
79
+ hallucinations (Kadavath et al., 2022). Building on this insight, we use a logit-based uncertainty approach to define a confidence indicator. Leveraging this indicator, our method dynamically balances reliance on the model's predictions and an external copy mechanism.
80
+
81
+ At each decoding step $t$ , the model produces a probability distribution over the vocabulary. The entropy of this distribution serves as a measure of uncertainty, capturing the dispersion of probabilities. Higher entropy values indicate greater uncertainty, while lower entropy values suggest that the model is more confident in its predictions:
82
+
83
+ $$
84
+ H _ {t} = - \sum_ {v \in V} p _ {\theta} (y _ {t} = v) \cdot \log p _ {\theta} (y _ {t} = v)
85
+ $$
86
+
87
+ We normalize the entropy by dividing it by the maximum possible entropy, $\log (|V|)$ , which corresponds to a uniform distribution:
88
+
89
+ $$
90
+ H _ {t} ^ {\mathrm {n o r m}} = \frac {H _ {t}}{\log (| V |)}
91
+ $$
92
+
93
+ The confidence score, $\lambda_{t}$ , is derived using an exponential transformation of the normalized entropy. This transformation ensures that lower entropy values correspond to higher confidence scores:
94
+
95
+ $$
96
+ \lambda_ {t} = \exp (- H _ {t} ^ {\mathrm {n o r m}})
97
+ $$
98
+
99
+ To prevent erratic behavior caused by sudden spikes or drops in uncertainty, we smooth the confidence scores by incorporating historical data. Specifically, the value is calculated using a smoothing factor that combines its current value with a running average of values from a specified past window, which mitigates any fluctuations and provides a more stable confidence metric. The confidence score interpolates between the model's predictions and the copy mechanism. A high confidence score increases reliance on the model's predictions, while a low score shifts preference to the copy mechanism. The final probability distribution at decoding step $t$ is given by:
100
+
101
+ $$
102
+ \begin{array}{l} p \left(y _ {t} \mid c, x, y _ {< t}\right) = \lambda_ {t} \cdot p _ {\theta} \left(y _ {t} \mid c, x, y _ {< t}\right) \\ + \left(1 - \lambda_ {t}\right) \cdot p _ {\text {c o p y}} \left(y _ {t} \mid c, x, y _ {< t}\right) \\ \end{array}
103
+ $$
104
+
105
+ # 4 Experiments
106
+
107
+ # 4.1 Metrics
108
+
109
+ We evaluate the generated answers against the reference answers for correctness using both lexical
110
+
111
+ and semantic similarity metrics. For lexical similarity, we compute the ROUGE-L F1 score (Lin, 2004). For semantic similarity, we use AlignScore (Zha et al., 2023), which computes the alignment score for each sentence in the generated answer against the reference answer and is aggregated to derive the overall score. For faithfulness, we assess the alignment between the generated answer and the provided source context using AlignScore (Zha et al., 2023). We also evaluate stylistic properties such as fluency and coherence using UniEval (Zhong et al., 2022), which assesses the quality of individual sentences and whether all the sentences collectively form a connected narrative.
112
+
113
+ # 4.2 Datasets
114
+
115
+ We experiment with the following datasets: CUAD (Hendrycks et al., 2021) frames contract information extraction as a question-answering task, pairing contracts with relevant questions and extractive answer spans. OALQA (Butler, 2023) is a Question answering dataset based on the Open Australian Legal Corpus, where each question is paired with the respective reference document, along with the reference answer. ObliQA (Gokhan et al., 2024) is a regulatory QA dataset from Abu Dhabi Global Markets financial regulations. Questions are paired with extractive clauses answering them within the whole document corpus. AQuAECHR is a legal question-answering dataset based on European Court of Human Rights (ECHR) judgments. Given a legal query and a corpus of ECHR judgements, the system must generate an answer following a retrieve-then-generate paradigm. CLERC (Hou et al., 2024) focuses on legal analysis generation for U.S. federal case documents. The model generates text continuations containing legal reasoning along with citations to relevant cases based on preceding case document content, which typically introduces case facts.
116
+
117
+ Unlike CUAD and OALQA, where each question is linked to a specific reference document, datasets like AQuAECHR, CLERC, and ObliQA require retrieval across entire document corpora. This retrieval setup is particularly challenging in legal contexts due to the ambiguity of legal queries and the interpretive complexity of legal precedents (Dworkin, 1986), in contrast to traditional information-seeking queries (Kwiatkowski et al., 2019; Rajpurkar, 2016) which usually have clear, unambiguous references. Effective retrieval systems in legal contexts must integrate both textual
118
+
119
+ and non-textual factors, such as jurisdiction, time period, and specific conditions, to ensure the relevance and authority of retrieved content (Santosh et al., 2024b). As our primary focus is on evaluating generative models' ability to produce faithfully grounded answers, we simulate these tasks within Oracle Documents—relevant documents obtained from reference answers (available as citations to documents in datasets like CLERC and AQuAECHR or verbatim extractive snippets in ObliQA), rather than across entire corpora. Then, a retrieval step is performed within these documents to extract relevant paragraphs or chunks, which are then provided as context for the model to synthesize answers that remain contextually grounded and relevant to the query. Detailed statistics of these datasets are provided in Table 6 of the Appendix.
120
+
121
+ # 4.3 Baselines and Implementation Details
122
+
123
+ We compare CoCoLex to the following baselines: 1) Regular Decoding. 2) CAD (Context-aware Decoding) (Shi et al., 2023), which enhances groundedness by sampling from a contrastive output distribution that amplifies the difference between output probabilities with and without context. CAD modifies the model's original output distribution by incorporating the pointwise mutual information (PMI) between the context $c$ and the generation $y_{t}$ , conditioned on $x, y_{< t}$ :
124
+
125
+ $$
126
+ \begin{array}{l} y _ {t} \sim \operatorname {s o f t m a x} \left[ (1 + \alpha) \operatorname {l o g i t} _ {\theta} \left(y _ {t} \mid c, x, y _ {< t}\right) \right. \\ \left. - \alpha \operatorname {l o g i t} _ {\theta} \left(y _ {t} \mid x, y _ {< t}\right) \right]. \\ \end{array}
127
+ $$
128
+
129
+ A larger $\alpha$ places more weight on the adjustment, while $\alpha = 0$ reduces to regular decoding. 3) Ada-CAD (Adaptive CAD) (Wang et al., 2024) dynamically infers $\alpha$ in CAD at every timestamp to get $\alpha_{t}$ based on the degree of conflict, measured by the Jensen-Shannon divergence (JSD) between the distributions representing contextual and parametric knowledge:
130
+
131
+ $$
132
+ \alpha_ {t} = \operatorname {J S D} \left(p _ {\theta} \left(y _ {t} \mid x, y _ {< t}\right) \| p _ {\theta} \left(y _ {t} \mid c, x, y _ {< t}\right)\right).
133
+ $$
134
+
135
+ We also derive CoLex, from CoCoLex, removing confidence-based dynamic interpolation and interpolating based on a static value to study the effect of the confidence guidance.
136
+
137
+ We apply these methods to mistralai/Mistral-7B-Instruct-v0.3 (Jiang and Yang, 2023) and Equall/Saul-7B-Instruct-v1 (Colombo et al., 2024), with Saul being specifically pre-trained on a legal unsupervised corpus
138
+
139
+ and instruction corpus, leveraging the base Mistral model. We use BM25 (Robertson et al., 2009) for retrieving top-k passages from the documents due to its strong performance in legal retrieval settings (Santosh et al., 2024b; Rosa et al., 2021). Implementation details are provided in App. B.
140
+
141
+ # 4.4 Results
142
+
143
+ We present the results on the five datasets in Table 1. We observe that context-aware decoding methods such as CAD and AdaCAD improve both correctness and faithfulness over regular decoding on the CUAD dataset across both models. However, they exhibit a decline in fluency and coherence scores. On OALQA, these methods improve correctness (as measured by AlignScore) only with the Mistral model and achieve comparable faithfulness scores across both models. For other datasets, including ObliQA, AQuAECHR, and CLERC, CAD and AdaCAD lead to a decline in both correctness and faithfulness across both models, although they show some improvement in lexical-based ROUGE scores. These results underscore that CAD and AdaCAD are primarily effective for short-text generation (as seen in CUAD) but struggle with long-form generation, particularly in maintaining fluency and coherence. Among them, AdaCAD performs slightly better, especially in long-range tasks.
144
+
145
+ Our proposed CoLex outperforms prior approaches by guiding the model to explicitly copy tokens from the context. This approach not only enhances faithfulness by aligning generations more closely with the provided context but also improves correctness. The improvement is more pronounced in long-range tasks. The copying mechanism does not limit CoLex's fluency and coherence, which are comparable to regular decoding, with only a marginal decline in some datasets. CoCoLex further enhances correctness and faithfulness by dynamically balancing copying and text generation based on the model's confidence. It also improves fluency and coherence compared to CoLex. Across both models, we observe that the legally pre-trained Saul underperforms the generalist Mistral model, consistent with prior findings (Santosh et al., 2024d). This is mainly due to Saul's difficulty in synthesizing information from the provided context when following instructions. However, our proposed methods substantially improve Saul's performance, mitigating its limitations through copy-based decoding, which explicitly guides the model to copy relevant tokens. Overall, our approach
146
+
147
+ <table><tr><td rowspan="2"></td><td colspan="5">Mistral-7B-Instruct-v0.3</td><td colspan="5">Saul-7B-Instruct-v1</td></tr><tr><td>Cor-RL</td><td>Cor-AS</td><td>Fth-AS</td><td>Flu</td><td>Coh</td><td>Cor-RL</td><td>Cor-AS</td><td>Fth-AS</td><td>Flu</td><td>Coh</td></tr><tr><td colspan="11">CUAD</td></tr><tr><td>Regular</td><td>54.29</td><td>68.24</td><td>76.31</td><td>82.14*</td><td>62.87</td><td>21.79</td><td>38.70</td><td>73.16</td><td>77.40</td><td>70.47</td></tr><tr><td>CAD</td><td>54.57</td><td>69.57</td><td>79.55</td><td>80.41</td><td>59.95</td><td>23.42</td><td>40.62</td><td>74.65</td><td>76.30</td><td>69.16</td></tr><tr><td>AdaCAD</td><td>54.54</td><td>69.63</td><td>79.56</td><td>79.32</td><td>61.43</td><td>23.35</td><td>40.60</td><td>74.55</td><td>76.82</td><td>69.63</td></tr><tr><td>CoLex</td><td>55.29</td><td>70.65</td><td>80.66</td><td>81.22</td><td>62.27</td><td>23.87</td><td>45.63</td><td>82.06</td><td>76.87</td><td>69.41</td></tr><tr><td>CoCoLex</td><td>55.77*</td><td>71.06*</td><td>80.96*</td><td>81.79</td><td>62.73*</td><td>25.04*</td><td>49.63*</td><td>84.84*</td><td>77.23</td><td>70.91*</td></tr><tr><td colspan="11">OALQA</td></tr><tr><td>Regular</td><td>40.53</td><td>41.39</td><td>59.85</td><td>79.78</td><td>84.62</td><td>40.16</td><td>32.26</td><td>52.84</td><td>79.32</td><td>81.94</td></tr><tr><td>CAD</td><td>39.90</td><td>42.90</td><td>59.00</td><td>78.32</td><td>79.60</td><td>39.57</td><td>31.74</td><td>52.89</td><td>76.75</td><td>73.90</td></tr><tr><td>AdaCAD</td><td>39.96</td><td>42.49</td><td>59.44</td><td>77.91</td><td>79.25</td><td>39.61</td><td>31.68</td><td>52.78</td><td>76.50</td><td>73.74</td></tr><tr><td>CoLex</td><td>46.50</td><td>48.61</td><td>60.14</td><td>79.66</td><td>86.44</td><td>50.10</td><td>50.41</td><td>57.23</td><td>78.36</td><td>84.19</td></tr><tr><td>CoCoLex</td><td>48.34*</td><td>49.84*</td><td>60.87*</td><td>79.94*</td><td>87.24*</td><td>50.91*</td><td>52.74*</td><td>59.19*</td><td>80.04*</td><td>86.02*</td></tr><tr><td colspan="11">ObliQA</td></tr><tr><td>Regular</td><td>33.86</td><td>73.35</td><td>90.84</td><td>75.38*</td><td>70.22</td><td>16.90</td><td>62.50</td><td>83.10</td><td>72.16</td><td>69.95</td></tr><tr><td>CAD</td><td>35.83</td><td>71.14</td><td>89.73</td><td>70.24</td><td>63.13</td><td>15.74</td><td>61.49</td><td>82.00</td><td>62.69</td><td>53.88</td></tr><tr><td>AdaCAD</td><td>35.72</td><td>71.04</td><td>89.61</td><td>69.73</td><td>62.98</td><td>15.64</td><td>61.09</td><td>81.87</td><td>62.05</td><td>53.57</td></tr><tr><td>CoLex</td><td>43.41</td><td>85.35</td><td>93.48</td><td>73.10</td><td>72.37</td><td>22.98</td><td>82.13</td><td>90.15</td><td>71.16</td><td>67.64</td></tr><tr><td>CoCoLex</td><td>45.12*</td><td>86.01*</td><td>95.96*</td><td>74.41</td><td>74.74*</td><td>23.50*</td><td>83.44*</td><td>91.05*</td><td>72.56*</td><td>70.18*</td></tr><tr><td colspan="11">AQuAECHR</td></tr><tr><td>Regular</td><td>21.77</td><td>52.79</td><td>89.66</td><td>74.71</td><td>79.99</td><td>17.87</td><td>48.30</td><td>80.68</td><td>73.82</td><td>68.66*</td></tr><tr><td>CAD</td><td>22.04</td><td>49.15</td><td>89.28</td><td>72.28</td><td>69.43</td><td>18.71</td><td>40.60</td><td>80.17</td><td>59.82</td><td>61.44</td></tr><tr><td>AdaCAD</td><td>22.13</td><td>48.69</td><td>89.37</td><td>71.27</td><td>69.06</td><td>18.68</td><td>40.68</td><td>80.58</td><td>59.41</td><td>62.35</td></tr><tr><td>CoLex</td><td>29.12</td><td>59.79</td><td>91.85</td><td>80.76</td><td>86.01</td><td>28.97</td><td>65.89</td><td>90.25</td><td>72.75</td><td>66.84</td></tr><tr><td>CoCoLex</td><td>29.84*</td><td>60.10*</td><td>92.27*</td><td>80.48</td><td>86.44*</td><td>29.28*</td><td>66.26*</td><td>91.15*</td><td>74.24*</td><td>67.91</td></tr><tr><td colspan="11">CLERC</td></tr><tr><td>Regular</td><td>10.42</td><td>42.38</td><td>74.02</td><td>77.27</td><td>78.41</td><td>9.39</td><td>23.40</td><td>55.91</td><td>73.76</td><td>65.24</td></tr><tr><td>CAD</td><td>10.56</td><td>34.98</td><td>66.35</td><td>74.37</td><td>73.09</td><td>9.06</td><td>24.10</td><td>56.04</td><td>71.09</td><td>65.17</td></tr><tr><td>AdaCAD</td><td>10.52</td><td>35.11</td><td>66.46</td><td>74.62</td><td>73.13</td><td>9.09</td><td>24.18</td><td>56.02</td><td>71.17</td><td>65.15</td></tr><tr><td>CoLex</td><td>12.71</td><td>54.94</td><td>78.62</td><td>78.16*</td><td>89.55</td><td>12.78*</td><td>33.02</td><td>59.58</td><td>76.36</td><td>71.01</td></tr><tr><td>CoCoLex</td><td>12.88*</td><td>58.12*</td><td>79.54*</td><td>77.92</td><td>90.55*</td><td>12.51</td><td>34.95*</td><td>62.79*</td><td>76.25</td><td>73.93*</td></tr></table>
148
+
149
+ enhances faithfulness and correctness without compromising fluency and coherence.
150
+
151
+ Table 1: Performance comparison of different decoding-based methods across five legal text generation datasets, using two language models. Cor, Fth, RL, AS, Flu, Coh denote Correctness, Faithfulness, ROUGE-L, AlignScore, Fluency and Coherence respectively. Entries marked with * are statistically significantly higher than the second-best performing baseline at the $95\%$ confidence level, according to the Wilcoxon signed-rank test.
152
+
153
+ <table><tr><td></td><td>Cor</td><td>Fth</td><td>Flu</td><td>Coh</td></tr><tr><td>Regular</td><td>4.40</td><td>4.24</td><td>4.88</td><td>4.88</td></tr><tr><td>AdaCAD</td><td>4.24</td><td>3.84</td><td>4.80</td><td>4.84</td></tr><tr><td>CoCoLex</td><td>4.64</td><td>4.44</td><td>4.96</td><td>4.92</td></tr></table>
154
+
155
+ Table 2: Human evaluation results on 25 randomly sampled questions from the AQuAECHR dataset.
156
+
157
+ Human Evaluation. We randomly sample 25 questions from the AQuAECHR dataset and generate responses using three methods—Regular, AdaCAD,
158
+
159
+ and CoCoLex—applied to the Mistral-7B model, yielding a total of 75 responses. Each response is assessed by a legal ECHR expert, across four criteria: correctness (relevance to the question and alignment with the reference answer), faithfulness (adherence to the provided passages in context), fluency, and coherence. Evaluations are conducted on a 5-point Likert scale, where 1 represents the lowest quality and 5 the highest. Table 2 presents the average scores for each criterion across methods. Notably, the legal expert consistently ranked CoCoLex higher than Regular and AdaCAD, reinforcing its superiority in generating legally faithful
160
+
161
+ responses. Additionally, the results highlight that AdaCAD underperforms compared to Regular in this task of long-range text generation, particularly struggling with faithfulness. A detailed case study is provided in Appendix D
162
+
163
+ # 4.5 Discussion and Analysis
164
+
165
+ # 4.5.1 Providing Document Context
166
+
167
+ Retrieval-augmented approaches for handling lengthy documents typically follow a two-step process: first, retrieving relevant evidence passages or chunks from these documents and then using these retrieved passages as context for the generator to generate an answer. However, this approach often suffers from chunking-related issues, where improper segmentation and concatenation of retrieved passages disrupt the semantics, leading to incomplete and incoherent information retrieval (Qian et al., 2024; Dong et al., 2023). This, in turn, makes it difficult for the model to stay aligned with the main query, eventually degrading the accuracy of the generated response.
168
+
169
+ To address this limitation, we introduce CoCoLex $^+$ , an extension of CoCoLex that leverages the entire document's encoded hidden states rather than restricting copying only the tokens in top-retrieved passages. By incorporating representations from the full document, CoCoLex $^+$ enables the model to capture a more comprehensive understanding of the document's content, leading to more contextually grounded responses. We chunk documents into overlapping segments to efficiently obtain these hidden state representations and extract contextualized hidden states for each token. To prevent redundancy across overlapping contexts, each token is assigned a single hidden state representation, taken from the chunk where it has the most autoregressive context. During inference, we continue to limit explicit textual context to the top-k retrieved passages, similar to CoCoLex, but augment it with hidden states from the full document to facilitate copying.
170
+
171
+ We evaluate CoCoLex+ on long-range generation tasks—CLERC and AQuAECHR—and present the results in Table 3. Given that CoCoLex+ enables copying from the entire document, we extend our faithfulness evaluation to measure alignment with the full document, in addition to the top-retrieved passages, as done previously. Our results show that CoCoLex+ consistently outperforms Co-CoLex in correctness across both datasets and mod
172
+
173
+ <table><tr><td></td><td>C-R</td><td>C-A</td><td>F-P</td><td>F-D</td><td>Fl</td><td>Co</td></tr><tr><td colspan="7">CLERC - Mistral-7B-Instruct-v0.3</td></tr><tr><td>CoCoLex</td><td>12.88</td><td>58.12</td><td>79.54</td><td>89.34</td><td>77.92</td><td>90.55</td></tr><tr><td>CocoLex+</td><td>13.01</td><td>60.66</td><td>80.17</td><td>90.12</td><td>77.84</td><td>90.52</td></tr><tr><td colspan="7">CLERC - Saul-7B-Instruct-v1</td></tr><tr><td>CoCoLex</td><td>12.51</td><td>34.95</td><td>62.79</td><td>62.71</td><td>76.25</td><td>73.93</td></tr><tr><td>CocoLex+</td><td>13.33</td><td>44.91</td><td>72.51</td><td>70.31</td><td>75.53</td><td>75.16</td></tr><tr><td colspan="7">AQuAECHR - Mistral-7B-Instruct-v0.3</td></tr><tr><td>CoCoLex</td><td>29.84</td><td>60.10</td><td>92.27</td><td>61.35</td><td>80.48</td><td>86.44</td></tr><tr><td>CocoLex+</td><td>30.06</td><td>60.37</td><td>92.62</td><td>62.71</td><td>80.26</td><td>86.28</td></tr><tr><td colspan="7">AQuAECHR - Saul-7B-Instruct-v1</td></tr><tr><td>CoCoLex</td><td>29.28</td><td>66.26</td><td>91.15</td><td>69.39</td><td>74.24</td><td>67.91</td></tr><tr><td>CocoLex+</td><td>29.63</td><td>67.45</td><td>88.39</td><td>71.53</td><td>74.29</td><td>67.42</td></tr></table>
174
+
175
+ Table 3: Performance comparison between CoCoLex and CoCoLex+, where CoCoLex+ enhances the copy mechanism to apply to all tokens in the document, rather than being limited to tokens in the retrieved chunks appended to the prompt. C-R(A), F-P(D), Fl, Co denote Correctness-ROUGE-L(AlignScore), Faithfulness-Passages (Documents), Fluency and Coherence.
176
+
177
+ els. Interestingly, it also enhances faithfulness with respect to retrieved passages on CLERC for both models and on AQuAECHR for Mistral, suggesting that additional global context improves the model's ability to stay grounded in the provided evidence. However, in AQuAECHR with Saul, we observe a slight decline in passage-level faithfulness and an increase in document-level faithfulness, indicating that Saul benefits more from whole-document copying than from restricting itself to retrieved tokens. Crucially, CoCoLex+ maintains fluency and coherence comparable to CoCoLex, despite handling a broader copying vocabulary. These findings highlight that expanding the model's access to full-document representations strengthens its ability to generate accurate, well-grounded responses, making CoCoLex+ particularly effective for long-form legal text generation.
178
+
179
+ # 4.5.2 Combining Strategies
180
+
181
+ While AdaCAD grounds generation by contrastively amplifying the difference between output probabilities with and without context—down weighting prior parametric knowledge when relevant contextual information is available, CoCoLex grounds generation by guiding the model to copy from retrieved context effectively. Given their complementary mechanisms, we extend CoCoLex by incorporating AdaCAD's contrastive probability distribution into CoCoLex's final probability com
182
+
183
+ <table><tr><td></td><td>C-RL</td><td>C-AS</td><td>F-AS</td><td>Flu</td><td>Coh</td></tr><tr><td colspan="6">CUAD - Mistral-7B-Instruct-v0.3</td></tr><tr><td>CoCo</td><td>55.77</td><td>71.06</td><td>80.96</td><td>81.79</td><td>62.73</td></tr><tr><td>Ada + CoCo</td><td>56.26</td><td>71.87</td><td>81.18</td><td>81.99</td><td>62.41</td></tr><tr><td colspan="6">CUAD - Saul-7B-Instruct-v1</td></tr><tr><td>CoCo</td><td>25.04</td><td>49.63</td><td>84.84</td><td>77.23</td><td>70.91</td></tr><tr><td>Ada + CoCo</td><td>25.38</td><td>50.46</td><td>85.05</td><td>77.18</td><td>70.89</td></tr><tr><td colspan="6">CLERC - Mistral-7B-Instruct-v0.3</td></tr><tr><td>CoCo</td><td>12.88</td><td>58.12</td><td>79.54</td><td>77.92</td><td>90.55</td></tr><tr><td>Ada + CoCo</td><td>12.10</td><td>50.24</td><td>72.09</td><td>75.51</td><td>86.51</td></tr><tr><td colspan="6">CLERC - Saul-7B-Instruct-v1</td></tr><tr><td>CoCo</td><td>12.51</td><td>34.95</td><td>62.79</td><td>76.25</td><td>73.93</td></tr><tr><td>Ada + CoCo</td><td>13.33</td><td>36.75</td><td>63.30</td><td>75.09</td><td>73.45</td></tr><tr><td colspan="6">AQuAECHR - Mistral-7B-Instruct-v0.3</td></tr><tr><td>CoCo</td><td>29.84</td><td>60.10</td><td>92.27</td><td>80.48</td><td>86.44</td></tr><tr><td>Ada + CoCo</td><td>27.74</td><td>55.89</td><td>90.70</td><td>80.19</td><td>81.84</td></tr><tr><td colspan="6">AQuAECHR - Saul-7B-Instruct-v1</td></tr><tr><td>CoCo</td><td>29.28</td><td>66.26</td><td>91.15</td><td>74.24</td><td>67.91</td></tr><tr><td>Ada + CoCo</td><td>26.30</td><td>57.79</td><td>90.10</td><td>69.15</td><td>63.71</td></tr></table>
184
+
185
+ putation, modifying $p_{\theta}$ directly.
186
+
187
+ We evaluate the combined AdaCAD + CoCoLex approach on CUAD, CLERC, and AQuAECHR across both models, with results in Table 3. Our findings indicate that this combination enhances performance in CUAD across both models and improves CLERC for Saul. However, we observe a decline in CLERC for Mistral and in AQuAECHR for both models. Notably, these trends closely align with AdaCAD's performance in Table 1: whenever AdaCAD improves over regular decoding (e.g., CUAD for both models, CLERC for Saul), the combined approach also yields gains. Conversely, when AdaCAD underperforms compared to regular decoding, the combination similarly results in a performance drop. This suggests that integrating AdaCAD with CoCoLex can be effective when AdaCAD itself outperforms regular decoding, reinforcing their complementarity.
188
+
189
+ # 4.5.3 Inference Time
190
+
191
+ We compute inference time for different methods using a randomly sampled $10\%$ subset of the CUAD and AQuAECHR datasets, running on an Nvidia A100 GPU. To account for variations in
192
+
193
+ Table 4: Demonstrating the complementarity of both approaches: CoCoLex combined with AdaCAD improves when AdaCAD outperforms regular decoding, but results in a decrease when AdaCAD is less effective.
194
+
195
+ <table><tr><td></td><td>CUAD</td><td>AQuAECHR</td></tr><tr><td>Regular</td><td>1.00x</td><td>1.00x</td></tr><tr><td>CAD</td><td>1.75x</td><td>1.71x</td></tr><tr><td>AdaCAD</td><td>1.77x</td><td>1.72x</td></tr><tr><td>CoLex</td><td>1.49x</td><td>1.61x</td></tr><tr><td>CoCoLex</td><td>1.51x</td><td>1.62x</td></tr><tr><td>Ada + CoCo</td><td>2.31x</td><td>2.25x</td></tr><tr><td>CoCoLex+</td><td>1.96x</td><td>2.96x</td></tr></table>
196
+
197
+ Table 5: Inference time comparison of different approaches, scaled to regular decoding.
198
+
199
+ output length across methods, we normalize inference time by the number of tokens generated and report relative inference times compared to regular decoding (1.00x). Our findings show that CAD and AdaCAD nearly double inference time, requiring an additional decoding step at each timestep to obtain logits with and without context. In contrast, CoLex and CoCoLex, while avoiding the extra decoding step of CAD/AdaCAD, incur a smaller overhead, which is the result of: indexing hidden states of tokens in the retrieved context, retrieving, normalizing, and interpolating token probabilities with copy-based probabilities at each timestep. When combining AdaCAD and CoCoLex, these overheads accumulate linearly since their processes are non-overlapping, further increasing inference time. Additionally, CoCoLex+, with its mechanism to index hidden states from the entire document, introduces further latency—especially for longer documents in AQuAECHR, where the overhead is more pronounced than CUAD.
200
+
201
+ # 5 Conclusion
202
+
203
+ We introduced CoCoLex, a decoding strategy that enhances faithfulness in legal text generation by dynamically balancing the model's token distribution with a copy-based distribution derived from retrieved context, guided by model confidence. Experiments on five legal datasets highlight the limitations of existing context-aware decoding methods, which improve faithfulness in short-range but struggle with long-range tasks. CoCoLex enhances generation fidelity and correctness in long-form tasks while maintaining fluency and coherence without substantial inference overhead. Our findings show that leveraging hidden state representations from the entire document, rather than restricting copying to top-retrieved chunks, mitigates context length constraints, enabling the model to capture richer information and improve faithfulness. We also find
204
+
205
+ that integrating contrastive-based approaches such as AdaCAD with CoCoLex is beneficial, reinforcing their complementarity. Future work could extend copying beyond the token level to incorporate larger semantic units, such as phrases or clauses, for improved contextual alignment.
206
+
207
+ # Limitations
208
+
209
+ To evaluate the faithfulness of generator models, our experiments assume an oracle document setting, where document retrieval is performed beforehand and provided as input. However, in real-world applications requiring retrieval across an entire document corpus—such as in benchmarks like CLERC, AQuAECHR, and ObliQA—the quality and correctness of generated text inherently depend on the accuracy and completeness of retrieval. If critical legal information is missing, poorly ranked, or incorrectly retrieved, the model may still produce misleading outputs. Addressing this retrieval bottleneck remains a key challenge, particularly in legal contexts, where case law documents, regulations, and statutes can be lengthy, nuanced, and difficult to rank effectively (Santosh et al., 2024b; Locke and Zuccon, 2022). Unlike standard information retrieval tasks that prioritize semantic similarity, legal retrieval must account for additional constraints such as precedential value, temporal relevance (Santosh et al., 2024e) and procedural applicability (Santosh et al., 2024a).
210
+
211
+ While CoCoLex improves long-form generation fidelity by encouraging direct copying, it does not explicitly handle cases requiring reasoning beyond the retrieved context, such as synthesizing multiple sources, reconciling conflicting precedents, or constructing persuasive legal arguments. Moreover, as CoCoLex relies on hidden state similarities to guide copying, its effectiveness depends on the model's ability to learn robust token representations, which may vary across architectures, pretraining objectives, and the pretraining corpus.
212
+
213
+ # Ethics Statement
214
+
215
+ All datasets used in this work are publicly available and have been utilized in compliance with their respective data usage policies. While datasets such as CLERC and AQuAECHR, which involve case law judgments, are not anonymized, our work engages with the data in a manner that we believe does not cause harm beyond the availability of this information.
216
+
217
+ LLMs, due to the historical biases inherent in their pre-training data, may perpetuate harmful prejudices and inaccuracies, potentially exacerbating existing gaps in legal knowledge and representation. This can lead to biased outputs, including factual inaccuracies and misrepresentations of legal citations. As such, caution is necessary in the responsible deployment of LLMs for legal information-seeking tasks. While LLMs can be powerful tools, they are not intended to replace legal professionals but to assist them by augmenting their expertise. Therefore, it is critical to employ LLMs with care in legal contexts, with constant monitoring for fairness, accuracy, and alignment with legal principles.
218
+
219
+ In the responsible deployment of LLMs, there is also the need to address broader questions surrounding the automation of legal tasks. The growing use of LLMs in legal practice should be carefully assessed to ensure that the integrity, professionalism, and accountability of the legal profession are maintained. As these technologies evolve, it is important to continually evaluate the impact of LLMs on the legal system, ensuring they complement legal professionals and enhance the equitable and effective delivery of legal services. This includes ongoing reflection on their potential biases, transparency, and the ethical implications of their integration into the legal workflow.
220
+
221
+ # Disclaimer
222
+
223
+ This paper was prepared for informational purposes by the Artificial Intelligence Research group of JP Morgan Chase Co. and its affiliates ("JP Morgan") and is not a product of the Research Department of JP Morgan. JP Morgan makes no representation and warranty whatsoever and disclaims all liability, for the completeness, accuracy, or reliability of the information contained herein. This document is not intended as investment research or investment advice, or a recommendation, offer or solicitation for the purchase or sale of any security, financial instrument, financial product, or service, or to be used in any way for evaluating the merits of participating in any transaction, and shall not constitute a solicitation under any jurisdiction or to any person, if such solicitation under such jurisdiction or to such person would be unlawful.
224
+
225
+ # References
226
+
227
+ Joseph J Avery, Patricia Sanchez Abril, and Alissa del Riego. 2023. Chatgpt, esq.: Recasting unauthorized
228
+
229
+ practice of law in the era of generative ai. Yale JL & Tech., 26:64.
230
+ Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George Bm Van Den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, et al. 2022. Improving language models by retrieving from trillions of tokens. In International conference on machine learning, pages 2206-2240. PMLR.
231
+ Umar Butler. 2023. Open australian legal qa.
232
+ Adam Byerly and Daniel Khashabi. 2024. How effective is self-consistency for long-context problems? arXiv preprint arXiv:2411.01101.
233
+ Sudhan Chitgopkar, Noah Dohrmann, Stephanie Monson, Jimmy Mendez, Finale Doshi-Velez, and Weiwei Pan. 2024. Accuracy isn't everything: Understanding the desiderata of ai tools in legal-financial settings. In NeurIPS 2024 Workshop on Behavioral Machine Learning.
234
+ Jonathan H Choi and Daniel Schwarcz. 2023. Ai assistance in legal analysis: An empirical study. Available at SSRN 4539836.
235
+ Jack Collens, Rachel Reimer, Gerald Schifman, and Pamela Wilkinson. 2024. Ai survey: Where artificial intelligence stands in the legal industry.
236
+ Pierre Colombo, Telmo Pessoa Pires, Malik Boudiaf, Dominic Culver, Rui Melo, Caio Corro, Andre FT Martins, Fabrizio Esposito, Vera Lucia Raposo, Sofia Morgado, et al. 2024. Saullm-7b: A pioneering large language model for law. arXiv preprint arXiv:2403.03883.
237
+ Matthew Dahl, Varun Magesh, Mirac Suzgun, and Daniel E Ho. 2024. Large legal fictions: Profiling legal hallucinations in large language models. Journal of Legal Analysis, 16(1):64-93.
238
+ Michiel De Jong, Yury Zemlyanskiy, Nicholas FitzGerald, Fei Sha, and William Cohen. 2021. Mention memory: incorporating textual knowledge into transformers through entity mention attention. arXiv preprint arXiv:2110.06176.
239
+ Zican Dong, Tianyi Tang, Lunyi Li, and Wayne Xin Zhao. 2023. A survey on long text modeling with transformers. arXiv preprint arXiv:2302.14502.
240
+ Jinhao Duan, Hao Cheng, Shiqi Wang, Chenan Wang, Alex Zavalny, Renjing Xu, Bhavya Kailkhura, and Kaidi Xu. 2023. Shifting attention to relevance: Towards the uncertainty estimation of large language models. arXiv preprint arXiv:2307.01379.
241
+ Ronald Dworkin. 1986. *Law's Empire*. Harvard University Press, Cambridge, MA.
242
+ Rajaa El Hamdani, Thomas Ronald, Fragkiskos D Malliaros, Nils Holzenberger, and Fabian Suchanek. 2024. The factuality of large language models in the
243
+
244
+ legal domain. In Proceedings of the 33rd ACM International Conference on Information and Knowledge Management, pages 3741-3746.
245
+ Ekaterina Fadeeva, Roman Vashurin, Akim Tsvigun, Artem Vazhentsev, Sergey Petrakov, Kirill Fedyanin, Daniil Vasilev, Elizaveta Goncharova, Alexander Panchenko, Maxim Panov, et al. 2023. Lpolygraph: Uncertainty estimation for language models. arXiv preprint arXiv:2311.07383.
246
+ Thibault Févry, Livio Baldini Soares, Nicholas FitzGerald, Eunsol Choi, and Tom Kwiatkowski. 2020. Entities as experts: Sparse memory access with entity supervision. arXiv preprint arXiv:2004.07202.
247
+ Sreyan Ghosh, Chandra Kiran Evuru, Sonal Kumar, S Ramaneswaran, S Sakshi, Utkarsh Tyagi, and Dinesh Manocha. 2023. Dale: Generative data augmentation for low-resource legal nlp. arXiv preprint arXiv:2310.15799.
248
+ Tuba Gokhan, Kexin Wang, Iryna Gurevych, and Ted Briscoe. 2024. Regnlp in action: Facilitating compliance through automated information retrieval and answer generation. arXiv preprint arXiv:2409.05677.
249
+ Stuart Greenhill. 2024. Lawyers cross into the new era of generative ai.
250
+ Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat, and Mingwei Chang. 2020. Retrieval augmented language model pre-training. In International conference on machine learning, pages 3929-3938. PMLR.
251
+ Lovisa Hagström, Sara Vera Marjanović, Haeun Yu, Arnav Arora, Christina Lioma, Maria Maistro, Pepa Atanasova, and Isabelle Augenstein. 2024. A reality check on context utilisation for retrieval-augmented generation. arXiv preprint arXiv:2412.17031.
252
+ Jakub Harasta, Tereza Novotná, and Jaromir Savelka. 2024. It cannot be right if it was written by ai: on lawyers' preferences of documents perceived as authored by an llm vs a human. Artificial Intelligence and Law, pages 1-38.
253
+ Shabnam Hassani. 2024. Enhancing legal compliance and regulation analysis with large language models. arXiv preprint arXiv:2404.17522.
254
+ Dan Hendrycks, Collin Burns, Anya Chen, and Spencer Ball. 2021. Cuad: An expert-annotated nlp dataset for legal contract review. arXiv preprint arXiv:2103.06268.
255
+ Justin Henry. 2024. We asked every am law 100 law firm how they're using gen ai. here's what we learned. The American Lawyer.
256
+ Abe Bohan Hou, Orion Weller, Guanghui Qin, Eugene Yang, Dawn Lawrie, Nils Holzenberger, Andrew Blair-Stanek, and Benjamin Van Durme. 2024. Clerc: A dataset for legal case retrieval and retrieval-augmented analysis generation. arXiv preprint arXiv:2406.17186.
257
+
258
+ Yuheng Huang, Jiayang Song, Zhijie Wang, Shengming Zhao, Huaming Chen, Felix Juefei-Xu, and Lei Ma. 2023. Look before you leap: An exploratory study of uncertainty measurement for large language models. arXiv preprint arXiv:2307.10236.
259
+ Gautier Izacard, Patrick Lewis, Maria Lomeli, Lucas Hosseini, Fabio Petroni, Timo Schick, Jane Dwivedi-Yu, Armand Joulin, Sebastian Riedel, and Edouard Grave. 2023. Atlas: Few-shot learning with retrieval augmented language models. Journal of Machine Learning Research, 24(251):1-43.
260
+ Cong Jiang and Xiaolei Yang. 2023. Legal syllogism prompting: Teaching large language models for legal judgment prediction. In Proceedings of the Nineteenth International Conference on Artificial Intelligence and Law, pages 417-421.
261
+ Hang Jiang, Xiajie Zhang, Robert Mahari, Daniel Kessler, Eric Ma, Tal August, Irene Li, Alex 'Sandy' Pentland, Yoon Kim, Deb Roy, et al. 2024. Leveraging large language models for learning complex legal concepts through storytelling. arXiv preprint arXiv:2402.17019.
262
+ Zhengbao Jiang, Frank F Xu, Luyu Gao, Zhiqing Sun, Qian Liu, Jane Dwivedi-Yu, Yiming Yang, Jamie Callan, and Graham Neubig. 2023. Active retrieval augmented generation. arXiv preprint arXiv:2305.06983.
263
+ Jeff Johnson, Matthijs Douze, and Hervé Jégou. 2019. Billion-scale similarity search with gpus. IEEE Transactions on Big Data, 7(3):535-547.
264
+ Saurav Kadavath, Tom Conerly, Amanda Askell, Tom Henighan, Dawn Drain, Ethan Perez, Nicholas Schiefer, Zac Hatfield-Dodds, Nova DasSarma, Eli Tran-Johnson, et al. 2022. Language models (mostly) know what they know. arXiv preprint arXiv:2207.05221.
265
+ Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, and Wen-tau Yih. 2020. Dense passage retrieval for open-domain question answering. arXiv preprint arXiv:2004.04906.
266
+ Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. 2019. Generalization through memorization: Nearest neighbor language models. arXiv preprint arXiv:1911.00172.
267
+ Omar Khattab, Keshav Santhanam, Xiang Lisa Li, David Hall, Percy Liang, Christopher Potts, and Matei Zaharia. 2022. Demonstrate-search-predict: Composing retrieval and language models for knowledge-intensive nlp. arXiv preprint arXiv:2212.14024.
268
+ Taehyeon Kim, Joonkee Kim, Gihun Lee, and Se-Young Yun. 2024a. Instructive decoding: Instruction-tuned large language models are self-refiner from noisy instructions. In The Twelfth International Conference on Learning Representations.
269
+
270
+ Youna Kim, Hyuhng Joon Kim, Cheonbok Park, Choonghyun Park, Hyunsoo Cho, Junyeob Kim, Kang Min Yoo, Sang-goo Lee, and Taeuk Kim. 2024b. Adaptive contrastive decoding in retrieval-augmented generation for handling noisy contexts. arXiv preprint arXiv:2408.01084.
271
+ Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin, Kenton Lee, et al. 2019. Natural questions: a benchmark for question answering research. Transactions of the Association for Computational Linguistics, 7:453-466.
272
+ Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Kuttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, et al. 2020. Retrieval-augmented generation for knowledge-intensive nlp tasks. Advances in Neural Information Processing Systems, 33:9459-9474.
273
+ Taiji Li, Zhi Li, and Yin Zhang. 2024. Improving faithfulness of large language models in summarization via sliding generation and self-consistency. In Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024), pages 8804-8817.
274
+ Xiang Lisa Li, Ari Holtzman, Daniel Fried, Percy Liang, Jason Eisner, Tatsunori Hashimoto, Luke Zettlemoyer, and Mike Lewis. 2022. Contrastive decoding: Open-ended text generation as optimization. arXiv preprint arXiv:2210.15097.
275
+ Chin-Yew Lin. 2004. Rouge: A package for automatic evaluation of summaries. In Text summarization branches out, pages 74-81.
276
+ Xi Victoria Lin, Xilun Chen, Mingda Chen, Weijia Shi, Maria Lomeli, Rich James, Pedro Rodriguez, Jacob Kahn, Gergely Szilvasy, Mike Lewis, et al. 2023. Ra-dit: Retrieval-augmented dual instruction tuning. arXiv preprint arXiv:2310.01352.
277
+ Michael A Livermore, Felix Herron, and Daniel Rockmore. 2023. Language model interpretability and empirical legal studies. Virginia Public Law and Legal Theory Research Paper, (2023-69).
278
+ Daniel Locke and Guido Zuccon. 2022. Case law retrieval: problems, methods, challenges and evaluations in the last 20 years. arXiv preprint arXiv:2202.07209.
279
+ Varun Magesh, Faiz Surani, Matthew Dahl, Mirac Suzgun, Christopher D Manning, and Daniel E Ho. 2024. Hallucination-free? assessing the reliability of leading ai legal research tools. arXiv preprint arXiv:2405.20362.
280
+ Inderjeet Nair and Natwar Modani. 2023. Exploiting language characteristics for legal domain-specific language model pretraining. In Findings of the Association for Computational Linguistics: EACL 2023, pages 2516-2526.
281
+
282
+ Hongjin Qian, Zheng Liu, Kelong Mao, Yujia Zhou, and Zhicheng Dou. 2024. Grounding language model with chunking-free in-context retrieval. arXiv preprint arXiv:2402.09760.
283
+ P Rajpurkar. 2016. Squad: 100,000+ questions for machine comprehension of text. arXiv preprint arXiv:1606.05250.
284
+ Ori Ram, Yoav Levine, Itay Dalmedigos, Dor Muhlgay, Amnon Shashua, Kevin Leyton-Brown, and Yoav Shoham. 2023. In-context retrieval-augmented language models. Transactions of the Association for Computational Linguistics, 11:1316-1331.
285
+ Stephen Robertson, Hugo Zaragoza, et al. 2009. The probabilistic relevance framework: Bm25 and beyond. Foundations and Trends® in Information Retrieval, 3(4):333-389.
286
+ Ian Rodgers, John Armour, and Mari Sako. 2023. How technology is (or is not) transforming law firms. Annual Review of Law and Social Science, 19(1):299-317.
287
+ Guilherme Moraes Rosa, Ruan Chaves Rodrigues, Roberto Lotufo, and Rodrigo Nogueira. 2021. Yes, bm25 is a strong baseline for legal case retrieval. arXiv preprint arXiv:2105.05686.
288
+ Julien Rossi, Svitlana Vakulenko, and Evangelos Kanoulas. 2021. Verbcl: A dataset of verbatim quotes for highlight extraction in case law. In Proceedings of the 30th ACM International Conference on Information & Knowledge Management, pages 4554-4563.
289
+ Ohad Rubin and Jonathan Berant. 2024. Retrievalprtrained transformer: Long-range language modeling with self-retrieval. Transactions of the Association for Computational Linguistics, 12:1197-1213.
290
+ TYS Santosh, Kevin D Ashley, Katie Atkinson, and Matthias Grabmair. 2024a. Towards supporting legal argumentation with nlp: Is more data really all you need? arXiv preprint arXiv:2406.10974.
291
+ TYS Santosh, Rashid Gustav Haddad, and Matthias Grabmair. 2024b. Ecthr-pcr: A dataset for precedent understanding and prior case retrieval in the european court of human rights. arXiv preprint arXiv:2404.00596.
292
+ TYS Santosh, Hassan Sarwat, Ahmed Abdou, and Matthias Grabmair. 2024c. Mind your neighbours: Leveraging analogous instances for rhetorical role labeling for legal documents. arXiv preprint arXiv:2404.01344.
293
+ T.Y.S.S Santosh, Weidinger Korbinian, Ichim Oana, and Grabmair Matthias. 2024d. Aquaechr: Attributed question answering for european court of human rights. arXiv preprint.
294
+
295
+ TYSS Santosh, Tuan-Quang Vuong, and Matthias Grabmair. 2024e. Chronoslex: Time-aware incremental training for temporal generalization of legal classification tasks. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 3022–3039.
296
+ Sara Sarto, Marcella Cornia, Lorenzo Baraldi, and Rita Cucchiara. 2022. Retrieval-augmented transformer for image captioning. In Proceedings of the 19th international conference on content-based multimedia indexing, pages 1-7.
297
+ Abigail See, Peter J Liu, and Christopher D Manning. 2017. Get to the point: Summarization with pointer-generator networks. arXiv preprint arXiv:1704.04368.
298
+ Weijia Shi, Xiaochuang Han, Mike Lewis, Yulia Tsvetkov, Luke Zettlemoyer, and Scott Wen-tau Yih. 2023. Trusting your evidence: Hallucinate less with context-aware decoding. arXiv preprint arXiv:2305.14739.
299
+ Harsh Trivedi, Niranjan Balasubramanian, Tushar Khot, and Ashish Sabharwal. 2022. Interleaving retrieval with chain-of-thought reasoning for knowledge-intensive multi-step questions. arXiv preprint arXiv:2212.10509.
300
+ Roman Vashurin, Ekaterina Fadeeva, Artem Vazhentsev, Lyudmila Rvanova, Akim Tsvigun, Daniil Vasilev, Rui Xing, Abdelrahman Boda Sadallah, Kirill Grishchenkov, Sergey Petrakov, et al. 2024. Benchmarking uncertainty quantification methods for large language models with lm-polygraph. arXiv preprint arXiv:2406.15627.
301
+ Han Wang, Archiki Prasad, Elias Stengel-Eskin, and Mohit Bansal. 2024. Adacad: Adaptively decoding to balance conflicts between contextual and parametric knowledge. arXiv preprint arXiv:2409.07394.
302
+ Shufan Wang, Yixiao Song, Andrew Drozdov, Aparna Garimella, Varun Manjunatha, and Mohit Iyyer. 2023. Knn-lm does not improve open-ended text generation. arXiv preprint arXiv:2305.14625.
303
+ Yuhuai Wu, Markus N Rabe, DeLesley Hutchins, and Christian Szegedy. 2022. Memorizing transformers. arXiv preprint arXiv:2203.08913.
304
+ Dani Yogatama, Cyprien de Masson d'Autume, and Lingpeng Kong. 2021. Adaptive semiparametric language models. Transactions of the Association for Computational Linguistics, 9:362-373.
305
+ Ori Yoran, Tomer Wolfson, Ori Ram, and Jonathan Berant. 2023. Making retrieval-augmented language models robust to irrelevant context. arXiv preprint arXiv:2310.01558.
306
+ Yuheng Zha, Yichi Yang, Ruichen Li, and Zhiting Hu. 2023. Alignscore: Evaluating factual consistency with a unified alignment function. arXiv preprint arXiv:2305.16739.
307
+
308
+ Zheng Zhao, Emilio Monti, Jens Lehmann, and Haytham Assem. 2024. Enhancing contextual understanding in large language models through contrastive decoding. arXiv preprint arXiv:2405.02750.
309
+ Ming Zhong, Yang Liu, Da Yin, Yuning Mao, Yizhu Jiao, Pengfei Liu, Chenguang Zhu, Heng Ji, and Jiawei Han. 2022. Towards a unified multidimensional evaluator for text generation. arXiv preprint arXiv:2210.07197.
310
+ Shuyan Zhou, Uri Alon, Frank F Xu, Zhiruo Wang, Zhengbao Jiang, and Graham Neubig. 2022. Docprompting: Generating code by retrieving the docs. arXiv preprint arXiv:2207.05987.
311
+ Wenxuan Zhou, Sheng Zhang, Hoifung Poon, and Muhao Chen. 2023. Context-faithful prompting for large language models. arXiv preprint arXiv:2303.11315.
312
+ Ran Zmigrod, Pranav Shetty, Mathieu Sibue, Zhiqiang Ma, Armineh Nourbakhsh, Xiaomo Liu, and Manuela Veloso. 2024. "What is the value of {templates}?" Rethinking document information extraction datasets for LLMs. In Findings of the Association for Computational Linguistics: EMNLP 2024, pages 13162-13185, Miami, Florida, USA. Association for Computational Linguistics.
313
+
314
+ # A Dataset
315
+
316
+ For computing metrics, in the case of CUAD and ObliQA, where the reference answers are extractive phrases or sentences from the dataset, we concatenate them to form the reference answer. In CUAD, which also contains questions where answers are unavailable in the contract, we focus only on instances with answers in the contract for faithfulness evaluation. Detailed stats on the dataset is provided in Table 6.
317
+
318
+ # B Implementation Details
319
+
320
+ We use greedy decoding with a Repetition Penalty of 1.5, for all our experiments. For CAD, we use a static value of $\alpha$ as 0.5. Following (Wang et al., 2024), we clamp the $\alpha$ value to a minimum of 0.3 in AdaCAD. In CoCoLex and CoLex, we use the last layer to extract the hidden states for the tokens. We use a smoothing parameter of 0.5 between the prior and the current $\lambda$ value. We use 0.5 as $\lambda$ in case of CoLex. We clamp the value of $\lambda$ in [0.2,0.8] for CoCoLex. For efficient computation, we leverage the FAISS (Johnson et al., 2019) library, designed for fast nearest-neighbor retrieval in high-dimensional spaces. We retrieve the top 3 passages from the oracle documents using BM25 as context for all datasets except for ObliQA and CUAD where we used 10.
321
+
322
+ # C Ablation Study
323
+
324
+ Number of Passages in the context We vary the number of top passages retrieved using BM25 from the oracle documents and append them as context. Table 7 reports the performance of Regular, AdaCAD, and CoCoLex using the Mistral-7B-Instruct-v0.3 model on the CLERC dataset. As the number of retrieved passages increases, more distractors are introduced, and performance scores consistently decline across all methods. Notably, Regular decoding experiences a sharp drop in correctness and faithfulness, highlighting its brittleness to distractors. While AdaCAD is more robust than Regular due to its contrastive decoding mechanism, which enhances reliance on context, it also becomes susceptible to distractors. In contrast, CoCoLex leverages confidence and similarity values to assess the relevance of retrieved passages, allowing it to selectively incorporate useful information based on confidence, eventually leading to filtering out distractions. This enables CoCoLex to maintain superior robustness against distractors.
325
+
326
+ Similarity Function We compare different similarity functions used in CoCoLex, to compute the similarity between the current hidden state and the hidden states of context tokens. Table 8 reports the performance on the CLERC dataset using the Mistral-7B-Instruct-v0.3 model. We observe that Euclidean distance consistently outperforms cosine similarity across all metrics.
327
+
328
+ Layer for hidden state representation We analyze the impact of selecting different layers for extracting hidden state representations of the current token and context tokens in CoCoLex. Table 8 reports the performance on the CLERC dataset using the Mistral-7B-Instruct-v0.3 model across different layers. Results indicate that using the last layer is more effective, as it provides a refined and contextually informed representation of the token, incorporating the full extent of model reasoning. In contrast, earlier layers primarily encode lower-level features and intermediate transformations, which may not fully capture the semantic and contextual nuances necessary for robust similarity computation. As a result, they are less effective in guiding accurate token retrieval for copying from the source context in CoCoLex.
329
+
330
+ <table><tr><td>Dataset</td><td>#Instances</td><td># Docs</td><td>Docs Length</td><td>Answer length</td></tr><tr><td>CUAD</td><td>4,182</td><td>1.00</td><td>7,125.60</td><td>31.11</td></tr><tr><td>OALQA</td><td>2,024</td><td>1.00</td><td>5,973.99</td><td>90.07</td></tr><tr><td>ObliQA</td><td>2,786</td><td>1.32</td><td>48,138.35</td><td>117.55</td></tr><tr><td>AQuAECHR</td><td>1,116</td><td>3.11</td><td>14,041.33</td><td>193.58</td></tr><tr><td>CLERC</td><td>1,000</td><td>2.79</td><td>4,687.04</td><td>187.53</td></tr></table>
331
+
332
+ Table 6: Detailed Statistics of datasets. Docs represent oracle reference documents associated with each question. Length is obtained in terms of the number of words. We report the mean for #Docs, Docs length and Answer length.
333
+
334
+ <table><tr><td></td><td>#Psg</td><td>Cor-AS</td><td>Fth-AS</td><td>Flu</td><td>Coh</td></tr><tr><td rowspan="3">Regular</td><td>3</td><td>42.38</td><td>74.02</td><td>77.27</td><td>78.41</td></tr><tr><td>6</td><td>40.78</td><td>69.22</td><td>76.84</td><td>76.17</td></tr><tr><td>10</td><td>35.70</td><td>66.12</td><td>75.02</td><td>75.05</td></tr><tr><td rowspan="3">AdaCAD</td><td>3</td><td>35.11</td><td>66.46</td><td>74.62</td><td>73.13</td></tr><tr><td>6</td><td>31.03</td><td>60.77</td><td>73.03</td><td>71.23</td></tr><tr><td>10</td><td>29.01</td><td>57.50</td><td>71.37</td><td>70.91</td></tr><tr><td rowspan="3">CoCoLex</td><td>3</td><td>58.12</td><td>79.54</td><td>77.92</td><td>90.55</td></tr><tr><td>6</td><td>57.46</td><td>78.48</td><td>76.88</td><td>90.01</td></tr><tr><td>10</td><td>56.95</td><td>77.80</td><td>76.18</td><td>89.31</td></tr></table>
335
+
336
+ Table 7: Performance comparison of Regular, Ada-CAD, and CoCoLex on the CLERC dataset using the Mistral-7B-Instruct-v0.3 model with varying numbers of passages as context. Cor, Fth, AS, Flu, and Coh denote Correctness, Faithfulness, AlignScore, Fluency, and Coherence, respectively.
337
+
338
+ <table><tr><td>Similarity</td><td>Cor-AS</td><td>Fth-AS</td><td>Flu</td><td>Coh</td></tr><tr><td>Cosine</td><td>55.16</td><td>77.26</td><td>76.42</td><td>87.28</td></tr><tr><td>Euclidean</td><td>58.12</td><td>79.54</td><td>77.92</td><td>90.55</td></tr></table>
339
+
340
+ # D Case Study
341
+
342
+ We provide Case Study 1 in Table 10 and responses provided by three decoding methods—Regular, AdaCAD, and CoCoLex—to a legal question derived from the AQuAECHR dataset. The question at hand revolves around how the Court determines whether restrictions on the right to marry are properly regulated and subjected to judicial review and how this impacts an applicant's ability to challenge the denial of authorization.
343
+
344
+ Among the methods, CoCoLex stands as the most faithful to the source document by directly incorporating key legal terminology and phrases
345
+
346
+ Table 8: Performance comparison of Co-CoLex on the CLERC dataset using the Mistral-7B-Instruct-v0.3 model with different distance metrics for computing similarity.
347
+
348
+ <table><tr><td>Layer</td><td>Cor-AS</td><td>Fth-AS</td><td>Flu</td><td>Coh</td></tr><tr><td>-1</td><td>58.12</td><td>79.54</td><td>77.92</td><td>90.55</td></tr><tr><td>-5</td><td>54.67</td><td>79.01</td><td>72.18</td><td>86.12</td></tr><tr><td>-10</td><td>52.19</td><td>78.45</td><td>72.87</td><td>85.19</td></tr><tr><td>-15</td><td>49.79</td><td>78.81</td><td>70.29</td><td>82.26</td></tr><tr><td>-20</td><td>47.78</td><td>77.18</td><td>68.18</td><td>83.19</td></tr><tr><td>-25</td><td>46.92</td><td>77.29</td><td>65.28</td><td>79.68</td></tr></table>
349
+
350
+ Table 9: Performance comparison of Co-CoLex on the CLERC dataset using the Mistral-7B-Instruct-v0.3 model with different layers for obtaining hidden state representation for computing similarity.
351
+
352
+ such as "arbitrary or disproportionate interference", "necessity test", and "pressing social need." It maintains the original text's structure and legal nuances, ensuring an accurate replication of the Court's reasoning and intent, including the distinction that Article 12 does not require "necessity" or "pressing social need" tests, making it the most complete response in terms of correctness.
353
+
354
+ On the other hand, Regular provides a structured response that correctly identifies the Court's approach, emphasizing the need for restrictions to be grounded in concrete facts and national law. However, it does not explicitly mention the lack of "necessity" or "pressing social need" tests under Article 12, which is an important nuance. While this answer stays faithful to the source in terms of reasoning, it tends to oversimplify legal concepts, losing important subtleties and omitting essential legal terms that could distort the original meaning. The Regular answer is still well-organized and easy to follow, presenting the Court's reasoning in two key principles, but it generalizes the legal reasoning rather than explicitly referencing the differentiation between Article 12 and Article 8.
355
+
356
+ AdaCAD captures the limitation imposed by national laws but is less precise in explaining the
357
+
358
+ Court's review process. The sentence structure makes it unclear how the judicial review process operates in practice. It deviates by implying that refusal could be seen as additional punishment without proper justification but does not clarify that the Court focuses on arbitrariness and proportionality rather than "necessity" or "social need." It struggles with readability due to awkward phrasing and missing articles, which result in some unclear sentences. Though it attempts to reflect the source, its clarity is hindered by these issues.
359
+
360
+ We present Case Study 2 in Table 11, sourced from the AQuAECHR dataset, which explores the circumstances under which detention following conviction can be considered unlawful.
361
+
362
+ CoCoLex is the most faithful to the source document. It integrates key legal nuances, such as the specific conditions under Article 5 § 1 (c) of the Convention and the relationship between expert reports and the detention process. This response accurately reflects the structure and content of the legal text, ensuring a faithful representation of the original case law. It is comprehensive, addressing both the requirement of a causal connection to the initial conviction and the protection against arbitrariness under Article 5. The phrasing is formal yet accessible, offering a clear exposition of the legal conditions under which detention following conviction may be deemed unlawful. Its consistent use of legal terminology enhances both the fluency and clarity of the answer. The response is logically structured, presenting the necessary legal principles in a sequence that mirrors the original case law, starting with the causal connection to the initial conviction, followed by the relevance of expert reports and protection against arbitrariness. Each condition under which detention is unlawful is clearly linked, making the response coherent and well-organized.
363
+
364
+ Regular is relatively faithful but somewhat less precise. It correctly identifies the necessity of a causal connection with the initial conviction and emphasizes the protection against arbitrariness as required by Article 5. However, it oversimplifies the discussion of expert reports and the specific timeframe for lawful detention, omitting critical details such as the requirement for expert reports to be sufficiently recent and the need for expert reports in the context of a review. The response is coherent but lacks the tight organization found in CoCoLex. The sequence of ideas could be more logically presented, particularly regarding the role
365
+
366
+ of expert reports and the protections under Article 5. While the phrasing is generally clear, it could benefit from more nuanced transitions to reflect the complexity of the legal principles discussed. Additionally, although the structure is grammatically sound and easy to follow, some of the phrasing feels formulaic, particularly in the transitions between legal concepts.
367
+
368
+ AdaCAD includes the core principles but lacks the depth and legal specificity present in CoCoLex. While it accurately mentions the need for a causal connection and references the issue of an unsuitable institution, it does not clarify that detention may be deemed unlawful due to insufficient expert reports and omits the protection against arbitrariness under Article 5. The response is less comprehensive in conveying the full scope of the legal reasoning outlined in the source passages. AdaCAD struggles with coherence, as the flow of ideas is interrupted by awkward phrasing. For instance, the transition between the causal connection and the discussion of the suitability of the institution could be smoother. Additionally, some constructions are grammatically clunky, such as "detention takes place in an institution that does not suit mental disorders present with the individual being held," which would benefit from clearer phrasing. These issues hinder the fluency and coherence of the response, making it more difficult to read.
369
+
370
+ Overall, maintaining fidelity to the original text is essential, especially in the legal domain, where even minor changes in wording can significantly impact the interpretation of rights and responsibilities. A model that deviates from legal fidelity risks presenting misleading information, which could distort legal reasoning or misrepresent the Court's stance. This is especially problematic in judicial contexts, where clarity, accuracy, and legal consistency are critical. CoCoLex's approach ensures that the model's output adheres to established legal principles, preserving the integrity of the Court's decisions and offering the most reliable method for generating legally faithful responses.
371
+
372
+ <table><tr><td>Question</td><td>In the context of restrictions on the right to marry, how does the Court determine whether the restrictions are properly regulated and subjected to judicial review, and how does this impact the applicant&#x27;s ability to challenge the denial of authorization?</td></tr><tr><td>Source Passages from 001-96453</td><td>80: Article 12, they added, did not guarantee an unlimited right to marry since this right was regulated by “the national laws” governing its exercise. Consequently, as the Court had held in the case of B. and L. v. the (no. 36536/02, judgment of 13 September 2005), this right was subject to limitations, although they could not restrict or reduce the right to such an extent that its very essence was impaired.
373
+ 84: It was natural that, as the Court had held in many cases concerning the rights of prisoners, any measure depriving a person of liberty inevitably entailed limitations on the exercise of Convention rights, including a measure of control on prisoners&#x27; contacts with the outside world. In the context of the right to marry this might mean that the authorities, in exercising their power in this area, could monitor the wedding ceremony and limit, for instance, the number of participants. However, they should maintain a fair balance between the demands of security in prison and the prisoner&#x27;s right to marry. Their discretion should be limited to, and their decisions based on, concrete facts, not on prejudice. A refusal should be restricted to situations where the marriage ceremony would jeopardise prison security – and not just be difficult to organise. Moreover, rules regulating the authorities&#x27; discretion should be laid down in the national law. In particular, the law ought to list specific circumstances in which the authorities should not give leave to marry – for example, if it would affect the process of rehabilitation. In this context, it must be stressed that the issues involved were of a sensitive nature; thus, unjustified refusal of leave to marry could be regarded as additional or disciplinary punishment.
374
+ 90: This conclusion is reinforced by the wording of Article 12. In contrast to Article 8 of the Convention, which sets forth the right to respect for private and family life, and with which the right “to marry and to found a family” has a close affinity, Article 12 does not include any permissible grounds for an interference by the State that can be imposed under paragraph 2 of Article 8 “in accordance with the law” and as being “necessary in a democratic society”, for such purposes as, for instance, “the protection of health or morals” or “the protection of the rights and freedoms of others”. Accordingly, in examining a case under Article 12 the Court would not apply the tests of “necessity” or “pressing social need” which are used in the context of Article 8 but would have to determine whether, regard being had to the State&#x27;s margin of appreciation, the impugned interference was arbitrary or disproportionate (see paragraph 88 above, with references to the Court&#x27;s case-law).</td></tr><tr><td>Regular</td><td>In the context of restrictions on the right to marry, as established by [001-96453], the Court determines whether such limitations are properly regulated and subjected to judicial review based upon two key factors. Firstly, any measures restricting this fundamental freedom must be limited to concrete facts rather than prejudice ([001-96453]). Secondly, rules governing these discretionary decisions should be laid down in national law with specific circumstances listed where authorization for marriage may not be granted - e.g., if it would affect rehabilitation processes or jeopardize prison security (ibid.). This approach allows applicants an opportunity to challenge denials through a legal framework that ensures fairness while maintaining balance between individual rights and societal needs within democratic societies&#x27; margins of appreciation.[001-96453]</td></tr><tr><td>AdaCAD</td><td>In the context of restrictions on the right to marry, [001-96453] states that Article 12 does not guarantee an unlimited right since it is regulated by “the national laws” governing its exercise. Consequently, for a restriction to be proper and subjected to judicial review, rules should govern authorities&#x27; discretion in this area with specific circumstances listed where leave to marry ought not given - such as affecting rehabilitation process ([ibid]). This means prisoners have the ability to challenge denial authorization if concrete facts were disregarded or prejudice influenced decisions rather than prison security jeopardy being involved; moreover, refusal cannot restrict so much that essence impaired due to sensitive nature which could constitute additional punishment without justification.[001-96453].</td></tr><tr><td>CoCoLex</td><td>In the context of restrictions on the right to marry, the Court determines whether the restrictions are properly regulated and subjected to judicial review by assessing whether the national laws governing the exercise of this right are in place [001-96453]. The Court also ensures that the discretion of the authorities in exercising their power to regulate the right to marry is limited to concrete facts, not prejudice, and that their decisions are based on specific circumstances listed in the national law [001-96453]. This means that the applicant has the ability to challenge the denial of authorization if it can be shown that the restrictions imposed are arbitrary or disproportionate, as the Court would not apply the tests of “necessity” or “pressing social need” but would determine whether the impugned interference was arbitrary or disproportionate [001-96453].</td></tr></table>
375
+
376
+ Table 10: Case study 1 on a question from the AQuAECHR dataset, including provided source passages and model generations from Regular, AdaCAD, and CoCoLex.
377
+
378
+ <table><tr><td>Question</td><td>Under what circumstances can detention following conviction be considered unlawful?</td></tr><tr><td>Source Passages</td><td>001-127697 56: The applicant alleged that what she considered to be the retroactive application of a departure from the case-law by the Supreme Court after she had been convicted had extended her detention by almost nine years, in violation of Article 7 of the Convention, which reads as follows:001-212829 35: In Kadusic v. Switzerland (no. 43977/13, 9 January 2018), which concerned a subsequent order of an institutional therapeutic measure under Swiss law, the Court was in principle prepared to accept that the order for an institutional measure amounted to a correction of the original judgment following the discovery of relevant new circumstances and that the fact that the measure was ordered in the context of proceedings for the review of a penalty imposed in a previous judgment may constitute a causal link between the initial conviction and the measure in issue, as required by the relevant case-law of the Court concerning sub-paragraph (a) of Article 5 § 1 (ibid., § 50). However, in the circumstances of that case, the Court found that the detention which followed the (new) judgment in the review proceedings lacked a sufficient causal connection with the initial conviction for being incompatible with its aims. The Court considered that the measure in question, which had been imposed a considerable period after the applicant&#x27;s initial conviction, had not been based on a sufficiently recent expert report and that the applicant had been detained in an institution unsuited to his mental disorders (ibid., §§ 53-60).001-187391 116: The Court is therefore of the general view that in order not to make it impracticable for the police to fulfil their duties of maintaining order and protecting the public, provided that they comply with the underlying principle of Article 5, which is to protect the individual from arbitrariness (see, Austin and Others v. the United Kingdom [GC], nos. 39692/09 and 2 others, § 56, ECHR 2012), the lawful detention of a person outside the context of criminal proceedings can, as a matter of principle, be permissible under Article 5 § 1 (c) of the Convention. As regards the circumstances in which such detention is justified, this is an issue relating to compliance with Article 5 § 1 (c) and will be dealt with in paragraphs 143 to 174 below.</td></tr><tr><td>Regular</td><td>Detention following conviction can be considered unlawful under the principles outlined in ECHR case law if it lacks a sufficient causal connection with the initial conviction [001-212829, § 53] or is based on an expert report that was not recent enough at the time of detainment. Additionally, such detentions must comply with Article 7 (prohibition against retroactive application) and protect individuals from arbitrariness as required by the underlying principle of Article 5 to ensure their rights are protected during this period [001-127697].</td></tr><tr><td>AdaCAD</td><td>Detention following conviction can be considered unlawful if there is a lack of sufficient causal connection between the initial conviction and subsequent detention [001-212829, § 53]. Additionally, it may also occur when such detainment takes place in an institution that does not suit mental disorders present with the individual being held [ibid., §§ 60], or occurs considerable period after the applicant&#x27;s original judgment without recent expert report.</td></tr><tr><td>CoCoLex</td><td>Detention following conviction can be considered unlawful under the principles outlined in the case law if it lacks a sufficient causal connection with the initial conviction [001-212829, § 50] or if it is based on a new judgment in the review proceedings that has been imposed a considerable period after the applicant&#x27;s initial conviction and has not been based on a sufficiently recent expert report [001-212829, §§ 53-60]. Additionally, detention outside the context of criminal proceedings can be unlawful if it is not permissible under Article 5 § 1 (c) of the Convention and does not comply with the underlying principle of Article 5, which is to protect the individual from arbitrariness [001-187391, § 56].</td></tr></table>
379
+
380
+ Table 11: Case study 2 on a question from the AQuAECHR dataset, including provided source passages and model generations from Regular, AdaCAD, and CoCoLex.
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba9b285b0f923f1372f4e607a2aaa7bfca13af329e9d13c09a860556b57402d6
3
+ size 1468142
2025/CoCoLex_ Confidence-guided Copy-based Decoding for Grounded Legal Text Generation/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/5b786453-3239-4e66-acfd-b24bc6f3170d_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22ed6aab98ad3c0a4a39b55f88938e0574275c818c94bf1f7765b6b9d9caf38a
3
+ size 482325
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/full.md ADDED
@@ -0,0 +1,540 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CoE: A Clue of Emotion Framework for Emotion Recognition in Conversations
2
+
3
+ Zhiyu Shen $^{1}$ , Yunhe Pang $^{1}$ , Yanghui Rao $^{1*}$ , Jianxing Yu $^{2}$
4
+
5
+ $^{1}$ School of Computer Science and Engineering, Guangdong Key Laboratory of Big Data Analysis and Processing, Sun Yat-sen University, Guangzhou, China
6
+
7
+ $^{2}$ School of Artificial Intelligence, Sun Yat-sen University, Zhuhai, China
8
+
9
+ {shenzhy23, pangyh8}@mail2.sysu.edu.cn, {raoyangh, yujx26}@mail.sysu.edu.cn
10
+
11
+ # Abstract
12
+
13
+ Emotion Recognition in Conversations (ERC) is crucial for machines to understand dynamic human emotions. While Large Language Models (LLMs) show promise, their performance is often limited by challenges in interpreting complex conversational streams. We introduce a Clue of Emotion (CoE) framework, which progressively integrates key conversational clues to enhance the ERC task. Building on CoE, we implement a multi-stage auxiliary learning strategy that incorporates roleplaying, speaker identification, and emotion reasoning tasks, each targeting different aspects of conversational emotion understanding and enhancing the model's ability to interpret emotional contexts. Our experiments on EmoryNLP, MELD, and IEMOCAP demonstrate that CoE consistently outperforms state-of-the-art methods, achieving a $2.92\%$ improvement on EmoryNLP. These results underscore the effectiveness of clues and multi-stage auxiliary learning for ERC, offering valuable insights for future research.
14
+
15
+ # 1 Introduction
16
+
17
+ Emotion Recognition in Conversations (ERC) (Poria et al., 2019; Zahiri and Choi, 2018) has emerged as a significant research direction, driven by its potential applications to improve human-computer interactions (Brave and Nass, 2007), virtual assistants (Chatterjee et al., 2021), and mental health monitoring (Monteith et al., 2022). Accurately identifying and interpreting emotions within conversational contexts is challenging due to the complexity and subtlety of emotional expressions.
18
+
19
+ Previous works have used recurrent-based models (Hu et al., 2023) and transformer-based discriminative models (Qin et al., 2023) to learn contextual representations, with some methods further
20
+
21
+ # Dialogue
22
+
23
+ Phoebe: "Alright, here's my $7.50. But I think you should know that this money is cursed."
24
+
25
+ Joey: "What?"
26
+
27
+ Phoebe: "Oh, I cursed it. So now bad things will happen to he who spends it."
28
+
29
+ Chandler: "That's alright, I'll take it. Bad things happen to me anyway. This way I can break 'em up with a movie."
30
+
31
+ # ERC Task
32
+
33
+ Please select the emotional label of Chandler's statement:
34
+
35
+ "That's alright, I'll take ..."
36
+
37
+ From: Joyful, Mad, Peaceful, Neutral, Sad, Powerful, Scared.
38
+
39
+ # | Personal
40
+
41
+ Chandler: known for his wit and
42
+
43
+ sarcasm, works in advertising ...
44
+
45
+ Phoebe:
46
+
47
+ # Scene
48
+
49
+ Ross's Apartment
50
+
51
+ Role-playing
52
+
53
+ Speaker Identification
54
+
55
+ Reasoning
56
+
57
+ ![](images/ef639234abc543d26f0ad652278d8622708699711080f49184129fe8b35424f9.jpg)
58
+
59
+ ![](images/43cdc0d276dee53ef1d27c301e6b82dcc4c992182e84654d894ca9341af33ddc.jpg)
60
+
61
+ ![](images/b6fca978091f6191d3ae10866ac2f1982087104c08f539f89ef2fcbcc42395af.jpg)
62
+
63
+ Chandler is using his characteristic wit and sarcasm to make light of the
64
+
65
+ situation, showing that he
66
+
67
+ The emotional label for Chandler's statement is Joyful
68
+
69
+ ![](images/5837d7c3565bc9142f2150d687c96d4efa1797b6322e1c646e378bc61e598e59.jpg)
70
+
71
+ Figure 1: This figure illustrates the CoE framework in the ERC task, where contextual information (e.g., Persona and Scene) on the left and auxiliary tasks (e.g., role-playing, speaker identification, and reasoning) on the right are integrated to infer Chandler's emotional label. These combined components enhance the model's ability to reason through emotional clues and determine that Chandler's emotional state is Joyful.
72
+
73
+ employing graph neural networks to model interactions and influences between individuals in conversations (Ghosal et al., 2019). Recently, generative language models (Brown, 2020) have demonstrated powerful zero-shot capabilities, introducing a new paradigm to various natural language processing tasks. In ERC, some approaches have transformed classification tasks into generation tasks by generating class tokens. InstructERC (Lei et al., 2023) is the first to construct an ERC method based on LLMs, utilizing similarity-based retrieval to build context-learning instructions and incorporating multi-task learning to fine-tune the model.
74
+
75
+ However, previous LLM-based methods (Zhang et al., 2023b; Fu, 2024; Lei et al., 2023) have overlooked the crucial role of dialogue-specific context
76
+
77
+ and history, limiting their ability to extract deeper insights from conversations and leading to an incomplete understanding of the emotions conveyed. This highlights the need for a model that can effectively capture and analyze the nuances of dialogue context and character information to provide a more comprehensive understanding of emotions.
78
+
79
+ We believe that previous research on the ERC task still requires further exploration of global dialogue scene information, a crucial component that affects emotion analysis in conversations (Poria et al., 2017). Despite the remarkable performance of current LLMs like o1 (OpenAI et al., 2025; Patil, 2025) and DeepSeek-R1 (DeepSeek-AI et al., 2025) in logical reasoning, mathematics, and programming tasks, their potential for deep information extraction in computational emotion analysis remains largely unexplored.
80
+
81
+ In light of these considerations, we propose the Clue of Emotion (CoE) framework to deeply explore the diverse textual clues of characters and scenes within dialogues. These clues enable the model to gain a profound understanding of the emotions expressed in the dialogue. As shown in Figure 1, we incorporate persona and scene as global textual clues to enrich the context of the dialogue and strengthen the model's understanding of conversational dynamics.
82
+
83
+ Additionally, we introduce auxiliary tasks, including role-playing, speaker identification, and rationale reasoning, coupled with a multi-stage training strategy to integrate these components effectively. The role-playing and speaker identification tasks serve as complementary role-enhancement tasks, enabling the LLM to understand character personalities and scene characteristics in depth. The rationale reasoning task employs a self-taught emotion reasoning approach, allowing the model to interpret characters' emotions in specific scenarios. Through this progressive training framework, we enhance the model's ability to accurately infer emotions in complex conversational contexts while effectively utilizing available dialogue clues.
84
+
85
+ Our experimental findings highlight important implications for the broader field of computational emotion analysis. The consistent performance improvements across multiple benchmarks suggest that exploring textual clues in conversations opens new avenues for enhancing LLMs' emotional intelligence. This approach points toward the development of more sophisticated conversational frameworks that better capture the nuanced rela
86
+
87
+ tionship between dialogue context and emotional expression. To the best of our knowledge, current models still underperform in emotion recognition tasks despite their well-established efficacy in other complex reasoning tasks, highlighting a notable research gap in conversational emotion modeling.
88
+
89
+ The main contributions of this study are summarized as follows:
90
+
91
+ - We propose the CoE framework, which simultaneously introduces persona and scene-based textual augmentations for dialogue scenarios and enhances the capabilities of LLMs through textual and parametric optimizations.
92
+ - We systematically design three auxiliary tasks within the CoE framework to train the LLM, enabling it to deeply understand and extract character traits and the underlying reasons for emotions in dialogue scenarios.
93
+ - We conduct comprehensive experiments on the entire method using three ERC benchmark datasets, and the outstanding results demonstrate its effectiveness. Additionally, we carry out in-depth experiments on multiple auxiliary tasks and ERC training strategies to explore the optimal training path for ERC.
94
+
95
+ # 2 Related Work
96
+
97
+ # 2.1 Emotion Recognition in Conversation
98
+
99
+ ERC has evolved from feature-based methods to deep learning approaches and recent LLM innovations. Traditional approaches include context-dependent emotion analysis with hand-crafted features (Poria et al., 2017), DialogueRNN's speaker state tracking (Majumder et al., 2019), and Graph Neural Network (GNN)-based like DialogueGCN (Ghosal et al., 2019) that models speaker interactions. While effective, these methods struggled with complex conversational dynamics.
100
+
101
+ Recent advances position LLMs as powerful tools for ERC. InstructERC reformulates ERC as a retrieval-based instruction-following task, achieving state-of-the-art zero-shot results on multiple datasets that rival previous baselines (Lei et al., 2023). General purpose LLMs such as ChatGPT show emergent zero-shot emotion recognition capabilities (Yang et al., 2023). Subsequent studies further highlight LLMs' promise for emotion cognition while noting their dependence on rich conversational context (Chen and Xiao, 2024; Sabour
102
+
103
+ et al., 2024). Nevertheless, the full potential of these high-capacity generative models for ERC, especially when cast as a classification problem, remains underexplored, motivating the development of our CoE framework.
104
+
105
+ # 2.2 Modeling Conversational Context
106
+
107
+ Prior studies have modeled speaker characteristics to capture conversational dynamics. For instance, DialogueGCN (Ghosal et al., 2019) uses speaker embeddings to represent inter-speaker interactions, while HeterMPC (Gu et al., 2022) employs heterogeneous GNNs for speaker representations. Recent work further infuses persona information into crosstalk GNNs to enhance multimodal ERC (Tu et al., 2024). These methods resonate with our persona clues, focusing on character traits and roles, though not explicitly categorized as such in earlier studies.
108
+
109
+ Works like the EmoSeC framework (Thuseethan et al., 2022) leverage scene context for emotion recognition, while datasets such as KD-EmoR (Pant et al., 2022) incorporate scene descriptions with Korean drama transcripts to enrich contextual representations, aiding emotion disambiguation. These approaches align with our scene clues concept, though prior work typically integrates such information within broader contextual frameworks without systematically separating these elements as our framework does.
110
+
111
+ # 2.3 Auxiliary Learning for ERC
112
+
113
+ Auxiliary tasks provide richer supervision signals for ERC. Multi-stage frameworks for emotion-cause pair extraction enhance model understanding of emotional triggers (Ding et al., 2020; Li et al., 2023). Role-playing and speaker identification, which we incorporate into CoE, improve speaker-aware emotion modeling (Li et al., 2020).
114
+
115
+ Other complementary tasks proposed in previous research like emotion shift analysis (Poria et al., 2019; Gao et al., 2022) and sarcasm recognition (Castro et al., 2019) improve robustness by handling complex emotional transitions and nuanced expressions that often confuse standard ERC models. Semi-supervised methods with context-augmented auxiliary tasks (Kang et al., 2021) further enhance performance in low-resource settings. Our multi-stage auxiliary learning strategy builds on these approaches, sequentially incorporating role-playing, speaker identification, and emotion reasoning to provide comprehensive supervision for our CoE framework.
116
+
117
+ # 3 Preliminaries
118
+
119
+ In the ERC task, our goal is to identify the speaker's emotion label at each turn of the conversation. Given a set of speakers $S$ and an emotion label set $\mathcal{E}$ , each $N$ -turn conversation $C$ is represented as $\{(s_1, u_1), (s_2, u_2), \ldots, (s_N, u_N)\}$ , where $s_i \in S$ is the speaker and $u_i$ is the utterance of the $i$ -th turn. The model can only utilize previous dialogue utterances $\{(s_1, u_1), (s_2, u_2), \ldots, (s_{t-1}, u_{t-1})\}$ as input to predict the emotion label $y_t$ for the $t$ -th dialogue utterance. The emotion labels are from a predefined set $\mathcal{E} = \{e_1, e_2, \ldots, e_o\}$ , where $o$ is the number of emotion categories.
120
+
121
+ # 4 Clue of Emotion
122
+
123
+ In this section, we first introduce the overall CoE framework (Section 4.1). Next, we present the auxiliary tasks (Section 4.2), encompassing three distinct domains of emotion-related capabilities. Finally, we discuss the design of the training strategy (Section 4.3).
124
+
125
+ # 4.1 CoE Framework
126
+
127
+ To effectively utilize critical conversational clues in the ERC task, we propose a CoE framework that synthesizes essential dialogue components. Our approach not only analyzes the utterance itself but also integrates the dialogue scenes, speaker personas, and dialogue history, providing a more comprehensive and structured understanding of the conversation. By combining these elements, the CoE framework can be applied to various tasks related to the ERC task. It can also be equipped with auxiliary tasks to enhance the model's acquisition of emotion-related domain-specific skills.
128
+
129
+ To demonstrate the advantages of the CoE framework, we consider a conversational scenario where multiple participants with distinct personas engage in a discussion. In such interactions, capturing emotional dynamics requires understanding not only the utterances but also the underlying speaker personas, the evolving dialogue context, and the scene. Each speaker may express emotions differently based on their persona, their role in the conversation, and the environment where they are situated. The CoE framework effectively captures subtle emotional shifts by incorporating these key conversational clues. Detailed descriptions of clues can be found in Section 5.1.1 and Appendix A.
130
+
131
+ To formalize the proposed CoE framework, we define the following components: the speaker set
132
+
133
+ # Main Task
134
+
135
+ ![](images/bfb7159e9ca6c8756be18bf1c6d0a0bb2a96d6dfd601045ae384c43d6f343ef9.jpg)
136
+
137
+ # Emotion Recognition in Conversations
138
+
139
+ Given Clues : System, Speaker Persona, Scene, History Dialogue.
140
+
141
+ Instruction: Please select the emotional label of <Phoebe: "God, I hope they kick his
142
+
143
+ ass!">from <Joyful, Mad, Peaceful, Neutral, Sad, Powerful, Scared>
144
+
145
+ # Auxiliary Tasks
146
+
147
+ ![](images/3a74e347c6943c29b2efb6ad072e54a9e052010ed734e69508a8c86abf98557f.jpg)
148
+
149
+ # (a) Role-Playing Task
150
+
151
+ Given Clues
152
+
153
+ System, Speaker Persona, Scene, History Dialogue
154
+
155
+ Instruction: You will stay in character whenever possible, and generate responses in
156
+
157
+ <Powerful> emotions if you were <Phoebe>
158
+
159
+ ![](images/233f5e70b02eaa6a029efe707f70eef1dd3bbbce0e0c9fdaba429a3a48adf65a.jpg)
160
+
161
+ # (b) Speaker Identification Task
162
+
163
+ Given Clues : System, Speaker Persona.
164
+
165
+ Instruction: Please select the Speaker of $<$ "God, I hope they kick his ass!," Emotion:
166
+
167
+ Powerful> from <Chandler, Ross, Joey, Phoebe, Monica, Rachel>
168
+
169
+ ![](images/a15d2816f674647af29cd33db033c0ebd04c105b38dd416efbc20c21e93dbd16.jpg)
170
+
171
+ # (c) STEeR: Self-Taught Emotion Rationale Reasoning
172
+
173
+ Given Clues: System, Speaker Persona, Scene, History Dialogue.
174
+
175
+ Instruction: Please analyze the emotional state of <Phoebe: "God, I hope they kick his ass!"> by first providing your rationale based on the given context, then select the emotional label from <Joyful, Mad, Peaceful, Neutral, Sad, Powerful, Sared>.
176
+
177
+ ![](images/1edb23c623611adb5628fd1853a21c66f66383da968f26db5ea33c501ebfa11b.jpg)
178
+ Figure 2: The CoE Framework
179
+
180
+ $S = \{s_1,s_2,\ldots ,s_M\}$ , where $M$ represents the number of speakers; the dialogue scene $D$ ; the speaker persona set $P = \{p_{1},p_{2},\dots ,p_{M}\}$ , where each $p_i$ corresponds to a speaker in $S$ ; and the historical context set $H = \{h_{1},h_{2},\dots ,h_{t - 1}\}$ , capturing previous dialogue history.
181
+
182
+ The emotion prediction task using CoE can be expressed as a function $f_{\text{emotion}}$ , which combines all these elements to predict the emotion label:
183
+
184
+ $$
185
+ e _ {i} = \arg \max _ {e \in \mathcal {E}} f _ {\text {e m o t i o n}} \left(u _ {i}, S, D, P, H, \mathcal {E}\right) \tag {1}
186
+ $$
187
+
188
+ where $e_i$ is the predicted emotion label for the utterance $u_i$ . Other illustrations of the CoE can be seen in Appendix A.
189
+
190
+ # 4.2 Auxiliary Learning Tasks
191
+
192
+ Previous work (Chen et al., 2024; Kung et al., 2021) has demonstrated that identifying and leveraging interdependent skills can enhance model performance by making the learning process more efficient. Similarly, we integrate auxiliary tasks related to the ERC task into the CoE framework to improve the ERC task performance by providing
193
+
194
+ additional insights into speaker behavior and conversational dynamics. We focus on three tasks: the role-playing task, the speaker identification task, and the self-taught emotion rationale reasoning (STEeR) task. These tasks capture key conversational elements, enabling the model to understand the emotion shift in dialogue better. By leveraging these auxiliary tasks, the model can enrich its understanding and boost performance in the ERC task. Detailed examples of the prompt templates used for each task are provided in Appendix E.
195
+
196
+ # 4.2.1 Role-Playing Task
197
+
198
+ Role-specific dialogue generation has been explored in personalizing dialogue agents (Zhang et al., 2018; Madotto et al., 2019), where conditioning on speaker profiles improves response prediction and dialogue coherence by adapting to speaker identity and style. More recently, LLMs have been trained to simulate specific personas by integrating profiles and emotional states (Shao et al., 2023; Wang et al., 2024), further enhancing the quality of generated dialogues. Similarly, role prediction is critical for ERC, as roles shape emotional expression, language style, and intent. The role-playing task enhances the model's ability to generate plausible dialogue by understanding how context, speaker identity, and emotional state influence communication. This ability to predict roles and infer intent is crucial for improving ERC performance within the CoE framework.
199
+
200
+ In this study, we simulate a role-playing task where the model generates the current utterance $u_{t}^{*}$ based on historical context $H = \{h_1,h_2,\dots ,h_{t - 1}\}$ and contextual clues (particularly the persona of speaker $s$ ). This task can be formulated as:
201
+
202
+ $$
203
+ u _ {t} ^ {*} = f _ {\text {r o l e}} (s, e, D, P, H) \tag {2}
204
+ $$
205
+
206
+ where $s$ represents the specified speaker, $e$ denotes the speaker's emotion when speaking. The function $f_{\mathrm{role}}(s,e,D,P,H)$ generates the most logically coherent utterance $u_t^*$ based on the context $H$ .
207
+
208
+ To process dialogue segments from various scenarios, we apply a series of filtering and transformation steps. The detailed process is provided in Appendix B.
209
+
210
+ # 4.2.2 Speaker Identification Task
211
+
212
+ Different speakers express emotions in distinct ways. Learning each speaker's characteristics helps the model understand the link between personal
213
+
214
+ traits and emotional expression. Previous models using hierarchical attention networks and GRUs (Liu et al., 2024) failed to connect emotional nuances directly to speaker personas, while InstructERC (Lei et al., 2023) struggled with missing persona information.
215
+
216
+ Our CoE incorporates speaker personas as key conversational elements and works complementarily with the role-playing task. Through joint learning, the model develops a deeper understanding of how character roles and personalities influence emotional expression, resulting in more accurate predictions of both identity and intent.
217
+
218
+ The speaker identification task aims to predict the specific speaker based on the utterance and expressed emotion. The task can be formulated as follows:
219
+
220
+ $$
221
+ s ^ {*} = \arg \max _ {s \in S} f _ {\text {s p e a k e r}} (u, e, S, P) \tag {3}
222
+ $$
223
+
224
+ where $u$ represents the current utterance, $e$ denotes the emotion of the speaker when speaking, and $f_{\mathrm{speaker}}(u,e,S,P)$ is an evaluation function.
225
+
226
+ # 4.2.3 Self-Taught Emotion Rationale Reasoning Task
227
+
228
+ When dealing with limited data samples, the model's self-learning mechanism can enhance performance. Inspired by the Self-Taught Reasoning (STaR) method (Zelikman et al., 2022), we adapted this approach for emotion rationale reasoning, resulting in the development of the Self-Taught Emotion Rationale Reasoning (STEeR) task. This method iteratively generates rationale data by itself to improve the model's ability to reason through emotional contexts.
229
+
230
+ Specifically, STEeR begins by generating a small number of initial rationales using GPT-4o ${}^{1}$ due to the large training dataset. However, GPT-4o's relatively low accuracy results in a higher proportion of incorrect answers. To address this, we use these initial rationales to generate further rationales in subsequent iterations, with feedback guiding the process. Over time, as the model generates more correct rationales, its reasoning accuracy improves progressively through each iteration. This iterative process strengthens the model's emotion reasoning capabilities by continuously refining its ability to generate accurate rationales. This is visually represented in Figure 2, where the rationale generation and feedback loop are depicted.
231
+
232
+ Algorithm 1: The Main Training Process of STEeR
233
+ Input: Pretrained LLM M, Dataset $\mathcal{D} = \{(x_i,y_i)\}_{i=1}^D$ , Training Dataset $\mathcal{D}_{train}$
234
+ 1 $M_0 \leftarrow M, D_0 \leftarrow D \setminus \mathcal{D}_{train} //$ Copy the original model and reasoning dataset (pre-generated)
235
+ 2 for $n \in 1 \dots N$ do
236
+ 3 $M_n \leftarrow$ train $(M_{n-1}, \mathcal{D}_{train})$ // Finetune the model on the updated memory dataset
237
+ 4 for $(x_i, y_i) \in \mathcal{D}_{n-1}$ do
238
+ 5 $(\hat{r}_i, \hat{y}_i) \leftarrow M_n(x_i) //$ Perform rationale generation
239
+ 6 $\mathcal{D}_{train} \leftarrow \mathcal{D}_{train} \cup \{(x_i, \hat{r}_i, y_i) | \hat{y}_i = y_i\} //$ Add correct rationales
240
+ 7 end
241
+ 8 $\mathcal{D}_n \leftarrow \mathcal{D}_{n-1} \setminus \mathcal{D}_{train} //$ Update dataset by removing generated samples
242
+ 9 end
243
+
244
+ The STEeR method operates in two stages: the initial data generation phase and the main STEeR training phase (see Algorithm 1). In the training phase, the model is fine-tuned iteratively using the generated rationales, with each cycle refining its emotional reasoning capacity. This integration of rationale generation and model fine-tuning enables continuous improvement in emotional reasoning tasks, helping the model better align with human standards for the ERC task. The data generation process is detailed in Appendix C.
245
+
246
+ # 4.3 Designing Multi-Stage Training Strategies
247
+
248
+ To effectively leverage each auxiliary task for ERC improvement, we designed a multi-stage training strategy. Each task contributes uniquely: Roleplaying enhances the model's ability to predict character roles and understand varied language styles and speaker intents. Speaker identification builds upon this by enabling the model to differentiate speakers and capture their unique emotional expressions. Finally, STEeR further strengthens the model's emotional intelligence, fostering its capacity for emotion reasoning and generating justifiable rationales. These synergistic tasks collectively form a robust foundation for our CoE framework.
249
+
250
+ Recognizing the challenge of determining the optimal training approach, we investigated both curriculum-based and mixed training strategies. Our experimental findings (Section 5.4) demonstrate that a multi-stage, mixed auxiliary training strategy provides the most significant performance improvements for the ERC task.
251
+
252
+ # 5 Experiments
253
+
254
+ # 5.1 Experimental Setup
255
+
256
+ # 5.1.1 Datasets
257
+
258
+ We conduct experiments on three ERC datasets: MELD (Poria et al., 2019), EmoryNLP (Zahiri and Choi, 2018), and IEMOCAP (Busso et al., 2008).
259
+
260
+ MELD (Poria et al., 2019): This dataset is derived from the Friends TV series, including over 1400 dialogues and 13000 utterances. Each dialogue involves multiple speakers and is annotated with seven emotions. We manually set persona information based on the six main characters from the Friends TV series to improve dialogue understanding. We also extract the scene context for each dialogue opening in the dataset.
261
+
262
+ EmoryNLP (Zahiri and Choi, 2018): This dataset contains 97 episodes and 12,606 utterances, with each utterance being annotated with seven emotions adapted from the Willcox's feeling wheel (Willcox, 1982). We extract scene information to provide clues about the setting of each dialogue. Similar to MELD, we also manually set persona information based on the six main characters.
263
+
264
+ IEMOCAP (Busso et al., 2008): This dataset contains video recordings of two-person interactions, capturing natural emotional exchanges between pairs of actors. It includes 151 sessions, with each session involving two speakers, resulting in 302 dialogues. Since the dataset consists of segmented video recordings, we rely on historical dialogue information to assist with the ERC task.
265
+
266
+ # 5.1.2 Metrics
267
+
268
+ To maintain consistency with previous methods, we used weighted F1 (W-F1) as the evaluation metric, as it better reflects the model's performance given the severe class imbalance in the tested datasets (Lei et al., 2023; Song et al., 2022). Furthermore, we ensured consistency in training/validation/test splits with both InstructERC (Lei et al., 2023) and COSMIC (Ghosal et al., 2020).
269
+
270
+ # 5.1.3 Training Setup
271
+
272
+ For our experiments, we kept the LLM parameter count around 7B. Considering computational constraints and time limitations, we employed the LoRA method for model fine-tuning. The rank of the LoRA adapter was set to 16, the learning rate was configured to 2e-4, and the LoRA scaling factor was set to 0.1. Our experiments were conducted on an $8 \times 32$ GB Nvidia V100 GPU cluster, utilizing FP16 precision for training. The final results were averaged across three independent runs.
273
+
274
+ # 5.1.4 Baselines
275
+
276
+ We select several ERC baselines to compare with our CoE. SPCL-CL (Song et al., 2022), COSMIC (Ghosal et al., 2020), and EACL (Yu et al., 2024) use transformer-based models, where SPCL-CL introduces a contrastive learning approach and EACL employs an emotion-anchored learning framework. UniMSE (Hu et al., 2022) and TelME (Yun et al., 2024) leverage multimodal data through teacher-student architectures. SACL (Hu et al., 2023) and EmotionIC (Liu et al., 2024) use recurrent-based methods. DualGATs (Zhang et al., 2023a) employs GNN-based methods. InstructERC (Lei et al., 2023) and BiosERC (Xue et al., 2024) use LLM-based methods. We also test the performance of GPT-4o (Hurst et al., 2024), and DeepSeek-R1 (DeepSeek-AI et al., 2025), a leading reasoning model, as strong baselines.
277
+
278
+ # 5.2 Main Results
279
+
280
+ Previous methods, such as COSMIC (Ghosal et al., 2020), leveraged commonsense knowledge through knowledge graphs to model mental states and contextual information, enhancing their ability to infer emotions. InstructERC (Lei et al., 2023) was the first to leverage generative large language models for the ERC task, leading to improved performance across all datasets and demonstrating the potential of generation-based modeling for emotion recognition in conversations. While these models incorporated external information sources, our approach directly and systematically models conversational elements such as speaker personas and scenes, embedding them explicitly within the task itself. Additionally, we incorporate auxiliary tasks to further enhance the model's ability to process these clues by utilizing supervised learning to refine its understanding of emotional dynamics.
281
+
282
+ Our results (Table 1) show that CoE outperformed previous methods across multiple datasets,
283
+
284
+ Table 1: Main Results for the ERC task
285
+
286
+ <table><tr><td>Methods</td><td>Backbone</td><td>EmoryNLP W-F1</td><td>MELD W-F1</td><td>IEMOCAP W-F1</td><td>Average W-F1</td></tr><tr><td>EmotionIC</td><td>RB</td><td>40.25</td><td>66.32</td><td>69.61</td><td>58.73</td></tr><tr><td>SACL</td><td>RB</td><td>39.65</td><td>66.45</td><td>69.22</td><td>58.44</td></tr><tr><td>DualGATs</td><td>GB</td><td>40.69</td><td>66.90</td><td>67.68</td><td>58.42</td></tr><tr><td>COSMIC</td><td>TB</td><td>38.11</td><td>65.21</td><td>65.28</td><td>56.2</td></tr><tr><td>SPCL-CL</td><td>TB</td><td>40.94</td><td>67.25</td><td>69.74</td><td>59.31</td></tr><tr><td>EACL</td><td>TB</td><td>40.24</td><td>67.12</td><td>70.41</td><td>59.26</td></tr><tr><td>UniMSE</td><td>TB (MM)</td><td>-</td><td>65.51</td><td>70.66</td><td>-</td></tr><tr><td>TelME</td><td>TB(MM)</td><td>-</td><td>67.37</td><td>70.48</td><td>-</td></tr><tr><td>GPT-4o</td><td>LLM</td><td>39.78</td><td>59.18</td><td>51.68</td><td>50.18</td></tr><tr><td>DeepSeek-R1</td><td>LLM</td><td>30.94</td><td>59.51</td><td>53.64</td><td>48.03</td></tr><tr><td>BiosERC</td><td>LLM</td><td>41.68</td><td>69.83</td><td>71.19</td><td>60.9</td></tr><tr><td>InstructERC</td><td>LLM</td><td>41.37</td><td>69.15</td><td>71.39</td><td>60.64</td></tr><tr><td>CoE</td><td>LLM</td><td>44.29</td><td>70.11</td><td>70.46</td><td>61.62</td></tr></table>
287
+
288
+ Backbone abbreviations: TB = Transformer-based, MM = Multimodal, RB = Recurrent-based, GB = GNN-based, LLM = Large Language Model.
289
+
290
+ achieving a $2.92\%$ improvement on the EmoryNLP dataset and a $0.96\%$ improvement on MELD, reflecting its effectiveness in various ERC benchmarks. Notably, despite their remarkable capabilities in logical reasoning and programming tasks, strong LLMs like GPT-4o and DeepSeek-R1 show limited performance in zero-shot ERC. CoE achieved the highest average W-F1 score $(+0.98\%)$ across the tested datasets, indicating its overall superiority in handling a variety of conversational contexts. These improvements stem from the CoE's ability to progressively integrate conversational clues, such as speaker personas and scenes, which are embedded directly within the task through the multi-stage auxiliary learning strategy. By enhancing its understanding of emotional subtleties and speaker-specific behaviors, CoE surpasses prior methods that rely on external knowledge sources. However, on the IEMOCAP dataset, which consists of scripted, discrete conversations between temporary actors, our method faced challenges due to the absence of persona and scene information, which are essential components for effectively capturing the full emotional context.
291
+
292
+ # 5.3 Ablation Studies
293
+
294
+ # 5.3.1 Effect of Different LLMs
295
+
296
+ To further evaluate the performance of LLMs in the ERC task, we conducted experiments using different LLMs, as shown in Figure 3. The experiments focused on the ERC task using the CoE framework without auxiliary tasks, allowing for a direct comparison of the performance of various LLMs.
297
+
298
+ Among the models tested, Mistral-7B-v0.1 demonstrated the best overall performance across the majority of datasets, leading to its selection as
299
+
300
+ ![](images/5e9326aee1ab98d08beb6a59a14e701fdfd2fb2c7ed3f70cb938acd3862138e7.jpg)
301
+ Figure 3: Comparison with Other LLMs
302
+
303
+ the base model for subsequent ablation studies on multi-stage auxiliary learning.
304
+
305
+ # 5.3.2 Ablation Study on Textual Clues
306
+
307
+ In this section, we conduct an ablation study to analyze the impact of textual clues, specifically persona and scene information, on the model's performance within the CoE framework. Importantly, these experiments do not incorporate auxiliary tasks, allowing for a focused analysis of the direct contributions of persona and scene clues. The results are summarized in Table 2, from which we can conclude that the study highlights the significance of persona and scene clues. Removing either persona or scene leads to a noticeable performance drop, indicating their essential role in providing context to the dialogue. The most significant decline occurs when both clues are removed, underscoring their complementary effect on improving the accuracy of the ERC task.
308
+
309
+ Table 2: Ablation Study on Textual Clues
310
+
311
+ <table><tr><td>Methods</td><td>EmoryNLP W-F1</td><td>MELD W-F1</td></tr><tr><td>LLM + Textual Clues</td><td>42.02**</td><td>69.31**</td></tr><tr><td>LLM + Textual Clues (w/o Persona)</td><td>41.51*</td><td>69.13**</td></tr><tr><td>LLM + Textual Clues (w/o Scene)</td><td>40.71**</td><td>-</td></tr><tr><td>LLM + Textual Clues (w/o Persona + Scene)</td><td>39.95**</td><td>-</td></tr></table>
312
+
313
+ Note: $^{*}p < 0.05$ $^{**}p < 0.01$ indicate the level of statistical significance.
314
+
315
+ # 5.3.3 Ablation Study on Auxiliary Tasks
316
+
317
+ We also conduct an in-depth analysis of the auxiliary tasks to evaluate their individual contributions. Table 3 illustrates the contribution of each auxiliary task to the main task's performance across both datasets, demonstrating that each task independently adds value to the model's emotion recognition capabilities.
318
+
319
+ Based on the results, the speaker identification task $(+1.08\%)$ on EmoryNLP, $+0.36\%$ on MELD) demonstrates the strongest effect on model performance, likely because it enables the model to link
320
+
321
+ emotional clues directly to individual personas, capturing subtle shifts in tone that vary between speakers. Although the role-playing task $(+0.38\%)$ on EmoryNLP, $+0.41\%$ on MELD) shows relatively smaller gains, its full potential may be realized when integrated with other auxiliary tasks during joint training, where it can enhance the model's understanding of personas. While STEeR's improvement $(+1.01\%)$ on EmoryNLP, $+0.27\%$ on MELD) is a little smaller than speaker's, its focus on emotion rationale reasoning still plays a key role in interpreting complex emotional states. The smaller improvement in MELD $(+0.36\%)$ may be due to the imbalanced distribution of emotion classes, where the model focuses more on the majority of neutral emotions, resulting in limited gains for rarer emotions.
322
+
323
+ Table 3: Performance Improvement of the Main Task with Each Individual Auxiliary Task
324
+
325
+ <table><tr><td>Tasks</td><td>EmoryNLP W-F1</td><td>MELD W-F1</td></tr><tr><td>Emotion CoE Only</td><td>42.02**</td><td>69.31**</td></tr><tr><td>Emotion CoE + Speaker CoE</td><td>43.10**</td><td>69.67**</td></tr><tr><td>Emotion CoE + Role-Playing CoE</td><td>42.40*</td><td>69.42*</td></tr><tr><td>Emotion CoE + Reasoning CoE</td><td>43.03**</td><td>69.58*</td></tr></table>
326
+
327
+ Note: *p<0.05, **p<0.01 indicate the level of statistical significance.
328
+
329
+ # 5.4 Train Strategy Study
330
+
331
+ In this section, we examine various training strategies designed to enhance model performance on the ERC task. The experiments were conducted in two phases: first, we performed a preliminary evaluation of a subset of the data to compare the effectiveness of mixed auxiliary training and curriculum training. Building on these findings, we then developed and tested two refined strategies for comprehensive evaluation.
332
+
333
+ # 5.4.1 Phase 1: Preliminary Evaluation of Training Approaches
334
+
335
+ In this initial phase, we conducted experiments on a subset of the dataset to assess the effectiveness of two key training strategies: curriculum-based sequential training (Soviany et al., 2022; Wang et al., 2021) and mixed auxiliary training (Chen et al., 2022). Given the high computational cost associated with training large models across various auxiliary task combinations, we focused on role-playing and speaker identification tasks using the EmoryNLP dataset for evaluation. These tasks were selected because they address critical aspects
336
+
337
+ of the ERC task, allowing us to more precisely evaluate the impact of different training strategies.
338
+
339
+ We compare three training strategies for ERC, as shown in Figure 4:
340
+
341
+ ![](images/3beed5a2373351812a3232a6d726498e871e8baea1d6ff9284a5b78f4b819fbe.jpg)
342
+ Figure 4: Three Training Strategies for ERC
343
+
344
+ 1. Curriculum-based Sequential Training Strategy: Each task is trained in a separate stage, with the ERC task always being the final stage of training.
345
+ 2. Mixed Training Strategy: All auxiliary tasks are merged into a single multi-task dataset for joint training, with a separate stage reserved for fine-tuning the model on the ERC task.
346
+ 3. Multi-Task Training Strategy: All tasks, including the ERC task, are mixed and trained together in a single stage as a multi-task setup.
347
+
348
+ The results in Table 4 of this small-scale experiment demonstrate that mixed auxiliary training consistently outperforms the curriculum-based training approach. This suggests that the mixed training strategy enables more dynamic knowledge sharing between tasks, making it a more suitable approach for the ERC task.
349
+
350
+ Table 4: Ablation Study on Different Strategies
351
+
352
+ <table><tr><td>Models</td><td>EmoryNLP
353
+ W-F1</td></tr><tr><td>Fully Mixed Strategy</td><td>42.46**</td></tr><tr><td>Mixed Auxiliary Strategy</td><td>43.64**</td></tr><tr><td>Curriculum-based Strategy A</td><td>43.30*</td></tr><tr><td>Curriculum-based Strategy B</td><td>43.35*</td></tr></table>
354
+
355
+ Note: ${}^{ * }p < {0.05},{}^{* * }p < {0.01}$ indicate the level of statistical significance.
356
+
357
+ # 5.4.2 Phase 2: Strategy Refinement and Full Evaluation
358
+
359
+ One key challenge is that the STEeR method cannot be jointly trained with other datasets due to its unique rationale generation process. This means a straightforward mixed training strategy is not effective for integrating STEeR with other tasks. Based on these findings from the small-scale experiments, we developed two refined strategies for full-scale evaluation to address these issues and optimize the training process.
360
+
361
+ - Strategy A: This strategy follows a three-stage training process. Firstly, the model is trained on a consisting of role-playing and speaker identification tasks. The model is then trained using the STEeR method. Finally, the model is trained for the ERC task.
362
+ - Strategy B: This approach begins by generating a rationale by using the STEeR method. This enriched dataset allows for joint training on all three auxiliary tasks simultaneously. Once the intensive joint training phase is complete, the model is trained for the ERC task.
363
+
364
+ Analysis of Strategy Refinement: Strategy A follows a structured, stepwise approach, where each training stage builds upon the previous one, enhancing the model's grasp of speaker identities, conversational roles, and emotional reasoning. This hierarchical progression enables the model to specialize in each aspect before progressing to the next, thereby creating a refined understanding at every level. On the other hand, Strategy B begins by generating a rationale dataset using the STEeR method, which enables the simultaneous joint training of all three auxiliary tasks. This joint approach fosters a more integrated prior model, providing a solid foundation for the ERC task.
365
+
366
+ We conducted experiments to compare the performance of the model under Strategy A and Strategy B. As shown in Table 5, the results indicate that Strategy B consistently outperformed Strategy A in the final ERC task. By pre-generating a rationale dataset, Strategy B facilitated a more effective integration of auxiliary tasks within its multi-stage auxiliary learning framework, enabling joint training that strengthened the model's overall capability for the ERC task. In contrast, segmentation in Strategy A can lead to weaker knowledge retention in earlier stages, potentially limiting the
367
+
368
+ model's capacity to fully leverage learned representations in the final ERC stage. For a detailed analysis of how different task combinations affect the model's performance, see Appendix D. These findings underscore the significance of integrating reasoning processes early in the training pipeline, which plays a crucial role in enhancing the model's performance across various ERC benchmarks by providing it with robust prior knowledge.
369
+
370
+ Table 5: Comparison of CoE Strategies A and B
371
+
372
+ <table><tr><td>Strategies</td><td>EmoryNLP
373
+ W-F1</td><td>MELD
374
+ W-F1</td></tr><tr><td>CoE Strategy A</td><td>43.68*</td><td>69.89*</td></tr><tr><td>CoE Strategy B</td><td>44.29**</td><td>70.11*</td></tr></table>
375
+
376
+ Note: *p<0.05, **p<0.01 indicate the level of statistical significance.
377
+
378
+ # 6 Conclusion
379
+
380
+ In this work, we present the CoE framework, which enhances ERC performance by utilizing personas and scene information. The framework combines role-playing, speaker identification, and STEeR to enhance emotional reasoning and understanding. Through multi-stage training strategies, we found that combining auxiliary tasks into a unified multi-task training phase outperforms other strategies, achieving state-of-the-art performance on the EmoryNLP and MELD datasets.
381
+
382
+ # Limitations
383
+
384
+ The CoE framework, while effective for text-based ERC, currently focuses only on textual modality. Future work could explore the integration of multimodal information, such as visual or acoustic cues, to further enhance emotion recognition capabilities. Additionally, the dataset constraints affected our analysis — IEMOCAP's scripted conversations between temporary actors lack the consistent speaker identities needed for speaker identification tasks, while MELD's incomplete scene information prevented certain ablation experiments. These limitations restricted our ability to fully evaluate the impact of contextual elements on ERC performance. To address these dataset limitations, future research could explore the automatic generation of persona and scene information to enrich contextual understanding in dialogues where such information is limited or missing.
385
+
386
+ # Acknowledgements
387
+
388
+ This work has been supported by the National Natural Science Foundation of China (62372483). The work of Jianxing Yu has been supported by the National Natural Science Foundation of China (62276279), Guangdong Basic and Applied Basic Research Foundation (2024B1515020032).
389
+
390
+ # References
391
+
392
+ Scott Brave and Cliff Nass. 2007. Emotion in human-computer interaction. In The Human-Computer Interaction Handbook, pages 103-118.
393
+ Tom B Brown. 2020. Language models are few-shot learners. arXiv preprint arXiv:2005.14165.
394
+ Carlos Busso, Murtaza Bulut, Chul Min Lee, Abe Kazemzadeh, Emily Mower, Samuel Kim, Jeannette N Chang, Sungbok Lee, and Shrikanth S Narayanan. 2008. Iemocap: Interactive emotional dyadic motion capture database. Language Resources and Evaluation, 42(4):335-359.
395
+ Santiago Castro, Devamanyu Hazarika, Verónica Pérez-Rosas, Roger Zimmermann, Rada Mihalcea, and Soujanya Poria. 2019. Towards multimodal sarcasm detection (an obviously perfect paper). In Proceedings of the 57th Conference of the Association for Computational Linguistics, ACL 2019, Florence, Italy, July 28- August 2, 2019, Volume 1: Long Papers, pages 4619-4629. Association for Computational Linguistics.
396
+ Rajdeep Chatterjee, Saptarshi Mazumdar, R Simon Sherratt, Rohit Halder, Tanmoy Maitra, and Debasis Giri. 2021. Real-time speech emotion analysis for smart home assistants. IEEE Transactions on Consumer Electronics, 67(1):68-76.
397
+ Hong Chen, Xin Wang, Chaoyu Guan, Yue Liu, and Wenwu Zhu. 2022. Auxiliary learning with joint task and data scheduling. In International Conference on Machine Learning, pages 3634-3647. PMLR.
398
+ Mayee Chen, Nicholas Roberts, Kush Bhatia, Jue Wang, Ce Zhang, Frederic Sala, and Christopher Ré. 2024. Skill-it! a data-driven skills framework for understanding and training language models. Advances in Neural Information Processing Systems, 36.
399
+ Yuyan Chen and Yanghua Xiao. 2024. Recent advancement of emotion cognition in large language models. CoRR, abs/2409.13354.
400
+ DeepSeek-AI, Daya Guo, and Dejian Yang et al. 2025. Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning. Preprint, arXiv:2501.12948.
401
+ Zixiang Ding, Rui Xia, and Jianfei Yu. 2020. End-to-end emotion-cause pair extraction based on sliding
402
+
403
+ window multi-label learning. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 3574-3583, Online. Association for Computational Linguistics.
404
+ Yumeng Fu. 2024. CKERC: Joint large language models with commonsense knowledge for emotion recognition in conversation. CoRR, abs/2403.07260.
405
+ Qingqing Gao, Biwei Cao, Xin Guan, Tianyun Gu, Xing Bao, Junyan Wu, Bo Liu, and Jiqin Cao. 2022. Emotion recognition in conversations with emotion shift detection based on multi-task learning. Knowledge-Based Systems, 248:108861.
406
+ Deepanway Ghosal, Navonil Majumder, Alexander F. Gelbukh, Rada Mihalcea, and Soujanya Poria. 2020. COSMIC: commonsense knowledge for emotion identification in conversations. In Findings of the Association for Computational Linguistics: EMNLP 2020, Online Event, 16-20 November 2020, volume EMNLP 2020 of Findings of ACL, pages 2470-2481. Association for Computational Linguistics.
407
+ Deepanway Ghosal, Navonil Majumder, Soujanya Poria, Niyati Chhaya, and Alexander F. Gelbukh. 2019. Dialoguegen: A graph convolutional neural network for emotion recognition in conversation. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing, EMNLP-IJCNLP 2019, Hong Kong, China, November 3-7, 2019, pages 154-164. Association for Computational Linguistics.
408
+ Jia-Chen Gu, Chao-Hong Tan, Chongyang Tao, Zhen-Hua Ling, Huang Hu, Xiubo Geng, and Daxin Jiang. 2022. Hetermpc: A heterogeneous graph neural network for response generation in multi-party conversations. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2022, Dublin, Ireland, May 22-27, 2022, pages 5086-5097. Association for Computational Linguistics.
409
+ Dou Hu, Yinan Bao, Lingwei Wei, Wei Zhou, and Songlin Hu. 2023. Supervised adversarial contrastive learning for emotion recognition in conversations. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics, pages 10835-10852, Toronto, Canada. Association for Computational Linguistics.
410
+ Guimin Hu, Ting-En Lin, Yi Zhao, Guangming Lu, Yuchuan Wu, and Yongbin Li. 2022. Unimse: Towards unified multimodal sentiment analysis and emotion recognition. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, EMNLP 2022, Abu Dhabi, United Arab Emirates, December 7-11, 2022, pages 7837-7851.
411
+ Aaron Hurst, Adam Lerer, and Adam P. Goucher et al. 2024. Gpt-4o system card. CoRR, abs/2410.21276.
412
+
413
+ Liangyi Kang, Jie Liu, Lingqiao Liu, Zhiyang Zhou, and Dan Ye. 2021. Semi-supervised emotion recognition in textual conversation via a context-augmented auxiliary training task. Information Processing and Management, 58(6):102717.
414
+ Po-Nien Kung, Sheng-Siang Yin, Yi-Cheng Chen, Tse-Hsuan Yang, and Yun-Nung Chen. 2021. Efficient multi-task auxiliary learning: selecting auxiliary data by feature similarity. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 416-428.
415
+ Shanglin Lei, Guanting Dong, Xiaoping Wang, Keheng Wang, and Sirui Wang. 2023. Instructerc: Reforming emotion recognition in conversation with a retrieval multi-task llms framework. arXiv preprint arXiv:2309.11911.
416
+ Chenbing Li, Jie Hu, Tianrui Li, Shengdong Du, and Fei Teng. 2023. An effective multi-task learning model for end-to-end emotion-cause pair extraction. Applied Intelligence, 53(3):3519-3529.
417
+ Jingye Li, Meishan Zhang, Donghong Ji, and Yijiang Liu. 2020. Multi-task learning with auxiliary speaker identification for conversational emotion recognition. CoRR, abs/2003.01478.
418
+ Yingjian Liu, Jiang Li, Xiaoping Wang, and Zhigang Zeng. 2024. Emotional: emotional inertia and contagion-driven dependency modeling for emotion recognition in conversation. Science China Information Sciences, 67(8):1-17.
419
+ Andrea Madotto, Zhaojiang Lin, Chien-Sheng Wu, and Pascale Fung. 2019. Personalizing dialogue agents via meta-learning. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 5454-5459, Florence, Italy. Association for Computational Linguistics.
420
+ Navonil Majumder, Soujanya Poria, Devamanyu Hazerika, Rada Mihalcea, Alexander F. Gelbukh, and Erik Cambria. 2019. Dialoguernn: An attentive RNN for emotion detection in conversations. In The Thirty-Third AAAI Conference on Artificial Intelligence, AAAI 2019, The Thirty-First Innovative Applications of Artificial Intelligence Conference, IAAI 2019, The Ninth AAAI Symposium on Educational Advances in Artificial Intelligence, EAAI 2019, Honolulu, Hawaii, USA, January 27 - February 1, 2019, pages 6818-6825. AAAI Press.
421
+ Scott Monteith, Tasha Glenn, John Geddes, Peter C Whybrow, and Michael Bauer. 2022. Commercial use of emotion artificial intelligence (ai): implications for psychiatry. Current Psychiatry Reports, 24(3):203-211.
422
+ OpenAI, Ahmed El-Kishky, Alexander Wei, Andre Saraiva, Borys Minaev, Daniel Selsam, David Dohan, Francis Song, Hunter Lightman, Ignasi Clavera, Jakub Pachocki, Jerry Tworek, Lorenz Kuhn, Lukasz Kaiser, Mark Chen, Max Schwarzer, Mostafa Rohaninejad, Nat McAleese, o3 contributors, Oleg
423
+
424
+ Mürk, Rhythm Garg, Rui Shu, Szymon Sidor, Vineet Kosaraju, and Wenda Zhou. 2025. Competitive programming with large reasoning models. Preprint, arXiv:2502.06807.
425
+ Sudarshan Pant, Eunchae Lim, Hyung-Jeong Yang, Guee-Sang Lee, Soo-Hyung Kim, Young-Shin Kang, and Hyerim Jang. 2022. Korean drama scene transcript dataset for emotion recognition in conversations. IEEE Access, 10:119221-119231.
426
+ Avinash Patil. 2025. Advancing reasoning in large language models: Promising methods and approaches. Preprint, arXiv:2502.03671.
427
+ Soujanya Poria, Erik Cambria, Devamanyu Hazarika, Navonil Majumder, Amir Zadeh, and Louis-Philippe Morency. 2017. Context-dependent sentiment analysis in user-generated videos. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics, pages 873-883.
428
+ Soujanya Poria, Navonil Majumder, Devamanyu Hazarika, and Rada Mihalcea. 2019. Meld: A multimodal multi-party dataset for emotion recognition in conversations. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 527-536.
429
+ Xiangyu Qin, Zhiyu Wu, Tingting Zhang, Yanran Li, Jian Luan, Bin Wang, Li Wang, and Jinshi Cui. 2023. Bert-erc: Fine-tuning bert is enough for emotion recognition in conversation. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 37, pages 13492-13500.
430
+ Sahand Sabour, Siyang Liu, Zheyuan Zhang, June M. Liu, Jinfeng Zhou, Alvionna S. Sunaryo, Tatia M. C. Lee, Rada Mihalcea, and Minlie Huang. 2024. Emobench: Evaluating the emotional intelligence of large language models. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics, ACL 2024, Bangkok, Thailand, August 11-16, 2024, pages 5986-6004. Association for Computational Linguistics.
431
+ Yunfan Shao, Linyang Li, Junqi Dai, and Xipeng Qiu. 2023. Character-LLM: A trainable agent for roleplaying. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 13153-13187, Singapore. Association for Computational Linguistics.
432
+ Xiaohui Song, Longtao Huang, Hui Xue, and Songlin Hu. 2022. Supervised prototypical contrastive learning for emotion recognition in conversation. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, EMNLP 2022, Abu Dhabi, United Arab Emirates, December 7-11, 2022, pages 5197-5206. Association for Computational Linguistics.
433
+ Petru Soviany, Radu Tudor Ionescu, Paolo Rota, and Nicu Sebe. 2022. Curriculum learning: A survey. International Journal of Computer Vision, 130(6):1526-1565.
434
+
435
+ Selvarajah Thuseethan, Sutharshan Rajasegarar, and John Yearwood. 2022. Emosec: Emotion recognition from scene context. Neurocomputing, 492:174-187.
436
+ Geng Tu, Feng Xiong, Bin Liang, and Ruifeng Xu. 2024. A persona-infused cross-task graph network for multimodal emotion recognition with emotion shift detection in conversations. In Proceedings of the 47th International ACM SIGIR Conference on Research and Development in Information Retrieval, SIGIR 2024, Washington DC, USA, July 14-18, 2024, pages 2266-2270. ACM.
437
+ Noah Wang, Z. y. Peng, Haoran Que, Jiaheng Liu, Wangchunshu Zhou, Yuhan Wu, Hongcheng Guo, Ruitong Gan, Zehao Ni, Jian Yang, Man Zhang, Zhaoxiang Zhang, Wanli Ouyang, Ke Xu, Wenhao Huang, Jie Fu, and Junran Peng. 2024. Rolellm: Benchmarking, eliciting, and enhancing role-playing abilities of large language models. In Findings of the Association for Computational Linguistics, ACL 2024, Bangkok, Thailand and virtual meeting, August 11-16, 2024, pages 14743-14777. Association for Computational Linguistics.
438
+ Xin Wang, Yudong Chen, and Wenwu Zhu. 2021. A survey on curriculum learning. IEEE Transactions on Pattern Analysis and Machine Intelligence, 44(9):4555-4576.
439
+ Gloria Willcox. 1982. The feeling wheel: A tool for expanding awareness of emotions and increasing spontaneity and intimacy. Transactional Analysis Journal, 12(4):274-276.
440
+ Jieying Xue, Minh-Phuong Nguyen, Blake Matheny, and Le-Minh Nguyen. 2024. Bioserc: Integrating biography speakers supported by llms for ERC tasks. In Artificial Neural Networks and Machine Learning - ICANN 2024 - 33rd International Conference on Artificial Neural Networks, Lugano, Switzerland, September 17-20, 2024, Proceedings, Part V, volume 15020 of Lecture Notes in Computer Science, pages 277-292. Springer.
441
+ Kailai Yang, Shaoxiong Ji, Tianlin Zhang, Qianqian Xie, Ziyan Kuang, and Sophia Ananiadou. 2023. Towards interpretable mental health analysis with large language models. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, EMNLP 2023, Singapore, December 6-10, 2023, pages 6056-6077. Association for Computational Linguistics.
442
+ Fangxu Yu, Junjie Guo, Zhen Wu, and Xinyu Dai. 2024. Emotion-anchored contrastive learning framework for emotion recognition in conversation. In *Findings of the Association for Computational Linguistics: NAACL* 2024, Mexico City, Mexico, June 16-21, 2024, pages 4521-4534. Association for Computational Linguistics.
443
+ Taeyang Yun, Hyunkuk Lim, Jeonghwan Lee, and Min Song. 2024. Telme: Teacher-leading multimodal fusion network for emotion recognition in conversation.
444
+
445
+ In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies NAACL 2024, Mexico City, Mexico, June 16-21, 2024, pages 82-95. Association for Computational Linguistics.
446
+ Samira M Zahiri and Jinho D Choi. 2018. Emotion recognition in conversations with transfer learning from generative conversation modeling. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Student Research Workshop, pages 27-36.
447
+ Eric Zelikman, Yuhuai Wu, and Noah D Goodman. 2022. Star: Self-taught reasoner. arXiv preprint arXiv:2203.14465.
448
+ Duzhen Zhang, Feilong Chen, and Xiuyi Chen. 2023a. Dualgats: Dual graph attention networks for emotion recognition in conversations. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics, pages 7395-7408.
449
+ Saizheng Zhang, Emily Dinan, Jack Urbanek, Arthur Szlam, Douwe Kiela, and Jason Weston. 2018. Personalizing dialogue agents: I have a dog, do you have pets too? In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics, pages 2204-2213, Melbourne, Australia. Association for Computational Linguistics.
450
+ Yazhou Zhang, Mengyao Wang, Prayag Tiwari, Qiuchi Li, Benyou Wang, and Jing Qin. 2023b. Dialoguellm: Context and emotion knowledge-tuned llama models for emotion recognition in conversations. CoRR, abs/2310.11374.
451
+
452
+ # A Details of CoE
453
+
454
+ In this study, we develop a CoE framework to fine-tune pre-trained language models for emotion-related tasks through supervised fine-tuning. Each item in the square bracket represents a key element, with the following descriptions:
455
+
456
+ - [System]: This part outlines the type of task the participant is required to perform (i.e., ERC, role-playing, or speaker identification), as well as the role the large language model needs to assume during the task.
457
+ - [Speaker_Persona]: This part provides detailed descriptions of the character's personality traits, professional backgrounds, and roles within the group. These descriptions help in establishing a clearer understanding of each character's persona.
458
+ - [Scene]: This section describes the specific location and environment where the dialogue takes place, such as "Monica and Rachel's apartment." Setting the scene is crucial for building the conversation context.
459
+ - [History_Dialogue]: This part records prior interactions between the characters, allowing the model to better understand the current conversational context and the dynamics between participants.
460
+ - [Predict]: This section provides instructions to guide the model in making predictions. For the ERC task, this might involve predicting the emotion of a specific dialogue segment; for role-playing, it entails predicting what the character will say next; and for speaker identification, it involves predicting the speaker of a particular utterance.
461
+ - [Target]: This represents the model's expected output, such as the prediction results that the model needs to learn.
462
+
463
+ # B Dialogue Processing Steps
464
+
465
+ To process dialogue segments from various scenarios, we follow these steps. In our notation, $C_i$ represents the $i$ -th dialogue segment in a conversation $C$ , and $u_{i,j}$ denotes the $j$ -th utterance in segment $C_i$ . We define $P$ as the predefined subset of speakers we wish to retain from the complete speaker set $S$ .
466
+
467
+ The processing consists of two main steps:
468
+
469
+ 1. For each dialogue segment $C_i$ , we remove the first utterance $u_{i,1}$ :
470
+
471
+ $$
472
+ F _ {1} \left(C _ {i}\right) = C _ {i} \backslash \{u _ {i, 1} \} \tag {4}
473
+ $$
474
+
475
+ 2. We retain only those dialogue segments where the speaker of the last utterance is in set $P$ :
476
+
477
+ $$
478
+ F _ {2} \left(C _ {i}\right) = \left\{ \begin{array}{l l} C _ {i} & \text {i f s p e a k e r o f l a s t u t t e r a n c e} \in P \\ \varnothing & \text {o t h e r w i s e} \end{array} \right. \tag {5}
479
+ $$
480
+
481
+ Combining the above steps, the processed dialogue set $P(C)$ is formed by:
482
+
483
+ $$
484
+ P (C) = \bigcup_ {i = 1} ^ {n} F _ {2} \left(F _ {1} \left(C _ {i}\right)\right) \tag {6}
485
+ $$
486
+
487
+ where $n$ is the total number of dialogue segments in conversation $C$ .
488
+
489
+ This indicates that for each dialogue segment $C_i$ , we first discard its first utterance (applying $F_1$ ), then check if the speaker of the last utterance is in our predefined set $P$ (applying $F_2$ ). If so, we keep the entire segment; otherwise, we discard it. Finally, we merge all retained segments to form the final dialogue set $P(C)$ .
490
+
491
+ # C Initial Data Generation Phase
492
+
493
+ The initial data generation phase, as illustrated in Algorithm 2, describes how we generate the first batch of rationales using GPT-4o. In this process, we iterate through the dataset and generate rationales for each sample. When the generated emotion label matches the ground truth, we add the corresponding rationale to our training dataset. This approach ensures that we only use high-quality rationales for training the model. After each iteration, we remove the processed samples from the original dataset to avoid redundant processing.
494
+
495
+ # D Analysis of Task Combinations
496
+
497
+ To investigate the contribution of different task combinations, we conducted experiments comparing three training strategies.
498
+
499
+ Our experiment shows that using only the Speaker Task followed by the STEeR Task and the ERC task yields a $43.43\%$ W-F1 score on EmoryNLP. Similarly, using only the Role-Playing Task followed by the STEeR Task and the ERC task achieves $43.10\%$ . However, combining both Speaker and Role-Playing Tasks before the STEeR
500
+
501
+ Algorithm 2: Pre Data Generation Process
502
+ Input: GPT Model GPT4, Dataset $\mathcal{D} = \{(x_i,y_i)\}_{i = 1}^D$
503
+ 1 $\mathcal{D}_0\gets \mathcal{D},\mathcal{D}_{train}\gets \emptyset / /$ Initialize a temporary dataset and the training dataset
504
+ 2 for $n\in 1\dots N$ do
505
+ 3 for $(x_{i},y_{i})\in \mathcal{D}_{n - 1}$ do
506
+ 4 $(\hat{r}_i,\hat{y}_i)\gets GPT4(x_i,y_i)\quad \forall (x_i,y_i)$ // Perform rationale generation
507
+ 5 $\mathcal{D}_{train}\gets \mathcal{D}_{train}\cup \{(x_i,\hat{r}_i,y_i)\mid \hat{y}_i = y_i\} /$ Add correct rationales
508
+ 6 end
509
+ 7 $\mathcal{D}_n\gets \mathcal{D}_{n - 1}\backslash \mathcal{D}_{train}$ // Update dataset by removing generated samples
510
+ 8 end
511
+
512
+ Task produces the best performance $(44.29\%)$ . The results indicate that while both speaker identification and role-playing tasks show meaningful contributions when paired with the STEeR task, the combination of both tasks achieves the best performance. This suggests that integrating role-playing with speaker identification creates a synergistic effect, improving the model's ability to better understand personas, including the characters' personalities and conversational dynamics. This enhances the model's overall emotion recognition ability, as the role-playing task complements the speaker identification task by focusing on different aspects of the speaker's identity and interaction style.
513
+
514
+ The findings suggest that the full potential of the role-playing task is realized when it is integrated with other tasks. Further evaluation of the auxiliary task could clarify its contribution to overall performance and justify its role in the training strategy.
515
+
516
+ # E Prompts Settings
517
+
518
+ In this section, we present the detailed prompt templates used for each task in the CoE framework. These prompts illustrate how we structured the inputs for the LLM to perform different tasks. Each prompt follows a consistent format with sections for system instructions, speaker persona information, scene description, dialogue history, prediction task, and target output. The following tables demonstrate the specific prompts used for the main
519
+
520
+ ERC task and each auxiliary task (speaker identification, role-playing, and emotion reasoning). These prompts show how we systematically incorporated textual clues and task-specific instructions to guide the model's learning process.
521
+
522
+ <table><tr><td></td><td>Prompt for ERC</td></tr><tr><td>[System]</td><td>As an expert in Conversational Emotion Recognition (ERC), your task is to [Predict] the emotion by analyzing the [Speaker_Persona], [Scene] and [Historydialogue] information.</td></tr><tr><td>[Speaker_Persona]</td><td>Chandler: Known for wit and sarcasm, works in advertising, group&#x27;s humorist with logical insights.
523
+ Phoebe: A masseuse and musician, eccentric with unique wisdom, offering empathy to the group.
524
+ Ross: A paleontologist and professor, adds intellectual depth, connections through family ties with Monica and past relationship with Rachel.
525
+ Rachel: Progresses from a waitress to fashion, influences group dynamics, evolving relationship with Ross.
526
+ Monica: A chef, known for organization, group&#x27;s anchor with hospitality, Ross&#x27;s sister.</td></tr><tr><td>[Scene]</td><td>Monica and Rachel&#x27;s place, the entire gang is present.</td></tr><tr><td>[History_Dialogue]</td><td>Monica: &quot;So ah, Phoebe, how was your date?&quot;
527
+ Phoebe: &quot;Oh well y&#x27;know.&quot;
528
+ Monica: &quot;Yeah, I do know.&quot;
529
+ ...
530
+ Chandler: &quot;Don&#x27;t worry.&quot;
531
+ Phoebe: &quot;God, I hope they kick his ass!&quot;</td></tr><tr><td>[Predict]</td><td>Please select the emotional label of &lt;Phoebe: &quot;God, I hope they kick his ass!&quot;&gt;from &lt;Joyful, Mad, Peaceful, Neutral, Sad, Powerful, Scared&gt;.</td></tr><tr><td>[Target]</td><td>Powerful</td></tr></table>
532
+
533
+ <table><tr><td></td><td>Prompt for Speaker Recognition Task</td></tr><tr><td>[System]</td><td>You are now an expert in Conversational Emotion Recognition. Your task is to predict the speaker by analyzing sentences. Here's a list of individuals and their [Speaker_Persona], which will assist you in understanding them better</td></tr><tr><td>[Speaker_Persona]</td><td>Chandler: Known for his wit and sarcasm, works in advertising, group's humorist with logical insights.
534
+ Ross: A paleontologist and professor, adds intellectual depth through family ties with Monica and past relationship with Rachel.
535
+ Joey: An aspiring actor, the group's innocent and charming member, deepening bond with Chandler through loyalty and simplicity.
536
+ Phoebe: A masseuse and musician, introduces eccentricity and unique wisdom, offering empathy to the group.
537
+ Monica: A chef, known for organization, group's anchor with hospitality, directly linking to Ross as his sister.
538
+ Rachel: Progresses from a waitress to fashion, influencing group dynamics, especially her evolving relationship with Ross.</td></tr><tr><td>[Predict]</td><td>Please select the Speaker of "&lt;God, I hope they kick his ass!&gt;", Emotion: Powerful &gt;from &lt;Chandler, Ross, Joey, Phoebe, Monica, Rachel&gt;.</td></tr><tr><td>[Target]</td><td>Phoebe</td></tr><tr><td></td><td>Prompt for Role-play Task</td></tr><tr><td>[System]</td><td>You are now an expert role-play actor. Analyze the character's [Speaker_Persona], [Scene], and [Historydialogue] to predict their most likely next line.</td></tr><tr><td>[Speaker_Persona]</td><td>Monica: Known for organization, acts as the group's anchor, fostering cohesion with hospitality, linking to Ross as his sister.Rachel: Progresses from a waitress to a career in fashion, influencing group dynamics, especially her relationship with Ross.Ross: A paleontologist and professor, adds intellectual depth through family ties with Monica and past relationship with Rachel.Chandler: Known for wit and sarcasm, works in advertising, the group's humorist with logical insights.Phoebe: A masseuse and musician, introduces eccentricity and unique wisdom, offering empathy to the group.</td></tr><tr><td>[Scene]</td><td>Monica and Rachel's, The entire gang is there.</td></tr><tr><td>[History_Dialogue]</td><td>Monica: "So ah, Phoebe, how was your date?"Phoebe: "Oh well y'know."Monica: "Yeah, I do know."Chandler: "Don't worry."</td></tr><tr><td>[Predict]</td><td>You will stay in character whenever possible, and generate responses in &lt;Powerful&gt;emotion as if you were &lt;Phoebe&gt;.</td></tr><tr><td>[Target]</td><td>God, I hope they kick his ass!</td></tr></table>
539
+
540
+ <table><tr><td></td><td>Prompt for Reasoning Task (STEeR)</td></tr><tr><td>[System]</td><td>As an expert in Conversational Emotion Recognition (ERC), your task is to [Predict] the emotion by analyzing the [Speaker_Persona], [Scene] and [Historydialogue] information.</td></tr><tr><td>[Speaker_Persona]</td><td>Monica: Known for organization, acts as the group&#x27;s anchor, fostering cohesion with hospitality, linking to Ross as his sister.Rachel: Progresses from a waitress to a career in fashion, influencing group dynamics, especially her relationship with Ross.Ross: A paleontologist and professor, adds intellectual depth through family ties with Monica and past relationship with Rachel.Chandler: Known for wit and sarcasm, works in advertising, the group&#x27;s humorist with logical insights.Phoebe: A masseuse and musician, introduces eccentricity and unique wisdom, offering empathy to the group.</td></tr><tr><td>[Scene]</td><td>Monica and Rachel&#x27;s, The entire gang is there.</td></tr><tr><td>[History_Dialogue]</td><td>Monica: &quot;So ah, Phoebe, how was your date?&quot;Phoebe: &quot;Oh well y&#x27;know.&quot;Monica: &quot;Yeah, I do know.&quot;...Chandler: &quot;Don&#x27;t worry.&quot;</td></tr><tr><td>[Predict]</td><td>Please analyze the emotional state of &lt;Phoebe: &quot;God, I hope they kick his ass!&quot;&gt;by first providing your rationale based on the given context, then select the emotional label from &lt;Joyful, Mad, Peaceful, Neutral, Sad, Powerful, Scared&gt;.</td></tr><tr><td>[Target]</td><td>[Rationale]In the dialogue, Phoebe starts feeling vulnerable about her date but transitions to confidence after receiving support from her friends. Her assertive statement, indicating a desire for action and control, reflects an empowered emotional state. The emotional label of &lt;Phoebe: &quot;God, I hope they kick his ass!&quot;&gt;is &lt;Powerful&gt;.</td></tr></table>
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b44b1b6f4d132e1ea18f6dad679e4f4236983ebe05b296c9025f421ce2ef3947
3
+ size 762908
2025/CoE_ A Clue of Emotion Framework for Emotion Recognition in Conversations/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/63817457-5e2b-4907-88ff-c95a00015592_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad00d7bed00dba840d73fcad563cb01ad67290fa0b36300df0b9653b05d9982f
3
+ size 1480637
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/full.md ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ![](images/023942007ac4adb0b9f07ae6110ad6a69c5bd0113fffc1a3819942df4eb96e32.jpg)
2
+
3
+ # CoIR: A Comprehensive Benchmark for Code Information Retrieval Models
4
+
5
+ Xiangyang Li* Kuicai Dong* Yi Quan Lee* Wei Xia Hao Zhang† Xinyi Dai Yasheng Wang Ruiming Tang† HUWEI NOAH'S ARK LAB
6
+
7
+ {lixiangyang34, kuicai.dong, lee.yi.quan, xiawei24, zhang.hao3, daixinyi5, wangyasheng, tangruiming}@huawei.com
8
+
9
+ # Abstract
10
+
11
+ Despite the substantial success of Information Retrieval (IR) in various NLP tasks, most IR systems predominantly handle queries and corpora in natural language, neglecting the domain of code retrieval. Code retrieval is critically important yet remains under-explored, with existing methods and benchmarks inadequately representing the diversity of code in various domains and tasks. Moreover, many models have begun to overfit existing leaderboards, limiting their generalizability and real-world applicability. Addressing this gap, we introduce CoIR (Code Information Retrieval Benchmark), a robust and comprehensive benchmark specifically designed to evaluate code retrieval capabilities. CoIR consists of ten meticulously curated code datasets, all of which have undergone thorough manual inspection and processing. These datasets cover eight distinct retrieval tasks across seven diverse domains, ensuring a broad and rigorous assessment of code retrieval performance. We first discuss the construction of CoIR and its diverse dataset composition. Further, we evaluate ten widely used retrieval models using CoIR, uncovering significant difficulties in performing code retrieval tasks even with state-of-the-art systems. To ensure seamless integration, CoIR is released as a user-friendly Python framework, aligned with the data schema of MTEB and BEIR for consistent cross-benchmark evaluation. Through CoIR, we aim to invigorate research in the code retrieval domain, providing a versatile benchmarking tool that encourages further development and exploration of code retrieval systems<sup>1</sup>.
12
+
13
+ # 1 Introduction
14
+
15
+ Information retrieval (IR) aims to retrieve relevant information from a large scale corpus. The
16
+
17
+ <table><tr><td>Benchmark</td><td>Domain</td><td>#PL</td><td>Retrieval Tasks</td><td>Eval Package</td></tr><tr><td>CoSQA</td><td>Web Query</td><td>1</td><td>Text-to-Code</td><td>×</td></tr><tr><td>CodeSearchNet</td><td>GitHub Functions</td><td>6</td><td>Text-to-Code</td><td>×</td></tr><tr><td>CodeRAG-Bench</td><td>Contest, Issue Fixing, StackOverflow, GitHub Functions</td><td>1</td><td>Text-to-Code Hybrid Code</td><td>×</td></tr><tr><td>XCodeEval</td><td>Contest</td><td>17</td><td>Text-to-Code Code-to-Code</td><td>×</td></tr><tr><td>CoIR (Ours)</td><td>GitHub Functions, Web Query, Database, Contest, Deep Learning, StackOverflow, Code Instruction</td><td>14</td><td>Text-to-Code Code-to-Code Code-to-Text Hybrid Code</td><td>✓</td></tr></table>
18
+
19
+ Table 1: Comparison between CoIR and other code retrieval benchmarks. #PL is the number of main programming languages used.
20
+
21
+ advances of pretrained Transformers (Vaswani et al., 2017) like BERT (Devlin et al., 2019) and RoBERTa (Liu et al., 2019) enable IR systems (Wang et al., 2022; Chen et al., 2024; Li et al., 2023b; Dong et al., 2025a) to leverage rich semantic embeddings to interpret and fulfill natural language search queries. Specifically, IR have successfully improve a wide range of Natural Language Processing (NLP) tasks such as Question Answering (QA) (Kolomiyets and Moens, 2011), Retrieval-Augmented Generation (RAG) (Liu et al., 2024; Dong et al., 2024, 2025b; Zhang et al., 2025; Jia et al., 2024), Information Extraction (Ziembinski, 2015; Sarhan, 2023), Text Summarization (Mahalakshmi and Fatima, 2022), Recommender System (Li et al., 2022, 2023a; Lin et al., 2025; Wang et al., 2024a) and etc. Although proven to be effective in text retrieval, standard IR methods often fall short in code retrieval (Husain et al., 2019).
22
+
23
+ Unlike standard text, code is semi-structured and inherently logical, consisting of syntactic rules and semantic information that require specific parsing and understanding. Such distinctive nature requires the system to adapt and interpret code
24
+
25
+ format accurately. Recognizing the importance of code data, pioneering works such as CodeBERT (Feng et al., 2020), CodeGPT (Lu et al., 2021) and UniXcoder (Guo et al., 2022) have conducted pre-training specifically on code corpora.
26
+
27
+ Code information retrieval is a critical component in accelerating development processes and improving code quality. Efficient code retrieval helps developers quickly find not only relevant code snippets, but also related information like code explanations, bug analyses, code summaries, and similar code instances. Commercial products have recently integrated tools for code retrieval, such as VS Code (Sole, 2019) and GitHub Code Search. Moreover, code-RAG systems (Zhang et al., 2023b,a; Choi et al., 2023; Su et al., 2024) have effectively leveraged on code retrieval to minimize hallucinations (i.e., errors in generated code) by Large Language Models (LLMs), thereby ensuring more accurate and reliable outputs.
28
+
29
+ Due to the importance of code retrieval, benchmarks (see Table 1) such as CodeSearchNet (Husain et al., 2019), CosQA (Huang et al., 2021), and XcodeEval (Khan et al., 2023), have been proposed to evaluate the code retrieval effectiveness. Despite these efforts, there remain three principal limitations: (1) Current benchmarks focus on a limited number of code retrieval tasks and have been extensively overfitted by many existing models. Commonly, these involve using a textual query to search for corresponding code snippets. However, the practical needs of code retrieval are far more diverse. In real-world scenarios, queries and retrieved corpus can involve both text and code. One might input a code snippet coupled with bug information, and seek detailed explanations, summaries, or even fixed code as output. Existing benchmarks do not adequately cater to such complex and varied query types, limiting the scope of their applicability and the robustness of the models tested. (2) there is a noticeable lack of diversity in data domains. For example, CodeSearchNet exclusively extracts code and code/comment pairs from GitHub, which represents a specific format of open-source projects. Similarly, XcodeEval focuses only on coding related to contest challenges, which may be overly specialized. Such narrow focus is not suitable for comprehensive evaluation in broader coding contexts. (3) there is no standard evaluation framework for code retrieval, which complicates the comparison and development of methods in this field. CodeSearchNet, CosQA, and XcodeEval em
30
+
31
+ ploy various types of evaluation metrics tailored to their specific tasks and formats leading to potential inconsistencies in measuring model performance across different benchmarks.
32
+
33
+ To address the limitations of existing code retrieval benchmarks, we introduce CoIR (Code Information Retrieval Benchmark), a more comprehensive and versatile benchmark. As summarized in Table 1, CoIR surpasses current benchmarks by offering broader domain coverage, more diverse retrieval tasks, and a standardized evaluation framework. It includes 10 datasets (8 existing and 2 newly-curated) and supports 4 primary retrieval tasks: (1) Text-to-Code, (2) Code-to-Code, (3) Code-to-Text, and (4) Hybrid Code Retrieval, with further breakdown into 8 sub-tasks. The datasets vary in size, ranging from 1K to 1M documents, with token counts ranging from 37 to 4.4K for queries and 113 to 1.5K for corpus.
34
+
35
+ We evaluated 10 popular retrieval models on CoIR, revealing that even state-of-the-art models perform suboptimally, highlighting the complexity of code retrieval. To simplify evaluation, we also provide a user-friendly Python framework that integrates seamlessly with BEIR and MTEB, allowing easy model evaluation via pip installation. Our key contributions are as follows:
36
+
37
+ - We present the first benchmark designed to comprehensively evaluate code retrieval. This benchmark, CoIR, integrates 10 datasets and addresses 4 key code retrieval tasks. To achieve this, we manually collected and curated existing datasets through a rigorous data cleaning and filtering process, while also creating two new datasets.
38
+ - Our evaluation of 10 popular retrieval systems reveals that even state-of-the-art models struggle in code retrieval. Through experimental analysis, we demonstrate that LLM-based retrieval models have the potential to pave the way for new directions in code and text retrieval. Additionally, our findings indicate that many existing models have already overfitted to current leaderboards, highlighting the necessity for more generalizable and robust retrieval approaches.
39
+ - We offer a robust community around CoIR, providing convenient evaluation tools, leaderboards, and other resources that facilitate the rapid advancement of code retrieval models.
40
+
41
+ ![](images/f76340f7581ea912ac87bbdd76e6cf90de29edc5ce17fdfe0720a9157b8e3255.jpg)
42
+ Figure 1: Overview of COIR benchmark.
43
+
44
+ ![](images/daefd7f0782cad013d2b68c1bfba45948c5659c87e2c270faf8ca07bfcacb0fa.jpg)
45
+
46
+ ![](images/22fc8a68dfe6252acd75d1210cc1c701d51e0b5ce516d8cb43996d996e0ae3d1.jpg)
47
+
48
+ # 2 Related Work
49
+
50
+ Existing Benchmarks. BEIR (Thakur et al., 2021) and MTEB (Muennighoff et al., 2023) have significantly advanced retrieval and embedding models across diverse text-based tasks but lack dedicated evaluations for code retrieval. Existing code benchmarks, such as CodeSearchNet (Husain et al., 2019), CosQA (Huang et al., 2021), and XcodeEval (Khan et al., 2023), suffer from limitations in task diversity, domain coverage, and evaluation consistency. Notably, CodeSearchNet has been extensively used, leading to overfitting in many models. In contrast, CoIR introduces a broader range of code retrieval tasks and a unified evaluation framework for standardized benchmarking.
51
+
52
+ Retrieval Models. Dense retrievers, which encode text into high-dimensional representations, are central to information retrieval (IR). Key methods include DPR (Karpukhin et al., 2020), Contriever (Izacard et al., 2022), E5 (Wang et al., 2022), GTE (Li et al., 2023b), BGE (Xiao et al., 2023), and BGE-M3 (Bai et al., 2024), with recent advances leveraging LLMs, such as E5-Mistral (Wang et al., 2024b) and OpenAI-Ada-002.
53
+
54
+ However, most research focuses on QA datasets like MS-Marco (Nguyen et al., 2016), with limited work on code retrieval. While models like CodeBERT (Feng et al., 2020), Voyage-Code-002, and UniXCoder (Guo et al., 2022) exploit programming language structures, neural retrieval for code remains underexplored. By providing benchmarks for code retrieval, we aim to stimulate innovation and advance state-of-the-art techniques in this area.
55
+
56
+ # 3 The CoIR Benchmark
57
+
58
+ # 3.1 Desiderata
59
+
60
+ CoIR provides a one-stop zero-shot evaluation benchmark for diverse code retrieval tasks, ensuring comprehensive assessment through well-curated tasks and datasets. To streamline evaluation, CoIR includes a one-click, end-to-end pipeline with three key features:
61
+
62
+ (1) Diversity: CoIR assesses models across 4 primary tasks, 8 sub-tasks, 10 datasets, and 14 programming languages (Figure 1). (2) Usability: Unlike traditional evaluations that require manual coding and result collection, CoIR offers an automated pipeline for both open-source and proprietary models, supporting metrics such as nDCG, precision, recall, and MAP. Results are stored in JSON format for easy access. (3) Overfitting Mitigation: Many models overfit to benchmarks like CodeSearchNet, leading to inflated performance with limited generalization. CoIR alleviates this by incorporating diverse tasks and datasets, offering a more reliable evaluation. Dataset statistics are in Table 2, with preparation details in B.1.
63
+
64
+ # 3.2 Overview of CoIR Tasks
65
+
66
+ In this section, we present an overview of each task in CoIR. For each task-specific dataset, we manually inspect and filter out instances that lack valid answers, exhibit ambiguity, contain irrelevant information, etc. The rationale for selecting each dataset, along with the detailed manual filtering process, is provided in Appendix B.1.
67
+
68
+ <table><tr><td>Main Task</td><td>Sub Task</td><td>Domain</td><td>Dataset</td><td>Language</td><td>#Query (train/dev/test)</td><td>#Corpus</td><td>LQuery</td><td>LCorpus</td></tr><tr><td rowspan="3">Text-to-Code Retrieval</td><td>Code Contest Retrieval</td><td>Code Contest</td><td>APPS</td><td>py</td><td>5k/-/3.8K</td><td>9K</td><td>1.4K</td><td>575</td></tr><tr><td>Web Query to Code Retrieval</td><td>Web query</td><td>CosQA</td><td>py</td><td>19k/-/500</td><td>21K</td><td>37</td><td>276</td></tr><tr><td>Text to SQL Retrieval</td><td>Database</td><td>Synthetic Text2SQL</td><td>sql</td><td>100k/-/6K</td><td>106K</td><td>83</td><td>127</td></tr><tr><td rowspan="2">Code-to-Text Retrieval</td><td rowspan="2">Code Summary Retrieval</td><td rowspan="2">Github Fuctions</td><td rowspan="2">CodeSearchNet</td><td>go, java, js</td><td rowspan="2">905k/41k/53K</td><td rowspan="2">1M</td><td rowspan="2">594</td><td rowspan="2">156</td></tr><tr><td>php, py, ruby</td></tr><tr><td rowspan="4">Code-to-Code Retrieval</td><td rowspan="2">Code Context Retrieval</td><td rowspan="2">Github Fuctions</td><td rowspan="2">CodeSearchNet -CCR†</td><td>go, java, js</td><td rowspan="2">905k/41k/53K</td><td rowspan="2">1M</td><td rowspan="2">154</td><td rowspan="2">113</td></tr><tr><td>php, py, ruby</td></tr><tr><td rowspan="2">Similar Code Retrieval</td><td>Deep Learning</td><td>CodeTrans Ocean-DL</td><td>py</td><td>564/72/180</td><td>816</td><td>1.6K</td><td>1.5K</td></tr><tr><td>Contest</td><td>CodeTrans Ocean-Contest</td><td>c++, py</td><td>561/226/446</td><td>1K</td><td>770</td><td>1.5K</td></tr><tr><td rowspan="4">Hybrid Code Retrieval</td><td rowspan="3">Single-turn Code QA</td><td>Stack Overflow</td><td>StackOverflow QA†</td><td>miscellaneous</td><td>13k/3k/2K</td><td>20K</td><td>1.4K</td><td>1.2K</td></tr><tr><td rowspan="2">Code Instruction</td><td rowspan="2">CodeFeedback -ST</td><td>html, c, css, sql</td><td rowspan="2">125k/-/31K</td><td rowspan="2">156K</td><td rowspan="2">722</td><td rowspan="2">1.5K</td></tr><tr><td>js, sql, py, shell ruby, rust, swift</td></tr><tr><td>Multi-turn Code QA</td><td>Code Instruction</td><td>CodeFeedback -MT</td><td>miscellaneous</td><td>53k/-/13K</td><td>66K</td><td>4.4K</td><td>1.5K</td></tr></table>
69
+
70
+ Table 2: Statistics of datasets in CoIR benchmark. # is the quantity of query/corpus instances. $L_{(\cdot)}$ refers to the average numbers of words per query/ corpus. Datasets marked by $^{\dagger}$ are created by us.
71
+
72
+ # 3.2.1 Main Task I: Text-to-Code Retrieval
73
+
74
+ Code Contest Retrieval. Code contest retrieval involves retrieving relevant code solutions for coding problems described in natural language, a challenging task due to the complexity of language and code, as well as the gap between human and machine languages. For this, we use the APPS dataset (Hendrycks et al., 2021), a diverse collection of problems from platforms like Codewars, AtCoder, Kattis, and Codeforces.
75
+
76
+ Web Query Code Retrieval. Web query code retrieval focuses on retrieving relevant code snippets based on concise web queries, typically just a few words. For this task, we use the CosQA (Huang et al., 2021) dataset, containing 20.6k labeled pairs of textual queries and Python functions.
77
+
78
+ Text-to-SQL Retrieval. Text-to-SQL is a key task in code generation, requiring models to generate SQL queries from natural language questions. We use the Synthetic Text-to-SQL dataset (Meyer et al., 2024), the largest and most diverse synthetic dataset, with around 106k examples.
79
+
80
+ # 3.2.2 Main Task II: Code-to-Text Retrieval
81
+
82
+ Code Summary Retrieval. Code summary retrieval evaluates a model's ability to use code to
83
+
84
+ retrieve code summaries or annotations. For this task, we employ the CodeSearchNet dataset (Husain et al., 2019), which consists of numerous code functions accompanied by code comments. This dataset spans six programming languages and includes over one million documents, providing a rich source of information for evaluating model performance.
85
+
86
+ 3.2.3 Main Task III: Code-to-Code Retrieval Code Context Retrieval. Code context retrieval is the task of retrieving the most relevant code segment that completes a given initial segment of code. This task is critical for code completion purposes. Here we modify the original CodeSearchNet dataset (Husain et al., 2019) to better suit our needs. Specifically, for each code snippet or function in CodeSearchNet, we randomly divide the code into two segments: (1) the initial segment serves as our query, and (2) the remaining segment forms the target corpus to be retrieved for this query. The length of each query is uniformly and randomly selected to comprise between $40\%$ and $70\%$ of the total number of characters in the original code.
87
+
88
+ Similar Code Retrieval. In the task of similar code retrieval, the primary objective is to assess a model's ability to retrieve similar code snippets.
89
+
90
+ Specifically, given a code snippet in one programming language or deep learning framework, the model needs to retrieve semantically equivalent code in a different language or framework. We utilize the CodeTransOcean dataset (Yan et al., 2023) for this purpose, creating two sub-datasets for similar code retrieval. These sub-datasets are named "CodeTransOcean-DL" and "CodeTransOcean-Contest", with the suffix indicating their respective domains. The "CodeTransOcean-DL" subset contains code written in different deep learning frameworks within the same programming language, such as TensorFlow and Paddlepaddle. Whereas the "CodeTransOcean-Contest" subset includes code written in different programming languages, such as Python and C++, for the same coding contest or competitive programming problem.
91
+
92
+ # 3.2.4 Main Task IV: Hybrid Code Retrieval
93
+
94
+ # Single-turn Code Question Answer Retrieval.
95
+
96
+ In single-turn code question-answering (QA), a retrieval model is required to find the corresponding answer for a given natural language question. Both the question and the answer typically consist of a mix of text and code snippets. For this task, we use two code QA datasets: StackOverflow QA $^2$ and CodeFeedQA (Zheng et al., 2024). The StackOverflow QA is derived from the original StackOverflow dataset by pairing questions with their highest upvoted answers, resulting in 19,931 pairs. Additionally, we sampled 1,202 query instances to validate the retrieval model's performance. The CodeFeedQA is a synthesized code instruction dataset generated by LLMs. From this dataset, we sampled $20\%$ of the queries to assess the model's performance.
97
+
98
+ Multi-turn Code Question Answer. In multi-turn code question-answer retrieval, the retrieval model must effectively utilize the context from multiple dialogue turns to accurately retrieve the answer for the subsequent turn. This task is challenging due to the extensive dialogue context, which can exceed 4,000 tokens, whereas most current retrieval models are limited to a context length of 512 tokens. Specifically, we employ the CodeFeedback multi-turn question-answer dataset, with dialogues generated by LLMs. Our test set comprises a total of 13,227 queries and 66,383 corpus.
99
+
100
+ # 3.3 Dataset and Diversity Analysis
101
+
102
+ In addition to the multitude of tasks, the datasets in CoIR also encompass a broad array of programming languages, such as Python, Java, and SQL, each featuring unique attributes. The distribution of these programming languages is long-tailed, as depicted in the bar graph in Figure 2. Despite this, the datasets maintain diversity, originating from varied sources including code contest websites, GitHub repositories, StackOverflow responses, etc. To quantify the diversity of CoIR, we calculated the weighted Jaccard similarity scores on unigram word overlap across all dataset pairs, displayed in a heatmap in Figure 2 (see Appendix C.2 for calculation details). The heatmap reveals generally low Jaccard similarity scores among dataset pairs, with notable exceptions being CodeFeedback Single-Turn (CodeFeedback-ST) and CodeFeedback Multi-Turn (CodeFeedback-MT), which are derived from the same domain. This signifies the challenge of CoIR as a benchmark. For optimal performance, a method must not only excel in major programming languages but also exhibit robust generalization ability across various domains.
103
+
104
+ # 3.4 CoIR Evaluation Software
105
+
106
+ To advance the evaluation of code retrieval capabilities, we introduce a streamlined, user-friendly Python framework for the CoIR benchmark evaluation. This framework is installable via pip using the command pip install and features a straightforward script that evaluates model performance across multiple datasets, outputting results in JSON format. Meanwhile, CoIR is compatible with several popular open-source frameworks, including HuggingFace and Sentence-Transformers, as well as API-based models such as OpenAI-Ada-002 and Voyage-Code-002. In line with BEIR and MTEB, all datasets have been standardized into a uniform format, facilitating the use of MTEB and BEIR frameworks for evaluating CoIR.
107
+
108
+ # 4 Experiment Setup
109
+
110
+ In this section, we evaluate and analyze the performance of the current state-of-the-art retrieval models on the eight subtasks of the CoIR benchmark. More details can be found in Appendix D.
111
+
112
+ Benchmarked Models. To comprehensively evaluate the capabilities of various state-of-the-art retrieval models for code retrieval tasks, we select 10 different retrieval models. For sparse retrieval, we utilized BM25 (Robertson et al.,
113
+
114
+ ![](images/54c2687114a40bc01bf99c1d74216dd3aa11215f23be894530e3c4863b2cc627.jpg)
115
+ Figure 2: Jaccard similarity and Programming Language Distributions of CoIR.
116
+
117
+ ![](images/6a0438316d15b48292f228a878e2ccfb687ca9c786b7c4d94fb0f0559a01614c.jpg)
118
+
119
+ 1994). For open-source dense models, we included E5-Base (Wang et al., 2022), GTE-Base (Li et al., 2023b), BGE-Base (Xiao et al., 2023), Contriever (Izacard et al., 2022), E5-Mistral (Wang et al., 2024b), BGE-M3 (Chen et al., 2024), and UniXcoder (Guo et al., 2022). For proprietary models, we included OpenAI-Ada-002 $^{3}$ and VoyageCode-002 $^{4}$ . Notably, both UniXcoder and VoyageCode-002 have been pre-trained on code data, making them robust baselines for comparison.
120
+
121
+ Implementation Details. For all open-source dense retrieval models, we set the input length of both queries and the corpus to 512. For proprietary models such as Voyage-Code-002, due to the constraint of tokens per minute (TPM), we set the length of the queries to 256 and the corpus to 512. Following previous work (Wang et al., 2024b), we utilize (i) last token pooling for E5-Mistral, and (ii) mean pooling for other models, to obtain semantic vector representations. Cosine similarity is employed to calculate the similarity between the query and corpus for ranking. Following BEIR (Thakur et al., 2021), we use NDCG@10 to evaluate the performance of retrieval models. For comprehensive evaluation, our scripts also provide metrics such as MAP, Recall, and Precision.
122
+
123
+ # 5 Results and Analysis
124
+
125
+ # 5.1 Main Results
126
+
127
+ Table 3 showcases the performance of existing embedding models on the CoIR benchmark. From the table, several conclusions can be drawn:
128
+
129
+ No Single Model Dominates Across All Tasks. Despite Voyage-Code-002 achieving the highest mean score of 56.26 on the benchmark, it does not universally surpass other models in every task. Models like E5-base and E5-Mistral exhibit superior performance in specific retrieval sub-tasks. This highlights the CoIR benchmark's complexity and suggests that different models excel in different facets, catering to varied task requirements.
130
+
131
+ Demonstration of Benchmark Diversity and Challenge. Models achieving top performance in mainstream text retrieval benchmarks, such as E5-Mistral, do not consistently excel across CoIR sub-tasks. For example, E5-Mistral scores highly in CodeTrans-Contest and StackOverflow QA but shows only median performance in APPS and CosQA for Text-to-Code tasks, and falls behind E5-base in CodeFeedBack-MT. This variation underscores the CoIR benchmark's challenge and the need for adaptive, robust code retrieval capabilities.
132
+
133
+ Effectiveness of Code-Specific Optimization. Models specialized for code retrieval, like VoyageCode-002, achieve strong results on CoIR, highlighting the impact of tailored optimization. Voyage-Code-002 excels in both Text-to-Code and Code-to-Text tasks, demonstrating the benefits of domain-specific training.
134
+
135
+ Figure 3 presents box plots for each model. Voyage-Code-002 achieves the highest average performance but with high variance, suggesting weaker generalization. In contrast, BGE-M3 shows better robustness with the lowest variance despite its moderate performance. This highlights the CoIR dataset's challenge and its value as a benchmark for code retrieval research.
136
+
137
+ <table><tr><td>Task (→)</td><td colspan="3">Text-to-Code</td><td>Code-to-Text</td><td colspan="3">Code-to-Code</td><td colspan="3">Hybrid Code</td><td rowspan="2">Avg</td></tr><tr><td>Model (param.) ↓</td><td>Apps</td><td>CosQA</td><td>Synthetic Text2sql</td><td>Code SearchNet</td><td>Code SN-CCR</td><td>CodeTrans -Contest</td><td>-DL</td><td>StackOver Flow QA</td><td>CodeFeedback -ST</td><td>-MT</td></tr><tr><td>BM25</td><td>0.95</td><td>13.96</td><td>16.92</td><td>26.75</td><td>34.69</td><td>50.13</td><td>8.69</td><td>56.80</td><td>54.32</td><td>34.73</td><td>29.79</td></tr><tr><td>Contriever (110M)</td><td>5.14</td><td>14.21</td><td>45.46</td><td>34.72</td><td>35.74</td><td>44.16</td><td>24.21</td><td>66.05</td><td>55.11</td><td>39.23</td><td>36.40</td></tr><tr><td>E5-base (110M)</td><td>11.52</td><td>32.59</td><td>52.31</td><td>67.99</td><td>56.87</td><td>62.50</td><td>21.87</td><td>86.86</td><td>74.52</td><td>41.99</td><td>50.90</td></tr><tr><td>BGE-Base (110M)</td><td>4.05</td><td>32.76</td><td>45.59</td><td>69.60</td><td>45.56</td><td>38.50</td><td>21.71</td><td>73.55</td><td>64.99</td><td>31.42</td><td>42.77</td></tr><tr><td>GTE-Base (110M)</td><td>3.24</td><td>30.24</td><td>46.19</td><td>43.35</td><td>35.50</td><td>33.81</td><td>28.80</td><td>62.71</td><td>55.19</td><td>28.48</td><td>36.75</td></tr><tr><td>UniXcoder (123M)</td><td>1.36</td><td>25.14</td><td>50.45</td><td>60.20</td><td>58.36</td><td>41.82</td><td>31.03</td><td>44.67</td><td>36.02</td><td>24.21</td><td>37.33</td></tr><tr><td>BGE-M3 (567M)</td><td>7.37</td><td>22.73</td><td>48.76</td><td>43.23</td><td>47.55</td><td>47.86</td><td>31.16</td><td>61.04</td><td>49.94</td><td>33.46</td><td>39.31</td></tr><tr><td>E5-Mistral (7B)</td><td>21.33</td><td>31.27</td><td>65.98</td><td>54.25</td><td>65.27</td><td>82.55</td><td>33.24</td><td>91.54</td><td>72.71</td><td>33.65</td><td>55.18</td></tr><tr><td>OpenAI-Ada-002</td><td>8.70</td><td>28.88</td><td>58.32</td><td>74.21</td><td>69.13</td><td>53.34</td><td>26.04</td><td>72.40</td><td>47.12</td><td>17.74</td><td>45.59</td></tr><tr><td>Voyage-Code-002</td><td>26.52</td><td>29.79</td><td>69.26</td><td>81.79</td><td>73.45</td><td>72.77</td><td>27.28</td><td>87.68</td><td>65.35</td><td>28.74</td><td>56.26</td></tr></table>
138
+
139
+ ![](images/347f3ee2fa48366c9492e69034624c572022212d5588616419f478a2ecd7b458.jpg)
140
+ Figure 3: The box plots of all model performances on CoIR benchmark.
141
+
142
+ # 5.2 Analysis of Retrieval Efficiency
143
+
144
+ In practical industrial settings, efficiency is also a critical factor for evaluating retrieval model. Factors such as embedding latency for query/corpus, retrieval latency from all embeddings, and the physical memory footprint of the index are critical. In this section, we analyze the efficiency of the current retrieval model using a portion of the CoIR dataset, designated as CodeFeedBack-ST, which comprises 156k corpus and 31k queries. For embedding latency, we record the time taken by each model to process a batch of data. This time was then divided by the number of samples in the batch to derive the average embedding time per sample. For retrieval latency, we measure the averaged retrieval time of all queries, where each query is tasked with retrieving 1,000 documents. The latency results are presented in Table 4.
145
+
146
+ Trade-off between Accuracy and Latency. High-performing models like E5-Mistral with excellent accuracy, suffer from noticeable embedding latency. Specifically, E5-Mistral's average embedding latency is 1840ms per sample, significantly higher than other evaluated models. This discrepancy highlights the common trade-off in retrieval
147
+
148
+ Table 3: NDCG@10 score of various retrievers on CoIR. The best score is marked in boldface.
149
+
150
+ <table><tr><td colspan="3">CodeFeedBack-ST
151
+ 156k corpus &amp; 31k queries</td><td>Embed
152
+ Latency</td><td>Retrieval
153
+ Latency</td><td>Index</td></tr><tr><td>Rank</td><td>Model</td><td>Dim.</td><td>GPU</td><td>GPU</td><td>Size</td></tr><tr><td>9</td><td>Contriever</td><td>768</td><td>7.8ms</td><td>38.1μs</td><td>0.3G</td></tr><tr><td>3</td><td>E5-Base</td><td>768</td><td>7.4ms</td><td>38.1μs</td><td>0.3G</td></tr><tr><td>5</td><td>BGE-Base</td><td>768</td><td>7.6ms</td><td>38.1μs</td><td>0.3G</td></tr><tr><td>8</td><td>GTE-Base</td><td>768</td><td>7.8ms</td><td>38.1μs</td><td>0.3G</td></tr><tr><td>7</td><td>UniXcoder</td><td>768</td><td>7.7ms</td><td>38.1μs</td><td>0.3G</td></tr><tr><td>6</td><td>BGE-M3</td><td>1024</td><td>31.4ms</td><td>42.9μs</td><td>0.6G</td></tr><tr><td>2</td><td>E5-Mistral</td><td>4096</td><td>1840ms</td><td>115.5μs</td><td>2.3G</td></tr><tr><td>4</td><td>OpenAI-Ada-002</td><td>1536</td><td>-</td><td>56.8μs</td><td>0.9G</td></tr><tr><td>1</td><td>Voyage-Code-002</td><td>1536</td><td>-</td><td>56.8μs</td><td>0.9G</td></tr></table>
154
+
155
+ Table 4: The average embedding/retrieval latency per instance using CodeFeedBack-ST. We retain models that have rankings in both BEIR and CoIR.
156
+
157
+ systems: higher accuracy often comes at the expense of increased latency.
158
+
159
+ Index Size Considerations. Index sizes vary significantly across different models. Simpler models such as Contriever, E5-Base, BGE-Base, GTE-Base, and UniXcoder have relatively small index sizes, around 0.3GB. In contrast, more complex models like E5-Mistral, OpenAI-Ada-002, and Voyage-Code-002 have larger index sizes ranging from 0.6GB up to 2.3GB. This suggests a trade-off between accuracy and memory demands. Advanced models with better performance is at the cost of more memory, which could be a limitation in resource-constrained environments.
160
+
161
+ # 5.3 Input Length Impact on Code Retrieval
162
+
163
+ This section examines how input length affects the performance of code retrieval tasks. We analyze results using four datasets: CodeFeedback-MT, CodeTransOcean-DL, APPS, and StackOverflow QA. Each dataset has an average query and corpus length that exceeds 1,000 words. We utilize two
164
+
165
+ models, GTE and BGE-M3, both of which have been optimized for long documents and support context length of 8k tokens. We experiment on two settings, with input length capped at 512 and 4,096 respectively. Note that tokens beyond the cap will be truncated. We report the results in Table 5.
166
+
167
+ <table><tr><td>Model (input #tokens)</td><td>Code FB-MT</td><td>Code TO-DL</td><td>APPS</td><td>Stack OF-QA</td></tr><tr><td>GTE (512)</td><td>28.48</td><td>28.80</td><td>3.24</td><td>62.71</td></tr><tr><td>GTE (4k)</td><td>51.32</td><td>27.33</td><td>5.08</td><td>78.63</td></tr><tr><td>BGE-M3 (512)</td><td>33.46</td><td>31.16</td><td>7.37</td><td>61.04</td></tr><tr><td>BGE-M3 (4k)</td><td>27.49</td><td>32.75</td><td>6.80</td><td>56.53</td></tr></table>
168
+
169
+ Impact of Input Length on Model Performance. For GTE model, extending the input length from 512 to 4,096 shows notable improvements in retrieval performance across most datasets. Specifically, retrieval scores in CodeFeedback-MT and StackOverflow QA increase significantly from 38.20 to 51.32, and from 64.36 to 78.63, respectively. In contrast, the BGE-M3 model shows inconsistent results. CodeTransOcean-DL shows a slight improvement in scores from 31.16 to 32.75, whereas scores for CodeFeedback-MT fall from 33.46 to 27.49. One possible reason can be that: although BGE-M3 has been optimized for long documents, the significant differences between code data and text data result in a performance degradation as the document length increases.
170
+
171
+ # 5.4 Comparison of CoIR and BEIR Rankings
172
+
173
+ Table 5: Effects of different input length.
174
+
175
+ <table><tr><td rowspan="2">Model</td><td colspan="2">Rank</td></tr><tr><td>CoIR</td><td>BEIR</td></tr><tr><td>Contriever</td><td>7</td><td>7</td></tr><tr><td>GTE-Base</td><td>6</td><td>2</td></tr><tr><td>BGE-M3</td><td>5</td><td>6</td></tr><tr><td>BGE-Base</td><td>4</td><td>3</td></tr><tr><td>OpenAI-Ada-002</td><td>3</td><td>5</td></tr><tr><td>E5-Base</td><td>2</td><td>4</td></tr><tr><td>E5-Mistral</td><td>1</td><td>1</td></tr></table>
176
+
177
+ Table 6: Retriever rankings in CoIR and BEIR.
178
+
179
+ This section evaluates seven retrieval models across CoIR and BEIR, adjusting rankings for consistency while excluding voyage-code-002 and UniXcoder due to their code-specific pretraining. We analyze key ranking shifts and patterns.
180
+
181
+ Key Insights. E5-Mistral consistently ranks first in both benchmarks, demonstrating robust performance in text and code retrieval. However, GTE
182
+
183
+ Base drops from $2^{\mathrm{nd}}$ in BEIR to $6^{\mathrm{th}}$ in CoIR, indicating that strong text retrieval does not ensure effective code retrieval. Conversely, E5-Base ranks higher in CoIR than in BEIR, suggesting better adaptation to code-related tasks.
184
+
185
+ These results underscore the necessity of specialized benchmarks like CoIR. While some models maintain stable rankings, others exhibit notable shifts, highlighting distinct challenges of code retrieval that general text benchmarks may overlook.
186
+
187
+ # 5.5 Overfitting in CodeSearchNet and How CoIR Helps
188
+
189
+ ![](images/939bc1902c8a80969ebf7ed664b2c7315522be601b3873b3a160fa0f515e57ff.jpg)
190
+ Figure 4: Overfitting in CodeSearchNet: Evidence from Score Differences. The values in the bar chart represent the scores of CodeSearchNet minus the scores of CoIR.
191
+
192
+ Figure 4 compares the performance of CodeSearchNet and CoIR across various retrieval models. Most models score significantly higher on CodeSearchNet, indicating a strong overfitting tendency. Notably, OpenAI-Ada-002 and VoyageCode-002 show large performance gaps, suggesting these models may have already overfitted to CodeSearchNet.
193
+
194
+ In contrast, CoIR provides a more balanced evaluation, mitigating overfitting. Among all models, E5-Mistral (7B) achieves the smallest performance gap while maintaining strong scores on both benchmarks, demonstrating that LLM-based retrieval models can effectively reduce overfitting. These results highlight CoIR's role in ensuring a more robust and generalizable benchmark.
195
+
196
+ # 6 Conclusion
197
+
198
+ In this paper, we introduce CoIR, a comprehensive benchmark for code retrieval. CoIR encompasses 4 distinct and 8 fine-grained retrieval tasks, supports 14 programming languages, and integrates 10 diverse datasets with over 2 million code snippets. Furthermore, we evaluate the performance of 10 retrieval models on CoIR, revealing that even state-of-the-art models struggle, underscoring its chal
199
+
200
+ lenging nature. Additionally, our analysis suggests that many existing models have overfitted to current leaderboards, highlighting the need for more generalizable and robust retrieval approaches. Moreover, we emphasize the promise of LLM-based retrieval models as a potential direction for future advancements. With CoIR, we aim to foster progress in code retrieval, encouraging researchers to develop more effective and resilient models to benefit the community.
201
+
202
+ # 7 Limitations
203
+
204
+ Even though we cover a wide range of tasks and domains in CoIR, no benchmark is perfect and each set of benchmark has its own limitations. It is crucial to make the limitations explicit in order to better interpret (1) retrieval results on these benchmark datasets and (2) to curate a better benchmark in the future that complements existing benchmarks in the field.
205
+
206
+ 1. Multilingual Tasks: Although we aim for a diverse retrieval evaluation benchmark, due to the limited availability of multilingual retrieval datasets for code information retrieval, all datasets covered in the CoIR benchmark are currently English. Future work could include multi- and cross-lingual tasks and models.
207
+ 2. Multi-faceted Search: Due to the existing paradigm that heavily emphasizes on semantic-based information retrieval, our benchmark mainly focuses on queries that aim to benchmark retrieval performance solely based on textual information. However, real-world information needs is often complex and could possibly rely on various corpus meta-data, especially so in code datasets where meta-data could play a huge role. For instance, the versioning of programming language or software libraries could make a huge difference to whether a functioning code snippet is retrieved. In essence incorporating queries that are multi-faceted can more accurately reflect real-world informational needs.
208
+ 3. $n$ -ary Match: With each query corresponding to exactly one ground-truth corpus, we dismiss the real-world informational needs where (1) a single query is could be relevant to multiple corpora and (2) the informational needs of a single query can only be satisfied by multiple corpora simultaneously.
209
+
210
+ Dedicated a particular section of CoIR for $n$ -nary / list-wise labels for each query would allow us to address how model perform on informational needs that are diverse and further enhance the diversity of tasks of the benchmark.
211
+
212
+ # 8 Ethical Considerations
213
+
214
+ We ensure that the distribution of each dataset complies with the corresponding licenses, all of which are listed below:
215
+
216
+ - APPS: Provided under "MIT License" for non-commercial research purposes.
217
+ - CodeTransOcean: Provided under Apache License 2.0 license.
218
+ CodeSearchNet: Provided under "MIT License" for non-commercial research purposes.
219
+ - CoSQA: Provided under "MIT License" for non-commercial research purposes.
220
+ - Synthetic Text2sql: Provided under Apache License 2.0 license.
221
+ - Code-Feedback: Provided under Apache License 2.0 license.
222
+ - CodeFeedback-Filtered-Instruction: Provided under Apache License 2.0 license.
223
+ - Stackoverflow QA: Provided under CC-BY-SA 3.0 license.
224
+
225
+ # References
226
+
227
+ Yang Bai, Anthony M. Colas, Christian Grant, and Daisy Zhe Wang. 2024. M3: A multi-task mixed-objective learning framework for open-domain multi-hop dense sentence retrieval. In Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation, LREC/COLING 2024, 20-25 May, 2024, Torino, Italy, pages 10846-10857. ELRA and ICCL.
228
+ Jianlv Chen, Shitao Xiao, Peitian Zhang, Kun Luo, Defu Lian, and Zheng Liu. 2024. BGE m3-embedding: Multi-lingual, multi-functionality, multi-granularity text embeddings through self-knowledge distillation. CoRR, abs/2402.03216.
229
+ YunSeok Choi, CheolWon Na, Hyojun Kim, and JeeHyong Lee. 2023. READSUM: retrieval-augmented adaptive transformer for source code summarization. IEEE Access, 11:51155-51165.
230
+ Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4171-4186, Minneapolis, Minnesota. Association for Computational Linguistics.
231
+ Kuicai Dong, Yujing Chang, Xin Deik Goh, Dexun Li, Ruiming Tang, and Yong Liu. 2025a. Mmdocir: Benchmarking multi-modal retrieval for long documents. Preprint, arXiv:2501.08828.
232
+ Kuicai Dong, Yujing Chang, Shijie Huang, Yasheng Wang, Ruiming Tang, and Yong Liu. 2025b. Benchmarking retrieval-augmented multimodal generation for document question answering. Preprint, arXiv:2505.16470.
233
+ Kuicai Dong, Derrick Goh Xin Deik, Yi Lee, Hao Zhang, Xiangyang Li, Cong Zhang, and Yong Liu. 2024. Mc-indexing: Effective long document retrieval via multi-view content-aware indexing. In *Findings of the Association for Computational Linguistics: EMNLP* 2024, pages 2673-2691.
234
+ Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, and Ming Zhou. 2020. CodeBERT: A pre-trained model for programming and natural languages. In Findings of the Association for Computational Linguistics: EMNLP 2020, pages 1536-1547, Online. Association for Computational Linguistics.
235
+ Daya Guo, Shuai Lu, Nan Duan, Yanlin Wang, Ming Zhou, and Jian Yin. 2022. UniXcoder: Unified cross-modal pre-training for code representation. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 7212-7225, Dublin, Ireland. Association for Computational Linguistics.
236
+
237
+ Dan Hendrycks, Steven Basart, Saurav Kadavath, Mantas Mazeika, Akul Arora, Ethan Guo, Collin Burns, Samir Puranik, Horace He, Dawn Song, and Jacob Steinhardt. 2021. Measuring coding challenge competence with apps. In Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks, volume 1.
238
+ Junjie Huang, Duyu Tang, Linjun Shou, Ming Gong, Ke Xu, Daxin Jiang, Ming Zhou, and Nan Duan. 2021. CoSQA: 20,000+ web queries for code search and question answering. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 5690-5700, Online. Association for Computational Linguistics.
239
+ Hamel Husain, Ho-Hsiang Wu, Tiferet Gazit, Miltiadis Allamanis, and Marc Brockschmidt. 2019. Code-searchnet challenge: Evaluating the state of semantic code search. CoRR, abs/1909.09436.
240
+ Sergey Ioffe. 2010. Improved consistent sampling, weighted minhash and 11 sketching. In 2010 IEEE International Conference on Data Mining, pages 246-255.
241
+ Gautier Izacard, Mathilde Caron, Lucas Hosseini, Sebastian Riedel, Piotr Bojanowski, Armand Joulin, and Edouard Grave. 2022. Unsupervised dense information retrieval with contrastive learning. Trans. Mach. Learn. Res., 2022.
242
+ Pengyue Jia, Derong Xu, Xiaopeng Li, Zhaocheng Du, Xiangyang Li, Xiangyu Zhao, Yichao Wang, Yuhao Wang, Huifeng Guo, and Ruiming Tang. 2024. Bridging relevance and reasoning: Rationale distillation in retrieval-augmented generation. arXiv preprint arXiv:2412.08519.
243
+ Jeff Johnson, Matthijs Douze, and Herve Jégou. 2021. Billion-scale similarity search with gpus. IEEE Trans. Big Data, 7(3):535-547.
244
+ Vladimir Karpukhin, Barlas Oguz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, and Wen-tau Yih. 2020. Dense passage retrieval for open-domain question answering. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 6769-6781, Online. Association for Computational Linguistics.
245
+ Mohammad Abdullah Matin Khan, M. Saiful Bari, Xuan Long Do, Weishi Wang, Md. Rizwan Parvez, and Shafiq R. Joty. 2023. xcodeeval: A large scale multilingual multitask benchmark for code understanding, generation, translation and retrieval. CoRR, abs/2303.03004.
246
+ Oleksandr Kolomiyets and Marie-Francine Moens. 2011. A survey on question answering technology from an information retrieval perspective. Inf. Sci., 181(24):5412-5434.
247
+
248
+ Xiangyang Li, Bo Chen, HuiFeng Guo, Jingjie Li, Chenxu Zhu, Xiang Long, Sujian Li, Yichao Wang, Wei Guo, Longxia Mao, et al. 2022. Inttower: the next generation of two-tower model for pre-ranking system. In Proceedings of the 31st ACM International Conference on Information & Knowledge Management, pages 3292-3301.
249
+ Xiangyang Li, Bo Chen, Lu Hou, and Ruiming Tang. 2023a. Ctrl: Connect collaborative and language model for ctr prediction. ACM Transactions on Recommender Systems.
250
+ Zehan Li, Xin Zhang, Yanzhao Zhang, Dingkun Long, Pengjun Xie, and Meishan Zhang. 2023b. Towards general text embeddings with multi-stage contrastive learning. CoRR, abs/2308.03281.
251
+ Jianghao Lin, Xinyi Dai, Yunjia Xi, Weiwen Liu, Bo Chen, Hao Zhang, Yong Liu, Chuhan Wu, Xiangyang Li, Chenxu Zhu, et al. 2025. How can recommender systems benefit from large language models: A survey. ACM Transactions on Information Systems, 43(2):1-47.
252
+ Huanshuo Liu, Hao Zhang, Zhijiang Guo, Kuicai Dong, Xiangyang Li, Yi Quan Lee, Cong Zhang, and Yong Liu. 2024. Ctrl: Adaptive retrieval-augmented generation via probe-guided control. arXiv e-prints, pages arXiv-2405.
253
+ Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019. Roberta: A robustly optimized BERT pretraining approach. CoRR, abs/1907.11692.
254
+ Shuai Lu, Daya Guo, Shuo Ren, Junjie Huang, Alexey Svyatkovskiy, Ambrosio Blanco, Colin B. Clement, Dawn Drain, Daxin Jiang, Duyu Tang, Ge Li, Li-dong Zhou, Linjun Shou, Long Zhou, Michele Tufano, Ming Gong, Ming Zhou, Nan Duan, Neel Sundaresan, Shao Kun Deng, Shengyu Fu, and Shujie Liu. 2021. Codexglue: A machine learning benchmark dataset for code understanding and generation. In Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks 1, NeurIPS Datasets and Benchmarks 2021, December 2021, virtual.
255
+ P. Mahalakshmi and N. Sabiyath Fatima. 2022. Summarization of text and image captioning in information retrieval using deep learning techniques. IEEE Access, 10:18289-18297.
256
+ Yev Meyer, Marjan Emadi, Dhruv Nathawani, Lipika Ramaswamy, Kendrick Boyd, Maarten Van Segbroeck, Matthew Grossman, Piotr Mlocek, and Drew Newberry. 2024. Synthetic-Text-To-SQL: A synthetic dataset for training language models to generate sql queries from natural language prompts.
257
+ Niklas Muennighoff, Nouamane Tazi, Loic Magne, and Nils Reimers. 2023. MTEB: Massive text embedding benchmark. In Proceedings of the 17th Conference
258
+
259
+ of the European Chapter of the Association for Computational Linguistics, pages 2014-2037, Dubrovnik, Croatia. Association for Computational Linguistics.
260
+ Tri Nguyen, Mir Rosenberg, Xia Song, Jianfeng Gao, Saurabh Tiwary, Rangan Majumder, and Li Deng. 2016. MS MARCO: A human generated machine reading comprehension dataset. In Proceedings of the Workshop on Cognitive Computation: Integrating neural and symbolic approaches 2016 co-located with the 30th Annual Conference on Neural Information Processing Systems (NIPS 2016), Barcelona, Spain, December 9, 2016, volume 1773 of CEUR Workshop Proceedings. CEUR-WS.org.
261
+ Stephen E. Robertson, Steve Walker, Susan Jones, Micheline Hancock-Beaulieu, and Mike Gatford. 1994. Okapi at TREC-3. In Proceedings of The Third Text Retrieval Conference, TREC 1994, Gaithersburg, Maryland, USA, November 2-4, 1994, volume 500-225 of NIST Special Publication, pages 109-126. National Institute of Standards and Technology (NIST).
262
+ Ingy Sarhan. 2023. Open Information Extraction for Knowledge Representation: Triple Extraction and Information Retrieval From Unstructured Text. Ph.D. thesis, Utrecht University, Netherlands.
263
+ Alessandro Del Sole. 2019. Introducing visual studio code. Visual Studio Code.
264
+ Hongjin Su, Shuyang Jiang, Yuhang Lai, Haoyuan Wu, Boao Shi, Che Liu, Qian Liu, and Tao Yu. 2024. ARKS: active retrieval in knowledge soup for code generation. CoRR, abs/2402.12317.
265
+ Nandan Thakur, Nils Reimers, Andreas Rückle, Abhishek Srivastava, and Iryna Gurevych. 2021. BEIR: A heterogeneous benchmark for zero-shot evaluation of information retrieval models. In Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks 1, NeurIPS Datasets and Benchmarks 2021, December 2021, virtual.
266
+ Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems 30: Annual Conference on Neural Information Processing Systems 2017, December 4-9, 2017, Long Beach, CA, USA, pages 5998-6008.
267
+ Hangyu Wang, Jianghao Lin, Xiangyang Li, Bo Chen, Chenxu Zhu, Ruiming Tang, Weinan Zhang, and Yong Yu. 2024a. Flip: Fine-grained alignment between id-based models and pretrained language models for ctr prediction. In Proceedings of the 18th ACM Conference on Recommender Systems, pages 94-104.
268
+ Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, and Furu Wei. 2022. Text embeddings by weakly-supervised contrastive pre-training. CoRR, abs/2212.03533.
269
+
270
+ Liang Wang, Nan Yang, Xiaolong Huang, Linjun Yang, Rangan Majumder, and Furu Wei. 2024b. Improving text embeddings with large language models. CoRR, abs/2401.00368.
271
+
272
+ Shitao Xiao, Zheng Liu, Peitian Zhang, and Niklas Muennighof. 2023. C-pack: Packaged resources to advance general chinese embedding. CoRR, abs/2309.07597.
273
+
274
+ Weixiang Yan, Yuchen Tian, Yunzhe Li, Qian Chen, and Wen Wang. 2023. CodeTransOcean: A comprehensive multilingual benchmark for code translation. In *Findings of the Association for Computational Linguistics: EMNLP* 2023, pages 5067-5089, Singapore. Association for Computational Linguistics.
275
+
276
+ Fengji Zhang, Bei Chen, Yue Zhang, Jacky Keung, Jin Liu, Daoguang Zan, Yi Mao, Jian-Guang Lou, and Weizhu Chen. 2023a. RepoCoder: Repository-level code completion through iterative retrieval and generation. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 2471-2484, Singapore. Association for Computational Linguistics.
277
+
278
+ Wenlin Zhang, Xiangyang Li, Kuicai Dong, Yichao Wang, Pengyue Jia, Xiaopeng Li, Yingyi Zhang, Derong Xu, Zhaocheng Du, Huifeng Guo, et al. 2025. Process vs. outcome reward: Which is better for agentic rag reinforcement learning. arXiv preprint arXiv:2505.14069.
279
+
280
+ Xiangyu Zhang, Yu Zhou, Guang Yang, and Taolue Chen. 2023b. Syntax-aware retrieval augmented code generation. In Findings of the Association for Computational Linguistics: EMNLP 2023, pages 1291-1302, Singapore. Association for Computational Linguistics.
281
+
282
+ Tianyu Zheng, Ge Zhang, Tianhao Shen, Xueling Liu, Bill Yuchen Lin, Jie Fu, Wenhu Chen, and Xiang Yue. 2024. Opencode interpreter: Integrating code generation with execution and refinement. CoRR, abs/2402.14658.
283
+
284
+ Radoslaw Z. Ziembinski. 2015. Unsupervised extraction of graph-stream structure for purpose of knowledge retrieval and information fusion. In Position Papers of the 2015 Federated Conference on Computer Science and Information Systems, FedCSIS 2015, Łódź, Poland, September 13-16, 2015, volume 6 of Annals of Computer Science and Information Systems, pages 53-60.
285
+
286
+ # A Dataset Filtering and Cleaning Process
287
+
288
+ The dataset used for code retrieval tasks must be of high quality, diverse, and appropriately challenging to ensure the development of robust models. To this end, we implemented a multi-stage filtering and cleaning process that removes irrelevant, incomplete, or overly simplistic code snippets, ensuring the dataset is representative of real-world programming tasks.
289
+
290
+ # A.1 Difficulty
291
+
292
+ To ensure that each selected dataset presents an appropriate level of difficulty, we have curated a large collection of datasets. For datasets that are overly simplistic and fail to effectively differentiate between model capabilities, we have opted to discard them. The performance of models on these overly simple datasets is summarized in Table 7.
293
+
294
+ # A.2 Dedduplication
295
+
296
+ The first step involved identifying and removing duplicate code snippets. Duplicate examples can distort the model's performance by introducing redundancy, which may lead to overfitting. Using hash-based techniques, we identified exact duplicates. This ensured that each code snippet in the dataset was unique and contributed distinct information.
297
+
298
+ # A.3 Alignment
299
+
300
+ For code retrieval tasks, the alignment between the code and its associated natural language description is critical. We filtered out examples where comments or documentation were missing, incomplete, or irrelevant to the functionality of the code. This step ensured that the dataset only contained examples with high-quality, informative descriptions that could aid in retrieval tasks.
301
+
302
+ # B Dataset Details
303
+
304
+ # B.1 Reasons for Dataset Selection
305
+
306
+ - APPS: A challenging dataset where state-of-the-art retrieval models achieve an NDCG@10 of only 26.52, highlighting its difficulty.
307
+ - CosQA: The largest web-based query-to-code dataset, featuring meticulously crafted queries to enhance retrieval performance.
308
+ - Synthetic Text-to-SQL: The largest synthetic text-to-SQL dataset, enabling robust evaluation of SQL generation models.
309
+ - CodeSearchNet: A widely used code retrieval dataset covering six programming languages, with a corpus of 1 million documents.
310
+ - CodeSearchNet-CCR: Specifically designed for the Code Context Retrieval task, which is crucial for improving code completion systems.
311
+
312
+ <table><tr><td>Model (NDCG@10)</td><td>Human-eval</td><td>XcodeEval (sampled 13k)</td><td>mbpp</td></tr><tr><td>E5-Base-v2</td><td>92.41</td><td>89.59</td><td>95.43</td></tr><tr><td>BGE-Base-en-v1.5</td><td>93.45</td><td>88.47</td><td>92.41</td></tr><tr><td>GTE-Base-en-v1.5</td><td>91.54</td><td>87.54</td><td>94.45</td></tr><tr><td>UniXcoder</td><td>92.44</td><td>90.85</td><td>90.56</td></tr></table>
313
+
314
+ Table 7: Model performance comparison on Simple Dataset
315
+
316
+ - CodeTransOcean-DL & CodeTransOcean-Contest: Well-suited for Similar Code Retrieval, encompassing deep learning implementations and competitive programming solutions across multiple languages.
317
+ - StackOverflow QA: Reflects real-world developer queries, making it ideal for evaluating models that retrieve answers based on complete questions.
318
+ - CodeFeedBack-ST: A high-quality synthetic QA dataset, beneficial for retrieval-augmented generation and large language models.
319
+ - CodeFeedBack-MT: Designed for Multi-turn Code QA, presenting a significant challenge due to its extensive dialogue context exceeding 4,000 tokens—far beyond the typical 512-token limit of most models.
320
+
321
+ Examples of queries and corpora present in each dataset can be viewed in tables 8 and 9.
322
+
323
+ # B.2 Text-to-Code Retrieval Datasets
324
+
325
+ APPS (Hendrycks et al., 2021). The original APPS dataset is a code generation dataset derived from programming problems shared on open-access sites frequented by programmers, including Codewars, AtCoder, Kattis, and Codeforces, where each example consists of a question description and its corresponding code solution. To adapt the original APPS dataset for retrieval, we use the original problem descriptions as the query to retrieve from a corpus of all code solutions. We retain the original dataset's train-test split and remove examples that do not have a corresponding code solution, resulting in a total of 5,000 samples for the training set and 3,765 samples for the test set.
326
+
327
+ CoSQA (Huang et al., 2021). The CosQA dataset comprises 20,604 human-annotated labels for pairs of natural language web queries and corresponding code snippets. We retain the original train/dev/test dataset splits of 19,604/500/500 and utilize the natural language web queries as queries
328
+
329
+ to retrieve from a corpus of all code snippets as intended in CoSQA.
330
+
331
+ Synthetic Text2Sql (Meyer et al., 2024). The Synthetic Text2Sql dataset is a comprehensive collection of high-quality synthetic Text-to-SQL samples, meticulously designed and generated using Gretel Navigator $^{5}$ . Each example consists of the following: (1) a problem description which can be resolved using SQL (2) information on the schema of relevant tables used (3) the corresponding SQL code solution (4) meta-data revolving problem described, for instance the type of domain or industry the problem falls under (e.g. healthcare, aerospace etc.) and the nature of the task at hand (e.g. reporting, analytics, dashboarding etc.). Here we use the natural language question description as the query to retrieve from a corpus of corresponding SQL code solutions. We follow the train-test split provided by Gretel where the 105,851 queries are divided into 100,000 queries for train and the remaining 5,851 for test.
332
+
333
+ # B.3 Code-to-Code Retrieval Datasets
334
+
335
+ CodeSearchNet-CCR (Husain et al., 2019). CodeSearchNet-Code Context Retrieval (CCR) is modified from the original CodeSearchNet dataset with 1 million (docstring, code) pairs sourced from open-source repositories hosted on GitHub. For each example present in the dataset, we randomly divide each code function into two code segments where all the initial segment serves as our query and all latter segments forms the corpus to be retrieved using the corresponding initial segment. The length of each query is uniformly and randomly selected to comprise between $40\%$ and $70\%$ of the total number of characters in the original code or function. We retain the original train/dev/test split of $905\mathrm{k} / 41\mathrm{k} / 53\mathrm{k}$ and also retain the partition by their respective language from CodeSearchNet.
336
+
337
+ CodeTransOcean-DL (Yan et al., 2023). CodeTransOcean-DeepLearning (DL) is derived from the DLTrans, a dataset featured in the Code
338
+
339
+ <table><tr><td colspan="2">Dataset</td><td>Query</td><td>Relevant-Corpus</td><td>Granularity</td></tr><tr><td rowspan="3">Text Query to Code Corpus</td><td>Apps</td><td>You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. &lt;Text omitted for brevity&gt; For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. &lt;Example Test Case Omitted&gt;</td><td>for haaghj in range(int(input)): x,y,k = list(map(int, input().split())) print(k + (y * k + k - 1 +x-2) // (x - 1))</td><td>Function</td></tr><tr><td>CosQA</td><td>python adjacency matrix from edge list</td><td>def get_adjacent_matrixelf(self): edges = selfedges numEdges = len(edges) + 1 adj = np.zeros([numEdges, numEdges]) for k in range(numEdges - 1): adj[edges[k].L, edges[k].R] = 1 adj[edges[k].R, edges[k].L] = 1 return adj</td><td>Function</td></tr><tr><td>Synthetic Text2Sql</td><td>Which buildings in the UK have both a green roof and solar panels installed?</td><td>SELECT b.name FROM Building b JOIN GreenRoof gr ON b.id = gr.building_id JOIN SolarPanel sp ON b.id = sp.building_id WHERE b country = &#x27;UK&#x27;;</td><td>Entire Code</td></tr><tr><td rowspan="3">CodeSearchNet-CCR</td><td>CodeSearchNet-CCR</td><td>def get Cumulative Spend(key): Get the sum of spending for this category up to and including the given month. query = {&#x27;ROUND(SUM(total_ex_vat), 2)} AS total &#x27;FROM{table}&#x27;WHERE date &lt;= &quot;{year}-{month:02}-01&quot; &#x27;AND lot={&#x27;lot&#x27;}&#x27;AND customer_section={&#x27;sector&#x27;}&#x27;AND supplier_type={&#x27;sme_large&#x27;}&#x27;.format(table=RAW_SALES_TABLE, year=key.year, month=key.month,</td><td>lot=key.bit, sector=keysector, sme_large=key.sme_large)) logging.debug(query) result = scraperwikisqlite.select(query) logging.debug(result) value = result[0][&#x27;total&#x27;] return float(result[0][&#x27;total&#x27;]) if value is not None else 0.0</td><td>Code Snippet</td></tr><tr><td>CodeTransOcean-DL</td><td>import tensorflow as tf from d21 import TensorFlow as d21 net = tf keras.models Sequential(tf.keras.layers.Flatten(), tf.keras.layers.Dense(256, activation=&#x27;relu&#x27;), tf.keras.layers.Dense(10)) batch_s, lr, num_epochs = 256, 0.1, 10 loss = tf.keras.losses. SparseCategoricalCrossentropy() trainer = tf.keras optimizer.SGD(lr) train_iter, test_iter = d21.load_data+fashion_mnist(batch_s) d21.train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer</td><td>from d21 import paddle as d21 import paddle from paddle import nn net = nnSEQUENTIAL(nn.Flatten(), nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10)) for layer in net: if type(layer) == nn.Linear: weight_attr = paddle_framework.ParamAttr(initializer=paddle(nn.initializer.Normal(mean=0.0, std=0.01)) layer.weight_attr = weight_attr batch_size, lr, num_epochs = 256, 0.1, 10 ... Code truncated for brevity</td><td>Entire Code</td></tr><tr><td>CodeTransOcean-Contest</td><td>def setup(): println(distance(&quot;kitten&quot;, &quot;sitting&quot;)) def distance(a, b): costs = [] for j in range(len(b) + 1): costs.append(j) for i in range(1, len(a) + 1): costs.append(j) for j in range(1, len(b) + 1): cj=min(1+min(costs[j], costs[j-1]), nw if a[i-1] == b[j-1] else nw+1) nw, costs[j] = costs[j], cj return costs[len(b)]</td><td>#include &lt;algorithm&gt; #include ... template &lt;typename StringType&gt; size_t levenshtein_distance(const StringType&amp; s1, const StringType&amp; s2) { const size_t m = s1.size(); const size_t n = s2.size(); if (m == 0) return n; if (n == 0) return m; std::vector&lt;size_t&gt; costs(n + 1); std::iota(costs.begin(), costs.end(), 0); size_t i = ... ... Code truncated for brevity}</td><td>Entire Code</td></tr></table>
340
+
341
+ Table 8: Examples of queries and relevant corpora for 6 datasets related to Text-to-Code and Code-to-Code retrieval (i.e. Apps, CosQA, Synthetic Text2sql, CodeSearchNet-CCR, CodeTransOcean-DL, and CodeTransOcean-Contest) in COIR. For brevity, we omit or truncate some portion of the query and corpus.
342
+
343
+ TransOcean benchmark which focuses on code translation. The original dataset consists of pairs of semantically equivalent deep learning code written using different deep learning libraries namely Ten
344
+
345
+ sortflow, Pytorch, PaddlePaddle and MXNet. For each pair of data, we use one of the codes in one of the framework as query to retrieve its counterpart written in a different framework. We follow
346
+
347
+ <table><tr><td colspan="2">Dataset</td><td>Query</td><td>Relevant-Corpus</td><td>Granularity</td></tr><tr><td>Code Query to Code Corpus</td><td>CodeSe ArchNet</td><td>def precedes(self, other):
348
+ &quot;\&quot;Returns a boolean indicating whether this element precedes other element\&quot;&quot;
349
+ try:
350
+ ancestor = next(commonancestors( AbstractElement, self, other))
351
+ except StopIteration:
352
+ raise Exception(&quot;Elements share no common ancestor&quot;)
353
+ # now we just do a depth first search
354
+ # and see who comes first def callback(e):
355
+ .... Code truncated for brevity</td><td>Returns a boolean indicating whether this element precedes the other element</td><td>Document String</td></tr><tr><td rowspan="3">Hybrid Code Query to Hybrid Code Corpus</td><td>StackOver Flow QA</td><td>With Rust Regular Expressions, how can I use named capture groups preceding a string? I&#x27;m using the sd tool which uses rust regular expressions, and I am trying to use it with a named capture group, however... &lt;Text omitted for brevity&gt; Here is a contrived example to illustrate it:
356
+ echo `abc&#x27; | sd -p (?P&lt;cg&gt;b)&#x27; $cgB&#x27;
357
+ # outputs: ac
358
+ # desired output: abBc
359
+ echo &#x27;abc&#x27; | sd -p (?P&lt;cg&gt;b)&#x27; $cgB&#x27;
360
+ # outputs as expected: ab Bc
361
+ # however, places a space there
362
+ I&#x27;ve tried &lt;$cg&gt;B, $cg(B), $cgØB, all don&#x27;t give abBc.
363
+ I&#x27;ve also checked the rust regex docs however the x flag, and other techniques seem only applicable to the search pattern, not the replace pattern.</td><td>We don&#x27;t need the sd tool to reproduce this behavior.
364
+ Here it is in pure Rust:
365
+ let re = regex::Regex::new(r?&quot;P&lt;n&gt;b&quot;) .unwrap();
366
+ let before = &quot;abc&quot;;
367
+ assert_eq!(re.replace_all(before, &quot;$nB&quot;), &quot;ac&quot;);
368
+ assert_eq!(re.replace_all(before, &quot;$\{n\}B&quot;), &quot;abBc&quot;);
369
+ The brace replacement syntax isn&#x27;t described in the front documentation but on that of the replace method:
370
+ The longest possible name is used. e.g., $1a looks up the capture group named 1a and not the capture group at index 1. To exert more precise control over the name, use braces, e.g., $[1]a. &lt;Text omitted for brevity&gt;</td><td>Code Snippet mixed with text</td></tr><tr><td>CodeFeed Back-ST</td><td>user: How would you extend the following code to add the features &quot;undo&quot; and &quot;redo&quot; while maintaining a constant time complexity for adding items?
371
+ def add_item(item, list):
372
+ list.append(item)
373
+ def undo(list):
374
+ if len(list) &gt; 0:
375
+ list.pop()
376
+ def redo(undone_list, list):
377
+ if len(undone_list) &gt; 0:
378
+ item = undone_list.pop()
379
+ list.append(item)</td><td>assistant: To add the features &quot;undo&quot; and &quot;redo&quot; while maintaining a constant time complexity for adding items, you can use ... Here&#x27;s an extended version of the code:
380
+ def add_item(item, item_list, undone_list, redone_list):
381
+ item_list.append(item)
382
+ redone_list.clear() # Clear the # redone_list as new item is added
383
+ def undo(item_list, undone_list, redone_list):
384
+ if len(item_list) &gt; 0:
385
+ .... Code omitted for brevity
386
+ In this version, we add three new parameters to the functions: &#x27;undone_list&#x27;... &lt;Text omitted for brevity&gt;</td><td>Code Snippet or Functions mixed with text</td></tr><tr><td>CodeFeed Back-MT</td><td>user: Convert a given 2D point to the polar representation. The point has coordinates (x,y), where x and y are integers between -1000 and 1000, inclusive. Additional Requirement:
387
+ &lt;text omitted for brevity&gt;
388
+ assistant: To convert a 2D point to polar representation, we need to calculate the polar coordinates (r, theta) using the given Cartesian coordinates (x,y).
389
+ We can use the arctangent function to calculate the value of theta. &lt;text omitted for brevity&gt; Now, let&#x27;s write the code to convert the given 2D point to polar representation using the atan2 function in Python:
390
+ import math
391
+ def convert_to_polar(x,y):
392
+ r = math.sqrt(x*x + y*y) # calculating the distance from the origin
393
+ theta = math atan2(y,x) # calculating the angle in radians using atan2 function return (r, theta)
394
+ ... Code truncated for brevity
395
+ user: &lt;text omitted for brevity&gt;,
396
+ assistant: &lt;text omitted for brevity&gt;,
397
+ user: Please generate the code to meet the original requirements without using arithmetic operations. Clarifying comments and documentation will also be appreciated.</td><td>assistant: I apologize for any misunderstanding, but converting from Cartesian coordinates to polar coordinates inherently requires mathematical operations – notably, addition, multiplication, and trigonometric operations. These are defined by the mathematical formulas for converting between the two coordinate systems:
398
+ r = sqrt(x² + y²), theta = atan2(y,x)
399
+ These formulas can&#x27;t be implemented without using arithmetic operations, due to their inherent mathematical nature. As per your requirement of not using any arithmetic operations to solve this problem, it&#x27;s essential to understand that it would be impossible to convert to polar coordinates, as the problem mainly depends on these arithmetic operations. Again, I emphasize that this kind of computation relies heavily on arithmetic operations, and it is a significant constraint that would make finding a software or coding solution impossible. However, if there&#x27;s any related issue or a different problem you need assistance with, I would be more than happy to assist!&quot;</td><td>Code Snippet or Functions mixed with text</td></tr></table>
400
+
401
+ Table 9: Examples of queries and relevant corpora for 4 datasets related to Code-to-Text and Hybrid Code retrieval (i.e. CodeSearchNet, StackOverflow QA, CodeFeedback-ST and CodeFeedback-MT) in COIR. For brevity, we omit or truncate some portion of the query and corpus
402
+
403
+ the original train/dev/test split of 564/72/180 in CodeTransOcean-DL.
404
+
405
+ CodeTransOcean-Contest (Yan et al., 2023). Similar to CodeTransOcean-DL, the
406
+
407
+ CodeTransOcean-Contest dataset is derived from the MultilingualTrans dataset in the CodeTransOcean benchmark. The dataset features a collection of code for various problems, for instance binary tree traversal, sorting algorithms, written in various languages featured in Rosetta Code $^{6}$ , a programming chrestomathy website. In CodeTransOcean-Contest, we focus on retrieving semantically equivalent $\mathrm{C + + }$ , Python code pairs as these two languages differs greatly in terms of syntax and language features. We filter the examples in MultilingualTrans that does not contain any $\mathrm{C + + }$ nor Python code pairs and we use the Python code in each pair as queries to retrieve its counterpart from all $\mathrm{C + + }$ code in the filtered dataset. We retain the dataset split as in MultilingualTrans resulting in a 561/226/221 examples for train/dev/test respectively.
408
+
409
+ # B.4 Code-to-Text Retrieval Datasets
410
+
411
+ CodeSearchNet (Husain et al., 2019). The CodeSearchNet is a dataset consisting of 1 million (docstring, code) pairs sourced from open-source repositories hosted on GitHub. It contains code and documentation for several programming languages. Instead of retrieving relevant code from the original description, we reverse the roles of the docstring and code by retrieving the relevant docstring using the code as a query. We follow the original CodeSearchNet train/dev/test split of $905\mathrm{k} / 41\mathrm{k} / 53\mathrm{k}$ and also retain the partition by their respective language.
412
+
413
+ # B.5 Hybrid Code Retrieval Datasets
414
+
415
+ StackOverflow QA<sup>7</sup>. We modify the original StackOverflow dataset from Kaggle<sup>8</sup>, which contains questions posted by users, the corresponding highest voted answer to the user's questions and tags pertaining to the user's questions. Both the question and the answer typically consist of a mix of text and code snippets. Out of a total of 1,048,576 questions, we randomly sample 19,931 questions and their corresponding answers from the StackOverflow QA dataset. We use the questions raised by the users as a query to retrieve the corresponding answer from other correct answers posted by users. We randomly split the data into train/dev/test sets with a 13,951/3,986/1,994 split respectively.
416
+
417
+ CodeFeedback-ST (Zheng et al., 2024). We utilize data from CodeFeedback-Filtered-Instruction to generate retrieval dataset for CodeFeedback-ST. CodeFeedback-Filtered-Instruction is a collection of instruction-tuning datasets where a language model takes cue from user's instruction in order to generate code to fulfil the user's instructions. The dataset consists of pairs of users instruction and the response to be expected from an assistant where both the user's instructions and the assistant's response could contain a mixture of text and code snippets. We use the user's instructions as query to retrieve the corresponding relevant expected assistant's reply. Of the 156,526 examples present, we split the train and test dataset into 125,221 and 31,307 train and test examples respectively.
418
+
419
+ CodeFeedback-MT (Zheng et al., 2024). We utilize examples from Code-Feedback dataset to generate retrieval dataset for CodeFeedBack-Multi Turn (MT). Code-Feedback is a collection of instruction-tuning datasets involving simulated multi-turn dialogues between 2 LLMs; one plays the role of a user and the other plays the role of assistant. To ensure that the generated replies of the assistant are of high quality, the LLM playing the role of assistant is aided by code compilers alongside multiple generation attempts to arrive at a desirable response. Each example comprises a sequence of exchanges alternating between the user and assistant, starting with the user and ending with the assistant. To construct CodeFeedBack-MT, we split each sequence into 2 portions, the first portion consists of the initial dialogue history, prior to the last reply by the assistant, and second part is made up of the final reply by the assistant. We use the initial portion of the dialogue as query to retrieve the corresponding reply by the assistant. We split the dataset into 53,106 and 13,277 for train and test respectively.
420
+
421
+ # C Metric
422
+
423
+ # C.1 NDCG Metric
424
+
425
+ Normalized Discounted Cumulative Gain (NDCG) is a popular metric used to evaluate the quality of rankings, particularly in information retrieval and recommender systems. It measures the usefulness, or gain, of an relevant item based on its position in the result list, discounted logarithmically by the position.
426
+
427
+ data The Discounted Cumulative Gain (DCG) is the sum of the gains of relevant items, discounted log
428
+
429
+ arithmically by their positions in the ranking. The normalized version, NDCG, compares the DCG of the ranked list to the DCG of the ideal ranking. This normalization ensures that the score is within the range [0, 1].
430
+
431
+ # DCG Calculation:
432
+
433
+ The DCG at position $p$ is calculated as:
434
+
435
+ $$
436
+ \mathbf {D C G} _ {p} = \sum_ {i = 1} ^ {p} \frac {2 ^ {r e l _ {i}} - 1}{\log_ {2} (i + 1)}
437
+ $$
438
+
439
+ where $rel_{i}$ is the relevance score of the item at position $i$ .
440
+
441
+ # IDCG (Ideal DCG) Calculation:
442
+
443
+ The Ideal DCG (IDCG) is the DCG of the ideal ranking. This is calculated by sorting all items by their relevance scores in descending order and then computing the DCG using the same formula.
444
+
445
+ $$
446
+ \mathrm {I D C G} _ {p} = \sum_ {i = 1} ^ {p} \frac {2 ^ {r e l _ {i} ^ {*}} - 1}{\log_ {2} (i + 1)}
447
+ $$
448
+
449
+ where $rel_i^*$ is the relevance score of the item at position $i$ in the ideal ranking.
450
+
451
+ # NDCG Calculation:
452
+
453
+ The NDCG at position $p$ is the ratio of the DCG at position $p$ to the IDCG at position $p$ :
454
+
455
+ $$
456
+ \mathrm {N D C G} _ {p} = \frac {\mathrm {D C G} _ {p}}{\mathrm {I D C G} _ {p}}
457
+ $$
458
+
459
+ This normalization ensures that NDCG values are bounded between 0 and 1, making comparisons across different queries or datasets meaningful.
460
+
461
+ By evaluating the NDCG, we can get a sense of how well our ranking system is performing relative to the best possible ranking. This is particularly useful when the relevance varies across items and lower-ranked items are less likely to be seen and thus should contribute less to the overall evaluation metric.
462
+
463
+ # C.2 Weighted Jaccard Similarity
464
+
465
+ The weighted Jaccard similarity $J(S,T)$ (Ioffe, 2010) is calculated as the unique word overlap for all words present in both the datasets. We define the normalized frequency for an unique word $k$ in a dataset to be the frequency of word $k$ divided over the sum of frequencies of all words in the dataset.
466
+
467
+ Let $S_{k}$ be the normalized frequency of word $k$ in the source dataset $S$ and $T_{k}$ for the target dataset $T$ respectively. The weighted Jaccard similarity between $S$ and $T$ is defined as:
468
+
469
+ $$
470
+ J (S, T) = \frac {\sum_ {k} \min (S _ {k} , T _ {k})}{\sum_ {k} \max (S _ {k} , T _ {k})}
471
+ $$
472
+
473
+ where the sum is over all unique words $k$ present in datasets $S$ and $T$ .
474
+
475
+ # D Implementation Details
476
+
477
+ # D.1 Implementation Environments
478
+
479
+ The experimental setup for performance and efficiency evaluation was conducted utilizing a Tesla V100 GPU with 32GB of memory and Intel Titan CPU and CUDA 11.2. The versions of the software utilized in this study are PyTorch 2.0.1 and Transformers 4.38.1. We utilized the Faiss IndexFlat(Johnson et al., 2021) to store vector embedding index.
480
+
481
+ # D.2 Retriever Resources
482
+
483
+ The huggingface models or API used of retrieval model used in CoIR is listed in Table 10.
484
+
485
+ # D.3 Dataset Resources
486
+
487
+ The urls of dataset resources used in CoIR is listed in Table 11.
488
+
489
+ # E Dataset Explanation of Reality
490
+
491
+ It is important to note that the current settings align with prevalent code retrieval benchmark methodologies in the field, such as CodeSearchNet and CoSQA, where the retrieved documents are considered the final answers to queries. Additionally, we have considered scenarios where retrieval serves as a stepping stone rather than just an endpoint. Specifically, our code-to-text and code-to-code tasks are designed to evaluate the model's ability to retrieve relevant text and code snippets that supplement and enhance the final answer.
492
+
493
+ Furthermore, we have developed a new dataset from Stack Overflow. This dataset is carefully curated and filtered from the original Stack Overflow dump. In this dataset, the provided answers are not always the final solution to the queries. Instead, they may represent a strategy for solving the problem or serve as a component of the solution, thus reflecting the nuanced and iterative nature of real-world code generation and retrieval tasks.
494
+
495
+ # F Clarification of Innovation
496
+
497
+ We are not merely integrating existing datasets; rather, we are introducing new datasets and tasks. CodeSearchNet-CCR and StackOverflowQA are
498
+
499
+ <table><tr><td>Model</td><td>Public Model Checkpoints (Link)</td></tr><tr><td>Contriever</td><td>https://huggingface.co/facebook/contriever-msmarco</td></tr><tr><td>E5-base</td><td>https://huggingface.co/intfloat/e5-base-v2</td></tr><tr><td>BGE-Base</td><td>https://huggingface.co/BAAI/bge-base-en-v1.5</td></tr><tr><td>GTE-Base</td><td>https://huggingface.co/Alibaba-NLP/gte-base-en-v1.5</td></tr><tr><td>UniXcoder</td><td>https://huggingface.co/microsoft/unixcoder-base</td></tr><tr><td>BGE-M3</td><td>https://huggingface.co/BAAI/bge-m3</td></tr><tr><td>E5-Mistral</td><td>https://huggingface.co/intfloat/e5-mistral-7b-instruct</td></tr><tr><td>OpenAI-Ada-002</td><td>https://openai.com/</td></tr><tr><td>Voyage-Code-002</td><td>https://www.voyageai.com/</td></tr></table>
500
+
501
+ Table 10: Publicly available model links used for evaluation in CoIR.
502
+
503
+ <table><tr><td>Corpus</td><td>Website (Link)</td></tr><tr><td>APPS</td><td>https://huggingface.co/datasets/codeparrot/apps</td></tr><tr><td>CoSQA</td><td>https://github.com/microsoft/CodeXGLUE/tree/main/Text-Code/NL-code-search-WebQuery</td></tr><tr><td>Synthetic Text2sql</td><td>https://huggingface.co/datasets/gretelai/synthetic_text_to sql</td></tr><tr><td>CodeSearchNet</td><td>https://huggingface.co/datasets/code-search-net/code_search_net</td></tr><tr><td>CodeTransOcean</td><td>https://huggingface.co/datasets/WeixiangYan/CodeTransOcean</td></tr><tr><td>Code-Feedback</td><td>https://huggingface.co/datasets/m-a-p/Code-Feedback</td></tr><tr><td>CodeFeedback-Filtered-Instruction</td><td>https://huggingface.co/datasets/m-a-p/CodeFeedback-Filtered-Instruction</td></tr></table>
504
+
505
+ Table 11: Corpus Name and Link used for datasets in CoIR.
506
+
507
+ datasets we created ourselves. StackOverflowQA was extracted from the original StackOverflow dump, and we introduced this dataset to ensure that the simulated tasks closely mirror real-world scenarios, such as searching for answers when encountering code issues.
508
+
509
+ Additionally, we introduced a new task, Code Context Retrieval, which involves retrieving the most relevant code segment that completes a given initial segment of code. This task is critical for code completion purposes, and the CodeSearchNet-CCR dataset was specifically created for this task.
510
+
511
+ Previously, only CosQA and CodeSearchNet were straightforwardly usable as code retrieval benchmarks. We have supplemented these with eight additional datasets, which we meticulously cleaned, manually filtered, and standardized. This process was quite labor-intensive.
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc812029e20e68bfe3389d9a3f816f14a8ca077f8416bebe366e31d57a433ebb
3
+ size 1460132
2025/CoIR_ A Comprehensive Benchmark for Code Information Retrieval Models/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_content_list.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_model.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/ba8c70d6-0d72-409f-95bd-44fb327a3a2d_origin.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8713b6b39afdeb3d661a27b31891559a761655f1540e144167b6f0079d3922f
3
+ size 2031973
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/full.md ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/images.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02e2d69bf92845fed7e9a0e7af47196589934a81c8b946f6b36b2b8352bf99be
3
+ size 661230
2025/CoMet_ Metaphor-Driven Covert Communication for Multi-Agent Language Games/layout.json ADDED
The diff for this file is too large to render. See raw diff
 
2025/CoRe-MMRAG_ Cross-Source Knowledge Reconciliation for Multimodal RAG/4d6bd5e4-e4fd-4ed2-a6b9-effaad773b5a_content_list.json ADDED
The diff for this file is too large to render. See raw diff