Skip to content

Commit

Permalink
fix adv debiasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Surya Dutta committed Nov 27, 2019
1 parent 231d5ff commit fca62b8
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 358 deletions.
393 changes: 120 additions & 273 deletions notebooks/Adversarial Debias Training.ipynb

Large diffs are not rendered by default.

96 changes: 76 additions & 20 deletions notebooks/Script Tester.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,70 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from importlib import reload\n",
"import sys\n",
"\n",
"src_path = '../src' # change as needed\n",
"sys.path.insert(0,src_path)"
"sys.path.insert(0,src_path)\n",
"\n",
"max_length = 128"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:absl:Using /tmp/tfhub_modules to cache modules.\n",
"100%|██████████| 397080/397080 [02:03<00:00, 3212.44it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" tag cat occurences\n",
"0 B-MISC 0 800\n",
"1 I-LOC 1 328160\n",
"2 I-MISC 2 139600\n",
"3 I-ORG 3 237760\n",
"4 I-PER 4 977800\n",
"5 O 5 6661880\n",
"6 [nerCLS] 6 397080\n",
"7 [nerPAD] 7 39623065\n",
"8 [nerSEP] 8 397080\n",
"9 [nerX] 9 2063015\n",
"\n",
" tag cat occurences\n",
"0 AFRICAN-AMERICAN 0 436788\n",
"1 EUROPEAN 1 208467\n",
"2 [raceCLS] 2 397080\n",
"3 [racePAD] 3 39623065\n",
"4 [raceSEP] 4 397080\n",
"5 [raceX] 5 9763760\n",
"\n",
" tag cat occurences\n",
"0 FEMALE 0 367299\n",
"1 MALE 1 277956\n",
"2 [genderCLS] 2 397080\n",
"3 [genderPAD] 3 39623065\n",
"4 [genderSEP] 4 397080\n",
"5 [genderX] 5 9763760\n",
"\n"
]
}
],
"source": [
"import data_generator;reload(data_generator)\n",
"\n",
"#Start session\n",
"max_length = 128\n",
"\n",
"train_data, val_data, test_data = data_generator.GetData(max_length)"
]
},
Expand All @@ -37,25 +80,31 @@
"import tensorflow as tf\n",
"tf.logging.set_verbosity(tf.logging.ERROR)\n",
"import model_utils; reload(model_utils)\n",
"\n",
"adam_customized = tf.keras.optimizers.Adam(lr=0.001, beta_1=0.91, beta_2=0.999, epsilon=None, decay=0.1, amsgrad=False)\n",
" \n",
"config = tf.ConfigProto()\n",
"config.gpu_options.allow_growth = True\n",
"sess = tf.Session(config=config)\n",
"\n",
"model = model_utils.NER()\n",
"model = model_utils.NER(max_length)\n",
" \n",
"model.generate(max_length, train_layers=4, optimizer = adam_customized, debias=False, debiasWeight=0.95)\n",
"\n",
"# Instantiate variables\n",
"model_utils.initialize_vars(sess)\n",
"\n",
"model.generate(bert_train_layers=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"model.fit(\n",
" train_data, \n",
" sess,\n",
" train_data,\n",
" val_data,\n",
" epochs=8,\n",
" batch_size=32\n",
" batch_size=32,\n",
" debias=True\n",
")"
]
},
Expand All @@ -65,7 +114,7 @@
"metadata": {},
"outputs": [],
"source": [
"cm = model.score(test_data)"
"bias = model.getBiasedPValues(test_data, num_iterations=1000)"
]
},
{
Expand All @@ -74,7 +123,7 @@
"metadata": {},
"outputs": [],
"source": [
"bias = model.getBiasedPValues(test_data, num_iterations=10000)"
"bias"
]
},
{
Expand All @@ -83,9 +132,16 @@
"metadata": {},
"outputs": [],
"source": [
"bias"
"sess.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file modified src/__pycache__/data_generator.cpython-37.pyc
Binary file not shown.
Binary file modified src/__pycache__/model_utils.cpython-37.pyc
Binary file not shown.
Binary file modified src/__pycache__/token_generator.cpython-37.pyc
Binary file not shown.
Loading

0 comments on commit fca62b8

Please sign in to comment.