sudo apt-get install python3-pip
sudo pip3 install virtualenv
from __future__ import print_function | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
def sample_gumbel(shape, eps=1e-20): | |
U = torch.rand(shape).cuda() | |
return -Variable(torch.log(-torch.log(U + eps) + eps)) |
import torch | |
import torch.nn as nn | |
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence | |
seqs = ['gigantic_string','tiny_str','medium_str'] | |
# make <pad> idx 0 | |
vocab = ['<pad>'] + sorted(set(''.join(seqs))) | |
# make model |
#!/usr/bin/env python | |
import numpy as np | |
import cv2 | |
from time import sleep | |
# create blank image - y, x | |
img = np.zeros((600, 1000, 3), np.uint8) | |
# setup text |
from numpy.random import choice as random_choice, randint as random_randint, rand | |
MAX_INPUT_LEN = 40 | |
AMOUNT_OF_NOISE = 0.2 / MAX_INPUT_LEN | |
CHARS = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .") | |
def add_noise_to_string(a_string, amount_of_noise): | |
"""Add some artificial spelling mistakes to the string""" | |
if rand() < amount_of_noise * len(a_string): | |
# Replace a character with a random character | |
random_char_position = random_randint(len(a_string)) |