Skip to content

Instantly share code, notes, and snippets.

View vinhkhuc's full-sized avatar

Vinh Khuc vinhkhuc

View GitHub Profile
# Source: https://course.spacy.io/
# =========================== Chapter 1 =========================== #
# Import the English language class
import spacy
from spacy.lang.en import English
from spacy.matcher import Matcher
# Create the nlp object
nlp = English()
@vinhkhuc
vinhkhuc / link-to-tensorboard-projector-for-question-embeddings.txt
Created October 20, 2018 22:05
Link to Tensorboard Projector for Question Embeddings
@vinhkhuc
vinhkhuc / qc-question-embeddings-projector-config.json
Created October 20, 2018 22:02
Tensorboard Projector Config for Question embeddings using TF's Universal Sentence Encoder
{
"embeddings": [
{
"tensorName": "QC Question Embeddings Using TF Sentence Embedding Encoder Large 3",
"tensorShape": [
5451,
300
],
"tensorPath": "https://gist.githubusercontent.com/vinhkhuc/3806dc8ef988d3c10ecfa6310de1943f/raw/738c1d07563612df2662a0aedc931a89cb64458b/qc-question-embeddings.tsv",
"metadataPath": "https://gist.githubusercontent.com/vinhkhuc/1f9fc9ad322c152ebe607e9bb5d7da55/raw/1518504769d8989f017caa171313991ae43f7e75/qc-embed-metadata.tsv"
@vinhkhuc
vinhkhuc / qc-question-embeddings.tsv
Created October 12, 2018 05:50
Question embeddings using TF's Universal Sentence Encoder (data: http://cogcomp.org/Data/QA/QC/, model: https://tfhub.dev/google/universal-sentence-encoder-large/3)
We can't make this file beautiful and searchable because it's too large.
0.0061718537 -0.0024363345 0.058415722 -0.019220708 -0.051817734 -0.042351343 -0.020908065 0.005183715 -0.013680814 -0.04262279 0.009524972 -0.02140069 0.023697063 0.043885317 0.034181613 -0.0083187 -0.06722789 0.013031735 0.007751275 -0.08180988 0.04614297 -0.06278132 -0.025033472 -0.043717187 -0.020316828 0.050261766 0.060791086 0.05705632 -0.012153195 0.03464042 -0.08152679 -0.058986522 0.0035639652 0.024647668 -0.059734866 0.015541221 -0.0065737423 0.020316336 -0.0148979565 -0.026047753 0.028355088 -0.026079465 -0.002358603 -0.0067062867 -0.009114266 0.0010216745 0.026439784 0.07460034 0.044666305 0.037209775 0.074898235 0.021767966 -0.052332643 -0.022787187 0.044321213 0.009379231 -0.026886253 0.034125276 -0.06483722 -0.01966572 -0.040497903 -0.0055085467 0.0017649964 0.021614494 -0.009420735 0.05497118 0.010820785 -0.01948987 -0.012267729 -0.010204952 -0.08628109 -0.083253555 -0.004771075 -0.021505628 0.083285354 0.026299926 0.057961594 0.02451058 0.023163367 0.018347874 -0.04912325 -0.03191776 -0.03019
@vinhkhuc
vinhkhuc / qc-embed-metadata.tsv
Created October 10, 2018 21:00
Question texts and labels (data: http://cogcomp.org/Data/QA/QC/)
Question Label
How did serfdom develop in and then leave Russia ? DESC:manner
What films featured the character Popeye Doyle ? ENTY:cremat
How can I find a list of celebrities ' real names ? DESC:manner
What fowl grabs the spotlight after the Chinese Year of the Monkey ? ENTY:animal
What is the full form of .com ? ABBR:exp
What contemptible scoundrel stole the cork from my lunch ? HUM:ind
What team did baseball 's St. Louis Browns become ? HUM:gr
What is the oldest profession ? HUM:title
What are liver enzymes ? DESC:def
@vinhkhuc
vinhkhuc / simple_mlp_tensorflow.py
Last active December 22, 2021 11:52
Simple Feedforward Neural Network using TensorFlow
# Implementation of a simple MLP network with one hidden layer. Tested on the iris data set.
# Requires: numpy, sklearn>=0.18.1, tensorflow>=1.0
# NOTE: In order to make the code simple, we rewrite x * W_1 + b_1 = x' * W_1'
# where x' = [x | 1] and W_1' is the matrix W_1 appended with a new row with elements b_1's.
# Similarly, for h * W_2 + b_2
import tensorflow as tf
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
@vinhkhuc
vinhkhuc / min-char-rnn-tensorflow.py
Last active May 17, 2019 02:48
Vanilla Char-RNN using TensorFlow
"""
Vanilla Char-RNN using TensorFlow by Vinh Khuc (@knvinh).
Adapted from Karpathy's min-char-rnn.py
https://gist.github.com/karpathy/d4dee566867f8291f086
Requires tensorflow>=1.0
BSD License
"""
import random
import numpy as np
import tensorflow as tf
@vinhkhuc
vinhkhuc / simple_mlp_theano.py
Last active December 6, 2020 05:46
Simple Feedforward Neural Network using Theano
# Implementation of a simple MLP network with one hidden layer. Tested on the iris data set.
# Requires: numpy, sklearn, theano
# NOTE: In order to make the code simple, we rewrite x * W_1 + b_1 = x' * W_1'
# where x' = [x | 1] and W_1' is the matrix W_1 appended with a new row with elements b_1's.
# Similarly, for h * W_2 + b_2
import theano
from theano import tensor as T
import numpy as np
from sklearn import datasets
from theano import tensor as T, function
x = T.dscalar('x')
y = x ** 2
dy = T.grad(cost=y, wrt=x) # Preparing symbolic gradient
df = function(inputs=[x], outputs=dy)
print(df(4)) # Output: 8
"""
Code to replicate Ron Kohavi's cross-validation experiment on the Iris data set.
"""
from sklearn import datasets, svm
from sklearn.cross_validation import cross_val_score, KFold, LeavePOut
import matplotlib.pyplot as plt
output_file = "cross-validation-experiment-iris.png"
iris = datasets.load_iris()