Skip to content

Instantly share code, notes, and snippets.

:octocat:
🍡 NLP 🍡

Junki Ohmura jojonki

:octocat:
🍡 NLP 🍡
Block or report user

Report or block jojonki

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
@jojonki
jojonki / global_variables.py
Created Feb 4, 2019
Hack for read-only class variables.
View global_variables.py
class MetaGlobalVariables(type):
@property
def HOGE(cls):
return cls._GlobalVariables__hoge # mangling
class GlobalVariables(object, metaclass=MetaGlobalVariables):
__hoge = 'xxxx'
# read OK
@jojonki
jojonki / simple_viterbi.py
Created Jan 3, 2019
Simple viterbi algorithm example
View simple_viterbi.py
# Use Graham's example.
# http://www.phontron.com/slides/nlp-programming-ja-03-ws.pdf
INF = 1e6
edge_list = [
None, # e0
{ # e1
'id': 1,
'score': 2.5,
'begin_node_id': 0,
View gist:cb18b14e789eb8bdb2ae2950eef1019f
defaults write com.adobe.illustrator AppleLanguages '("ja")'
@jojonki
jojonki / load_glove_weight_sample.py
Created Aug 9, 2018
Glove embeddings in PyTorch
View load_glove_weight_sample.py
import numpy as np
import torch
from torch import nn
class Model(nn.Module):
def __init__(self, vocab_size, embd_size, pre_embd_w=None):
super(Model, self).__init__()
self.embd = nn.Embedding(vocab_size, embd_size, padding_idx=0)
@jojonki
jojonki / get_current_git_revision.py
Created Jun 24, 2018
Get a current Git revision in python
View get_current_git_revision.py
import subprocess
rev = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8')
View gist:09ad308e5604f77c48be9749eab74002
liens = [line.rstrip('\n') for line in open('file')]
@jojonki
jojonki / covariance_matrix.py
Last active Apr 18, 2018
A simple example of covariance matrix
View covariance_matrix.py
import numpy as np
data = np.array([[40, 35, 80],
[80, 50, 90],
[20, 55, 40],
[94, 80, 88],
[90, 30, 100]])
print('Input data (N, featuers):', data, data.shape)
N = data.shape[0]
n_dim = data.shape[1]
@jojonki
jojonki / pca_t-SNE_mnist.ipynb
Created Apr 17, 2018
Comparison of MNIST visualization between PCA and t-SNE
View pca_t-SNE_mnist.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jojonki
jojonki / pack_padded_sequence-pad_packed_sequence.ipynb
Created Apr 17, 2018
A simple usage of pack_padded_sequence and pad_packed_sequence in pytorch
View pack_padded_sequence-pad_packed_sequence.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jojonki
jojonki / read_lines_until_eof.py
Created Apr 4, 2018
Read lines until the EOF in Python
View read_lines_until_eof.py
refs = []
while True:
try:
ref = input()
refs.append(ref)
except EOFError:
break
You can’t perform that action at this time.