Semantic Distance Measurement based on Multi-Kernel Gaussian Processes

Yinzhu Cheng, Haihua Xie, Yaqing Wang, Miao He, Mingming SunarXiv 2025 · DOI · arXiv

Introduction

In contemporary Natural Language Processing (NLP), measuring the semantic distance between text segments is a foundational requirement for tasks ranging from information retrieval to in-context learning (ICL). Traditionally, researchers have relied on task-agnostic metrics such as cosine similarity applied to fixed embeddings. However, these "one-size-fits-all" rulers assume a globally smooth and linear semantic space, which often fails to capture the nuanced requirements of specific tasks. For instance, in fine-grained sentiment analysis, the distance between "positive" and "very positive" requires a different geometric interpretation than the distance between "neutral" and "negative."

To address this, we present a framework for task-aware semantic distance measurement using Multi-Kernel Gaussian Processes (MK-GP). By learning a specialized ruler that adapts to the label space's specific geometry, this approach significantly enhances the performance of Large Language Models (LLMs) in downstream applications.

The MK-GP Framework

The core of the proposed method is the transition from fixed distance metrics to a supervised metric learning approach. The MK-GP framework treats the mapping from text embeddings to task labels as a function sampled from a Gaussian Process prior. This allows the model to quantify uncertainty and define similarity through a learned covariance function.

The MK-GP framework: (A) The metric learning phase uses supervised labels to optimize kernel parameters through negative log-likelihood maximization. (B) The inference phase utilizes the frozen, task-aware distance to calculate semantic similarity scores.

Multi-Kernel Design

A single kernel often lacks the flexibility to capture both local nuances and global trends. MK-GP utilizes a combination of two distinct kernel types:

  • Matérn Kernels: These are employed to capture local smoothness and stationary structures within the embedding space, effectively managing "neighborhood" logic.
  • Polynomial Kernels: These capture global, non-stationary trends and non-linear "margin-like" structures, which are essential for identifying broader ordinal progressions in data like sentiment scales.

By optimizing the weighted sum of these kernels, the model learns a task-specific geometry where the "distance" between points is determined by how rapidly the task labels change in that region of the embedding space.

Learning Task-Specific Geometry

The fundamental insight of this work is that semantic distance should be a function of the task labels rather than just the vector representations. As illustrated below, the process involves mapping raw text into a BERT embedding space, which is then transformed via the multi-kernel mapping into a Reproducing Kernel Hilbert Space (RKHS). In this final space, the task-specific boundaries become linearly separable and the distance metric becomes truly task-aware.

Conceptual mapping process: Raw text is embedded via BERT and then projected into a Reproducing Kernel Hilbert Space (RKHS) using Matérn and Polynomial kernels to achieve task-specific separability.

Experimental Evaluation

The framework was rigorously tested across five sentiment analysis datasets with varying granularity: SST5 (movie reviews), SemEval17 (tweets), ABSIA (restaurant reviews), and Amazon product reviews (PR_Baby and PR_Software). These datasets present challenges such as fine-grained labels (5 to 7 classes) and non-linear linguistic phenomena like sarcasm.

Key Results

  • Superior Accuracy: MK-GP consistently outperformed standard selection strategies, including Random, BM25, and Cosine Similarity, across all tested LLM families (GPT-4o, DeepSeek-V3, and ERNIE 4.5).
  • Efficiency: Despite the computational overhead typically associated with Gaussian Processes, the model is highly practical. Training on 1,000 samples for 500 epochs takes approximately 170 seconds on a single consumer-grade GPU (NVIDIA RTX 3080).
  • Architecture Agnostic: The improvements provided by MK-GP are independent of the underlying LLM, suggesting it can serve as a universal "plug-and-play" enhancement for retrieval-based ICL pipelines.

Conclusion and Future Work

By replacing generic distance metrics with task-aware rulers learned via Multi-Kernel Gaussian Processes, we can provide LLMs with more relevant demonstrations, leading to higher accuracy in complex reasoning tasks. While currently focused on sentiment analysis, future research will explore the scalability of this method using sparse GP approximations and its application to multimodal settings and Retrieval-Augmented Generation (RAG).

Summary updated

BibTeX
@misc{cheng2025semantic,
  author = {Yinzhu Cheng and Haihua Xie and Yaqing Wang and Miao He and Mingming Sun},
  title = {{Semantic Distance Measurement based on Multi-Kernel Gaussian Processes}},
  year = {2025},
  eprint = {2512.12238},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.12238},
}
Figure