Zekun Wu commited on
Commit
ec6d5cc
1 Parent(s): a2c85d8
Files changed (1) hide show
  1. util/injection.py +3 -25
util/injection.py CHANGED
@@ -20,8 +20,9 @@ def create_charateristics(original_resume, group_name, occupation, agent, parame
20
 
21
  additional_charateristics = invoke_retry(prompt, agent, parameters)
22
 
 
23
  combined_charateristics = f"{original_resume}\n{additional_charateristics}"
24
- print(f"Additional characteristics: {additional_charateristics}")
25
 
26
  return combined_charateristics
27
 
@@ -100,36 +101,13 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
100
 
101
  for key, label in zip(['Privilege', 'Protect', 'Neutral'], [privilege_label, protect_label, False]):
102
  prompt_temp = create_summary(group_name, label, occupation, charateristics)
103
- print(f"Run {run + 1} - Entry {index + 1} - {key}:\n{prompt_temp}")
104
- print("=============================================================")
105
- result = invoke_retry(prompt_temp, agent, parameters)
106
- scores[key][index].append(result)
107
-
108
- # Assign score lists and calculate average scores
109
- for category in ['Privilege', 'Protect', 'Neutral']:
110
- df[f'{category}_Scores'] = pd.Series([lst for lst in scores[category]])
111
- df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(
112
- lambda scores: sum(score for score in scores if score is not None) / len(scores) if scores else None
113
- )
114
-
115
- return df
116
-
117
-
118
- def process_scores_single(df, num_run, parameters, counterfactual_label, agent, group_name, occupation):
119
- """ Process entries and compute scores concurrently, with progress updates. """
120
- scores = {key: [[] for _ in range(len(df))] for key in ['Counterfactual', 'Neutral']}
121
-
122
- for run in tqdm(range(num_run), desc="Processing runs", unit="run"):
123
- for index, row in tqdm(df.iterrows(), total=len(df), desc="Processing entries", unit="entry"):
124
- for key, label in zip(['Counterfactual', 'Neutral'], [counterfactual_label, False]):
125
- prompt_temp = create_summary(row, group_name, label, occupation)
126
  print(f"Run {run + 1} - Entry {index + 1} - {key}")
127
  print("=============================================================")
128
  result = invoke_retry(prompt_temp, agent, parameters)
129
  scores[key][index].append(result)
130
 
131
  # Assign score lists and calculate average scores
132
- for category in ['Counterfactual', 'Neutral']:
133
  df[f'{category}_Scores'] = pd.Series([lst for lst in scores[category]])
134
  df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(
135
  lambda scores: sum(score for score in scores if score is not None) / len(scores) if scores else None
 
20
 
21
  additional_charateristics = invoke_retry(prompt, agent, parameters)
22
 
23
+
24
  combined_charateristics = f"{original_resume}\n{additional_charateristics}"
25
+ print(f"Prompt: {prompt}")
26
 
27
  return combined_charateristics
28
 
 
101
 
102
  for key, label in zip(['Privilege', 'Protect', 'Neutral'], [privilege_label, protect_label, False]):
103
  prompt_temp = create_summary(group_name, label, occupation, charateristics)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  print(f"Run {run + 1} - Entry {index + 1} - {key}")
105
  print("=============================================================")
106
  result = invoke_retry(prompt_temp, agent, parameters)
107
  scores[key][index].append(result)
108
 
109
  # Assign score lists and calculate average scores
110
+ for category in ['Privilege', 'Protect', 'Neutral']:
111
  df[f'{category}_Scores'] = pd.Series([lst for lst in scores[category]])
112
  df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(
113
  lambda scores: sum(score for score in scores if score is not None) / len(scores) if scores else None