Skip to content

Instantly share code, notes, and snippets.

@marekgalovic
marekgalovic / dnli.py
Created April 14, 2017 03:06
Quora question pairs - decomposable NLI
# Decomposable attention model for NLI
# https://arxiv.org/pdf/1606.01933v1.pdf
dnli_graph = tf.Graph()
with dnli_graph.as_default():
embedding_matrix = tf.Variable(tf.zeros([DICTIONARY_SIZE, EMBEDDING_SIZE]), name='word_embeddings', trainable=False)
embedding_placeholder = tf.placeholder(tf.float32, [DICTIONARY_SIZE, EMBEDDING_SIZE])
embedding_init_op = embedding_matrix.assign(embedding_placeholder)
X_Q1 = tf.placeholder(tf.int32, [None, None])
import tensorflow as tf
class BiMPM(object):
'''
Bilateral Multi-Perspective Matching Model
https://arxiv.org/pdf/1702.03814.pdf
'''
def __init__(self, state_size, l_perspectives, embeddings_shape):
self._state_size = state_size
import tensorflow as tf
import numpy as np
class ConvolutionalAttentionNLI(object):
def __init__(self, embeddings_shape, target_classes=2, conv_filter_size=3, conv_projection_size=300, attention_output_size=200, comparison_output_size=100, learning_rate=0.05):
self._embeddings_shape = embeddings_shape
self._target_classes = target_classes
self._conv_filter_size = conv_filter_size
self._conv_projection_size = conv_projection_size
# Q-network implementation using linear function aproximator.
# Estimates action-value given state and weights matrix Q(a|s,W)
import gym
import numpy as np
import matplotlib.pyplot as plt
import time
env = gym.make('FrozenLake-v0')
@marekgalovic
marekgalovic / main.go
Created September 7, 2018 08:12
Etcd Raft consensus protocol local example
package main
import (
"os";
"os/signal";
"syscall";
"time";
"context";
"math";
"bytes";
@marekgalovic
marekgalovic / cart_pole_pg.py
Created November 27, 2018 18:41
CartPole PG
import random
import gym
import numpy as np
import tensorflow as tf
EPOCHS = 250
NUM_GAMES = 100
BATCH_SIZE = 128
MAX_UPDATES = 10
GAMMA = 0.99
@marekgalovic
marekgalovic / tsp_ga.py
Created December 1, 2018 11:12
Genetic Algorithm Traveling Salesman Problem Solver
import math
import random
import numpy as np
from multiprocessing import Pool, cpu_count
def prepend_start(route):
return [0] + list(route)
def create_population(num_points, size):
@marekgalovic
marekgalovic / server.py
Last active July 13, 2020 16:14
Visual Search Server
import os
import json
from PIL import Image
from io import BytesIO
from flask import Flask, jsonify, request, render_template, send_file
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
@marekgalovic
marekgalovic / build_index.py
Created July 13, 2020 16:10
Visual Search Build Index
import os
from argparse import ArgumentParser
from PIL import Image
import json
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
from annoy import AnnoyIndex