refresh
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
# "👍", "👎", "❤", "🔥", "🥰", "👏", "😁",
|
||||
# "🤔", "🤯", "😱", "🤬", "😢", "🎉", "🤩",
|
||||
# "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱",
|
||||
# "🥴", "😍", "🐳", "❤🔥", "🌚", "🌭", "💯",
|
||||
# "🤣", "⚡", "🍌", "🏆", "💔", "🤨", "😐",
|
||||
# "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭",
|
||||
# "🤓", "👻", "👨💻", "👀", "🎃", "🙈", "😇",
|
||||
# "😨", "🤝", "✍", "🤗", "🫡", "🎅", "🎄",
|
||||
# "☃", "💅", "🤪", "🗿", "🆒", "💘", "🙉",
|
||||
# "🦄", "😘", "💊", "🙊", "😎", "👾", "🤷♂",
|
||||
# "🤷", "🤷♀", "😡"
|
||||
|
||||
toxic_reactions = {
|
||||
"071": "🕊",
|
||||
"073": "👀",
|
||||
"075": "🙈",
|
||||
"077": "🙊",
|
||||
"079": "🙏",
|
||||
"081": "🤔",
|
||||
"083": "😐",
|
||||
"085": "🤨",
|
||||
"087": "🥴",
|
||||
"089": "🤯",
|
||||
"091": "😢",
|
||||
"093": "😭",
|
||||
"095": "😨",
|
||||
"097": "😱",
|
||||
"099": "🤬"
|
||||
}
|
||||
|
||||
grads = list(toxic_reactions.keys())
|
||||
grads.sort()
|
||||
grads.reverse()
|
||||
|
||||
abusive_reactions = {
|
||||
"085": "🫡",
|
||||
"088": "💅",
|
||||
"091": "🤷♀",
|
||||
"094": "👾",
|
||||
"097": "👻",
|
||||
"099": "😈"
|
||||
}
|
||||
|
||||
abusive_grads = list(abusive_reactions.keys())
|
||||
abusive_grads.sort()
|
||||
abusive_grads.reverse()
|
||||
|
||||
def get_toxic_reply(tx):
|
||||
percentage = tx * 100
|
||||
for key in grads:
|
||||
if percentage > int(key):
|
||||
return toxic_reactions[key]
|
||||
|
||||
|
||||
def get_abusive_reply(tx):
|
||||
percentage = tx * 100
|
||||
for key in abusive_grads:
|
||||
if percentage > int(key):
|
||||
return abusive_reactions[key]
|
@@ -1,31 +0,0 @@
|
||||
import torch
|
||||
from transformers import AutoTokenizer, \
|
||||
AutoModelForSequenceClassification
|
||||
|
||||
tiny_tox_model_path = 'cointegrated/rubert-tiny-toxicity'
|
||||
tiny_tox_tokenizer = AutoTokenizer.from_pretrained(tiny_tox_model_path)
|
||||
tiny_tox_model = AutoModelForSequenceClassification.from_pretrained(
|
||||
tiny_tox_model_path)
|
||||
|
||||
|
||||
# if torch.cuda.is_available():
|
||||
# model.cuda()
|
||||
|
||||
|
||||
def text2toxicity(text, aggregate=True) -> float:
|
||||
""" Calculate toxicity of a text (if aggregate=True)
|
||||
or a vector of toxicity aspects (if aggregate=False)"""
|
||||
proba = 0.0
|
||||
with torch.no_grad():
|
||||
inputs = tiny_tox_tokenizer(
|
||||
text.lower(),
|
||||
return_tensors='pt',
|
||||
truncation=True,
|
||||
padding=True
|
||||
).to(tiny_tox_model.device)
|
||||
proba = torch.sigmoid(tiny_tox_model(**inputs).logits).cpu().numpy()
|
||||
if isinstance(text, str):
|
||||
proba = proba[0]
|
||||
if aggregate:
|
||||
return 1 - proba.T[0] * (1 - proba.T[-1])
|
||||
return float(proba)
|
Reference in New Issue
Block a user