Skip to content

Instantly share code, notes, and snippets.

View tokestermw's full-sized avatar

Motoki Wu tokestermw

View GitHub Profile
@smhanov
smhanov / dawg.py
Last active August 18, 2025 12:59
Use a DAWG as a map
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Please see http://stevehanov.ca/blog/index.php?id=115 for the accompanying article.
#
# Based on Daciuk, Jan, et al. "Incremental construction of minimal acyclic finite-state automata."
# Computational linguistics 26.1 (2000): 3-16.
#
# Updated 2014 to use DAWG as a mapping; see
# Kowaltowski, T.; CL. Lucchesi (1993), "Applications of finite automata representing large vocabularies",
# Software-Practice and Experience 1993
@Newmu
Newmu / adam.py
Last active October 19, 2024 08:20
Adam Optimizer
"""
The MIT License (MIT)
Copyright (c) 2015 Alec Radford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@fheisler
fheisler / q.py
Created March 31, 2015 23:02
Q-learning Tic-tac-toe
import random
class TicTacToe:
def __init__(self, playerX, playerO):
self.board = [' ']*9
self.playerX, self.playerO = playerX, playerO
self.playerX_turn = random.choice([True, False])
def play_game(self):
@jiumem
jiumem / Callback.md
Last active May 8, 2018 22:45
keras for deep learning
class LossHistory(Callback):
    def __init__(self, X_train, y_train, layer_index):
        super(Callback, self).__init__()
        self.layer_index = layer_index
        if X_train.shape[0] >= 1000:
            mask = np.random.choice(X_train.shape[0], 1000)
            self.X_train_subset = X_train[mask]
            self.y_train_subset = y_train[mask]
        else:
@entron
entron / imdb_cnn_kim_small_embedding.py
Last active September 16, 2023 16:23
Keras implementation of Kim's paper "Convolutional Neural Networks for Sentence Classification" with a very small embedding size. The test accuracy is 0.853.
'''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/env python
# coding: utf-8
"""Sampling Sequence Data from model"""
import numpy as np
import tensorflow as tf
import json
import cPickle as pickle
import itertools as it
from rnnlib import PTBModel
def get_H_n(X):
return X[:, -1, :] # get last element from time dim
def get_Y(X):
return X[:, :110, :] # get first xmaxlen elem from time dim
def get_R(X):
Y, alpha = X.values() # Y should be (L,k) and alpha should be (L,) and ans should be (k,)
@EderSantana
EderSantana / resnet_all_conv.py
Last active March 30, 2019 14:43
Resnet + all conv implementation example
"""
Possibly correct implementation of an all conv neural network using a single residual module
This code was written for instruction purposes and no attempt to get the best results were made.
References:
Deep Residual Learning for Image Recognition: http://arxiv.org/pdf/1512.03385v1.pdf
STRIVING FOR SIMPLICITY, THE ALL CONVOLUTIONAL NET: http://arxiv.org/pdf/1412.6806v3.pdf
A video walking through the code and main ideas: https://youtu.be/-N_zlfKo4Ec
@danijar
danijar / blog_tensorflow_sequence_labelling.py
Last active January 12, 2024 15:18
TensorFlow Sequence Labelling
# Example for my blog post at:
# http://danijar.com/introduction-to-recurrent-networks-in-tensorflow/
import functools
import sets
import tensorflow as tf
def lazy_property(function):
attribute = '_' + function.__name__