Spaces:
Running
Running
Zekun Wu
commited on
Commit
•
c2ac8ae
1
Parent(s):
e845a55
update
Browse files- util/injection.py +24 -1
util/injection.py
CHANGED
@@ -124,8 +124,31 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
|
|
124 |
|
125 |
print(f"Scores: {scores}")
|
126 |
|
127 |
-
for category in ['Privilege_characteristics', 'Privilege_normal','Protect_characteristics', 'Protect_normal',
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
df[f'{category}_Scores'] = pd.Series([lst if isinstance(lst, list) else [] for lst in scores[category]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(calculate_avg_score)
|
130 |
|
|
|
|
|
|
|
131 |
return df
|
|
|
124 |
|
125 |
print(f"Scores: {scores}")
|
126 |
|
127 |
+
for category in ['Privilege_characteristics', 'Privilege_normal', 'Protect_characteristics', 'Protect_normal',
|
128 |
+
'Neutral_characteristics', 'Neutral_normal']:
|
129 |
+
# Debug: Print the scores for the current category
|
130 |
+
print(f"Processing category: {category}")
|
131 |
+
print(f"Scores: {scores[category]}")
|
132 |
+
|
133 |
+
# Ensure the scores are lists
|
134 |
df[f'{category}_Scores'] = pd.Series([lst if isinstance(lst, list) else [] for lst in scores[category]])
|
135 |
+
|
136 |
+
# Debug: Check the Series after assignment
|
137 |
+
print(f"Series for {category}_Scores:\n{df[f'{category}_Scores']}")
|
138 |
+
|
139 |
+
# Calculate the average score with additional debug info
|
140 |
+
def calculate_avg_score(score_list):
|
141 |
+
if isinstance(score_list, list) and score_list:
|
142 |
+
valid_scores = [score for score in score_list if score is not None]
|
143 |
+
if valid_scores:
|
144 |
+
avg_score = sum(valid_scores) / len(valid_scores)
|
145 |
+
print(f"Valid scores: {valid_scores}, Average score: {avg_score}")
|
146 |
+
return avg_score
|
147 |
+
return None
|
148 |
+
|
149 |
df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(calculate_avg_score)
|
150 |
|
151 |
+
# Debug: Print the calculated average scores
|
152 |
+
print(f"Average scores for {category}:\n{df[f'{category}_Avg_Score']}")
|
153 |
+
|
154 |
return df
|