Update training code
Browse files- app.py +1 -1
- train_abuse_model.py +12 -2
app.py
CHANGED
@@ -4,7 +4,7 @@ import subprocess
|
|
4 |
def run_training():
|
5 |
try:
|
6 |
# Run train.py using subprocess and capture output
|
7 |
-
result = subprocess.run(["python", "
|
8 |
# Return stdout if success, otherwise stderr
|
9 |
return result.stdout if result.returncode == 0 else f"Error:\n{result.stderr}"
|
10 |
except Exception as e:
|
|
|
4 |
def run_training():
|
5 |
try:
|
6 |
# Run train.py using subprocess and capture output
|
7 |
+
result = subprocess.run(["python", "train_abuse_model.py"], capture_output=True, text=True)
|
8 |
# Return stdout if success, otherwise stderr
|
9 |
return result.stdout if result.returncode == 0 else f"Error:\n{result.stderr}"
|
10 |
except Exception as e:
|
train_abuse_model.py
CHANGED
@@ -11,6 +11,9 @@ from sklearn.metrics import classification_report, precision_recall_fscore_suppo
|
|
11 |
|
12 |
from torch.utils.data import Dataset
|
13 |
|
|
|
|
|
|
|
14 |
# Hugging Face transformers
|
15 |
from transformers import (
|
16 |
AutoTokenizer,
|
@@ -22,6 +25,7 @@ from transformers import (
|
|
22 |
TrainingArguments
|
23 |
)
|
24 |
|
|
|
25 |
# Check for GPU availability
|
26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
27 |
|
@@ -125,8 +129,14 @@ def evaluate_model_with_thresholds(trainer, test_dataset):
|
|
125 |
"pred_labels": final_pred_str
|
126 |
}
|
127 |
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
# Define text and label columns
|
132 |
text_column = "post_body"
|
|
|
11 |
|
12 |
from torch.utils.data import Dataset
|
13 |
|
14 |
+
# Hugging Face Hub
|
15 |
+
from huggingface_hub import hf_hub_download
|
16 |
+
|
17 |
# Hugging Face transformers
|
18 |
from transformers import (
|
19 |
AutoTokenizer,
|
|
|
25 |
TrainingArguments
|
26 |
)
|
27 |
|
28 |
+
|
29 |
# Check for GPU availability
|
30 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
31 |
|
|
|
129 |
"pred_labels": final_pred_str
|
130 |
}
|
131 |
|
132 |
+
|
133 |
+
# Load dataset from Hugging Face Hub
|
134 |
+
path = hf_hub_download(
|
135 |
+
repo_id="rshakked/abusive-relashionship-stories",
|
136 |
+
filename="Abusive Relationship Stories - Technion & MSF.xlsx",
|
137 |
+
repo_type="dataset"
|
138 |
+
)
|
139 |
+
df = pd.read_excel(path)
|
140 |
|
141 |
# Define text and label columns
|
142 |
text_column = "post_body"
|