mirror of
https://github.com/wassname/eliciting_suppressed_knowledge.git
synced 2026-09-09 11:21:56 +08:00
fixed
This commit is contained in:
+285
-37
@@ -478,7 +478,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 89,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -494,6 +494,19 @@
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Dataset({\n",
|
||||
" features: ['acts-mlp.down_proj', 'acts-self_attn', 'acts-mlp.up_proj', 'loss', 'logits', 'hidden_states', 'attention_mask', 'label', 'llm_ans', 'llm_log_prob_true', 'supr_amounts'],\n",
|
||||
" num_rows: 316\n",
|
||||
"})"
|
||||
]
|
||||
},
|
||||
"execution_count": 89,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
@@ -537,7 +550,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 90,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -547,18 +560,53 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 92,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'acts-mlp.down_proj': torch.Size([4, 90, 2048]),\n",
|
||||
" 'acts-self_attn': torch.Size([4, 90, 2048]),\n",
|
||||
" 'acts-mlp.up_proj': torch.Size([4, 90, 6144]),\n",
|
||||
" 'loss': torch.Size([]),\n",
|
||||
" 'logits': torch.Size([151936]),\n",
|
||||
" 'hidden_states': torch.Size([13, 90, 2048]),\n",
|
||||
" 'attention_mask': torch.Size([90]),\n",
|
||||
" 'label': torch.Size([]),\n",
|
||||
" 'llm_ans': torch.Size([2]),\n",
|
||||
" 'llm_log_prob_true': torch.Size([]),\n",
|
||||
" 'supr_amounts': torch.Size([13, 1, 2048])}"
|
||||
]
|
||||
},
|
||||
"execution_count": 92,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"{k: v.shape for k,v in ds_a2[0].items() if isinstance(v, torch.Tensor)}\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 93,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Dataset({\n",
|
||||
" features: ['acts-mlp.down_proj', 'acts-self_attn', 'acts-mlp.up_proj', 'loss', 'logits', 'hidden_states', 'attention_mask', 'label', 'llm_ans', 'llm_log_prob_true', 'supr_amounts'],\n",
|
||||
" num_rows: 316\n",
|
||||
"})"
|
||||
]
|
||||
},
|
||||
"execution_count": 93,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"ds_a2"
|
||||
]
|
||||
@@ -572,9 +620,20 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 94,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"72"
|
||||
]
|
||||
},
|
||||
"execution_count": 94,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"test_fraction = 0.2\n",
|
||||
"TRAIN_TEST_SPLIT = int(max_length * (1- test_fraction))\n",
|
||||
@@ -590,7 +649,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 95,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -607,7 +666,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 96,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -662,7 +721,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 97,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -673,7 +732,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 98,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -757,7 +816,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 99,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -768,7 +827,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 100,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -793,7 +852,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 101,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -822,7 +881,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 102,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -842,7 +901,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 103,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -854,7 +913,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 104,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -897,7 +956,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 105,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -908,7 +967,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 106,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -947,7 +1006,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 107,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -967,9 +1026,53 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['supr_amounts',\n",
|
||||
" 'hidden_states',\n",
|
||||
" 'acts-mlp.down_proj',\n",
|
||||
" 'acts-self_attn',\n",
|
||||
" 'acts-mlp.up_proj']"
|
||||
]
|
||||
},
|
||||
"execution_count": 131,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"X_cols = [\"supr_amounts\", \"hidden_states\",] + act_groups\n",
|
||||
"X_cols"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 155,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"datasets dict_keys(['supr_amounts', 'hidden_states', 'acts-mlp.down_proj', 'acts-self_attn', 'acts-mlp.up_proj', 'supressed_hs(-5)', 'supressed_hs(-1)', 'supressed_hs(-0.5)', 'supressed_hs(-0.1)', 'supressed_hs(-0.01)', 'supressed_hs(0)', 'supressed_hs(0.01)', 'supressed_hs(0.1)', 'supressed_hs(0.5)', 'supressed_hs(1)', 'supressed_hs(5)'])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('supressed_hs(-1)', 'magnitude(0.01)', 'min:'),\n",
|
||||
" ('supressed_hs(5)', 'magnitude(0.05)', 'first')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 155,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"datasets = {}\n",
|
||||
"\n",
|
||||
@@ -979,7 +1082,8 @@
|
||||
"\n",
|
||||
"# differen't suppressed activations\n",
|
||||
"for eps in [-5, -1, -0.5, -0.1, -0.01, -0, 0, 0.01, 0.1, 0.5, 1, 5]:\n",
|
||||
" datasets[f'supressed_hs_{eps}'] = lambda ds_a2: transform_hs_sup(ds_a2, eps)\n",
|
||||
" datasets[f'supressed_hs({eps})'] = lambda ds_a2: transform_hs_sup(ds_a2, eps)\n",
|
||||
"print('datasets', datasets.keys())\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# filters/transformers which we apply to all\n",
|
||||
@@ -991,7 +1095,7 @@
|
||||
"}\n",
|
||||
"# also diff magnitude filters\n",
|
||||
"for eps in [0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99]:\n",
|
||||
" filters[f'magnitude_{eps}'] = lambda x: filter_high_magnitude(x, eps)\n",
|
||||
" filters[f'magnitude({eps})'] = lambda x: filter_high_magnitude(x, eps)\n",
|
||||
"\n",
|
||||
"# # 2. token aggregators\n",
|
||||
"# token_level_funcs = {\n",
|
||||
@@ -1032,7 +1136,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 156,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -1051,7 +1155,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 157,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -1061,14 +1165,51 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 158,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ds"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "ce1b48247ff94eb58b6678138ba88a57",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
" 0%| | 0/1664 [00:00<?, ?it/s]"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[32m2025-05-04 15:07:38.842\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_supressed_hs_-1__magnitude_0.01__min_.json, skipping 0.57\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.843\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_supressed_hs_5__magnitude_0.05__first.json, skipping 0.59\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.844\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_acts-self_attn_magnitude_0.75__sum.json, skipping 0.62\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.844\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_hidden_states_entropy_flatten.json, skipping 0.65\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.845\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_supressed_hs_-0.01__magnitude_min_.json, skipping 0.52\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.845\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m9\u001b[0m - \u001b[1mAlready processed ../outputs/ds_at-QwenQwen3-1.7B-truthfulQA-bool-train-316-90_v2_acts-mlp.down_proj_magnitude_0.99__mean.json, skipping 0.70\u001b[0m\n",
|
||||
"\u001b[32m2025-05-04 15:07:38.846\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m15\u001b[0m - \u001b[1mProcessing supressed_hs(1), magnitude(0.75), min:\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"results = []\n",
|
||||
"for i, (ds_key, filter_key, token_key) in tqdm(enumerate(perms), total=len(perms)):\n",
|
||||
"\n",
|
||||
" name = f\"{ds_key}_{filter_key}_{token_key}\"\n",
|
||||
" name = f\"{ds_key}|{filter_key}|{token_key}\"\n",
|
||||
" res_f = output_path / f\"{acts_outfile.stem}_{ds_key}_{filter_key}_{token_key}.json\"\n",
|
||||
" res_f = sanitize_path(res_f)\n",
|
||||
" if res_f.exists():\n",
|
||||
@@ -1095,7 +1236,7 @@
|
||||
" # train the model\n",
|
||||
" y = ds_a2[\"label\"].to('cuda').float()\n",
|
||||
" score = train_linear_prob_on_dataset(X, y, name=f\"{ds_key}_{filter_key}_{token_key}\")\n",
|
||||
" results.append((ds_key, filter_key, token_key, score))\n",
|
||||
" # results.append((ds_key, filter_key, token_key, score))\n",
|
||||
"\n",
|
||||
" res = {\n",
|
||||
" \"ds_key\": ds_key,\n",
|
||||
@@ -1116,6 +1257,15 @@
|
||||
" clear_mem()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ds(ds_a2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -1140,7 +1290,18 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.6392156862745099"
|
||||
]
|
||||
},
|
||||
"execution_count": 162,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"X = ds_a2['llm_ans'].exp()\n",
|
||||
@@ -1153,7 +1314,7 @@
|
||||
"score = roc_auc_score(y_test, X_test).item()\n",
|
||||
"if score<0.5:\n",
|
||||
" score = 1-score\n",
|
||||
"results.append(('llm_ans', score))\n",
|
||||
"results.append(('llm_ans||', score))\n",
|
||||
"score"
|
||||
]
|
||||
},
|
||||
@@ -1161,7 +1322,18 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.8431372549019609"
|
||||
]
|
||||
},
|
||||
"execution_count": 163,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"X = torch.sigmoid(ds_a2['llm_log_prob_true']/10) # would be better to calibrate or logreg\n",
|
||||
"y = ds_a2['label']\n",
|
||||
@@ -1169,7 +1341,7 @@
|
||||
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_fraction, shuffle=False)\n",
|
||||
"\n",
|
||||
"score = roc_auc_score(y_test, X_test).item()\n",
|
||||
"results.append(('llm_log_prob_true', score))\n",
|
||||
"results.append(('llm_log_prob_true||', score))\n",
|
||||
"score"
|
||||
]
|
||||
},
|
||||
@@ -1191,7 +1363,52 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('supressed_hs(-1)|magnitude(0.01)|min:', np.float64(0.5725490196078431)),\n",
|
||||
" ('supressed_hs(5)|magnitude(0.05)|first', np.float64(0.5852941176470589)),\n",
|
||||
" ('acts-self_attn|magnitude(0.75)|sum', np.float64(0.6156862745098038)),\n",
|
||||
" ('hidden_states|entropy|flatten', 0.653921568627451),\n",
|
||||
" ('supressed_hs(-0.01)|magnitude|min:', np.float64(0.5156862745098039)),\n",
|
||||
" ('acts-mlp.down_proj|magnitude(0.99)|mean', np.float64(0.696078431372549)),\n",
|
||||
" ('llm_ans||', 0.6392156862745099),\n",
|
||||
" ('llm_log_prob_true||', 0.8431372549019609)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 164,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"results"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Qwen/Qwen3-1.7B Top results\n",
|
||||
"| | name | auroc |\n",
|
||||
"|---:|:----------------------------------------|---------:|\n",
|
||||
"| 7 | llm_log_prob_true|| | 0.843137 |\n",
|
||||
"| 5 | acts-mlp.down_proj|magnitude(0.99)|mean | 0.696078 |\n",
|
||||
"| 3 | hidden_states|entropy|flatten | 0.653922 |\n",
|
||||
"| 6 | llm_ans|| | 0.639216 |\n",
|
||||
"| 2 | acts-self_attn|magnitude(0.75)|sum | 0.615686 |\n",
|
||||
"| 1 | supressed_hs(5)|magnitude(0.05)|first | 0.585294 |\n",
|
||||
"| 0 | supressed_hs(-1)|magnitude(0.01)|min: | 0.572549 |\n",
|
||||
"| 4 | supressed_hs(-0.01)|magnitude|min: | 0.515686 |\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
@@ -1206,9 +1423,25 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"top reduction for each data type\n",
|
||||
"| data | name | auroc |\n",
|
||||
"|:-------------------|:----------------------------------------|---------:|\n",
|
||||
"| llm_log_prob_true | llm_log_prob_true|| | 0.843137 |\n",
|
||||
"| acts-mlp.down_proj | acts-mlp.down_proj|magnitude(0.99)|mean | 0.696078 |\n",
|
||||
"| hidden_states | hidden_states|entropy|flatten | 0.653922 |\n",
|
||||
"| llm_ans | llm_ans|| | 0.639216 |\n",
|
||||
"| acts-self_attn | acts-self_attn|magnitude(0.75)|sum | 0.615686 |\n",
|
||||
"| supressed_hs | supressed_hs(5)|magnitude(0.05)|first | 0.585294 |\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df['data'] = df['name'].apply(lambda x: x.split()[0])\n",
|
||||
"df['data'] = df['name'].apply(lambda x: x.split('|')[0].split('(')[0])\n",
|
||||
"# FIXME this is not keeping name and auroc paired\n",
|
||||
"# df['reduction'] = df['name'].apply(lambda x: x.split()[-1])\n",
|
||||
"df2 = df.groupby('data').apply(lambda g: g.sort_values(\"auroc\", ascending=False).iloc[0], include_groups=False).sort_values(\"auroc\", ascending=False)\n",
|
||||
@@ -1220,7 +1453,22 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "KeyError",
|
||||
"evalue": "\"['acts-mlp.up_proj'] not in index\"",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[169], line 9\u001b[0m\n\u001b[1;32m 6\u001b[0m sns\u001b[38;5;241m.\u001b[39mset_theme()\n\u001b[1;32m 8\u001b[0m c \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mllm_ans\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mllm_log_prob_true\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhidden_states\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msupressed_hs\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m+\u001b[39m act_groups\n\u001b[0;32m----> 9\u001b[0m df3 \u001b[38;5;241m=\u001b[39m \u001b[43mdf2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mT\u001b[49m\u001b[43m[\u001b[49m\u001b[43mc\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39mrename(columns\u001b[38;5;241m=\u001b[39m{\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mllm_ans\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mLLM Answer\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 11\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mllm_log_prob_true\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mLLM Probability\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 12\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhidden_states\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHidden States\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124macts\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mActivations: up_proj\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 14\u001b[0m \u001b[38;5;66;03m# 'logits': 'Logits',\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msupressed_hs\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSupressed Hidden States\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 16\u001b[0m })\u001b[38;5;241m.\u001b[39mT\u001b[38;5;241m.\u001b[39msort_values(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mauroc\u001b[39m\u001b[38;5;124m\"\u001b[39m, ascending\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m# df3.plot.barh()\u001b[39;00m\n\u001b[1;32m 18\u001b[0m sns\u001b[38;5;241m.\u001b[39mbarplot(data\u001b[38;5;241m=\u001b[39mdf3, x\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mauroc\u001b[39m\u001b[38;5;124m'\u001b[39m, y\u001b[38;5;241m=\u001b[39mdf3\u001b[38;5;241m.\u001b[39mindex)\n",
|
||||
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/2025/eliciting_suppressed_knowledge/.venv/lib/python3.10/site-packages/pandas/core/frame.py:4108\u001b[0m, in \u001b[0;36mDataFrame.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 4106\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_iterator(key):\n\u001b[1;32m 4107\u001b[0m key \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(key)\n\u001b[0;32m-> 4108\u001b[0m indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_indexer_strict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcolumns\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m[\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m 4110\u001b[0m \u001b[38;5;66;03m# take() does not accept boolean indexers\u001b[39;00m\n\u001b[1;32m 4111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(indexer, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdtype\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mbool\u001b[39m:\n",
|
||||
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/2025/eliciting_suppressed_knowledge/.venv/lib/python3.10/site-packages/pandas/core/indexes/base.py:6200\u001b[0m, in \u001b[0;36mIndex._get_indexer_strict\u001b[0;34m(self, key, axis_name)\u001b[0m\n\u001b[1;32m 6197\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 6198\u001b[0m keyarr, indexer, new_indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_reindex_non_unique(keyarr)\n\u001b[0;32m-> 6200\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_raise_if_missing\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkeyarr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindexer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis_name\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 6202\u001b[0m keyarr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtake(indexer)\n\u001b[1;32m 6203\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(key, Index):\n\u001b[1;32m 6204\u001b[0m \u001b[38;5;66;03m# GH 42790 - Preserve name from an Index\u001b[39;00m\n",
|
||||
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/2025/eliciting_suppressed_knowledge/.venv/lib/python3.10/site-packages/pandas/core/indexes/base.py:6252\u001b[0m, in \u001b[0;36mIndex._raise_if_missing\u001b[0;34m(self, key, indexer, axis_name)\u001b[0m\n\u001b[1;32m 6249\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNone of [\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mkey\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m] are in the [\u001b[39m\u001b[38;5;132;01m{\u001b[39;00maxis_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m]\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6251\u001b[0m not_found \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(ensure_index(key)[missing_mask\u001b[38;5;241m.\u001b[39mnonzero()[\u001b[38;5;241m0\u001b[39m]]\u001b[38;5;241m.\u001b[39munique())\n\u001b[0;32m-> 6252\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mnot_found\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not in index\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
||||
"\u001b[0;31mKeyError\u001b[0m: \"['acts-mlp.up_proj'] not in index\""
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# plot it\n",
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user