Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ class ToxicityDataset(Dataset):
|
|
63 |
|
64 |
# Based on user model selection, prepare Dataset and DataLoader
|
65 |
infer_dataset = ToxicityDataset(tweet_df, tokenizer, MAX_LENGTH)
|
66 |
-
infer_params = {"batch_size": INFER_BATCH_SIZE, "shuffle":
|
67 |
infer_loader = DataLoader(infer_dataset, **infer_params)
|
68 |
|
69 |
class BertClass(torch.nn.Module):
|
@@ -123,9 +123,10 @@ def inference():
|
|
123 |
final_outputs.extend(torch.sigmoid(outputs).cpu().detach().numpy().tolist())
|
124 |
return final_outputs, final_targets
|
125 |
|
|
|
126 |
prediction, targets = inference()
|
127 |
-
st.write(prediction)
|
128 |
|
|
|
129 |
best_preds = []
|
130 |
best_labels = []
|
131 |
for example in prediction:
|
@@ -135,7 +136,7 @@ for example in prediction:
|
|
135 |
best_preds.append(best_prediction)
|
136 |
best_labels.append(best_label)
|
137 |
|
138 |
-
st.write("
|
139 |
display_table = tweets_raw[["comment_text"]]
|
140 |
display_table["Toxicity Classification"] = best_labels
|
141 |
display_table["Probability"] = best_preds
|
|
|
63 |
|
64 |
# Based on user model selection, prepare Dataset and DataLoader
|
65 |
infer_dataset = ToxicityDataset(tweet_df, tokenizer, MAX_LENGTH)
|
66 |
+
infer_params = {"batch_size": INFER_BATCH_SIZE, "shuffle": True}
|
67 |
infer_loader = DataLoader(infer_dataset, **infer_params)
|
68 |
|
69 |
class BertClass(torch.nn.Module):
|
|
|
123 |
final_outputs.extend(torch.sigmoid(outputs).cpu().detach().numpy().tolist())
|
124 |
return final_outputs, final_targets
|
125 |
|
126 |
+
# Get predictions!
|
127 |
prediction, targets = inference()
|
|
|
128 |
|
129 |
+
# Format and present findings.
|
130 |
best_preds = []
|
131 |
best_labels = []
|
132 |
for example in prediction:
|
|
|
136 |
best_preds.append(best_prediction)
|
137 |
best_labels.append(best_label)
|
138 |
|
139 |
+
st.write("Toxicity Classification Result:")
|
140 |
display_table = tweets_raw[["comment_text"]]
|
141 |
display_table["Toxicity Classification"] = best_labels
|
142 |
display_table["Probability"] = best_preds
|