View USE1_install.py
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
!pip3 install --upgrade tensorflow-gpu | |
# Install TF-Hub. | |
!pip3 install tensorflow-hub |
View InferSent2_loadmodel.py
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
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
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
from sentence_transformers import SentenceTransformer | |
sbert_model = SentenceTransformer('bert-base-nli-mean-tokens') |
View SE1_setup.py
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 nltk | |
nltk.download('punkt') | |
from nltk.tokenize import word_tokenize | |
import numpy as np |
View 1_tokenize.py
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
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 |
View augment_ResNet.py
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
# 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
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 pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline |
View sample_01.py
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
print("Hello") |
View click_rate_context.py
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
# 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
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
# calculate precision-recall AUC | |
auc_prc = auc(recall, precision) | |
print(auc_prc) |
NewerOlder