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
""" 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): |
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 | |
# 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; | |
} |
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 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) |
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
[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" |
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
# 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 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
<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> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 sequence_mask(x, length, value=0.): | |
xp = cuda.get_array_module(length.data) | |
# create permutation on (length.ndim + 1) dimension and expand dims until it has shame rank as x | |
perms = xp.arange(x.shape[length.ndim]).reshape( | |
[1] * length.ndim + [-1] + [1] * (x.ndim - length.ndim -1)) | |
length = length.reshape([1] * (length.ndim - 1) + [-1] + [1] * (x.ndim - length.ndim)) | |
pad = xp.ones_like(x) * value | |
mask = xp.broadcast_to(perms, x.shape) < length | |
return F.where(mask, x, pad) |
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
@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) |
NewerOlder