...

/

Ethical Considerations in ML Development

Ethical Considerations in ML Development

Explore questions regarding ethical considerations and ML interpretability.

Ethical machine learning focuses on trust, safety, and responsibility. In this lesson, we’ll explore how to detect adversarial attacks and why openness and transparency are essential in model development.

Adversarial examples

You are working on an image classification model that is deployed in a real-world application. To ensure the model’s robustness, you want to identify adversarial examples—images that have been subtly modified to mislead the model.

Write a Python function to compute the similarity between an original image and a potentially adversarial image using a measure like Mean Squared Error (MSE). Discuss how such a similarity measure can help identify adversarial examples.

Sample answer

Adversarial attacks can compromise model safety, especially in important systems like self-driving cars (e.g., stop signs altered to mislead detection systems). Implementing such detection mechanisms enhances the robustness of ML models in sensitive applications.

Let’s look at a sample implementation below:

Press + to interact
Python 3.10.4
import numpy as np
# Function to calculate Mean Squared Error (MSE) between two images
def calculate_mse(original_image, adversarial_image):
"""
Calculate the Mean Squared Error (MSE) between two images.
Args:
original_image (numpy.ndarray): The original image as a 2D or 3D array.
adversarial_image (numpy.ndarray): The potentially adversarial image as a 2D or 3D array.
Returns:
float: The MSE value.
"""
if original_image.shape != adversarial_image.shape:
raise ValueError("Images must have the same dimensions")
mse = np.mean((original_image - adversarial_image) ** 2)
return mse
# Example usage
# Simulating two 2D grayscale images (values range from 0 to 255)
original_image = np.array([[100, 150], [200, 250]])
adversarial_image = np.array([[102, 149], [198, 252]])
mse_value = calculate_mse(original_image, adversarial_image)
print(f"Mean Squared Error (MSE): {mse_value:.2f}")

Let's look at a brief code breakdown. ...