Specifying and Testing k-Safety Properties for Machine-Learning Models

Maria Christakis, Hasan Ferit Eniser, Jörg Hoffmann, Adish Singla, Valentin Wüstholz

TL;DR

This paper introduces NOMOS, a novel specification language for defining general functional-correctness properties (k-safety properties) for machine learning models. They also present an automated testing framework that uses metamorphic testing to find violations of these properties, demonstrating its effectiveness across various domains and even using detected violations to improve model training.

What Problem Does This Paper Address?

As machine learning (ML) models become more integrated into critical applications like image classification and decision-making, ensuring their reliability is paramount. While significant research has focused on verifying specific properties like robustness and fairness, a major challenge remains in specifying and testing general functional-correctness expectations. For instance, how do we formally express that a credit-scoring model should behave consistently under certain input changes, beyond just fairness or robustness? This paper tackles this gap by proposing a way to express and test these broader, multi-execution properties.

Methods

The core of the paper lies in two main contributions:

  • NOMOS Specification Language: Inspired by formal methods' "hyperproperties," NOMOS allows users to define k-safety properties. These properties involve reasoning about k different executions of the ML model. A NOMOS specification consists of a precondition (conditions under which the model is invoked), the code to invoke the model (potentially multiple times), and a postcondition (the expected relationship between the model's outputs for these executions). This language is domain-agnostic and can express properties like monotonicity, robustness, and fairness as special cases.
  • Metamorphic Testing Framework: To automatically validate NOMOS specifications, the authors developed a framework that leverages metamorphic testing. This technique is ideal because it doesn't require a perfect oracle (a known correct output for every input). Instead, it transforms an input and checks if the relationship between the original and transformed output holds as specified. The framework translates NOMOS specifications into test harnesses that generate inputs, run the model, and check for violations of the specified k-safety properties.

Datasets

The authors evaluated their framework on models trained using the following datasets:

  • COMPAS: Used for recidivism risk prediction (tabular data).
  • GermanCredit: Used for credit scoring (tabular data).
  • MNIST: A benchmark dataset for handwritten digit classification (images).
  • SpeechCommand: A dataset for classifying short spoken commands (speech).
  • HotelReview: Used for sentiment analysis of hotel reviews (natural language).
  • LunarLander: A reinforcement learning environment for landing a lunar module (action policies).

Key Insights and Ideas

  • Generalizing Properties: The concept of "k-safety properties" provides a powerful and unified way to express a wide range of functional-correctness expectations for ML models, going beyond existing, more narrowly defined properties like robustness and fairness.
  • Formal Methods Inspiration: Adapting concepts from formal methods (hyperproperties, Hoare logic, design by contract) to the ML domain offers a structured and expressive way to define model behavior.
  • Metamorphic Testing as an Oracle: Metamorphic testing is a natural fit for validating k-safety properties because these properties inherently define expected relationships between outputs from different (transformed) inputs, effectively creating a dynamic oracle.
  • Actionable Violations: Property violations detected by the framework are not just indicators of bugs; they can be actively used to improve model training, suggesting a path towards more reliable ML systems.

Key Results

  • The NOMOS language and testing framework were applied to models trained on six different datasets across five domains.
  • The framework successfully detected property violations for all datasets, finding violations for 24 out of 30 specified properties.
  • The number of unique bugs detected varied significantly across datasets and properties, with some properties showing hundreds or even thousands of violations.
  • A feasibility study on the LunarLander environment demonstrated that incorporating detected "buggy states" into the training process (guided training) led to policies with fewer bugs and comparable or improved rewards compared to standard training. Figure 5 shows a consistent decrease in bugs over time with guided training.

Limitations and Future Work

  • Model Repair and Guided Training: The authors highlight model repair and guided training as promising future directions, building upon their feasibility study. They suggest adapting adversarial training techniques for improved effectiveness.
  • Input Generation: For the testing community, exploring more advanced input generation techniques, such as coverage-guided testing, could reduce testing time and increase bug detection efficiency, especially for guided training.
  • Formal Verification: For the formal methods community, developing tools for formally verifying that a property holds for all inputs is a natural next step, particularly for safety-critical applications.
  • Domain-Specific Functions: While NOMOS is domain-agnostic, its expressiveness relies on user-defined domain-specific functions (e.g., blur, wNoise). The paper acknowledges that extending the grammar with more such functions could enhance its applicability.

Summary updated

BibTeX
@inproceedings{christakis2023specifying,
  author = {Maria Christakis and Hasan Ferit Eniser and Jörg Hoffmann and Adish Singla and Valentin Wüstholz},
  title = {{Specifying and Testing k-Safety Properties for Machine-Learning Models}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2023},
  url = {https://openreview.net/forum?id=TLHZZTeyrr},
}
Figure