Skip to content

Instantly share code, notes, and snippets.

View MLWhiz's full-sized avatar
🤓
Focusing

Rahul Agarwal MLWhiz

🤓
Focusing
View GitHub Profile
@MLWhiz
MLWhiz / _.md
Created October 12, 2015 23:23
reddit base
@MLWhiz
MLWhiz / _.md
Created October 12, 2015 23:25
reddit api with JSONP
@MLWhiz
MLWhiz / _.md
Created October 13, 2015 00:53
reddit base
@MLWhiz
MLWhiz / _.md
Last active October 13, 2015 01:00
reddit base circles
@MLWhiz
MLWhiz / Polar Area Chart (Game of Thrones).markdown
Created October 13, 2015 15:03
Polar Area Chart (Game of Thrones)
@MLWhiz
MLWhiz / _.md
Created October 13, 2015 18:26
reddit base
def get_model(features,clipvalue=1.,num_filters=40,dropout=0.1,embed_size=501):
features_input = Input(shape=(features.shape[1],))
inp = Input(shape=(maxlen, ))
# Layer 1: Word2Vec Embeddings.
x = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp)
# Layer 2: SpatialDropout1D(0.1)
x = SpatialDropout1D(dropout)(x)
class Alex_NeuralNet_Meta(nn.Module):
def __init__(self,hidden_size,lin_size, embedding_matrix=embedding_matrix):
super(Alex_NeuralNet_Meta, self).__init__()
# Initialize some parameters for your model
self.hidden_size = hidden_size
drp = 0.1
# Layer 1: Word2Vec Embeddings.
self.embedding = nn.Embedding(max_features, embed_size)
def pytorch_model_run_cv(x_train,y_train,features,x_test, model_obj, feats = False,clip = True):
seed_everything()
avg_losses_f = []
avg_val_losses_f = []
# matrix for the out-of-fold predictions
train_preds = np.zeros((len(x_train)))
# matrix for the predictions on the test set
test_preds = np.zeros((len(x_test)))
splits = list(StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=SEED).split(x_train, y_train))
for i, (train_idx, valid_idx) in enumerate(splits):
# Some preprocesssing that will be common to all the text classification methods you will see.
puncts = [',', '.', '"', ':', ')', '(', '-', '!', '?', '|', ';', "'", '$', '&', '/', '[', ']', '>', '%', '=', '#', '*', '+', '\\', '•', '~', '@', '£',
'·', '_', '{', '}', '©', '^', '®', '`', '<', '→', '°', '€', '™', '›', '♥', '←', '×', '§', '″', '′', 'Â', '█', '½', 'à', '…',
'“', '★', '”', '–', '●', 'â', '►', '−', '¢', '²', '¬', '░', '¶', '↑', '±', '¿', '▾', '═', '¦', '║', '―', '¥', '▓', '—', '‹', '─',
'▒', ':', '¼', '⊕', '▼', '▪', '†', '■', '’', '▀', '¨', '▄', '♫', '☆', 'é', '¯', '♦', '¤', '▲', 'è', '¸', '¾', 'Ã', '⋅', '‘', '∞',
'∙', ')', '↓', '、', '│', '(', '»', ',', '♪', '╩', '╚', '³', '・', '╦', '╣', '╔', '╗', '▬', '❤', 'ï', 'Ø', '¹', '≤', '‡', '√', ]
def clean_text(x):
x = str(x)