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.
@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()