Exercises: Responsible AI Development
These exercises progress from concept checks to challenging applications, including Python coding exercises. Estimated completion time: 4-5 hours.
Difficulty Guide: - * Foundational (5-10 min each) - ** Intermediate (10-20 min each) - *** Challenging (20-40 min each) - **** Advanced/Research (40+ min each)
Part A: Conceptual Understanding *
Test your grasp of core concepts from Chapter 29.
A.1. Section 29.1 compares three major responsible AI frameworks: Microsoft's, Google's, and the OECD AI Principles. Identify one strength and one limitation for each framework.
A.2. Explain the purpose of a model card (Mitchell et al., 2019) as described in Section 29.2. Who are the intended audiences for a model card, and what does each audience need from it?
A.3. Section 29.3 introduces datasheets for datasets (Gebru et al., 2021). Explain the connection between datasheets and model cards. Why does the chapter argue that publishing model cards without datasheets is "like publishing a drug label without disclosing the clinical trial population"?
A.4. Define red-teaming in the context of AI development (Section 29.5). How does red-teaming differ from standard testing? What types of failures is it designed to uncover that standard testing might miss?
A.5. Section 29.6 discusses model drift. Define concept drift, data drift, and performance degradation, and explain why each requires ongoing monitoring rather than one-time evaluation.
A.6. What is an "out-of-scope use" in the context of a model card? Why is documenting out-of-scope uses important for responsible AI deployment? Provide one example from VitraMed's clinical prediction model.
A.7. Section 29.4.2 applies the ModelCard dataclass to VitraMed's patient risk model. Identify three ethical considerations documented in VitraMed's model card and explain why each is important.
Part B: Applied Analysis **
Analyze scenarios, arguments, and real-world situations using concepts from Chapter 29.
B.1. A company trains a sentiment analysis model on English-language product reviews and deploys it to analyze customer feedback globally, including from customers who write in English as a second language. The model was not tested on non-native English text. Using the model card framework, identify the intended use, the out-of-scope use, and at least three risks that should be documented in the card's ethical considerations section.
B.2. Dr. Adeyemi states: "Every dataset is a political document" (Section 29.3.3). Apply this claim to the following dataset: a collection of 500,000 resume-outcome pairs (resume text and whether the applicant was hired) from a large technology company's hiring pipeline over the past five years. What "political" choices does this dataset embed? How would a datasheet expose them?
B.3. Section 29.5 describes red-teaming methodologies. A healthcare AI company has built a model that suggests potential diagnoses based on patient-reported symptoms. Design a red-teaming exercise for this model. Specify: (a) the composition of the red team, (b) at least five attack scenarios they should test, and (c) the criteria for determining whether the model passes or fails each test.
B.4. The chapter describes VitraMed's model card revealing that the model performs significantly less accurately for patients over 65 and for patients from predominantly Hispanic neighborhoods. Using the disaggregated metrics framework from Section 29.4.2, explain why aggregate accuracy (92%) is misleading without disaggregated reporting. Propose a standard for what disaggregated groups should be reported for a healthcare prediction model.
B.5. A financial services company deploys a fraud detection model that flags potentially fraudulent transactions for human review. After deployment, the model's false positive rate for transactions originating from certain ZIP codes (correlated with minority communities) is three times higher than for other ZIP codes. Using the monitoring framework from Section 29.6, explain: (a) how this drift should have been detected, (b) what the company's immediate obligations are, and (c) what the model card should document about this finding.
B.6. Compare VitraMed's approach to model documentation with the approaches described in the case studies. What does VitraMed do well? What gaps remain? Propose three specific improvements to VitraMed's model card.
Part C: Python Coding Exercises -*
These exercises require you to work with the ModelCard dataclass from Chapter 29.
C.1. ** Basic ModelCard Creation. Create a ModelCard instance for the following system: a university's student dropout prediction model. The model uses GPA, course completion rates, LMS engagement data, and financial aid status to predict which first-year students are at risk of not returning for their second year. Fill in all fields with realistic values, including disaggregated metrics for at least three demographic groups.
# Your code here
# Use the ModelCard dataclass from Section 29.4
# Generate and print the report
C.2. ** ModelCard Comparison. Create two ModelCard instances for the same prediction task (e.g., loan approval) but with different models: one trained on traditional credit data only, and one trained on traditional plus alternative data. Populate both cards with realistic metrics. Write a function compare_cards(card1: ModelCard, card2: ModelCard) -> str that generates a side-by-side comparison report highlighting differences in performance, fairness, and ethical considerations.
C.3. *** Datasheet Generator. Create a DataSheet dataclass inspired by Gebru et al. (2021) that documents a dataset. Your datasheet should include fields for:
- Dataset name, purpose, and creator
- Collection methodology and timeframe
- Data subjects: who is represented, who is missing
- Sensitive attributes present
- Known limitations and biases
- Recommended uses and non-recommended uses
- Maintenance and update schedule
Include a generate_report() method. Create a datasheet for VitraMed's patient training data based on the information in the chapter.
C.4. *** Model Monitoring Simulator. Write a ModelMonitor class that simulates deployment monitoring. The monitor should:
- Accept baseline performance metrics (from the model card)
- Accept new performance measurements over time (simulated as a list of metric dictionaries)
- Detect drift: flag when any metric degrades by more than a configurable threshold
- Generate alerts with severity levels (info, warning, critical)
- Produce a monitoring report showing metrics over time and any detected drift
# Example usage:
# monitor = ModelMonitor(
# model_name="Patient Risk Predictor",
# baseline_metrics={"accuracy": 0.92, "f1_score": 0.88, "auc": 0.95},
# drift_threshold=0.05
# )
# monitor.add_measurement({"accuracy": 0.91, "f1_score": 0.87, "auc": 0.94})
# monitor.add_measurement({"accuracy": 0.88, "f1_score": 0.82, "auc": 0.90})
# print(monitor.generate_report())
C.5. *** Red Team Report Generator. Create a RedTeamReport dataclass that documents the results of a red-teaming exercise. Include fields for:
- System under test
- Red team composition
- Test date and scope
- List of attack scenarios tested (each with: description, result, severity, and recommendation)
- Overall risk assessment
- A generate_report() method
Create a red team report for VitraMed's clinical prediction model with at least five attack scenarios.
C.6. * *Integrated Documentation Pipeline. Create a function generate_documentation_suite(model_card: ModelCard, datasheet: DataSheet, monitor: ModelMonitor) -> str that takes a model card, a datasheet, and a model monitor and produces a unified documentation report. The report should include:
- The model card report
- The datasheet report
- A monitoring summary
- A cross-reference section that highlights discrepancies (e.g., the model card claims accuracy of 0.92 but monitoring shows current accuracy of 0.88)
This exercise connects the ModelCard (Chapter 29), a DataSheet (from C.3), and a ModelMonitor (from C.4) into the documentation pipeline described in the chapter.
Part D: Synthesis & Critical Thinking ***
These questions require you to integrate multiple concepts and think beyond the material presented.
D.1. The chapter presents model cards and datasheets as transparency tools. But transparency to whom? A model card written for a technical reviewer will be unintelligible to an affected community member. A datasheet written for regulators may not help an engineer improve the model. Write a 500-word analysis of the "audience problem" in AI documentation: Who should model cards be written for, and how should they be adapted for different audiences?
D.2. Section 29.5 describes red-teaming as an adversarial testing methodology. Critics argue that red-teaming is fundamentally limited because it tests for failures the red team can imagine -- but the most dangerous failures are the ones no one anticipated. Evaluate this critique. Is red-teaming valuable despite this limitation? What complementary approaches might address the "unknown unknowns" problem?
D.3. The chapter describes a documentation pipeline: datasheet (documenting data) -> quality audit (assessing data quality) -> lineage tracker (following data through processing) -> model card (documenting the model). In practice, this pipeline is rarely implemented end-to-end. Why? Identify at least three organizational barriers and propose mechanisms to overcome them.
D.4. Model cards document a model's characteristics at a point in time. But models and their contexts change. A model card generated at deployment becomes stale as the model drifts, the population changes, and new use cases emerge. Propose a framework for "living model cards" -- documentation that updates dynamically with monitoring data. What would this require technically and organizationally?
Part E: Research & Extension ****
These are open-ended projects for students seeking deeper engagement.
E.1. Model Card in the Wild. Locate a published model card from a technology company or open-source project (Google, Hugging Face, and others have published model cards for various systems). Evaluate the card against the framework from Section 29.2. What is documented well? What is missing? How would you improve it?
E.2. Datasheet Audit. Select a publicly available dataset from Kaggle, UCI Machine Learning Repository, or a government open data portal. Create a datasheet for the dataset using the Gebru et al. (2021) framework. Document what you can determine about the dataset's collection, composition, and limitations. Note what information is unavailable and explain why its absence is a problem.
E.3. Responsible AI Framework Comparison. Research responsible AI frameworks from at least four organizations (e.g., Microsoft, Google, OECD, EU AI Act, Singapore PDPC, IEEE). Write a 1,500-word comparative analysis evaluating: common principles, unique elements, enforcement mechanisms, and practical utility. Which framework would you recommend for a healthcare AI company, and why?
Solutions
Selected solutions are available in appendices/answers-to-selected.md.