Skip to content

Instantly share code, notes, and snippets.

View ceshine's full-sized avatar

CeShine Lee ceshine

View GitHub Profile
@ceshine
ceshine / frozen_lake.py
Created October 11, 2016 14:13
A simple q-learning algorithm for frozen lake env of OpenAI based on keras-rl
# -*- coding: utf-8 -*-
"""
@author: CeShine
Using keras-rl (https://github.com/matthiasplappert/keras-rl) to provide basic framework,
and embedding layer to make it essentially a Q-table lookup algorithm.
"""
import tempfile
@ceshine
ceshine / bactrader_sample.py
Last active May 4, 2023 12:38
A Simple Strategy Trading Two Stocks (back trader)
"""A Simple Strategy Trading Two Stocks
Original code: https://blog.csdn.net/qq_26948675/article/details/80016633
Modified based on: https://www.backtrader.com/blog/posts/2018-04-22-improving-code/improving-code.html
Replaced the local CSV files with online data from IEX.
Unfortunately, this strategy is not profitable for the two stocks picked.
"""
@ceshine
ceshine / birnn.ipynb
Created November 12, 2017 08:52
Figuring How Bidirectional RNN works in Pytorch
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / stlr.py
Last active March 5, 2023 12:13
Pytorch Slanted Triangular Learning Rate Scheduler
class STLR(torch.optim.lr_scheduler._LRScheduler):
def __init__(self, optimizer, max_mul, ratio, steps_per_cycle, decay=1, last_epoch=-1):
self.max_mul = max_mul - 1
self.turning_point = steps_per_cycle // (ratio + 1)
self.steps_per_cycle = steps_per_cycle
self.decay = decay
super().__init__(optimizer, last_epoch)
def get_lr(self):
residual = self.last_epoch % self.steps_per_cycle
@ceshine
ceshine / jupyter_notebook_config.py
Created August 23, 2017 12:31
Jupyter Notebook Post-save Hook: Auto-convert a Python script and a HTML from the notebook
# Reference: https://svds.com/jupyter-notebook-best-practices-for-data-science/
import os
from subprocess import check_call
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d)
@ceshine
ceshine / profiling.ipynb
Created April 24, 2020 06:31
Tensorflow Profiler with Custom Training Loop
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / run_tf_glue.ipynb
Created December 26, 2019 06:55
Train huggingface/transformers BERT model on Cloud CPU with TF 2.1 (nightly build)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / avazu_ftrl_concurrent.go
Last active August 5, 2021 11:07
Kaggle Avazu Challenge: FTRL-Proximal with L1 & L2 implemented in Go (Concurrent/Multi-threaded)
// Based on tinrtgu's Python script here:
// https://www.kaggle.com/c/avazu-ctr-prediction/forums/t/10927/beat-the-benchmark-with-less-than-1mb-of-memory
package main
import (
"encoding/csv"
"os"
"strconv"
"hash/fnv"
"math"
@ceshine
ceshine / streamlit.py
Created March 14, 2021 06:41
Streamlit Script that Cache the loading of a FAISS index (live at https://news-search.veritable.pw)
import os
import sqlite3
import datetime
from typing import List
import faiss
import numpy as np
import pandas as pd
import joblib
import requests
@ceshine
ceshine / demo.py
Created February 19, 2021 05:31
Demo of the @patch_to decorator from fastcore
from fastcore.basics import patch_to
class Demo:
val = 10
def __init__(self, val):
self.val = val
# ====================
# The default mode