Skip to content

Instantly share code, notes, and snippets.

View vyraun's full-sized avatar

Vikas Raunak vyraun

View GitHub Profile
@vyraun
vyraun / audio_tools.py
Created September 21, 2019 07:37 — forked from kastnerkyle/audio_tools.py
Audio tools for numpy/python. Constant work in progress.
raise ValueError("DEPRECATED/FROZEN - see https://github.com/kastnerkyle/tools for the latest")
# License: BSD 3-clause
# Authors: Kyle Kastner
# Harvest, Cheaptrick, D4C, WORLD routines based on MATLAB code from M. Morise
# http://ml.cs.yamanashi.ac.jp/world/english/
# MGC code based on r9y9 (Ryuichi Yamamoto) MelGeneralizedCepstrums.jl
# Pieces also adapted from SPTK
from __future__ import division
import numpy as np
# -*- coding: utf-8 -*-
# Authors: jfsantos, Kyle Kastner
import sys
import numpy as np
import wave
import scipy as sp
from scipy.io import wavfile
def segment_axis(a, length, overlap=0, axis=None, end='cut', endvalue=0):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vyraun
vyraun / mutual_info.py
Created September 21, 2019 07:28 — forked from kastnerkyle/mutual_info.py
mutual info for discrete variables (in this example, 2 images)
import numpy as np
from scipy.misc import imread
from itertools import product
# https://www.mathworks.com/matlabcentral/fileexchange/36538-very-fast-mutual-information-betweentwo-images?focused=3869473&tab=function
def mutual_info(X, Y, levels=256):
# example inputs are images, but it shouldn't matter
X = X.astype("float32")
Y = Y.astype("float32")
@vyraun
vyraun / custom_layers.md
Created August 8, 2019 01:39
Blog - Custom layers in Keras

Building custom layers in Keras

About Keras

Keras is currently one of the most commonly used deep learning libraries today. And part of the reason why it's so popular is its API. Keras was built as a high-level API for other deep learning libraries ie Keras as such does not perform low-level tensor operations, instead provides an interface to its backend which are built for such operations. This allows Keras to abstract a lot of the underlying details and allows the programmer to concentrate on the architecture of the model. Currently Keras supports Tensorflow, Theano and CNTK as its backends.

Let's see what I mean. Tensorflow is one of the backends used by Keras. Here's the code for MNIST classification in TensorFlow and Keras. Both models are nearly identical and applies to the same problem. But if you compare the codes you g

@vyraun
vyraun / top-k-top-p.py
Created May 4, 2019 16:21 — forked from thomwolf/top-k-top-p.py
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (..., vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
"""
top_k = min(top_k, logits.size(-1)) # Safety check
if top_k > 0:
# Remove all tokens with a probability less than the last token of the top-k
@vyraun
vyraun / ffmpeg.md
Created April 18, 2019 22:57 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@vyraun
vyraun / tmux_cheatsheet.markdown
Last active March 14, 2019 23:25 — forked from henrik/tmux_cheatsheet.markdown
tmux cheatsheet

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@vyraun
vyraun / BERT_science.py
Created February 11, 2019 03:43 — forked from roeeaharoni/BERT_science.py
Generate the sciences of the future using BERT! (as seen on https://twitter.com/roeeaharoni/status/1089089393745371136)
import torch
from pytorch_pretrained_bert import BertForMaskedLM, BertTokenizer
import random
# Requires pytorch_pretrained_bert: https://github.com/huggingface/pytorch-pretrained-BERT
# returns the probabilities over the vocabulary for the masked words in sent
def get_preds(sent):
tokenized = bert_tokenizer.tokenize(sent)
tokenized = ['[CLS]'] + ['[MASK]' if x == 'mask' else x for x in tokenized] + ['[SEP]']
@vyraun
vyraun / biggan-search.ipynb
Created November 26, 2018 19:45 — forked from kylemcdonald/biggan-search.ipynb
BigGAN Search
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.