Skip to content

Instantly share code, notes, and snippets.

Avatar

CeShine Lee ceshine

View GitHub Profile
@ceshine
ceshine / birnn.ipynb
Created Nov 12, 2017
Figuring How Bidirectional RNN works in Pytorch
View birnn.ipynb
Loading
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 Oct 26, 2021
Pytorch Slanted Triangular Learning Rate Scheduler
View stlr.py
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 Aug 23, 2017
Jupyter Notebook Post-save Hook: Auto-convert a Python script and a HTML from the notebook
View jupyter_notebook_config.py
# 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 / run_tf_glue.ipynb
Created Dec 26, 2019
Train huggingface/transformers BERT model on Cloud CPU with TF 2.1 (nightly build)
View run_tf_glue.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / bactrader_sample.py
Last active Aug 24, 2021
A Simple Strategy Trading Two Stocks (back trader)
View bactrader_sample.py
"""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 / avazu_ftrl_concurrent.go
Last active Aug 5, 2021
Kaggle Avazu Challenge: FTRL-Proximal with L1 & L2 implemented in Go (Concurrent/Multi-threaded)
View avazu_ftrl_concurrent.go
// 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 Mar 14, 2021
Streamlit Script that Cache the loading of a FAISS index (live at https://news-search.veritable.pw)
View streamlit.py
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 Feb 19, 2021
Demo of the @patch_to decorator from fastcore
View demo.py
from fastcore.basics import patch_to
class Demo:
val = 10
def __init__(self, val):
self.val = val
# ====================
# The default mode
@ceshine
ceshine / avazu_ftrl.go
Last active Feb 4, 2021
Kaggle Avazu Challenge: FTRL-Proximal with L1 & L2 implemented in Go (single-threaded)
View avazu_ftrl.go
// 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 / frozen_lake.py
Created Oct 11, 2016
A simple q-learning algorithm for frozen lake env of OpenAI based on keras-rl
View frozen_lake.py
# -*- 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