Now available here: https://github.com/y0ast/pytorch-snippets/tree/main/fast_mnist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create the rect you would like your text to be inside of... | |
CGRect maxTextRect = CGRectMake(0, 0, 200, 60); | |
//Create the attributed string | |
NSAttributedString *theString = //... do all the setup. | |
//Find the rect that the string will draw into **inside the maxTextRect** | |
CGRect actualRect = [theString boundingRectWithSize:maxTextRect.size options:NSStringDrawingUsesLineFragmentOrigin context:nil]; | |
//Offset the actual rect inside the maxTextRect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Why not simply use textField:shouldChangeCharactersInRange:replacementString:? | |
=== | |
If you google how to limit a length of text field, you'll see many implementations simply using textField:shouldChangeCharactersInRange:replacementString: like | |
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
{ | |
return [[textField.text stringByReplacingCharactersInRange:range withString:string] length] <= MAX_LENGTH; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Source code with the blog post at http://monik.in/a-noobs-guide-to-implementing-rnn-lstm-using-tensorflow/ | |
import numpy as np | |
import random | |
from random import shuffle | |
import tensorflow as tf | |
# from tensorflow.models.rnn import rnn_cell | |
# from tensorflow.models.rnn import rnn | |
NUM_EXAMPLES = 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pylint: disable=C0111,too-many-arguments,too-many-instance-attributes,too-many-locals,redefined-outer-name,fixme | |
# pylint: disable=superfluous-parens, no-member, invalid-name | |
import sys | |
sys.path.insert(0, "../../python") | |
import mxnet as mx | |
import numpy as np | |
import cv2, random | |
from io import BytesIO | |
from captcha.image import ImageCaptcha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
from torch.optim import lr_scheduler | |
import torch.utils.data as data | |
from torch.nn.utils.rnn import pack_padded_sequence as pack, pad_packed_sequence as unpack | |
import torchaudio | |
import torchaudio.transforms as tat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Ander Martinez Sanchez | |
from __future__ import division, print_function | |
from math import exp, log | |
from collections import Counter | |
def ngram_count(words, n): | |
if n <= len(words): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required tensorflow 0.12 | |
# required gensim 0.13.3+ for new api model.wv.index2word or just use model.index2word | |
from gensim.models import Word2Vec | |
import tensorflow as tf | |
from tensorflow.contrib.tensorboard.plugins import projector | |
# loading your gensim | |
model = Word2Vec.load("YOUR-MODEL") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
class TextCNN(object): | |
""" | |
A CNN for text classification. | |
Uses an embedding layer, followed by a convolutional, max-pooling and softmax layer. | |
""" | |
def __init__( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Read a CSV/TSV with a header row (!) and put it into a new sqlite table | |
import sys | |
import csv | |
import sqlite3 | |
class Importer (object): |
OlderNewer