... or Why Pipelining Is Not That Easy
Golang Concurrency Patterns for brave and smart.
By @kachayev
def smart_procrustes_align_gensim(base_embed, other_embed, words=None): | |
"""Procrustes align two gensim word2vec models (to allow for comparison between same word across models). | |
Code ported from HistWords <https://github.com/williamleif/histwords> by William Hamilton <wleif@stanford.edu>. | |
(With help from William. Thank you!) | |
First, intersect the vocabularies (see `intersection_align_gensim` documentation). | |
Then do the alignment on the other_embed model. | |
Replace the other_embed model's syn0 and syn0norm numpy matrices with the aligned version. | |
Return other_embed. |
# Source: | |
# https://github.com/farizrahman4u/seq2seq/blob/master/seq2seq/layers/state_transfer_lstm.py | |
from keras import backend as K | |
from keras.layers.recurrent import LSTM | |
class StateTransferLSTM(LSTM): | |
"""LSTM with the ability to transfer its hidden state. | |
This layer behaves just like an LSTM, except that it can transfer (or |
#!/usr/bin/env python | |
# Ander Martinez Sanchez | |
from __future__ import division, print_function | |
from math import exp, log | |
from collections import Counter | |
def ngram_count(words, n): | |
if n <= len(words): |
from numpy.random import choice as random_choice, randint as random_randint, rand | |
MAX_INPUT_LEN = 40 | |
AMOUNT_OF_NOISE = 0.2 / MAX_INPUT_LEN | |
CHARS = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .") | |
def add_noise_to_string(a_string, amount_of_noise): | |
"""Add some artificial spelling mistakes to the string""" | |
if rand() < amount_of_noise * len(a_string): | |
# Replace a character with a random character | |
random_char_position = random_randint(len(a_string)) |
#!/usr/bin/python3 | |
import math | |
import random | |
import sys | |
from argparse import ArgumentParser | |
from collections import defaultdict | |
from util.functions import trace | |
def parse_args(): |
# usage (single sentence): | |
# ref = ['This', 'is', 'a', 'pen', '.'] | |
# hyp = ['There', 'is', 'a', 'pen', '.'] | |
# stats = get_bleu_stats(ref, hyp) | |
# bleu = calculate_bleu(stats) # => 0.668740 | |
# | |
# usage (multiple sentences): | |
# stats = defaultdict(int) | |
# for ref, hyp in zip(refs, hyps): | |
# for k, v in get_bleu_stats(ref, hyp).items(): |
'''This scripts implements Kim's paper "Convolutional Neural Networks for Sentence Classification" | |
with a very small embedding size (20) than the commonly used values (100 - 300) as it gives better | |
result with much less parameters. | |
Run on GPU: THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python imdb_cnn.py | |
Get to 0.853 test accuracy after 5 epochs. 13s/epoch on Nvidia GTX980 GPU. | |
''' | |
from __future__ import print_function |
#!/usr/bin/python3 | |
import datetime | |
import sys | |
import math | |
import numpy as np | |
from argparse import ArgumentParser | |
from collections import defaultdict | |
from chainer import FunctionSet, Variable, functions, optimizers |
... or Why Pipelining Is Not That Easy
Golang Concurrency Patterns for brave and smart.
By @kachayev
"""A simple implementation of a greedy transition-based parser. Released under BSD license.""" | |
from os import path | |
import os | |
import sys | |
from collections import defaultdict | |
import random | |
import time | |
import pickle | |
SHIFT = 0; RIGHT = 1; LEFT = 2; |