Skip to content

Instantly share code, notes, and snippets.

@thomwolf
thomwolf / top-k-top-p.py
Last active January 2, 2024 07:43
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
"""
assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear
top_k = min(top_k, logits.size(-1)) # Safety check
@gngdb
gngdb / Efficient Top 1 Error Scatter Plot.ipynb
Last active February 5, 2023 17:19
Graphing performance for a report.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@RRethy
RRethy / gist:ad8a9a3b1112a48226ec3336fa981224
Last active April 21, 2024 03:40
Seamlessly editing remote files in (Neo)Vim with Netrw and scp

Seamlessly editing remote files in (Neo)Vim with Netrw and scp

Neovim and Vim both come bundled with a standard plugin called Netrw. Netrw acts a file explorer (similar to NERDTree), but more importantly has the ability to work with scp (as well as sftp, rcp, ftp, and lots of others :h netrw-nread) to let you edit files and browse directories that are hosted on a remote machine, inside of your local Vim instance.

This is useful since you are able to use your Vim setup and plugins without copying over your dotfiles to the remote machine. As well, since the file is copied to your local machine, there will be no delay when typing.

Setup

This is optional for Vim, but required for Neovim (check this Neovim issue explaining why).

@eamartin
eamartin / notebook.ipynb
Last active November 6, 2022 18:53
Understanding & Visualizing Self-Normalizing Neural Networks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / shortbold.md
Last active August 3, 2017 16:58
Jupyter shortbold markdown cell, just paste into a markdown cell to enjoy shortbold MathJax for the rest of the notebook!

$ \newcommand{\aB}{\mathbf{a}} \newcommand{\bB}{\mathbf{b}} \newcommand{\cB}{\mathbf{c}} \newcommand{\dB}{\mathbf{d}} \newcommand{\eB}{\mathbf{e}} \newcommand{\fB}{\mathbf{f}} \newcommand{\gB}{\mathbf{g}} \newcommand{\hB}{\mathbf{h}} \newcommand{\iB}{\mathbf{i}}

Name t
Jovan 0.143522377788
Wilford 0.171813290491
Newton 0.192343843426
Maurice 0.193607112432
Emmanuel 0.20571087052
Joseph 0.210762071958
Milton 0.21296788724
Ahmad 0.214983745995
Julius 0.218052193228
@simonkamronn
simonkamronn / hyperband.py
Created November 11, 2016 16:06
Hyperband for hyperparameter optimization
# https://people.eecs.berkeley.edu/~kjamieson/hyperband.html
# you need to write the following hooks for your custom problem
from problem import get_random_hyperparameter_configuration,run_then_return_val_loss
max_iter = 81 # maximum iterations/epochs per configuration
eta = 3 # defines downsampling rate (default=3)
logeta = lambda x: log(x)/log(eta)
s_max = int(logeta(max_iter)) # number of unique executions of Successive Halving (minus one)
B = (s_max+1)*max_iter # total number of iterations (without reuse) per execution of Succesive Halving (n,r)
@kylemcdonald
kylemcdonald / showarray.py
Created January 3, 2016 08:56
Minimal code for rendering a numpy array as an image in a Jupyter notebook in memory. Borrowed from the Deep Dream notebook.
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(a)
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
IPython.display.display(IPython.display.Image(data=f.getvalue()))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willurd
willurd / web-servers.md
Last active April 23, 2024 23:07
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000