Skip to content

Instantly share code, notes, and snippets.

View khuangaf's full-sized avatar
:octocat:
Focusing

Kung-Hsiang Steeve Huang khuangaf

:octocat:
Focusing
View GitHub Profile
class CnnPolicy(object):
def __init__(self, sess, ob_space, ac_space, nbatch, nsteps, reuse=True):
ob_shape = (nbatch,) + ob_space.shape
actdim = ac_space.shape[0]
window_length = ob_space.shape[1] -1
X = tf.placeholder(tf.float32, ob_shape, name='Ob') #obs
with tf.variable_scope("model", reuse=reuse) as scope:
w0 = tf.slice(X, [0,0,0,0],[-1,-1,1,1])
x = tf.slice(X, [0,0,1,0],[-1,-1,-1,-1])
@khuangaf
khuangaf / ppo2
Last active January 22, 2018 09:46
class Model(object):
def __init__(self, *, policy, ob_space, ac_space, nbatch_act, nbatch_train,
nsteps, ent_coef, vf_coef, max_grad_norm, training):
sess = tf.get_default_session()
if training:
act_model = policy(sess, ob_space, ac_space, nbatch_act, 1, reuse=False)
else:
act_model = policy(sess, ob_space, ac_space, nbatch_act, 1, reuse=True)
train_model = policy(sess, ob_space, ac_space, nbatch_train, nsteps, reuse=True)
import numpy as np
import os
from random import shuffle
import re
import urllib.request
import zipfile
import lxml.etree
#download the data
urllib.request.urlretrieve("https://wit3.fbk.eu/get.php?path=XML_releases/xml/ted_en-20160408.zip&filename=ted_en-20160408.zip", filename="ted_en-20160408.zip")
# extract subtitle
# remove parenthesis
input_text_noparens = re.sub(r'\([^)]*\)', '', input_text)
# store as list of sentences
sentences_strings_ted = []
for line in input_text_noparens.split('\n'):
m = re.match(r'^(?:(?P<precolon>[^:]{,20}):)?(?P<postcolon>.*)$', line)
sentences_strings_ted.extend(sent for sent in m.groupdict()['postcolon'].split('.') if sent)
# store as list of lists of words
sentences_ted = []
for sent_str in sentences_strings_ted:
from gensim.models import Word2Vec
model_ted = Word2Vec(sentences=sentences_ted, size=100, window=5, min_count=5, workers=4, sg=0)
model_ted.wv.most_similar(“man”)
from gensim.models import FastText
model_ted = FastText(sentences_ted, size=100, window=5, min_count=5, workers=4,sg=1)
model_ted.wv.most_similar(“shht”)
model_ted.wv.most_similar("Gastroenteritis")
from spotlight.interactions import Interactions
implicit_interactions = Interactions(user_ids, item_ids)
explicit_interactions = Interactions(user_ids, item_ids, ratings)