Ariel Hsieh commited on
Commit
9ab46c1
1 Parent(s): d8d9ab4
Files changed (1) hide show
  1. app.py +35 -7
app.py CHANGED
@@ -21,16 +21,44 @@ st.title("Toxic Tweets")
21
  tokenizer = AutoTokenizer.from_pretrained("Ariel8/toxic-tweets-classification")
22
  model = AutoModelForSequenceClassification.from_pretrained("Ariel8/toxic-tweets-classification")
23
 
24
- X_train = ["BlackKite being a faggot"]
 
 
 
 
 
 
 
 
 
 
 
25
  batch = tokenizer(X_train, truncation=True, padding='max_length', return_tensors="pt")
26
  labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
27
 
28
- with torch.no_grad():
29
- outputs = model(**batch)
30
- predictions = torch.sigmoid(outputs.logits)*100
31
- probs = predictions[0].tolist()
32
- for i in range(len(probs)):
33
- st.write(f"{labels[i]}: {round(probs[i], 3)}%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # if model == "roberta-large-mnli":
36
  # #1
 
21
  tokenizer = AutoTokenizer.from_pretrained("Ariel8/toxic-tweets-classification")
22
  model = AutoModelForSequenceClassification.from_pretrained("Ariel8/toxic-tweets-classification")
23
 
24
+ tweets = ["BlackKite being a faggot",
25
+ "Yo bitch Ja Rule is more succesful then you'll ever be whats up with you and hating you sad mofuckas...i should bitch slap ur pethedic white faces and get you to kiss my ass you guys sicken me. Ja rule is about pride in da music man. dont diss that shit on him. and nothin is wrong bein like tupac he was a brother too...fuckin white boys get things right next time.,",
26
+ ":Dear god this site is horrible.",
27
+ "I think its crap that the link to roggenbier is to this article. Somebody that knows how to do things should change it.",
28
+ ":::::I have added more wikilinks to my sections and included more secondary sources as you suggested. For all the citations under human disease section, I went through them and exchanged review articles for the primary sources. Thanks again for all your input!",
29
+ "DJ Robinson is gay as hell! he sucks his dick so much!!!!!",
30
+ "I WILL BURN YOU TO HELL IF YOU REVOKE MY TALK PAGE ACCESS!!!!!!!!!!!!!",
31
+ "um, taking a shot here... Um lets say Three separate people whos wills are to each other.",
32
+ "How dare you vandalize that page about the HMS Beagle! Don't vandalize again, demon!",
33
+ ":Thanks for the comment about Wiki-defenderness. I like that one. I usually wikiling Wiki-defender. I agree that at first he was somewhat innocent but now have my doubts as he is being really agressive about the whole matter."]
34
+
35
+
36
  batch = tokenizer(X_train, truncation=True, padding='max_length', return_tensors="pt")
37
  labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
38
 
39
+ results = []
40
+ for b in batch:
41
+ with torch.no_grad():
42
+ outputs = model(**b)
43
+ predictions = torch.sigmoid(outputs.logits)*100
44
+ probs = predictions[0].tolist()
45
+ # for i in range(len(probs)):
46
+ # st.write(f"{labels[i]}: {round(probs[i], 3)}%")
47
+ results.append(probs)
48
+
49
+ # main_class = []
50
+ # toxic_type = []
51
+ for i in range(len(tweets)):
52
+ first_max = max(results[i])
53
+ fm_index = results[i].index(first_max)
54
+ second_max = max(results[i][2:])
55
+ sm_index = results[i].index(second_max)
56
+ #main_class.append((labels[fm_index],first_max))
57
+ #toxic_type.append((labels[sm_index],second_max))
58
+ d = {'tweet':[tweets[i]],'Main Classification':[labels[fm_index]],'Score':[first_max],
59
+ 'Toxicity Type':[labels[sm_index]],'Toxicity Score':[second_max]}
60
+ dataframe = pd.DataFrame(data=d)
61
+ st.table(dataframe)
62
 
63
  # if model == "roberta-large-mnli":
64
  # #1