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 MaxNorm(object): | |
def __init__(self, max_value=1, frequency=5): | |
self.frequency = frequency | |
self.max_value = max_value | |
self.tiny = _finfo(torch.FloatTensor([])).tiny | |
def __call__(self, module): | |
if hasattr(module, "weight"): | |
w = module.weight.data | |
norms = w.norm(p=2, dim=w.dim() - 1, keepdim=True) |
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/local/miniconda3/bin/python | |
# A snippet for reading a Unicode string from clipboard, convert the string to one that is ASCII compatible, and then paste it to the clipboard. This converts for example "ß" to "ss".. | |
# The code is based on the answer https://stackoverflow.com/a/25802742/3706018. | |
import pasteboard | |
import subprocess | |
from unidecode import unidecode | |
pb = pasteboard.Pasteboard() | |
asciidata = unidecode(pb.get_contents()) |
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
@font-face { | |
font-family: "DejaVu Sans Mono"; | |
font-weight: normal; | |
font-style: normal; | |
src: local('"DejaVu Sans Mono"'), url('fonts/dejavu.ttf') format('truetype'); | |
} | |
@font-face { | |
font-family: "DejaVu Sans Mono"; | |
font-weight: normal; | |
font-style: italic; |
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
;;; emacs-zotero-bib-fetch.el --- Manage Zotero collections from emacs | |
;; | |
;; Filename: emacs-zotero-bib-fetch.el | |
;; Author: Anders Johansson, based on zotelo by Spinu Vitalie | |
;; Maintainer: Anders Johansson | |
;; Copyright (C) 2011-2014, Anders Johansson and Spinu Vitalie | |
;; Created: 1 Jul 2014 | |
;; Version: 1.2 | |
;; URL: https://github.com/andersjohansson/emacs-zotero-bib-fetch | |
;; Keywords: zotero, emacs, reftex, bibtex, bibliography manager |
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 | |
# Install CUDA Toolkit 10 | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb | |
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub && sudo apt update | |
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb | |
sudo apt update | |
sudo apt install -y cuda |
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
{ | |
"title": "Emacs keys", | |
"rules": [ | |
{ | |
"description": "Change right_option + a to right_control + a", | |
"manipulators": [ | |
{ | |
"type": "basic", | |
"from": { | |
"key_code": "a", |
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 | |
def hamming_score(pred, answer): | |
out = ((pred & answer).sum(dim=1) / (pred | answer).sum(dim=1)).mean() | |
if out.isnan(): | |
out = torch.tensor(1.0) | |
return out | |
answer = torch.tensor([[0, 1, 0], [0, 1, 1], [1, 0, 1], [0, 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 flatten_json(json): | |
if type(json) == dict: | |
for k, v in list(json.items()): | |
if type(v) == dict: | |
flatten_json(v) | |
json.pop(k) | |
for k2, v2 in v.items(): | |
json[k+"."+k2] = v2 | |
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 collections import OrderedDict | |
from torchvision import models | |
def gen_feature_extractor(model, output_layer): | |
layers = OrderedDict() | |
for (k, v) in model._modules.items(): | |
layers[k] = v | |
if k == output_layer: |
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
{ | |
"shortcuts": [ | |
{ | |
"command": "notebook:toggle-all-cell-line-numbers", | |
"keys": [ | |
"Alt L" | |
], | |
"selector": ".jp-Notebook:focus" | |
}, | |
// Moving cells |
OlderNewer