Skip to content

Instantly share code, notes, and snippets.


Mike Clark wassname

Block or report user

Report or block wassname

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
wassname /
Created Jul 29, 2019
how to cache with non immutable function inputs
def cache_load_utturances(ttl=360000):
Decorator for wrapping simple cache around load_utterances.
Since some arguments are unhashable (tokenizer) or immutable (list) we need to make the key manually
def decorate(func):
def wrapper(**kwargs):
wassname /
Last active Jun 26, 2019
pandas classification report
import pandas as pd
import sklearn.metrics
import numpy as np
def classification_report(*args, **kwargs):
out_df = pd.DataFrame(sklearn.metrics.classification_report(*args, **kwargs, output_dict=True)).T
# Order cols
# Round
out_df[["precision","recall","f1-score"]]= out_df[["precision","recall","f1-score"]].apply(lambda x: round(x,2))
wassname /
Last active May 31, 2019
Running stats (mean, standard deviation) for python, pytorch, etc
import numpy as np
# handle pytorch tensors etc, by using tensorboardX's method
from tensorboardX.x2num import make_np
except ImportError:
def make_np(x):
return np.array(x).copy().astype('float16')
class RunningStats(object):
class RunningMean(object):
def __init__(self, sum=0, i=0):
self.sum = sum
self.i = i
def __add__(self, other):
return RunningMean(self.sum+other, self.i+1)
def add(self, loss):
wassname /
Last active May 19, 2019
Transformer in ~80 lines of code from Thomas Wolf's tweet
Transformer in ~80 lines of code.
From Thomas Wolf's tweet
import torch
from torch import nn
class Transformer(nn.Module):
wassname /
Last active Mar 15, 2019
jaccard_distance_loss for pytorch
class JaccardDistanceLoss(torch.nn.Module):
def __init__(self, smooth=100, dim=1, size_average=True, reduce=True):
Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|)
= sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|))
The jaccard distance loss is usefull for unbalanced datasets. This has been
shifted so it converges on 0 and is smoothed to avoid exploding or disapearing
wassname /
Last active Jun 21, 2019
xubuntu on a Thinkpad Yoga x380

This are a collection of fixes and tweaks I used to get Xubuntu 18.04 LTS working on a lenovo thinkpad X380 yoga laptop.

View Samsung Smart-TV Blocklist Adlist (for PiHole)
# This is a blocklist to block samsung smart tv's sending meta data at home.
# Please help to collect domains!
# It could be that the TV does not receive any more updates or other services no longer work. Please report such an incident.
wassname / pytorch_losses.ipynb
Created Sep 25, 2018
Comparing the shape of mse, l1 (mae), smoothl1loss etc in pytorch as they approach 0 error
View pytorch_losses.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View LG Smart-TV Blocklist Adlist (for PiHole)
# added after fork
# from and others
You can’t perform that action at this time.