Get startedGet started for free

Checking toxicity

You work at a social media company and need to evaluate the comments that are being left on the platform to ensure users are respecting the code of conduct.

Your task is to carefully assess the toxicity level of comments of user_1 and user_2.

The toxicity metric has been loaded for you as toxicity_metric.

This exercise is part of the course

Introduction to LLMs in Python

View Course

Exercise instructions

  • Calculate the individual toxicity of each sequence.
  • Calculate the the maximum toxicity.
  • Calculate the toxicity ratio per comment.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the individual toxicities
toxicity_1 = toxicity_metric.compute(predictions=____)
toxicity_2 = toxicity_metric.compute(predictions=____)
print("Toxicities (user_1):", toxicity_1['toxicity'])
print("Toxicities (user_2): ", toxicity_2['toxicity'])

# Calculate the maximum toxicities
toxicity_1_max = toxicity_metric.compute(____)
toxicity_2_max = toxicity_metric.compute(____)
print("Maximum toxicity (user_1):", toxicity_1_max['max_toxicity'])
print("Maximum toxicity (user_2): ", toxicity_2_max['max_toxicity'])

# Calculate the toxicity ratios
toxicity_1_ratio = ____(____)
toxicity_2_ratio = ____(____)
print("Toxicity ratio (user_1):", toxicity_1_ratio['toxicity_ratio'])
print("Toxicity ratio (user_2): ", toxicity_2_ratio['toxicity_ratio'])
Edit and Run Code