Skip to content

Instantly share code, notes, and snippets.

View speedcell4's full-sized avatar

Yiran Wang speedcell4

View GitHub Profile
@speedcell4
speedcell4 / masked.py
Last active August 8, 2017 01:35
masked_softmax and masked_softmax_cross_entropy
import chainer.functions as F
from chainer import Variable, cuda
def masked_softmax(x, mask, axis=1):
xp = cuda.get_array_module(x, mask)
with cuda.get_device_from_array(x, mask):
exp_x = F.exp(x)
zeros = xp.zeros_like(x.data)
sum_exp_x = F.sum(F.where(mask, exp_x, zeros), axis=axis, keepdims=True)
@speedcell4
speedcell4 / dynet-helper.cc
Created July 21, 2017 04:51
DyNet helpers
#ifndef DYNET_HELPER_H
#define DYNET_HELPER_H
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include "dynet/dynet.h"
#include "dynet/expr.h"
import chainer.functions as F
import chainer.links as L
import numpy as np
from chainer import Chain
from chainer import cuda, training, Variable
from chainer import datasets, iterators, optimizers, initializers
from chainer.training import extensions
from sklearn.datasets import load_iris
@speedcell4
speedcell4 / A.cpp
Last active April 30, 2017 13:54
Google Code Jam 2017 - Round 1C
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <deque>
#include <map>
#include <queue>
@speedcell4
speedcell4 / common_citings.py
Created March 2, 2017 12:18
find out the common citings of given papers
from functools import reduce
from typing import List
from typing import Set
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import Chrome
URLs = [
r'https://scholar.google.com/scholar?cites=17690265189765140803&as_sdt=2005&sciodt=0,5&hl=ja',
r'https://scholar.google.com/scholar?cites=14180674818440394404&as_sdt=2005&sciodt=0,5&hl=ja',
@speedcell4
speedcell4 / distributed.py
Created December 7, 2016 05:25
tensorflow distributed framework
import tensorflow as tf
tf.app.flags.DEFINE_string('ps_hosts', '', 'Comma-separated list of hostname:port pairs')
tf.app.flags.DEFINE_string('worker_hosts', '', 'Comma-separated list of hostname:port pairs')
tf.app.flags.DEFINE_string('job_name', '', 'One of ps or worker')
tf.app.flags.DEFINE_integer('task_index', 0, 'Index of task within the job')
tf.app.flags.DEFINE_string('logdir', 'logdir', 'Directory to log')
FLAGS = tf.app.flags.FLAGS
@speedcell4
speedcell4 / iris_classifier.py
Last active December 7, 2016 05:15
Tensorflow practice
import numpy as np
import tensorflow as tf
from numpy.random import RandomState
from sklearn.model_selection import StratifiedShuffleSplit
from tensorflow.contrib.layers import fully_connected
tf.logging.set_verbosity(tf.logging.INFO)
random_state = RandomState()
@speedcell4
speedcell4 / R1B-a.cpp
Last active May 1, 2016 08:31
Google Code Jam 2016
#include <iostream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <algorithm>
using namespace std;
typedef long long i64;
@speedcell4
speedcell4 / A.cpp
Last active February 16, 2016 10:38
Codeforces #622
#include <iostream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <algorithm>
using namespace std;
typedef long long i64;
@speedcell4
speedcell4 / regex-alf-nu.md
Last active August 29, 2015 14:22
solution to Regex Golf

solutions to Regex Golf

Play

  1. Warmup: foo
  2. Anchors: ick$
  3. Ranges: ^[a-f]+$
  4. Backrefs: (...).*\1
  5. Four: (.)(.\1){3}