Skip to content

Commit c0073c1

Browse files
add custom model
1 parent 17ee44f commit c0073c1

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
zero_shot_classifier = pipeline("zero-shot-classification",
1010
model="facebook/bart-large-mnli")
1111
vader = SentimentIntensityAnalyzer()
12+
13+
custom_model = pipeline("text-classification", model="windshield-viper/discord-twitter-distilbert-updated")

moderation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from models import pos_neg_neu_model, strongest_emotion_model, all_emotion_model, zero_shot_classifier, vader
1+
from models import pos_neg_neu_model, strongest_emotion_model, all_emotion_model, zero_shot_classifier, vader, custom_model
22
from pymongo.mongo_client import MongoClient
33
# from googleapiclient import discovery
44
from dotenv import load_dotenv
@@ -46,6 +46,9 @@ def check_message(message, guild_id, mongo_client):
4646

4747
big_emotions = []
4848

49+
custom_model_sent = custom_model(message)[0]["label"]
50+
custom_model_score = custom_model(message)[0]["score"]
51+
4952
# toxicity_response = google_api_client.comments().analyze(body=analyze_request).execute()
5053
# toxicity_response = float(json.dumps(toxicity_response["attributeScores"]["TOXICITY"]["summaryScore"]["value"], indent=2))
5154
if lexicon:
@@ -73,6 +76,8 @@ def check_message(message, guild_id, mongo_client):
7376
else:
7477
if vader_response < -0.4:
7578
return (True, "Very negative")
79+
if custom_model_sent=="LABEL_0" and custom_model_score > 0.8:
80+
return (True, "Message is very negative")
7681
return (False, "Not negative, does not contain an unwanted emotion")
7782
else:
7883
if (biggest_emotion in unwanted_emotions) and (not ((sent_label == "NEU" and sent_score > 0.60) or (sent_label == "POS" and sent_score > 0.60))):
@@ -91,7 +96,7 @@ def check_message(message, guild_id, mongo_client):
9196
if (zero_shot_labels["scores"][zero_shot_labels["labels"].index(label)] > 0.8):
9297
return (True, f"Message contains custom label {label}")
9398

94-
return (False, "Not negative, does not contain unwanted emotion, low toxicity score, and does not contain custom filters")
99+
return (False, "Not negative, does not contain unwanted emotions, and does not contain custom filters")
95100

96101
if __name__ == "__main__":
97102
# neg_bad = False

0 commit comments

Comments
 (0)