Skip to content

Instantly share code, notes, and snippets.

Sung-ju Kim goddoe

Block or report user

Report or block goddoe

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
@goddoe
goddoe / SelfAttention.py
Last active Sep 15, 2019
SelfAttention
View SelfAttention.py
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, input_dim, output_dim, dropout=0.1):
super(SelfAttention, self).__init__()
self.q = nn.Linear(input_dim, output_dim)
self.k = nn.Linear(input_dim, output_dim)
self.v = nn.Linear(input_dim, output_dim)
View SelfAttention.py
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, input_dim, output_dim, dropout=0.1):
super(SelfAttention, self).__init__()
self.q = nn.Linear(input_dim, output_dim)
self.k = nn.Linear(input_dim, output_dim)
@goddoe
goddoe / publish quality graph using matplotlib.py
Created Sep 10, 2019
publish quality graph using matplotlib
View publish quality graph using matplotlib.py
plt.rc('font', family='serif')
plt.rc('xtick', labelsize='x-large')
plt.rc('ytick', labelsize='x-large')
# plt.rc('text', usetex=True)
plt.rc('axes', labelsize='x-large')
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1)
View python in makefile
Reference : xorho, https://stackoverflow.com/questions/2043453/executing-multi-line-statements-in-the-one-line-command-line
80
this style can be used in makefiles too (and in fact it is used quite often).
python - <<EOF
import sys
for r in range(3): print 'rob'
EOF
@goddoe
goddoe / write_read_tsv.py
Last active Aug 16, 2019
tsv write and read using csv package.
View write_read_tsv.py
import os
from collections import namedtuple
from ast import literal_eval
from os.path import dirname
export_path = "path/to/export"
# Read & Write using native python
# write tsv
os.makedirs(dirname(export_path), exist_ok=True)
View repeat vs expand pytorch.py
import torch
A = torch.randn([12, 9, 64])
B = torch.randn([12, 9, 64])
Ar = A.repeat(1, 1, 9).view(12, 81, 64)
Br = B.repeat(1, 9, 1)
C = torch.cat((Ar, Br), dim=2)
D = torch.cat([A.unsqueeze(2).expand(-1, -1, 9, -1),
B.unsqueeze(1).expand(-1, 9, -1, -1)], dim=-1).view(12, 81, 128)
print ((C-D).abs().max().item()) # should be 0
View timeout.py
from functools import wraps
import errno
import os
import signal
class TimeoutError(Exception):
pass
@goddoe
goddoe / solution.txt
Last active Jul 17, 2019
ssh: connect to host bitbucket.org port 22: Connection timed out
View solution.txt
I have done below mentioned things and it started working.
vim ~/.ssh/config
Add these lines and save it.
Host github.com
StrictHostKeyChecking no
Host bitbucket.org
Hostname altssh.bitbucket.org
View ctags.sh
# https://www.fusionbox.com/blog/detail/navigating-your-django-project-with-vim-and-ctags/590/
ctags -R --fields=+l --languages=python --python-kinds=-iv ./
@goddoe
goddoe / weight_init.py
Created Mar 26, 2019 — forked from jeasinema/weight_init.py
A simple script for parameter initialization for PyTorch
View weight_init.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''
You can’t perform that action at this time.