MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to LLMs in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode