Skip to content

Instantly share code, notes, and snippets.

View nishnik's full-sized avatar

Nishant Nikhil nishnik

View GitHub Profile
@nishnik
nishnik / DL.sh
Last active October 17, 2016 11:09
Bash commands to install different Deep Learning related softwares
#! /bin/bash
# DL, ML, NLP
sudo apt-get update
# scipy, matplotlib
sudo apt-get install python-dev python-pip python-matplotlib python-scipy
#tensorflow
sudo pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
"""
Andrej Karpathy's code compatible in python3
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
def load_dataset():
"Load the sample dataset. must be numbered from 1"
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
def createC1(dataset):
"Create a list of candidate item sets of size one."
c1 = []
for transaction in dataset:
for item in transaction:
@nishnik
nishnik / vae.py
Created February 1, 2017 03:54
Variational Auto-Encoder introduction
# relu activation function
def relu(x):
return T.switch(x<0, 0, x)
class VAE:
"""This class implements the Variational Auto Encoder"""
def __init__(self, continuous, hu_encoder, hu_decoder, n_latent, x_train, b1=0.95, b2=0.999, batch_size=100, learning_rate=0.001, lam=0):
# let us keep the discussion to not continuous
@nishnik
nishnik / scrape_metaKGP_scores.py
Created April 13, 2017 21:09
Scrapes scores from MetaKGP's "Contribution Scores" page
from bs4 import BeautifulSoup
import requests
data_list = []
link = "https://wiki.metakgp.org/w/Special:ContributionScores"
response = requests.get(link)
html = response.content
source = BeautifulSoup(html, "lxml")
trs = source.findAll("tr")
run = False
@nishnik
nishnik / Pytorch_maxpool2d.py
Created November 14, 2017 17:03
Basic implementation of maxpool2d in pytorch, based on it you can create kmaxpool
stride = 3
new_var = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
for dim1 in range(x.shape[0]):
tmp = Variable(torch.zeros([x.shape[1]//stride, x.shape[2]//stride, 1]))
for i in range(0, x.shape[1], stride):
for j in range(0, x.shape[2], stride):
tmp_max = x[dim1][i][j]
for k in range(stride):
for m in range(stride):
tmp_max = torch.max(tmp_max, x[dim1][i+k][j+m])
@nishnik
nishnik / Pytorch_get2max.py
Created November 14, 2017 17:29
Gets 2 maximum element form max pooling
import numpy as np
y = np.array([[1.0, 7.0, 1.0],[3.0, 4.0, 2], [1, 7, 1]])
x = torch.from_numpy(y)
x = Variable(x)
x = x.resize(1, 3, 3)
stride = 2
new_var = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
new_var2 = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
for dim1 in range(x.shape[0]):
tmp = Variable(torch.zeros([x.shape[1]//stride, x.shape[2]//stride, 1]))
@nishnik
nishnik / lstm.py
Created February 16, 2018 09:20
Load imdb preprocessed dataset and simple lstm over it - PyTorch, Keras
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.datasets import imdb
import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
@nishnik
nishnik / fill_it_up.js
Created April 19, 2018 09:32
Feedback - erp
var val = "3"
var radio_buttons = document.querySelectorAll('input[value="' + val +'"]');
var i = 0;
for (i=0; i<radio_buttons.length ; i++){
radio_buttons[i].checked = true;
}
var radio_buttons = document.querySelectorAll('input[value="5' + val +'"]');
var i = 0;
for (i=0; i<radio_buttons.length ; i++){
radio_buttons[i].checked = true;
@nishnik
nishnik / find_max_col
Created July 18, 2018 21:50
Finds the minimum and maximum value in 3rd column of a text file
cat crowds_zara01_train.txt | awk -F ' ' '{print $3}' | sort -n | sed -n '1p;$p'