Skip to content

Instantly share code, notes, and snippets.

View bertjiazheng's full-sized avatar

Jia Zheng bertjiazheng

View GitHub Profile
@WetHat
WetHat / PY-Drawing3D.ipynb
Last active May 31, 2024 13:08
Matplotlib: 3D Arrows and 3D Annotations
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Randl
Randl / ieee_fullname.bst
Last active June 26, 2023 11:06
CVPR bibliography with natbib support
% Fixed extra right bracket
%
% Evgenii Zheltonozhskii, 09/28/2020, zheltonozhskiy@gmail.com
%
% ---------------------------------------------------------------
% Modified CVPR ieee_fullname.bst to support natbib
%
% Evgenii Zheltonozhskii, 03/10/2019, zheltonozhskiy@gmail.com
%
% ---------------------------------------------------------------
@thomwolf
thomwolf / top-k-top-p.py
Last active May 14, 2024 00:20
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