Skip to content

Instantly share code, notes, and snippets.

View DerekChia's full-sized avatar
🎯
Focusing

Derek Chia DerekChia

🎯
Focusing
View GitHub Profile
@DerekChia
DerekChia / start_docker_registry.bash
Created February 29, 2020 07:55 — forked from PieterScheffers/start_docker_registry.bash
Start docker registry with letsencrypt certificates (Linux Ubuntu)
#!/usr/bin/env bash
# install docker
# https://docs.docker.com/engine/installation/linux/ubuntulinux/
# install docker-compose
# https://docs.docker.com/compose/install/
# install letsencrypt
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
@DerekChia
DerekChia / requirements.txt
Last active December 13, 2019 08:08
DeepSpeech no TensorFlow
# Main training requirements
numpy == 1.15.4
progressbar2
pandas
six
pyxdg
attrdict
absl-py
# Requirements for building native_client files
@DerekChia
DerekChia / w2v_find_similar_words.py
Created December 3, 2018 10:33
w2v_find_similar_words
# Find similar words
w2v.vec_sim("machine", 3)
class word2vec():
## Removed##
# Input vector, returns nearest word(s)
def vec_sim(self, word, top_n):
v_w1 = self.word_vec(word)
word_sim = {}
@DerekChia
DerekChia / w2v_get_vector.py
Last active December 3, 2018 10:32
w2v_get_vector
# Get vector for word
vec = w2v.word_vec("machine")
class word2vec():
## Removed ##
# Get vector from word
def word_vec(self, word):
w_index = self.word_index[word]
v_w = self.w1[w_index]
@DerekChia
DerekChia / w2v_training_error_backpropagation.py
Last active December 1, 2018 15:26
w2v_training_error_backpropagation
class word2vec():
##Removed##
for i in range(self.epochs):
self.loss = 0
for w_t, w_c in training_data:
##Removed##
# Calculate error
# 1. For a target word, calculate difference between y_pred and each of the context words
@DerekChia
DerekChia / w2v_training_forward_pass.py
Last active December 3, 2018 10:44
w2v_training_forward_pass
class word2vec():
def train(self, training_data):
##Removed##
# Cycle through each epoch
for i in range(self.epochs):
# Intialise loss to 0
self.loss = 0
# Cycle through each training sample
@DerekChia
DerekChia / w2v_training_1.py
Created December 1, 2018 11:43
w2v_training_1
# Training
w2v.train(training_data)
class word2vec():
def train(self, training_data):
# Initialising weight matrices
# Both s1 and s2 should be randomly initialised but for this demo, we pre-determine the arrays (getW1 and getW2)
# getW1 - shape (9x10) and getW2 - shape (10x9)
self.w1 = np.array(getW1)
self.w2 = np.array(getW2)
@DerekChia
DerekChia / w2v_training.py
Last active December 1, 2018 12:25
w2v_training
# Training
w2v.train(training_data)
class word2vec():
def train(self, training_data):
# Initialising weight matrices
# Both s1 and s2 should be randomly initialised but for this demo, we pre-determine the arrays (getW1 and getW2)
# getW1 - shape (9x10) and getW2 - shape (10x9)
self.w1 = np.array(getW1)
self.w2 = np.array(getW2)
@DerekChia
DerekChia / w2v_generate_training_data_2.py
Last active December 1, 2018 11:11
w2v_generate_training_data_2
# Initialise object
w2v = word2vec()
# Numpy ndarray with one-hot representation for [target_word, context_words]
training_data = w2v.generate_training_data(settings, corpus)
@DerekChia
DerekChia / w2v_generate_training_data_func.py
Last active December 1, 2018 11:35
w2v_generate_training_data_func
class word2vec():
def __init__(self):
self.n = settings['n']
self.lr = settings['learning_rate']
self.epochs = settings['epochs']
self.window = settings['window_size']
def generate_training_data(self, settings, corpus):
# Find unique word counts using dictonary
word_counts = defaultdict(int)