-
Notifications
You must be signed in to change notification settings - Fork 916
V chguan/add icml ex nlp code #90
Changes from 3 commits
f4f3591
f0d6a2f
503df31
5ad5e9b
babe101
b2ca990
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"*Copyright (c) Microsoft Corporation. All rights reserved.*\n", | ||
"\n", | ||
"*Licensed under the MIT License.*\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Explain a saved pytorch NLP model\n", | ||
"\n", | ||
"This is a torturial on how to explain any layer in a saved pytorch model. We use the 3rd layer of the pre-trained BERT-base (12 layers) model for simplicity as an example.\n", | ||
"\n", | ||
"This torturial assumes you've already read another [Torturial on explain simple model](./explain_simple_model.ipynb). If you haven't, you may need to go through that first." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pytorch_pretrained_bert import BertModel, BertTokenizer\n", | ||
"import logging\n", | ||
"from urllib import request\n", | ||
"import torch\n", | ||
"import json\n", | ||
"import ssl\n", | ||
"import sys\n", | ||
"\n", | ||
"sys.path.append(\"../../\")\n", | ||
"\n", | ||
"from utils_nlp.interpreter.Interpreter import Interpreter\n", | ||
"\n", | ||
"logging.getLogger().setLevel(logging.WARNING)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 0 Prepare Phi, x, words and regularization term\n", | ||
"\n", | ||
"we first load the pre-trained model we need to explain and define the sentence we use in our case. Suppose the sentence we want to study is `rare bird has more than enough charm to make it memorable.`, and the layer we need to explain is the 3rd layer." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", | ||
"\n", | ||
"# suppose the sentence is as following\n", | ||
"text = \"rare bird has more than enough charm to make it memorable.\"\n", | ||
"\n", | ||
"# get the tokenized words.\n", | ||
"tokenizer = BertTokenizer.from_pretrained(\"bert-base-uncased\")\n", | ||
"words = [\"[CLS]\"] + tokenizer.tokenize(text) + [\"[SEP]\"]\n", | ||
"\n", | ||
"# load BERT base model\n", | ||
"model = BertModel.from_pretrained(\"bert-base-uncased\").to(device)\n", | ||
"for param in model.parameters():\n", | ||
" param.requires_grad = False\n", | ||
"model.eval()\n", | ||
"\n", | ||
"# get the x (here we get x by hacking the code in the pytorch_pretrained_bert package)\n", | ||
"tokenized_ids = tokenizer.convert_tokens_to_ids(words)\n", | ||
"segment_ids = [0 for _ in range(len(words))]\n", | ||
"token_tensor = torch.tensor([tokenized_ids], device=device)\n", | ||
"segment_tensor = torch.tensor([segment_ids], device=device)\n", | ||
"x = model.embeddings(token_tensor, segment_tensor)[0]\n", | ||
"\n", | ||
"# extract the Phi we need to explain, suppose the layer we are interested in is layer 3\n", | ||
"def Phi(x):\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor suggestion here, maybe we can add a parameter called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! |
||
" global model\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is making global the model needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems that the code can still run without this line hmmmmm. |
||
" x = x.unsqueeze(0)\n", | ||
" attention_mask = torch.ones(x.shape[:2]).to(x.device)\n", | ||
" extended_attention_mask = attention_mask.unsqueeze(1).unsqueeze(2)\n", | ||
" extended_attention_mask = extended_attention_mask.to(dtype=torch.float)\n", | ||
" extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0\n", | ||
" # extract the 3rd layer\n", | ||
" model_list = model.encoder.layer[:3]\n", | ||
" hidden_states = x\n", | ||
" for layer_module in model_list:\n", | ||
" hidden_states = layer_module(hidden_states, extended_attention_mask)\n", | ||
" return hidden_states[0]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# here, we load the regularization we already calculated for simplicity\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here could you just print the regularization value? out of curiosity, how did you get this value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add the print here. We get this by sampling. We first sample part of the training data of BERT, then pass them to BERT and collect the 3rd hidden state and calculate the std values of every dimension of them (the std values are the regular values). |
||
"data = request.urlopen(\"https://nlpbp.blob.core.windows.net/data/regular.json\").read()\n", | ||
"regularization = json.loads(data)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1 Explain the Phi and x\n", | ||
"\n", | ||
"We first initialize an interpreter class, and pass necessary parameters in it." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"interpreter = Interpreter(x=x, Phi=Phi, regularization=regularization, words=words).to(\n", | ||
" device\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We optimize the interpreter to get the result." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"interpreter.optimize(iteration=5000, lr=0.01, show_progress=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Then, we can get the sigma we have optimized" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"array([0.17282525, 0.14378461, 0.1557987 , 0.2305536 , 0.20187221,\n", | ||
" 0.21250647, 0.19196394, 0.13568228, 0.26310277, 0.23032397,\n", | ||
" 0.24152805, 0.13371354, 0.2737328 , 0.36158693], dtype=float32)" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"interpreter.get_sigma()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Finally, we visualize the explained result." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAB7CAYAAAAhbxT1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAFCtJREFUeJzt3XuYXVV9xvHvOwnmQiAkBCMVIZEnomAxlgACgqGlihdASxQraOIdrxUfy6PVUgqWp4oV+6BRwdqgYkGlIqACCgQBDRAgNy6R3JAAIqGIxEAIya9/rHUye86cM+cyc87sJO/neYZZZ+219lp77bX3b19OBkUEZmZmZdMz3B0wMzOrxQHKzMxKyQHKzMxKyQHKzMxKyQHKzMxKyQHKzMxKyQHKzMxKyQHKzMxKyQHKzMxKaWQrhXvG7Bojxk/uVF9q2vzMM11tD4CRLQ3LkJi4+5iutvfMxu7/BZGeEep6m5ue3dz1Njc+ub7rbe61985db3PDpu4fJyN6ujtvH1v7p662BzBlytiutzlh1LiutvfAmt+xbt3jDU8ILc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DlBmZlZKDlBmZlZKDlBmZlZKDlBmZlZKDlBmZlZKDlBmZlZK/w9E5exSEJe5SQAAAABJRU5ErkJggg==\n", | ||
"text/plain": [ | ||
"<Figure size 432x288 with 2 Axes>" | ||
] | ||
}, | ||
"metadata": { | ||
"needs_background": "light" | ||
}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"interpreter.visualize()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can see that the word 'rare', 'bird', 'charm', 'memorable' is important to the third layer." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @Frozenmad, these two notebooks are pretty small. Do you think it make sense to merge them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll try to merge them together~