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
#!/usr/bin/python | |
import h5py | |
import psycopg2 | |
import psycopg2.extras | |
from math import sqrt | |
import ipdb | |
import numpy as np | |
from tqdm import tqdm |
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 | |
from torch.nn.utils.rnn import PackedSequence | |
from typing import overload, Optional | |
class Base(torch.nn.Module): | |
def __init__(self): | |
super().__init__() | |
@overload | |
@torch._jit_internal._overload_method | |
def forward(self, inputs, hx=None): |
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
#!/bin/bash | |
set -x | |
if [ $# -ne 2 ]; then | |
REPO=dmlc | |
BRANCH=master | |
else | |
REPO=$1 | |
BRANCH=$2 |
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
Rule: | |
- DOMAIN-SUFFIX,digicert.com,DIRECT | |
- DOMAIN-SUFFIX,mzstatic.com,Domestic | |
- DOMAIN-SUFFIX,akadns.net,Domestic | |
- DOMAIN-SUFFIX,aaplimg.com,Domestic | |
- DOMAIN-SUFFIX,cdn-apple.com,Domestic | |
- DOMAIN-SUFFIX,apple.com, Domestic | |
- DOMAIN-SUFFIX,icloud.com,Domestic | |
- DOMAIN-SUFFIX,icloud-content.com,Domestic | |
- DOMAIN,e.crashlytics.com,REJECT |
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 att_animation(maps_array, mode, src, tgt, head_id): | |
weights = [maps[mode2id[mode]][head_id] for maps in maps_array] | |
fig, axes = plt.subplots(1, 2) | |
axes[0].set_yticks(np.arange(len(src))) | |
axes[0].set_xticks(np.arange(len(tgt))) | |
axes[0].set_yticklabels(src) | |
axes[0].set_xticklabels(tgt) | |
plt.setp(axes[0].get_xticklabels(), rotation=45, ha="right", | |
rotation_mode="anchor") | |
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
# This part for jupyter notebook setting (if you wants to save, don't use this) | |
# %matplotlib inline | |
# %config InlineBackend.figure_format = 'svg' | |
# import numpy as np | |
# import matplotlib.pyplot as plt | |
# plt.rcParams["animation.html"] = "jshtml" | |
import networkx as nx | |
from networkx.algorithms import bipartite |
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
class Flatten(nn.Module): | |
def __init__(self): | |
super(Flatten, self).__init__() | |
def forward(self, x): | |
return x.view(x.size(0), -1) |
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 is_cuda(operation): | |
if isinstance(operation, th.nn.Module): | |
return 'cuda' in str(type(operation.parameters().next())) | |
elif isinstance(operation, th._TensorBase): | |
return 'cuda' in str(type(operation)) | |
elif isinstance(operation, Variable): | |
return 'cuda' in str(type(operation.data)) | |
else: | |
raise Exception("Operation is not nn.Module or Variable or Tensor") |