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
wassname / less_simple_cache.py
Created Jul 29, 2019
how to cache with non immutable function inputs
View less_simple_cache.py
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):
@simple_cache.wraps(func)
def wrapper(**kwargs):
@wassname
wassname / pandas_classification_report.py
Last active Jun 26, 2019
pandas classification report
View pandas_classification_report.py
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
out_df[["precision","recall","f1-score","support"]]
# Round
out_df[["precision","recall","f1-score"]]= out_df[["precision","recall","f1-score"]].apply(lambda x: round(x,2))
@wassname
wassname / running_stats.py
Last active May 31, 2019
Running stats (mean, standard deviation) for python, pytorch, etc
View running_stats.py
import numpy as np
# handle pytorch tensors etc, by using tensorboardX's method
try:
from tensorboardX.x2num import make_np
except ImportError:
def make_np(x):
return np.array(x).copy().astype('float16')
class RunningStats(object):
View runningmean.py
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
wassname / simple_transformer.py
Last active May 19, 2019
Transformer in ~80 lines of code from Thomas Wolf's tweet https://twitter.com/Thom_Wolf/status/1129658539142766592
View simple_transformer.py
"""
Transformer in ~80 lines of code.
From Thomas Wolf's tweet https://twitter.com/Thom_Wolf/status/1129658539142766592.
"""
import torch
from torch import nn
class Transformer(nn.Module):
@wassname
wassname / jaccard_distance_loss.py
Last active Mar 15, 2019
jaccard_distance_loss for pytorch
View jaccard_distance_loss.py
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
gradient.
@wassname
wassname / linux_x380.md
Last active Jun 21, 2019
xubuntu on a Thinkpad Yoga x380
View linux_x380.md

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.
abtauthprd.samsungcloudsolution.com
acr0.samsungcloudsolution.com
ad.samsungadhub.com
ads.samsungads.com
amauthprd.samsungcloudsolution.com
api-hub.samsungyosemite.com
@wassname
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)
127.0.0.1 us.rdx2.lgtvsdp.com
127.0.0.1 us.info.lgsmartad.com
127.0.0.1 us.ibs.lgappstv.com
127.0.0.1 us.lgtvsdp.com
127.0.0.1 ad.lgappstv.com
127.0.0.1 smartshare.lgtvsdp.com
127.0.0.1 ibis.lgappstv.com
# added after fork
# from https://www.reddit.com/r/pihole/comments/6qmpv6/blacklists_for_lg_webos_tvs/ and others
You can’t perform that action at this time.