The model is automatically loaded in a hosted inference API, where users can test it in the UI of hugging face. We just need to add a detailed description (code and text) on what is the model? and how to use the model.
# Use a pipeline as a high-level helper
from transformers import pipeline
sentiment_task = pipeline("text-classification", model="tattle-admin/july22-xlmtwtroberta-da-multi")
sentiment_task("Use Uli to redact slurs and abusive content, archive problematic content, and collectively push back against online gender based violence")
# LABEL MEANING - LABEL_0 = None and LABEL_1 = Hate
Full classification example
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import numpy as np
from scipy.special import softmax
tokenizer = AutoTokenizer.from_pretrained("tattle-admin/july22-xlmtwtroberta-da-multi")
model = AutoModelForSequenceClassification.from_pretrained("tattle-admin/july22-xlmtwtroberta-da-multi")
label_map = {
0: 'None',
1: 'Hate'
}
def preprocess(text):
new_text = []
for t in text.split(" "):
t = '@user' if t.startswith('@') and len(t) > 1 else t
t = 'http' if t.startswith('http') else t
new_text.append(t)
return " ".join(new_text)
text = "Use Uli to redact slurs and abusive content, archive problematic content, and collectively push back against online gender based violence"
clean_text = preprocess(text)
encoded_input = tokenizer(clean_text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
# Print labels and scores
ranking = np.argsort(scores)
ranking = ranking[::-1]
for i in range(scores.shape[0]):
l = label_map[ranking[i]]
s = scores[ranking[i]]
print(f"{i+1}) {l} {np.round(float(s), 4)}")
# LABEL MEANING - LABEL_0 = None and LABEL_1 = Hate
This is the ogbv-ml-rest model loaded on hugging face - https://huggingface.co/tattle-admin/july22-xlmtwtroberta-da-multi
The model is automatically loaded in a hosted inference API, where users can test it in the UI of hugging face. We just need to add a detailed description (code and text) on what is the model? and how to use the model.
I have written the code part of it.
This is a good example of how a
text classification
model should look on hugging face - https://huggingface.co/cardiffnlp/twitter-roberta-base-sentiment-latestCode Example
This is a colab notebook where the code is available if someone wants to test it out - https://colab.research.google.com/drive/1vKuIkbOrBcGRKcKQAcg-67vV1lmZBOQE?usp=sharing
Example Pipeline
Full classification example
Output