Skip to content

Instantly share code, notes, and snippets.

@yang-zhang
yang-zhang / fastai_fixup.py
Created May 30, 2018 01:36
Fixup function for text from fast.ai
re1 = re.compile(r' +')
def fixup(x):
x = x.replace('#39;', "'").replace('amp;', '&').replace('#146;', "'").replace(
'nbsp;', ' ').replace('#36;', '$').replace('\\n', "\n").replace('quot;', "'").replace(
'<br />', "\n").replace('\\"', '"').replace('<unk>','u_n').replace(' @.@ ','.').replace(
' @-@ ','-').replace('\\', ' \\ ')
return re1.sub(' ', html.unescape(x))
# https://github.com/fastai/fastai/blob/master/courses/dl2/imdb.ipynb
@yang-zhang
yang-zhang / pdb.md
Created May 30, 2018 15:00
pdb cheatsheet
  • s / n / c
  • u / d
  • p
  • l
@yang-zhang
yang-zhang / inds_topn.py
Created June 1, 2018 16:01
Get indices of n largest elements in a numpy array
# https://stackoverflow.com/questions/6910641/how-to-get-indices-of-n-maximum-values-in-a-numpy-array
import numpy as np
top_n = 3
arr = np.array([1, 3, 2, 4, 5])
arr.argsort()[-top_n:][::-1]
# array([4, 3, 1])
@yang-zhang
yang-zhang / ewma.ipynb
Last active June 3, 2018 18:45
Exponential moving average (EMA) aka exponentially weighted moving average (EWMA) in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yang-zhang
yang-zhang / mac_show_hidden.md
Created June 6, 2018 02:06
Custom Search How to Show Hidden Files on MacOS with a Keyboard Shortcut

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@yang-zhang
yang-zhang / dict2df.py
Created June 20, 2018 15:19
Convert a dictionary to pandas dataframe
dict_ = {'001.jpg': 'dog', '002.jpg': 'cat', }
df = pd.DataFrame.from_dict(dict_, orient='index').reset_index()
df.columns = ['image_name', 'tags']
@yang-zhang
yang-zhang / pluralsight_advanced_python_course_notes.md
Created June 23, 2018 01:22
Pluralsight advanced Python course notes

while else # nobreak

@yang-zhang
yang-zhang / pytorch_references.md
Last active July 5, 2018 02:23
Pytorch references

for i, l in enumerate(self.linears):