# AI and ML ethics and safety

ML has the potential to transform society in many meaningful ways,
either positively or negatively. It's critical to consider the ethical
implications of your models and the systems they're a part of.
Your ML projects should benefit society. They shouldn't cause harm or be susceptible to misuse. They shouldn't perpetuate, reinforce, or exacerbate biases or prejudices. They shouldn't collect or use personal data irresponsibly.

<br />

## Google's AI principles

Google advocates developing ML and AI applications that adhere to its
[Responsible AI principles](https://ai.google/responsibility/principles/).

Beyond adhering to responsible AI principles, aim to develop systems
that incorporate the following:

- Fairness
- Privacy
- Transparency
- Safety

### Fairness

Avoid creating or reinforcing unfair
[bias](https://developers.google.com/machine-learning/glossary#bias-ethicsfairness).
Models exhibit bias when their
training data has some of the following characteristics:

- Doesn't reflect the real-world population of
  their users.

- Preserves biased decisions or outcomes, for example, criminal justice
  decisions like incarceration times.

- Uses features with more predictive power for certain groups of users.

The previous examples are just some ways models become biased. Understanding
your data thoroughly is critical for uncovering and resolving any potential
biases it contains. The first step for developing fair models is verifying the
training data accurately reflects the distribution of your users. The following
are further practices to help create fair models:

- Identify underrepresented groups in evaluation datasets or groups that might
  experience worse model quality compared to other groups. You might need to
  oversample a subgroup of your users to increase their presence in the
  training data.

- Use
  [golden datasets](https://developers.google.com/machine-learning/glossary#golden-dataset)
  (also known as benchmark datasets) to validate the model against fairness
  issues and detect implicit bias.

- Avoid including sensitive features in datasets, like gender or ethnicity.

- Avoid including features with little empirical or explanatory power, but
  especially in sensitive contexts where the trained model is used to perform
  high-impact tasks in areas such as healthcare, finance, education,
  employment, and so forth. For example, in a model for approving home loans,
  don't include names in the training data. Not only is an applicant's name
  irrelevant to the prediction task, but leaving such an irrelevant feature
  in the dataset also has the potential to create implicit bias or
  allocative harms. For instance, the model might correlate male names with
  a higher probability for repayment, or vice versa.

- Measure potential adverse impact a model's predictions might have on
  particular groups, and consider intentional bias correction techniques if
  you find adverse impact in a sensitive context.

### Privacy

Incorporate privacy design principles from the beginning.

The following are privacy related laws and policies to be aware of and
adhere to:

- [European Union's Digital Markets Act (DMA)](https://wikipedia.org/wiki/Digital_Markets_Act)
  for consent to share or use personal data.

- [European Union GDPR](https://wikipedia.org/wiki/General_Data_Protection_Regulation) laws.

Moreover, be sure to remove all personally identifiable information (PII) from
datasets and confirm your model and data repositories are set up with the right
permissions, for example, not world-readable.


### Transparency

Be accountable to people. For example, make it easy for others to
understand what your model does, how it does it, and why it does it.

[Model cards](https://modelcards.withgoogle.com/face-detection)

provide a template to document your model and create transparency artifacts.

### Safety

Design models to operate safely in adversarial conditions. For example, test
your model with potential hostile inputs to confirm your model is secure.
Furthermore, check for potential failure conditions. Teams typically use
specially designed datasets to test their models with inputs or conditions that
caused the model to fail in the past.

### Check Your Understanding

You're developing a model to quickly approve auto loans. What ethical implications should you consider? Does the model perpetuate existing biases or stereotypes? Correct. Models should be trained on high-quality datasets that have been inspected for potential implicit biases or prejudices. Does the model serve predictions with low-enough latency? Can the model be deployed to devices, like phones?

Always consider the broader social contexts your models operate within. Work to
be sure your handling of sensitive data doesn't violate privacy issues,
perpetuate bias, or infringe on someone else's intellectual property.