Skip to content

Instantly share code, notes, and snippets.

View gavincangan's full-sized avatar

Barnabas Gavin Cangan gavincangan

View GitHub Profile
@gavincangan
gavincangan / spline_interpolation.py
Created June 1, 2019 03:17 — forked from komasaru/spline_interpolation.py
Python script to calc 3D-Spline-Interpolation.
#! /usr/local/bin/python3.6
"""
3-D spline interpolation
(with graph drawing by matplotlib)
"""
import matplotlib.pyplot as plt
import sys
import traceback
class SplineInterpolation:
@gavincangan
gavincangan / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created May 31, 2019 01:52 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@gavincangan
gavincangan / bezier_curves.py
Created May 24, 2019 17:57 — forked from astrojuanlu/bezier_curves.py
Interactive Bézier curves with Python using just matplotlib.
import matplotlib
matplotlib.use('webagg')
import numpy as np
from scipy.special import binom
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
@gavincangan
gavincangan / tf_beam_decoder.py
Created July 19, 2018 20:38 — forked from igormq/tf_beam_decoder.py
Tensorflow Beam Search
import tensorflow as tf
def beam_decoder(decoder_inputs, initial_state, cell, loop_function, scope=None,
beam_size=7, done_token=0
):
"""
Beam search decoder
Args:
decoder_inputs: A list of 2D Tensors [batch_size x input_size].
@gavincangan
gavincangan / beamsearch.py
Created July 18, 2018 17:23 — forked from udibr/beamsearch.py
beam search for Keras RNN
# variation to https://github.com/ryankiros/skip-thoughts/blob/master/decoding/search.py
def keras_rnn_predict(samples, empty=empty, rnn_model=model, maxlen=maxlen):
"""for every sample, calculate probability for every possible label
you need to supply your RNN model and maxlen - the length of sequences it can handle
"""
data = sequence.pad_sequences(samples, maxlen=maxlen, value=empty)
return rnn_model.predict(data, verbose=0)
def beamsearch(predict=keras_rnn_predict,
@gavincangan
gavincangan / AttentionWithContext.py
Created July 17, 2018 21:22 — forked from nigeljyng/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
class AttentionWithContext(Layer):
"""
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf]
"Hierarchical Attention Networks for Document Classification"
by using a context vector to assist the attention
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape
@gavincangan
gavincangan / get_available_gpus.py
Created July 12, 2018 17:15 — forked from jovianlin/get_available_gpus.py
Get List of Devices in TensorFlow
from tensorflow.python.client import device_lib
def get_available_gpus():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU']
get_available_gpus()