Skip to content

Instantly share code, notes, and snippets.

View USE1_install.py
!pip3 install --upgrade tensorflow-gpu
# Install TF-Hub.
!pip3 install tensorflow-hub
View InferSent2_loadmodel.py
from models import InferSent
import torch
V = 2
MODEL_PATH = 'encoder/infersent%s.pkl' % V
params_model = {'bsize': 64, 'word_emb_dim': 300, 'enc_lstm_dim': 2048,
'pool_type': 'max', 'dpout_model': 0.0, 'version': V}
model = InferSent(params_model)
model.load_state_dict(torch.load(MODEL_PATH))
View SBert1_loadmodel.py
from sentence_transformers import SentenceTransformer
sbert_model = SentenceTransformer('bert-base-nli-mean-tokens')
View SE1_setup.py
import nltk
nltk.download('punkt')
from nltk.tokenize import word_tokenize
import numpy as np
View 1_tokenize.py
from nltk.tokenize import word_tokenize
# Tokenization of each document
tokenized_sent = []
for s in sentences:
tokenized_sent.append(word_tokenize(d.lower()))
tokenized_sent
@purva91
purva91 / augment_ResNet.py
Last active Sep 1, 2021
Pretrained_Image.py
View augment_ResNet.py
# Add our data-augmentation parameters to ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255., rotation_range = 40, width_shift_range = 0.2, height_shift_range = 0.2, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1.0/255.)
train_generator = train_datagen.flow_from_directory(train_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224))
validation_generator = test_datagen.flow_from_directory( validation_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224))
View import_packages.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
@purva91
purva91 / click_rate_context.py
Last active Dec 6, 2019
counterfactual analysis
View click_rate_context.py
# set ads
num_ads = 3
ads = np.asarray(["ad_{}".format(i) for i in range(num_ads)])
# assign random priors to contexts
ad_interaction_priors = np.asarray([0.1, 0.3, 0.6])
user_context_priors = {context:np.random.permutation(ad_interaction_priors) for context in user_contexts}
View prc_auc
# calculate precision-recall AUC
auc_prc = auc(recall, precision)
print(auc_prc)