This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from scipy import sparse | |
from pathlib import Path | |
from joblib import Parallel, delayed | |
from itertools import chain | |
from random import shuffle | |
from tqdm import tqdm | |
from gensim.models import Word2Vec | |
import logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cudf | |
import cugraph | |
from numba import cuda | |
from numba.cuda.random import create_xoroshiro128p_states, xoroshiro128p_uniform_float32 | |
import numpy as np | |
# gdf = cudf.read_csv('zachary.ssv', header=None, sep=' ', dtype=['int32', 'int32']) | |
gdf = cudf.read_csv('Flickr-labelled.edgelist', header=None, sep=' ', dtype=['int32', 'int32']) | |
gdf.columns = ['src', 'dest'] | |
gdf = gdf.sort_values(by='src') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remap prefix from 'C-b' to 'C-a' | |
unbind C-b | |
set-option -g prefix C-a | |
bind-key C-a send-prefix | |
# split panes using | and - | |
bind | split-window -h | |
bind - split-window -v | |
unbind '"' | |
unbind % |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"0": "tench, Tinca tinca", | |
"1": "goldfish, Carassius auratus", | |
"2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias", | |
"3": "tiger shark, Galeocerdo cuvieri", | |
"4": "hammerhead, hammerhead shark", | |
"5": "electric ray, crampfish, numbfish, torpedo", | |
"6": "stingray", | |
"7": "cock", | |
"8": "hen", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.to(device) | |
model.eval() | |
model.zero_grad() | |
def forward_func(inputs, attention_mask=None): | |
return model(inputs, attention_mask=attention_mask).logits | |
lig = LayerIntegratedGradients(forward_func, model.bert.embeddings) | |
all_input_ids, all_ref_input_ids, all_attributions, all_pred_probs, all_pred_class, all_true_class, all_attr_class, all_attr_score, all_convergence_scores = ([] for i in range(9)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os # noqa | |
sys.path.insert(0, ".") # noqa | |
import torch | |
from utils.styled_plot import plt | |
from utils.dataset import load_test_image, preprocess_image, normalize_image, convert_idx_to_label | |
from classifiers.cnn_classifier import ImageNetClassifier | |
from solutions.explainers import plot_attributions, aggregate_attribution, normalize_attribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.optim as optim | |
import torchvision | |
import torchvision.transforms as transforms | |
from pathlib import Path | |
from tqdm.auto import tqdm | |
print(torch.cuda.is_available()) | |
dev = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") | |
# dev = torch.device("cpu") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_simple_gradient_expl(model, images, targets, absolute=False): | |
images.requires_grad = True | |
outputs = model(images) | |
outputs = outputs.gather(1, targets.unsqueeze(1)) | |
grad = torch.autograd.grad(torch.unbind(outputs), images, create_graph=True)[0] # create_graph=True for second order derivative | |
expl = grad.abs() if absolute else grad | |
return expl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
import types | |
import torch | |
from typing import List, Optional, Tuple, Union, Dict | |
import transformers | |
from transformers.modeling_outputs import BaseModelOutputWithPast | |
from transformers.utils import logging as hf_logging | |
logger = hf_logging.get_logger(__name__) |
OlderNewer