Downloads · 30 days
12
13% of all-time downloads
Bombek1/toxic-bert-litert
toxic-bert-litert is a machine learning model from Bombek1. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for litert. The card lists the license as apache-2.0.
This is a LiteRT (formerly TensorFlow Lite) export of unitary/toxic-bert.
Downloads · 30 days
12
13% of all-time downloads
All-time downloads
96
Public
Repo size
437 MB
Likes
0
Public
Click a slice to open those files.
.tflite437 MB · 100%
From the Hugging Face model README
This is a LiteRT (formerly TensorFlow Lite) export of unitary/toxic-bert.
It is optimized for mobile and edge inference (Android/iOS/Embedded).
| Attribute | Value |
|---|---|
| Task | Toxicity Detection |
| Format | .tflite (Float32) |
| File Size | 417.1 MB |
| Input Length | 128 tokens |
| Output Dim | 6 |
import numpy as np
from ai_edge_litert.interpreter import Interpreter
from transformers import AutoTokenizer
model_path = "unitary_toxic-bert.tflite"
interpreter = Interpreter(model_path=model_path)
interpreter.allocate_tensors()
tokenizer = AutoTokenizer.from_pretrained("unitary/toxic-bert")
labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
def predict(text):
# Tokenize
inputs = tokenizer(text, max_length=128, padding="max_length", truncation=True, return_tensors="np")
# Set inputs
input_details = interpreter.get_input_details()
interpreter.set_tensor(input_details[0]['index'], inputs['input_ids'].astype(np.int64))
interpreter.set_tensor(input_details[1]['index'], inputs['attention_mask'].astype(np.int64))
# Run inference
interpreter.invoke()
# Get output (Logits)
output_details = interpreter.get_output_details()
logits = interpreter.get_tensor(output_details[0]['index'])[0]
# Softmax to get probabilities
probs = np.exp(logits) / np.sum(np.exp(logits))
# Get top label
top_idx = np.argmax(probs)
return labels[top_idx], probs[top_idx]
label, confidence = predict("This is amazing!")
print(f"Result: {label} ({confidence:.2f})")
Converted by Bombek1 using litert-torch