Use the Detoxify class to load a model and predict toxicity scores for a single string or a list of strings.
Supported model names include:
original (BERT-based)unbiased (RoBERTa-based)multilingual (XLM-RoBERTa-based)original-small (Albert-based)unbiased-small (Albert-based)
You can also specify a device (e.g., 'cuda') to allocate the model to a specific hardware device.
from detoxify import Detoxify
# Predict on a single string
results = Detoxify('original').predict('example text')
# Predict on a list of strings
results = Detoxify('unbiased').predict(['example text 1','example text 2'])
# Use the multilingual model
results = Detoxify('multilingual').predict(['example text','exemple de texte'])
# Specify a device (e.g., GPU)
model = Detoxify('original', device='cuda')
from detoxify import Detoxify
# each model takes in either a string or a list of strings
results = Detoxify('original').predict('example text')
results = Detoxify('unbiased').predict(['example text 1','example text 2'])
results = Detoxify('multilingual').predict(['example text','exemple de texte','texto de ejemplo','testo di esempio','texto de exemplo','örnek metin','пример текста'])
# to specify the device the model will be allocated on (defaults to cpu), accepts any torch.device input
model = Detoxify('original', device='cuda')
# optional to display results nicely (will need to pip install pandas)
import pandas as pd
print(pd.DataFrame(results, index=input_text).round(5))