Skip to content

Instantly share code, notes, and snippets.

View poppingtonic's full-sized avatar
💭
👟

Brian Muhia poppingtonic

💭
👟
View GitHub Profile
@thomwolf
thomwolf / top-k-top-p.py
Last active September 10, 2024 05:44
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
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active August 30, 2024 19:17
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;
@ashwinrayaprolu
ashwinrayaprolu / Install.md
Created April 20, 2019 06:40
OpenVINO Ubuntu Xenial, Virtualbox and Vagrant Install, Intel NCS2 (Neural Compute Stick 2)
@coffeemug
coffeemug / age-of-em-review.markdown
Last active March 7, 2017 11:58
Age of Em Review

Every piece of speculation about the future I've ever encountered broadly pattern-matches into one of four genres: forecasting, prophecy, literary works of fiction, and rants. Age of Em doesn't autocomplete into any of these, and I think both my irritation and fascination with it come from the same source -- the audacity of creating an entirely new genre of futurism.

Here are rough properties of the existing four genres:

  • Forescasting - narrow subject matter, falsifiable details that

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@jsheedy
jsheedy / iter_file.py
Last active June 16, 2024 15:27
Sometimes you need a file-like object when all you have is an iterator, for instance when using psycopg2's cursor.copy_from. This class will handle the impedance mismatch.
import io
import sys
class IteratorFile(io.TextIOBase):
""" given an iterator which yields strings,
return a file like object for reading those strings """
def __init__(self, it):
self._it = it
self._f = io.StringIO()
@oguya
oguya / fah-config.xml
Created September 30, 2015 12:21
FAHClient config. file—/etc/fahclient/config.xml
<config>
<!-- See sample config: /usr/share/doc/fahclient/sample-config.xml -->
<!-- Client Control
Don't fold anonymously, provide user info. -->
<fold-anon v='false'/>
<!-- Folding Slot Configuration -->
<gpu v='true'/> <!-- If true, attempt to autoconfigure GPUs -->
#!/usr/bin/perl
# This filter changes all words to Title Caps, and attempts to be clever
# about *un*capitalizing small words like a/an/the in the input.
#
# The list of "small words" which are not capped comes from
# the New York Times Manual of Style, plus 'vs' and 'v'.
#
# 10 May 2008
# Original version by John Gruber:
@mremond
mremond / README
Last active May 4, 2020 16:57
Phoenix Elixir framework with ejabberd - Tutorial
Please read original blog post for reference:
http://blog.process-one.net/embedding-ejabberd-into-an-elixir-phoenix-web-application/
@zmaril
zmaril / core.clj
Last active December 16, 2015 14:19
Simple rejection sampling based probabilistic programming library. An approximation of church.
(ns hacklheber.core)
(defn flip
"A function which returns true or false randomly. Can optionally be
supplied a number for a bias."
([] (> 0.5 (rand)))
([p] (> p (rand))))
(defn- memo-bangs
"If a variable is bound with a bang, then it will be memoized."