GhadeerALbadani commited on
Commit
b71ebc3
·
verified ·
1 Parent(s): e9a5c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -7,10 +7,10 @@ MODEL_NAME = "GhadeerALbadani/mmbert-Multilingual_detection_of_hate_speech"
7
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
  model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
9
 
10
- labels = {
11
- 0: "Not Hate Speech",
12
- 1: "Hate Speech"
13
- }
14
 
15
  def predict(text):
16
 
@@ -24,9 +24,12 @@ def predict(text):
24
  with torch.no_grad():
25
  outputs = model(**inputs)
26
 
27
- prediction = torch.argmax(outputs.logits, dim=1).item()
28
 
29
- return labels[prediction]
 
 
 
30
 
31
  demo = gr.Interface(
32
  fn=predict,
 
7
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
  model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
9
 
10
+ labels = [
11
+ "Not Hate Speech",
12
+ "Hate Speech"
13
+ ]
14
 
15
  def predict(text):
16
 
 
24
  with torch.no_grad():
25
  outputs = model(**inputs)
26
 
27
+ probs = torch.nn.functional.softmax(outputs.logits, dim=1)[0]
28
 
29
+ return {
30
+ labels[0]: float(probs[0]),
31
+ labels[1]: float(probs[1])
32
+ }
33
 
34
  demo = gr.Interface(
35
  fn=predict,