Systems that find the same program written in two different languages, for example a Java function and its Python equivalent, almost always end in a similarity score that has a hidden knob. A Gaussian kernel has a bandwidth. A contrastive encoder has a temperature and a margin. These knobs are tuned on the languages where labeled pairs exist and then applied, untouched, to languages where none do. This proposal argues that this silent transfer of a tuned scale is a main reason similarity-based code matching ports poorly across languages. Verbose languages such as Java and C++ and terse ones such as Ruby and Python produce feature vectors with very different magnitudes and densities, so a bandwidth that separates clones well in one language pair can make every pair look identical, or every pair look unrelated, in another.
We propose to measure this effect directly and to remove it with a kernel that has no scale to tune. The candidate is the generalized min-max (GMM) kernel, a similarity equal to the sum of coordinate-wise minima divided by the sum of coordinate-wise maxima. It works on mixed-sign data by splitting each coordinate into positive and negative parts. We would compute it over lightweight code features that need no type checker or data-flow analysis. The central claim is testable in two sentences: in zero-shot cross-language clone detection, a Gaussian kernel tuned on source languages loses a measurable share of its oracle accuracy on unseen languages, while a tuning-free GMM kernel on the same features recovers most of that loss with nothing to tune. If true, it gives a portable, cheap baseline that can be dropped into any new language, and a diagnostic for when learned systems are failing for the same reason.
Core Claim and What Is New
The two directions meet at one point. Cho et al. describe the bandwidth dilemma geometrically in Kernel Methods for Deep Learning: too narrow a kernel turns every point into an isolated island, and too wide a kernel collapses everything into one cluster. Which regime a given bandwidth lands in depends on the typical distance between feature vectors, and that distance is exactly what differs between a 40-line Java method and its 8-line Ruby counterpart. Cross-language portability work has not treated this as a portability problem. ZC3: Zero-Shot Cross-Language Code Clone Detection aligns languages with contrastive, adversarial and cycle-consistency losses, and its authors note that the resulting model is highly sensitive to loss weights, margins and learning rates. That sensitivity requires grid searches that do not scale to many low-resource languages. This observation motivates us. We ask how much of the problem lives in the scale of the final similarity alone.
The method comes from Ping Li's work in Linearized GMM Kernels and Normalized Random Fourier Features. That paper introduces the tuning-free GMM kernel and its linearization by generalized consistent weighted sampling (GCWS). GCWS is a hashing scheme that turns each vector into a short sparse binary code, so the kernel can be approximated with linear tools and a standard index. The paper reports GMM beating a best-tuned Gaussian kernel across 50+ datasets, for example 99.61% versus 97.61% on DailySports. Those results are within-domain classification. Nobody has asked whether "no bandwidth" also means "no re-tuning when the domain shifts", and a change of programming language is a clean, high-stakes domain shift on which to ask it.
The closest work connecting code and kernel tuning is Code-Aware Cross-Program Transfer Hyperparameter Optimization (CaTHPO). It embeds a program's syntax tree and uses that embedding inside a Gaussian-process surrogate to tune the program's runtime knobs. Its direction is the reverse of ours: it uses code to tune something else, with language-specific parsers and its own surrogate kernel left untuned. We instead study the hyperparameters of the code-similarity function itself and their portability across languages. We do not touch Bayesian optimization.
Research Program
We would build one retrieval pipeline with interchangeable feature views and interchangeable similarity functions, so that every comparison varies exactly one thing.
The feature views run from parser-free to parser-light. The first is character 3-gram counts after stripping whitespace and lowercasing, exactly as in DeSoCoRe: Detecting Source Code Re-Use across Programming Languages. The second is identifier subtoken counts. The third is counts of syntax-tree node-type paths of length up to three, using only generic node types. That is the level of structure that Language-Agnostic Representation Learning of Source Code from Structure and Context found necessary for multilingual transfer, where text-only multilingual training gave no gain and structure-aware training lifted Ruby summarization F1 from 27.50 to 31.24. The fourth is frozen mean-pooled embeddings from a pretrained code encoder of the kind ZC³ builds on. These are mixed-sign, which is the case the GMM kernel was designed for.
The similarity functions are cosine, a Gaussian kernel with bandwidth $\gamma$, and GMM. For a vector $x$ with nonnegative coordinates (after the positive/negative split), GMM is
$$ \mathrm{GMM}(x,y) = \frac{\sum_i \min(x_i, y_i)}{\sum_i \max(x_i, y_i)}. $$
It has no free parameter. Each snippet vector is normalized to unit sum so the kernel does not reward sheer length. For corpus-scale retrieval we replace exact GMM with GCWS hashes and Gaussian kernels with normalized random Fourier features (NRFF), a randomized low-dimensional approximation of the Gaussian kernel from the same Li paper. This keeps all methods on the same linear index and at the same compute cost.
The analysis has three parts. First, for every held-out language pair we sweep $\gamma$ densely and record three quantities: the oracle bandwidth, the accuracy at that oracle, and the accuracy at the bandwidth chosen on the source pairs. Second, we test whether the shift in oracle bandwidth is predicted by measurable language statistics, namely mean feature-vector norm and the number of nonzero features, which would confirm the mechanism. Third, we compare GMM's absolute accuracy against both the source-tuned and the oracle Gaussian kernel. The quantity we care about is the transfer gap: the score with the oracle $\gamma$ minus the score with the source-tuned $\gamma$, averaged over held-out pairs. GMM's gap is zero by construction, so the question is whether its level matches the oracle.
Baselines
The naive reference point is DeSoCoRe-style cosine similarity over character 3-gram frequencies (DeSoCoRe), run with no tuning on every pair. It is the "do nothing" option because it needs neither a parser nor a hyperparameter. It is also partly scale-free, which makes it a sharper control than an arbitrary weak baseline. Beating it on the same features is the first bar.
The tuned-kernel baselines are the Gaussian kernel in two forms. The first takes its $\gamma$ from grid search on source-language labeled pairs only, which is the honest zero-shot protocol. The second takes $\gamma$ from the median-heuristic, which sets the bandwidth from the median pairwise distance of unlabeled target-language vectors. It costs no labels and directly corrects for scale differences, so it is the strongest cheap competitor to our claim. Both use the same features, the same NRFF dimension, and the same number of grid points that the oracle sweep uses. We also report the oracle Gaussian kernel tuned on target labels as an upper reference, not as a competitor.
The strongest existing method is ZC³ (ZC3), run with its published configuration on CSNcc, AtCoder and Google CodeJam. The file reports only relative gains for ZC³: average MAP improvement of 53.01% over baselines across six CSNcc settings, 67.12% on AtCoder, and 51.30% on Google CodeJam. No reported absolute MAP was found on Lacuna for ZC³ on these benchmarks, so we will re-run it and report absolute MAP alongside our numbers. For fairness, ZC³ receives the same source-language hyperparameter budget as our tuned baselines, with no target-language tuning.
The key-ingredient ablation holds the features fixed and swaps only the similarity function among cosine, source-tuned Gaussian, median-heuristic Gaussian and GMM. A second ablation removes the node-type path view to test whether light structure is what carries transfer, as Code Transformer's text-only failure predicts. A third compares exact GMM with its GCWS hash approximation at several hash counts. More hashes only help, so this tests approximation cost rather than introducing a new sensitivity. We count our proposal a success if GMM exceeds source-tuned Gaussian MAP on most held-out pairs, lands within a few points of the oracle, and beats cosine on the same features.
Why not just…?
Why not just use cosine similarity, which also has no knob? This is the most serious threat. Cosine is invariant to vector length and may already absorb most of the verbosity mismatch. Li's evidence compares GMM with tuned Gaussian kernels, not with cosine, so the file gives no evidence either way. The ablation that fixes features and swaps only the similarity settles it. If cosine matches GMM, the conclusion becomes "scale-freeness is what matters, and nonlinearity adds nothing". We would report that plainly, and the transfer-gap measurement would still stand as the contribution.
Why not just set the bandwidth per language with the median heuristic? It needs only unlabeled target code and directly targets the scale mismatch we hypothesize, so it may close much of the gap. We run it as a baseline. It fixes only a global scale, whereas languages also differ in which features are dense and which are sparse. GMM's per-coordinate min/max ratio is unaffected by such differences, while a single global $\gamma$ cannot adapt to them. If the median heuristic matches the oracle, our mechanism is confirmed but our remedy is unnecessary, and we would say so.
Why not just train a better neural aligner like ZC³ and drop kernels altogether? ZC³'s own authors report that its loss weights, margins and learning rates need costly grid searches. That is the same portability problem moved into the network. Our experiment tests whether that sensitivity is partly a scoring-scale problem. We swap ZC³'s final similarity for GMM over its frozen embeddings and check whether accuracy on held-out languages becomes less dependent on its tuned temperature and margin. If ZC³ dominates on absolute MAP, the GMM pipeline remains useful as a training-free fallback for languages with no data. We would not claim it as a replacement.
Why not just use execution-based checking? Agnostics shows that input/output testing works across languages, but only for self-contained runnable programs. Snippet-level clone corpora and code-search databases are mostly not runnable, so execution cannot score them.
Proposed Experiments
The primary testbeds are the three ZC³ benchmarks. On CSNcc (Ruby, Python, Java), we tune on one pair and test on pairs involving the held-out language. On AtCoder and Google CodeJam (Python–Java), we tune in one direction and test in the other, and also tune on one benchmark and test on the other. We then extend to XLCoST, using its parallel programs across C++, Java, Python, C#, JavaScript, PHP and C as program-level cross-language retrieval. Hyperparameters are tuned on Java–Python only, and every other pair is treated as unseen. The metric is MAP, as in ZC³, with the transfer gap defined above as the secondary metric.
The decisive checks are three. First, the oracle bandwidth must actually shift across languages and track feature density or norm. If it does not, the premise is wrong and the project reduces to a kernel comparison. Second, GMM must recover most of the transfer gap without tuning and beat the source-tuned Gaussian kernel on held-out pairs. Third, GMM must beat both cosine and median-heuristic Gaussian on identical features. Failing the third check would redirect the claim from "use GMM" to "use any scale-free similarity", which is a narrower but still useful result for anyone porting code tools to a new language.
References
- Kernel Methods for Deep Learning
- ZC3: Zero-Shot Cross-Language Code Clone Detection
- Linearized GMM Kernels and Normalized Random Fourier Features
- Code-Aware Cross-Program Transfer Hyperparameter Optimization
- DeSoCoRe: Detecting Source Code Re-Use across Programming Languages
- Language-Agnostic Representation Learning of Source Code from Structure and Context
- Agnostics: Learning to Synthesize Code in Any Programming Language with a Universal Reinforcement Learning Environment
- XLCoST: A Benchmark Dataset for Cross-lingual Code Intelligence