Skip to content

Instantly share code, notes, and snippets.

@norouzi
norouzi / edit_distance_marginal.py
Last active November 2, 2017 21:45
Reward Augmented Maximum Likelihood (RAML; https://arxiv.org/pdf/1609.00150.pdf) -- Python code snippet to compute marginal distribution of different #edits for a given sequence length, temperature, and vocab size.
import scipy.misc as misc
import numpy as np
len_target = 20
v = 60 # Vocabulary size
T = .9 # Temperature
max_edits = len_target
x = np.zeros(max_edits)
for n_edits in range(max_edits):
def ComputeHammingCDF(len_target, temprature, vocab):
max_edits = len_target + 1 # we allow between 0 and len_target subs
a = np.zeros(max_edits)
for n_subs in range(max_edits):
count_n_subs = []
tot_edits = misc.comb(len_target, n_subs)
a[n_subs] = np.log(tot_edits) + n_subs * np.log(len(vocab) - 1) # number of sequences: tot_edits * (N-1) ^ n_subs
a[n_subs] += - n_subs / float(temprature) * np.log(len(vocab) - 1) - n_subs / float(temprature) # tot_edits * (N-1) ^ n_subs * ((N-1)e) ^ (-n_subs / T)
p_subs = a - np.max(a)
p_subs = np.exp(p_subs)
@norouzi
norouzi / coco_prompts.txt
Last active April 21, 2022 00:54
Captions from MS COCO
a wooden bench sits on top of a grass hill
A person is flying through the air near some mountains on his snowboard.
Two ducklings laying together in a grassy field.
A black and white picture of a family with one girl looking off to the side.
A large elephant walking next to a man
Three elderly men are sitting on a bench.
The Big Ben clock tower towering over the city of London.
Two young fully clothed ladies on a made-up bed.
A group of books on top of a book shelf.
A small child sitting down with a plate of food on his lap and using his hands to eat the food.
@norouzi
norouzi / interesting_prompts.txt
Last active April 20, 2022 21:40
Interesting text prompts for text > image synthesis models
a triangular purple flower pot. a purple flower pot in the shape of a triangle
a triangular orange picture frame. an orange picture frame in the shape of a triangle
a triangular pink stop sign. a pink stop sign in the shape of a triangle
a cube made of denim. a cube with the texture of denim.
a sphere made of kitchen tile. a sphere with the texture of kitchen tile.
a cube made of brick. a cube with the texture of brick.
a collection of nail is sitting on a table
a single clock is sitting on a table
a couple of glasses are sitting on a table
an illustration of a large red elephant sitting on a small blue mouse
@norouzi
norouzi / auto_prompts.txt
Last active April 21, 2022 01:58
Machine checkable text prompts for text > image synthesis models
a vehicle composed of two wheels held in a frame one behind the other, propelled by pedals and steered with handlebars attached to the front wheel.
a large motor vehicle carrying passengers by road, typically one serving the public on a fixed route and for a fare.
a small vessel propelled on water by oars, sails, or an engine.
a connection point by which firefighters can tap into a water supply.
a machine next to a parking space in a street, into which the driver puts money so as to be authorized to park the vehicle for a particular length of time.
a device consisting of a circular canopy of cloth on a folding metal frame supported by a central rod, used as protection against rain or sometimes sun.
a separate seat for one person, typically with a back and four legs.
an appliance or compartment which is artificially kept cool and used to store food and drink.
a mechanical or electrical device for measuring time.
an instrument used for cutting cloth, paper, and other thin material, consisting of two blades laid