This file contains hidden or 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 itertools import cycle, count | |
| import string | |
| alphabet = string.ascii_lowercase + string.ascii_uppercase + ' ' + string.digits + string.punctuation | |
| encode = dict(zip(alphabet, count())).get | |
| decode = dict(zip(count(), alphabet)).get | |
| add = lambda a, b: decode((encode(b) + encode(a)) % len(alphabet)) | |
| sub = lambda a, b: decode((encode(b) - encode(a)) % len(alphabet)) |
This file contains hidden or 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 torchvision | |
| import matplotlib.pyplot as plt | |
| import matplotlib.patches as patches | |
| from matplotlib.backend_bases import MouseEvent | |
| import torch | |
| def onclick(event): | |
| x = torch.tensor([event.ydata, event.xdata]).float() | |
| d = (y - x).float().norm(dim=-1) |
This file contains hidden or 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 | |
| from time import sleep | |
| from itertools import count | |
| from pdb import set_trace | |
| import matplotlib.pyplot as plt | |
| def softmax(x): | |
| y = np.exp(x - x.max(-1, keepdims=True)) | |
| return y / y.sum(-1, keepdims=True) |
This file contains hidden or 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 | |
| import torch | |
| import torchvision | |
| import matplotlib.pyplot as plt | |
| def relu(x): | |
| return numpy.maximum(0, x) | |
| def relu_derivative(x): | |
| return (x > 0).astype(float) |
NewerOlder