Spaces:
Runtime error
Runtime error
Update agentic_classifier.py
Browse files- agentic_classifier.py +24 -32
agentic_classifier.py
CHANGED
@@ -36,39 +36,31 @@ def run_inference(df, INPUT, TASK, classifier, label_mapping, rev_map, task_labe
|
|
36 |
|
37 |
return inferences
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
50 |
-
# classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
51 |
-
# rev_map = {v: k for k, v in model.config.id2label.items()}
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
#
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# "ac_classifier": ("agentic", "communal"),
|
62 |
-
# }
|
63 |
-
# label_mapping = {
|
64 |
-
# "ac_classifier": {
|
65 |
-
# 0: "communal",
|
66 |
-
# 1: "agentic",
|
67 |
-
# }
|
68 |
-
# }
|
69 |
|
70 |
-
|
71 |
-
# df["per_ac"] = [i[0] for i in inferences]
|
72 |
-
# df["con_ac"] = [i[1] for i in inferences]
|
73 |
-
|
74 |
-
# return df
|
|
|
36 |
|
37 |
return inferences
|
38 |
|
39 |
+
def compute_agentic_communal(df,hallucination=False):
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained("emmatliu/language-agency-classifier")
|
41 |
+
model = AutoModelForSequenceClassification.from_pretrained("emmatliu/language-agency-classifier")
|
42 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
43 |
+
rev_map = {v: k for k, v in model.config.id2label.items()}
|
44 |
|
45 |
+
if hallucination:
|
46 |
+
INPUT = "hallucination"
|
47 |
+
else:
|
48 |
+
INPUT = "text"
|
|
|
|
|
|
|
49 |
|
50 |
+
TASK = "ac_classifier"
|
51 |
+
task_label_mapping = {
|
52 |
+
# Track percentage agentic / percentage agentic + percentage communal
|
53 |
+
"ac_classifier": ("agentic", "communal"),
|
54 |
+
}
|
55 |
+
label_mapping = {
|
56 |
+
"ac_classifier": {
|
57 |
+
0: "communal",
|
58 |
+
1: "agentic",
|
59 |
+
}
|
60 |
+
}
|
61 |
|
62 |
+
inferences = run_inference(df, INPUT, TASK, classifier, label_mapping, rev_map, task_label_mapping)
|
63 |
+
df["per_ac"] = [i[0] for i in inferences]
|
64 |
+
df["con_ac"] = [i[1] for i in inferences]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
return df
|
|
|
|
|
|
|
|