Skip to content

Instantly share code, notes, and snippets.

View koreyou's full-sized avatar

Yuta Koreeda koreyou

View GitHub Profile
@koreyou
koreyou / bm25.py
Created November 1, 2019 05:26
Implementation of OKapi BM25 with sklearn's TfidfVectorizer
""" Implementation of OKapi BM25 with sklearn's TfidfVectorizer
Distributed as CC-0 (https://creativecommons.org/publicdomain/zero/1.0/)
"""
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy import sparse
class BM25(object):
@koreyou
koreyou / find_chainer_usage.py
Last active May 29, 2018 11:33
Find usage of deep learning library "Chainer" within Github repositories
import requests
import re
import time
"""
Prerequisite: Create access tokens
You need private access token to have full access to Github search
API.
Generate your access token in [here](https://github.com/settings/tokens)
@koreyou
koreyou / .gitconfig
Created March 21, 2018 12:41
My git configuration
[user]
email = koreyou@mac.com
name = Yuta Koreeda
[core]
editor = emacs -nw
[alias]
# Adopted from https://www.jacobtomlinson.co.uk/quick%20tip/2016/01/18/pretty-git-logs-with-git-lg/
lg = !"git lg1"
@koreyou
koreyou / startup.py
Created January 7, 2018 07:58
ipython startup (deprecated)
# coding: utf-8
"""
This is the ipython startup script that I used to use in university.
(but not anymore)
Place it in ~/.ipython/profile_default/startup/startup.py for it to work
"""
import numpy as np
import math
import matplotlib.pyplot as plt
import matplotlib
@koreyou
koreyou / shuf
Created January 6, 2018 09:31
Linux shuf command with seed option
#!/bin/bash
# seeding adopted from https://stackoverflow.com/a/41962458/7820599
get_seeded_random()
{
seed="$1";
openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \
</dev/zero 2>/dev/null;
}
@koreyou
koreyou / early_stopping_chainer.ipynb
Created October 29, 2017 13:35
Implementation of early stopping for Chainer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@koreyou
koreyou / split.html
Created October 28, 2017 02:35
Vertically split colors within one <div> element
<div style="background-image: linear-gradient(bottom, #FFD51A 50%, #FAC815 50%);
background-image: -o-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -moz-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -webkit-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -ms-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
display: inline-block;">aaaa</div>
@koreyou
koreyou / optimizer_comparison.ipynb
Created October 27, 2017 11:12
Comparison of the behaviours of the SGD optimizers
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@koreyou
koreyou / safe_mkdir.py
Created September 12, 2017 16:00
Safer directory creation
@contextlib.contextmanager
def safe_mkdir(path, dir=None):
""" Create a directory in safe(r) way. Specified directory is created only when
whole operations in `with` scoped is completed successfully. All the files
that are created within the temporaly generated dir will be kept within.
This may not work in some OS.
"""
if dir is None:
dir = os.path.dirname(path)
@koreyou
koreyou / lock_decorator.py
Last active September 9, 2017 05:09
lock decorator
def lock(f):
""" decorator which locks class method
You need property _lock defined as in the following.
self._lock = threading.Lock()
"""
def body(self, *args, **kwargs):
with self._lock:
return f(self, *args, **kwargs)
return body