Epicure: Distilling Sequence Model Predictions into Patterns

Miltiadis Allamanis, Earl T. BarrarXiv 2023 · DOI

Introduction: The High-Entropy Challenge in Sequence Prediction

Machine learning models for sequence prediction, such as those generating function names in source code, often struggle with a "high entropy" problem. A model might produce dozens of plausible candidates, each with a low individual probability. For instance, if a model predicts fetch_data_from_cache while the ground truth is get_cached_data, standard metrics mark it as a failure despite the model capturing the semantic essence of the operation.

In software engineering tools, this specificity leads to high false-alarm rates in anomaly detection. Developers do not always need a perfect character-for-character match; they need accurate, high-level abstractions. EPICURE addresses this by distilling probabilistic outputs into high-precision abstract patterns.

Methodology: From Concrete Predictions to Abstract Lattices

EPICURE is a model-agnostic post-processing wrapper that sifts through the top results (e.g., the top 100 results from a beam search) of any sequence generator.

1. Pattern Generation via Anti-Unification

The core of EPICURE is a join operation ($⊔$) based on anti-unification. By treating predictions as sequences of subtokens, it identifies commonalities. For example, joining the predictions [load, data, msgpack] and [load, file, msgpack] results in the pattern [load, ⋆, msgpack], where ⋆ is a wildcard representing zero or more arbitrary elements.

2. Lattice Construction and Probability Assignment

EPICURE iteratively applies this join operation to build a hierarchical lattice. The bottom nodes represent specific predictions, while higher nodes represent increasingly general patterns that subsume them. The probability of an abstract pattern is calculated as the sum of the probabilities of all concrete predictions it matches.

Figure 1: An example of a generated lattice where specific predictions are distilled into higher-level patterns with aggregated probabilities.

3. Distillation

Given a confidence threshold (e.g., $θ > 0.5$), EPICURE selects the most specific patterns that meet that threshold. This ensures the output is both highly likely to be correct and as descriptive as possible, representing a majority consensus of the model's probability mass.

Evaluation and Key Results

The authors evaluated EPICURE using the UniXcoder-base model on the CodeSearchNet corpus and a custom Python test set of 250,000 samples from GitHub repositories created after the model's training data cutoff to prevent memorization.

Performance Metrics

The method was compared against a standard baseline that filters the top prediction by a probability threshold.

  • Naming Accuracy: At a 10% False Alarm Rate, EPICURE's patterns matched ground-truth names 61% more often than the best single-model prediction.
  • RegexAcc and Complete Matches: EPICURE consistently outperformed the baseline across various error tolerances. RegexAcc measures how many subtokens of the ground truth are captured by the pattern, while Complete Matches tracks exact hits.
Figure 2: Performance comparison between EPICURE (solid black) and the baseline (dashed red) across False Alarm Rates for RegexAcc and Complete Matches.

Insights and Future Directions

EPICURE prioritizes precision over specificity. By allowing models to "admit" uncertainty through wildcards, it provides more reliable suggestions for high-precision scenarios like automated code review or anomaly detection. The lattice structure also offers interpretability; if a function named save_file is flagged against a distilled pattern of load⋆, the discrepancy is immediately clear to a developer.

Future work may involve moving beyond simple wildcards to more complex regular expressions or grammar-aware patterns, potentially extending the technique to other sequence tasks like machine translation or image captioning.

Summary updated

Abstract

Most machine learning models predict a probability distribution over concrete outputs and struggle to accurately predict names over high entropy sequence distributions. Here, we explore finding abstract, high-precision patterns intrinsic to these predictions in order to make abstract predictions that usefully capture rare sequences. In this short paper, we present Epicure, a method that distils the predictions of a sequence model, such as the output of beam search, into simple patterns. Epicure maps a model's predictions into a lattice that represents increasingly more general patterns that subsume the concrete model predictions. On the tasks of predicting a descriptive name of a function given the source code of its body and detecting anomalous names given a function, we show that Epicure yields accurate naming patterns that match the ground truth more often compared to just the highest probability model prediction. For a false alarm rate of 10%, Epicure predicts patterns that match 61% more ground-truth names compared to the best model prediction, making Epicure well-suited for scenarios that require high precision.
BibTeX
@misc{allamanis2023epicure,
  author = {Miltiadis Allamanis and Earl T. Barr},
  title = {{Epicure: Distilling Sequence Model Predictions into Patterns}},
  year = {2023},
  eprint = {2308.08203},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.08203},
}
Figure