From fd77d007ea4d8a715db77cb1e8f78ca11cf9b548 Mon Sep 17 00:00:00 2001 From: Todd Morrill Date: Fri, 22 May 2020 19:26:38 -0400 Subject: [PATCH 1/6] initial skorch hyperparam opt implementation --- .gitignore | 4 + machine-learning/model.py | 44 + machine-learning/skorch-hyperparam-opt.ipynb | 1117 ++++++++++++++++++ 3 files changed, 1165 insertions(+) create mode 100644 machine-learning/model.py create mode 100644 machine-learning/skorch-hyperparam-opt.ipynb diff --git a/.gitignore b/.gitignore index 70702445..70255b20 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ _build/ mydask.png dataframes/data .idea/ +.devcontainer/ +.data/ +.vector_cache/ +__pycache__ \ No newline at end of file diff --git a/machine-learning/model.py b/machine-learning/model.py new file mode 100644 index 00000000..54cc9192 --- /dev/null +++ b/machine-learning/model.py @@ -0,0 +1,44 @@ +# more details can be found here: https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/4%20-%20Convolutional%20Sentiment%20Analysis.ipynb +import torch +import torch.nn as nn +import torch.nn.functional as F + + +class CNN(nn.Module): + def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0.2, pretrained_embeddings=None): + + super().__init__() + self.embedding = nn.Embedding.from_pretrained(torch.FloatTensor(pretrained_embeddings)) + self.embedding.weight.requires_grad = False # save some computation + embedding_dim = self.embedding.embedding_dim + self.conv_0 = nn.Conv1d(in_channels = 1, + out_channels = n_filters, + kernel_size = (filter_sizes[0], embedding_dim)) + self.conv_1 = nn.Conv1d(in_channels = 1, + out_channels = n_filters, + kernel_size = (filter_sizes[1], embedding_dim)) + self.conv_2 = nn.Conv1d(in_channels = 1, + out_channels = n_filters, + kernel_size = (filter_sizes[2], embedding_dim)) + self.fc = nn.Linear(len(filter_sizes) * n_filters, 2) + self.dropout = nn.Dropout(dropout) + + def forward(self, text): + #text = [batch size, sent len] + embedded = self.embedding(text) + #embedded = [batch size, sent len, emb dim] + embedded = embedded.unsqueeze(1) + #embedded = [batch size, 1, sent len, emb dim] + conved_0 = F.relu(self.conv_0(embedded).squeeze(3)) + conved_1 = F.relu(self.conv_1(embedded).squeeze(3)) + conved_2 = F.relu(self.conv_2(embedded).squeeze(3)) + #conved_n = [batch size, n_filters, sent len - filter_sizes[n] + 1] + pooled_0 = F.max_pool1d(conved_0, conved_0.shape[2]).squeeze(2) + pooled_1 = F.max_pool1d(conved_1, conved_1.shape[2]).squeeze(2) + pooled_2 = F.max_pool1d(conved_2, conved_2.shape[2]).squeeze(2) + #pooled_n = [batch size, n_filters] + cat = self.dropout(torch.cat((pooled_0, pooled_1, pooled_2), dim = 1)) + #cat = [batch size, n_filters * len(filter_sizes)] + logits = self.fc(cat) + #logits = [batch_size, output_dim] + return F.softmax(logits, dim=-1) \ No newline at end of file diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb new file mode 100644 index 00000000..54344473 --- /dev/null +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -0,0 +1,1117 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install -q dask_cuda torch torchtext skorch\n", + "!pip -q install dask[dataframe] --upgrade" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Hyperparameter optimization with Skorch\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Dask" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

Client

\n", + "\n", + "
\n", + "

Cluster

\n", + "
    \n", + "
  • Workers: 1
  • \n", + "
  • Cores: 1
  • \n", + "
  • Memory: 33.68 GB
  • \n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "from dask_cuda import LocalCUDACluster\n", + "from distributed import Client\n", + "\n", + "# if you have GPU(s), use dask_cuda to automatically make use of them in your dask cluster\n", + "if torch.cuda.is_available():\n", + " cluster = LocalCUDACluster()\n", + " client = Client(cluster)\n", + "else:\n", + " client = Client(processes=False, threads_per_worker=4,\n", + " n_workers=1, memory_limit='2GB')\n", + "client" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# for reproducibility\n", + "import random\n", + "import numpy as np\n", + "\n", + "SEED = 42\n", + "\n", + "random.seed(SEED)\n", + "np.random.seed(SEED)\n", + "torch.manual_seed(SEED)\n", + "torch.backends.cudnn.deterministic = True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create Data" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import torchtext\n", + "from torchtext import data\n", + "from torchtext import datasets" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# takes approx. 10 minutes to download data and embeddings (will be cached for re-use)\n", + "\n", + "# set up fields\n", + "TEXT = data.Field(lower=True, include_lengths=True, batch_first=True)\n", + "LABEL = data.Field(sequential=False, unk_token=None)\n", + "\n", + "# make splits for data\n", + "train, test = datasets.IMDB.splits(TEXT, LABEL)\n", + "\n", + "# will be used to initialize model embeddings layer\n", + "vocab = torchtext.vocab.GloVe(name='6B', dim=100)\n", + "\n", + "# build the vocabulary\n", + "max_size = 25_000 # shorten for demonstrative purposes\n", + "TEXT.build_vocab(train, vectors=vocab, max_size=max_size)\n", + "LABEL.build_vocab(train)\n", + "\n", + "# make iterator for splits\n", + "train_iter, test_iter = data.BucketIterator.splits(\n", + " (train, test), batch_sizes=(32, 64), device=device)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['', '', 'the', 'a', 'and']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# itos := index-to-string\n", + "# note the 2 extra tokens added for us: '', ''\n", + "TEXT.vocab.itos[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "assert (len(TEXT.vocab.itos) == max_size + 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.']\n", + "\n", + "pos\n" + ] + } + ], + "source": [ + "# peek at the data\n", + "print(train.examples[0].text)\n", + "print()\n", + "print(train.examples[0].label)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# sadly train_iter isn't actually an iter..\n", + "# peek at a batch of data\n", + "batch = next(iter(train_iter))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([[ 45, 123, 25, ..., 1, 1, 1],\n", + " [5311, 3868, 2, ..., 1, 1, 1],\n", + " [ 133, 8, 42, ..., 1, 1, 1],\n", + " ...,\n", + " [ 9, 176, 10, ..., 1, 1, 1],\n", + " [1467, 10, 30, ..., 1, 1, 1],\n", + " [ 82, 1297, 9, ..., 1, 1, 1]], device='cuda:0')\n", + "tensor([147, 347, 361, 66, 147, 262, 336, 105, 255, 132, 128, 162, 122, 184,\n", + " 195, 100, 226, 127, 152, 159, 120, 204, 267, 209, 129, 486, 95, 151,\n", + " 140, 247, 127, 167], device='cuda:0')\n" + ] + } + ], + "source": [ + "# numericalized tokens\n", + "print(batch.text[0])\n", + "# sequence lengths\n", + "print(batch.text[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,\n", + " 1, 1, 1, 1, 0, 1, 0, 0], device='cuda:0')" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "batch.label" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "defaultdict(None, {'neg': 0, 'pos': 1})" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# stoi := string-to-index\n", + "# check on the meaning of these zeroes and ones\n", + "LABEL.vocab.stoi" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Define your network" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "# was having trouble with when model was defined in the notebook\n", + "# Can't get attribute ‘CNN' on )" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# smoketest\n", + "model = CNN(pretrained_embeddings=vocab.vectors).to(device)\n", + "model(batch.text[0].to(device))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "del model" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Quick attempt at model training" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "import skorch\n", + "from skorch import NeuralNetClassifier\n", + "import torch.optim as optim" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# this is a really unfortunate hack to make torchtext batching semantics work with skorch and dask\n", + "# the downside here is that we're no longer padding to the longest sequence in the batch, rather\n", + "# we're padding to the longest sequence in the *dataset*, which results in signifcantly more\n", + "# computation and thus significantly more time to train a model\n", + "# of course, you could set a max sequence length but that's not an ideal solution\n", + "# another solution would be to create a different dataset object, but then you can't use torchtext,\n", + "# which really is quite handy\n", + "\n", + "# train=True shuffles the data\n", + "train_iter_skorch = torchtext.data.Iterator(train, batch_size=len(train), train=True, sort=False, device='cpu')\n", + "test_iter_skorch = torchtext.data.Iterator(test, batch_size=len(test), train=False, sort=False, device='cpu')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "# takes some time to numericalize the whole dataset\n", + "\n", + "# also notice that skorch and dask expect numpy arrays, which isn't ideal since it ties you to the cpu.\n", + "# meanwhile, projects like https://rapids.ai/ are moving toward all GPU computation, avoiding the cpu altogether.\n", + "for batch in train_iter_skorch:\n", + " X_train = batch.text[0].numpy()\n", + " y_train = batch.label.numpy()\n", + "\n", + "for batch in test_iter_skorch:\n", + " X_test = batch.text[0].numpy()\n", + " y_test = batch.label.numpy()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(25000, 2470)" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# notice how awfully large the second dimension is\n", + "X_train.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "import torch.nn as nn" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "# NB: not ideal to be using softmax + log + NLLLoss\n", + "# see discussion: https://github.com/skorch-dev/skorch/issues/637\n", + "skorch_model = NeuralNetClassifier(\n", + " CNN,\n", + " device=device,\n", + " max_epochs=2,\n", + " lr=0.001,\n", + " optimizer=optim.Adam,\n", + " criterion=nn.NLLLoss,\n", + " train_split=skorch.dataset.CVSplit(.2), # NB: this witholds 20% of the training data for validation\n", + " module__n_filters=100,\n", + " module__filter_sizes=(2,3,4),\n", + " module__dropout=0.2,\n", + " module__pretrained_embeddings=vocab.vectors,\n", + " batch_size=32,\n", + " verbose=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " epoch train_loss valid_acc valid_loss dur\n", + "------- ------------ ----------- ------------ -------\n", + " 1 \u001b[36m0.6302\u001b[0m \u001b[32m0.7516\u001b[0m \u001b[35m0.5243\u001b[0m 66.5468\n", + " 2 \u001b[36m0.4797\u001b[0m \u001b[32m0.7994\u001b[0m \u001b[35m0.4413\u001b[0m 59.9177\n" + ] + }, + { + "data": { + "text/plain": [ + "[initialized](\n", + " module_=CNN(\n", + " (embedding): Embedding(400000, 100)\n", + " (conv_0): Conv1d(1, 100, kernel_size=(2, 100), stride=(1,))\n", + " (conv_1): Conv1d(1, 100, kernel_size=(3, 100), stride=(1,))\n", + " (conv_2): Conv1d(1, 100, kernel_size=(4, 100), stride=(1,))\n", + " (fc): Linear(in_features=300, out_features=2, bias=True)\n", + " (dropout): Dropout(p=0.2, inplace=False)\n", + " ),\n", + ")" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "skorch_model.fit(X_train, y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.79112" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# quick check on the test set accuracy\n", + "skorch_model.score(X_test, y_test)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(array([0, 1]), array([12500, 12500]))" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# random guessing would 50% accuracy so the model is indeed training\n", + "np.unique(y_test, return_counts=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "del skorch_model" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Grid search with Hyperband" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "# https://ml.dask.org/hyper-parameter-search.html#hyperband-parameters-rule-of-thumb\n", + "EPOCHS = 5\n", + "NUM_TRAINING_EXAMPLES = len(train)*.8\n", + "n_examples = EPOCHS * NUM_TRAINING_EXAMPLES\n", + "n_params = 8\n", + "\n", + "# it's not immediately obvious to beginners how all these parameters interact with each other\n", + "max_iter = n_params\n", + "chunk_size = n_examples // n_params" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "# suppose we want to set max_iter to be the commensurate with the number of examples required\n", + "# for the model converge (as cited in the documentation)\n", + "\n", + "# it's a bit unclear how n_params relates to BOTH the number of data points required\n", + "# for the model to converge AND how many hyperparameters to try out (i.e. n_iter in RandomizedSearchCV)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "import math" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chunk size: 12500.0\n", + "Total chunks: 2\n", + "Last chunk size: 12500.0\n" + ] + } + ], + "source": [ + "# choose chunk size so that the remainder is not a tiny number\n", + "print(f'Chunk size: {chunk_size}')\n", + "print(f'Total chunks: {math.ceil(len(X_train) / chunk_size)}')\n", + "last_chunk_size = len(X_train) % chunk_size\n", + "if last_chunk_size == 0: # i.e. chunk_size evenly divides X_train\n", + " last_chunk_size = chunk_size\n", + "print(f'Last chunk size: {last_chunk_size}')\n", + "\n", + "assert (len(X_train) % chunk_size > 10 or len(X_train) % chunk_size == 0), 'Choose another chunk size'" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "import dask.array as da\n", + "\n", + "X = da.from_array(X_train, chunks=(chunk_size, X_train.shape[-1]))\n", + "y = da.from_array(y_train, chunks=(chunk_size))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Array Chunk
Bytes 494.00 MB 247.00 MB
Shape (25000, 2470) (12500, 2470)
Count 3 Tasks 2 Chunks
Type int64 numpy.ndarray
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + " 2470\n", + " 25000\n", + "\n", + "
" + ], + "text/plain": [ + "dask.array" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "import torch.nn as nn" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "# reinitialize and set train_split=None to let hyperband handle validation set splitting\n", + "skorch_model = NeuralNetClassifier(\n", + " CNN,\n", + " device=device,\n", + " lr=0.001,\n", + " optimizer=optim.Adam,\n", + " criterion=nn.NLLLoss,\n", + " train_split=None, # let hyperband handle it\n", + " module__n_filters=100,\n", + " module__filter_sizes=(2, 3, 4),\n", + " module__dropout=0.2,\n", + " module__pretrained_embeddings=vocab.vectors,\n", + " batch_size=32,\n", + " verbose=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "from scipy.stats import loguniform" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "# define parameter grid\n", + "params = {'module__filter_size': [(1,2,3), (2, 3, 4), (3, 4, 5)], \n", + " 'module__n_filters': [25,50,100],\n", + " 'module__dropout': loguniform(1e-1, 3e-1),\n", + " 'batch_size': [32, 64],\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "from dask_ml.model_selection import HyperbandSearchCV" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "search = HyperbandSearchCV(\n", + " skorch_model,\n", + " params,\n", + " max_iter=max_iter,\n", + " verbose=True,\n", + " test_size=0.2 # validation size\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "26" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "search.metadata[\"partial_fit_calls\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "import time" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "# to clear up any confusion, every time partial_fit is called, we're passing in chunk_size number of\n", + "# data points. Then skorch handles the batch size either by being set explicitly or as part of the param grid.\n", + "\n", + "# to compare this grid search to number of epochs, we have 26 partial_fit calls * 10k data points = 260k examples\n", + "# with a training set size of 25k * .8 = 20k data points, this is 13 epochs!\n", + "# considering that it takes approximately 5 epochs to train a model, you would get through less than 3 sets of \n", + "# hyperparameters if manually searching. Instead we'll search through ~5." + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[CV, bracket=1] creating 3 models\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 160.00 MB detected in task graph: \n", + " [[u ... .1570]]),\n", + "), 0]\n", + "Consider scattering large objects ahead of time\n", + "with client.scatter to reduce scheduler burden and \n", + "keep data on workers\n", + "\n", + " future = client.submit(func, big_data) # bad\n", + "\n", + " big_future = client.scatter(big_data) # good\n", + " future = client.submit(func, big_future) # good\n", + " % (format_bytes(len(b)), s)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[CV, bracket=0] creating 2 models\n", + "[CV, bracket=0] For training there are between 10000 and 10000 examples in each chunk\n", + "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "tornado.application - ERROR - Multiple exceptions in yield list\n", + "Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 849, in callback\n", + " result_list.append(f.result())\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", + " yielded = self.gen.throw(*exc_info)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 625, in _fit\n", + " prefix=self.prefix,\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", + " value = future.result()\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", + " yielded = self.gen.throw(*exc_info)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 233, in _fit\n", + " metas = yield client.gather(new_scores)\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", + " value = future.result()\n", + " File \"/opt/conda/lib/python3.7/site-packages/distributed/client.py\", line 1826, in _gather\n", + " raise exception.with_traceback(traceback)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 116, in _create_model\n", + " return model, {\"model_id\": ident, \"params\": params, \"partial_fit_calls\": 0}\n", + " File \"/opt/conda/lib/python3.7/contextlib.py\", line 130, in __exit__\n", + " self.gen.throw(type, value, traceback)\n", + " File \"/opt/conda/lib/python3.7/site-packages/distributed/utils.py\", line 676, in log_errors\n", + " raise\n", + " File \"/opt/conda/lib/python3.7/site-packages/distributed/utils.py\", line 676, in log_errors\n", + " raise\n", + " File \"/opt/conda/lib/python3.7/bdb.py\", line 88, in trace_dispatch\n", + " return self.dispatch_line(frame)\n", + " File \"/opt/conda/lib/python3.7/bdb.py\", line 113, in dispatch_line\n", + " if self.quitting: raise BdbQuit\n", + "bdb.BdbQuit\n" + ] + }, + { + "ename": "BdbQuit", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mBdbQuit\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 673\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdefault_client\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mif_delegate_has_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"best_estimator_\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"estimator\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mf\u001b[0;34m()\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallback_timeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 330\u001b[0m \u001b[0mfuture\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0masyncio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait_for\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfuture\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 331\u001b[0;31m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 332\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_hyperband.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[0;31m# _fit is run in parallel because it's also a tornado coroutine\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 400\u001b[0;31m \u001b[0m_SHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mSHAs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_brackets_ids\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 401\u001b[0m \u001b[0mSHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_brackets_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_SHAs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 402\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mcallback\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 847\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mchildren\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 848\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 849\u001b[0;31m \u001b[0mresult_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 850\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 624\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 625\u001b[0;31m \u001b[0mprefix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprefix\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 626\u001b[0m )\n\u001b[1;32m 627\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_results\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(model, params, X_train, y_train, X_test, y_test, additional_calls, fit_params, scorer, random_state, verbose, prefix)\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0;31m# async for future, result in seq:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 233\u001b[0;31m \u001b[0mmetas\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_scores\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 234\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlog_delay\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlog_delay\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36m_gather\u001b[0;34m(self, futures, errors, direct, local_worker)\u001b[0m\n\u001b[1;32m 1824\u001b[0m \u001b[0mexc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1825\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1826\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1827\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1828\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"skip\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_create_model\u001b[0;34m()\u001b[0m\n\u001b[1;32m 114\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mlog_errors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpdb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_params\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 116\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"model_id\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mident\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"params\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"partial_fit_calls\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 117\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/contextlib.py\u001b[0m in \u001b[0;36m__exit__\u001b[0;34m()\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 130\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 131\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;31m# Suppress StopIteration *unless* it's the same exception that\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mlog_errors\u001b[0;34m()\u001b[0m\n\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0mpdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 676\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 677\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 678\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mlog_errors\u001b[0;34m()\u001b[0m\n\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0mpdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 676\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 677\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 678\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/bdb.py\u001b[0m in \u001b[0;36mtrace_dispatch\u001b[0;34m()\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;31m# None\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'line'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 88\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch_line\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 89\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'call'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/bdb.py\u001b[0m in \u001b[0;36mdispatch_line\u001b[0;34m()\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop_here\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbreak_here\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muser_line\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 113\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquitting\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mBdbQuit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 114\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrace_dispatch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mBdbQuit\u001b[0m: " + ] + } + ], + "source": [ + "# it's been erroring out with a less than helpful error message. This started happening right around \n", + "# when I started passing module__pretrained_embeddings=vocab.vectors. Unclear if this is the culprit.\n", + "\n", + "# NB: this took ~900 seconds on a single Nvidia GTX 980 Ti\n", + "# notice how the number of training datapoints relates to the chunk size and our test_size\n", + "# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\n", + "start = time.time()\n", + "search.fit(X, y)\n", + "end = time.time()\n", + "duration = round(end - start, 2)\n", + "print(f'Time to complete grid search: {duration} seconds')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Integration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`HyperbandSearchCV` follows the Scikit-learn API and mirrors Scikit-learn's `RandomizedSearchCV`. This means that it \"just works\". All the Scikit-learn attributes and methods are available:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.best_score_" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.best_estimator_" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.cv_results_" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cv_results = pd.DataFrame(search.cv_results_)\n", + "cv_results.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.score(X_test, y_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.predict(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "search.predict(X_test).compute()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It also has some other attributes." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "hist = pd.DataFrame(search.history_)\n", + "hist.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This illustrates the history after every `partial_fit` call. There's also an attributed `model_history_` that records the history for each model (it's a reorganization of `history_`)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Learn more" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook covered basic usage `HyperbandSearchCV`. The following documentation and resources might be useful to learn more about `HyperbandSearchCV`, including some of the finer use cases:\n", + "\n", + "* [A talk](https://www.youtube.com/watch?v=x67K9FiPFBQ) introducing `HyperbandSearchCV` to the SciPy 2019 audience and the [corresponding paper](https://conference.scipy.org/proceedings/scipy2019/pdfs/scott_sievert.pdf)\n", + "* [HyperbandSearchCV's documentation](https://ml.dask.org/modules/generated/dask_ml.model_selection.HyperbandSearchCV.html)\n", + "\n", + "Performance comparisons can be found in the SciPy 2019 talk/paper." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 171af05e0a53fd907ad536f3f8fc79e3621d7a4b Mon Sep 17 00:00:00 2001 From: Todd Morrill Date: Sat, 23 May 2020 11:32:49 -0400 Subject: [PATCH 2/6] fix param grid typo and pretrained embeddings --- machine-learning/Untitled1.ipynb | 6 - machine-learning/model.py | 4 +- machine-learning/skorch-hyperparam-opt.ipynb | 809 +++++++++++++++---- 3 files changed, 633 insertions(+), 186 deletions(-) delete mode 100644 machine-learning/Untitled1.ipynb diff --git a/machine-learning/Untitled1.ipynb b/machine-learning/Untitled1.ipynb deleted file mode 100644 index 2fd64429..00000000 --- a/machine-learning/Untitled1.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/machine-learning/model.py b/machine-learning/model.py index 54cc9192..55469aa5 100644 --- a/machine-learning/model.py +++ b/machine-learning/model.py @@ -2,13 +2,15 @@ import torch import torch.nn as nn import torch.nn.functional as F +import torchtext class CNN(nn.Module): def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0.2, pretrained_embeddings=None): super().__init__() - self.embedding = nn.Embedding.from_pretrained(torch.FloatTensor(pretrained_embeddings)) + # will be used to initialize model embeddings layer + self.embedding = nn.Embedding.from_pretrained(pretrained_embeddings) self.embedding.weight.requires_grad = False # save some computation embedding_dim = self.embedding.embedding_dim self.conv_0 = nn.Conv1d(in_channels = 1, diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb index 54344473..d80e4fd3 100644 --- a/machine-learning/skorch-hyperparam-opt.ipynb +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -37,7 +37,7 @@ "\n", "

Client

\n", "\n", "\n", @@ -53,7 +53,7 @@ "" ], "text/plain": [ - "" + "" ] }, "execution_count": 2, @@ -130,7 +130,7 @@ "# takes approx. 10 minutes to download data and embeddings (will be cached for re-use)\n", "\n", "# set up fields\n", - "TEXT = data.Field(lower=True, include_lengths=True, batch_first=True)\n", + "TEXT = data.Field(lower=True, include_lengths=True, batch_first=True, )\n", "LABEL = data.Field(sequential=False, unk_token=None)\n", "\n", "# make splits for data\n", @@ -146,7 +146,7 @@ "\n", "# make iterator for splits\n", "train_iter, test_iter = data.BucketIterator.splits(\n", - " (train, test), batch_sizes=(32, 64), device=device)" + " (train, test), batch_sizes=(32, 64), device='cpu')" ] }, { @@ -222,16 +222,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 45, 123, 25, ..., 1, 1, 1],\n", - " [5311, 3868, 2, ..., 1, 1, 1],\n", - " [ 133, 8, 42, ..., 1, 1, 1],\n", + "tensor([[ 542, 5101, 41, ..., 1, 1, 1],\n", + " [ 10, 7, 31, ..., 1, 1, 1],\n", + " [ 0, 49, 15842, ..., 1, 1, 1],\n", " ...,\n", - " [ 9, 176, 10, ..., 1, 1, 1],\n", - " [1467, 10, 30, ..., 1, 1, 1],\n", - " [ 82, 1297, 9, ..., 1, 1, 1]], device='cuda:0')\n", - "tensor([147, 347, 361, 66, 147, 262, 336, 105, 255, 132, 128, 162, 122, 184,\n", - " 195, 100, 226, 127, 152, 159, 120, 204, 267, 209, 129, 486, 95, 151,\n", - " 140, 247, 127, 167], device='cuda:0')\n" + " [ 25, 86, 311, ..., 1, 1, 1],\n", + " [ 9, 157, 168, ..., 1, 1, 1],\n", + " [ 10, 49, 235, ..., 1, 1, 1]])\n", + "tensor([132, 121, 72, 343, 112, 90, 226, 982, 118, 341, 145, 64, 149, 87,\n", + " 244, 270, 122, 94, 141, 76, 154, 151, 429, 97, 104, 76, 120, 125,\n", + " 120, 118, 134, 154])\n" ] } ], @@ -250,8 +250,8 @@ { "data": { "text/plain": [ - "tensor([1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,\n", - " 1, 1, 1, 1, 0, 1, 0, 0], device='cuda:0')" + "tensor([1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0,\n", + " 0, 1, 0, 1, 1, 0, 1, 1])" ] }, "execution_count": 12, @@ -311,38 +311,38 @@ { "data": { "text/plain": [ - "tensor([[0.4709, 0.5291],\n", - " [0.2993, 0.7007],\n", - " [0.2609, 0.7391],\n", - " [0.3476, 0.6524],\n", - " [0.4323, 0.5677],\n", - " [0.3394, 0.6606],\n", - " [0.2745, 0.7255],\n", - " [0.3152, 0.6848],\n", - " [0.4568, 0.5432],\n", - " [0.4189, 0.5811],\n", - " [0.4351, 0.5649],\n", - " [0.4204, 0.5796],\n", - " [0.3963, 0.6037],\n", - " [0.3482, 0.6518],\n", - " [0.3528, 0.6472],\n", - " [0.4137, 0.5863],\n", - " [0.3327, 0.6673],\n", - " [0.3380, 0.6620],\n", - " [0.4874, 0.5126],\n", - " [0.2904, 0.7096],\n", - " [0.2868, 0.7132],\n", - " [0.3196, 0.6804],\n", - " [0.3689, 0.6311],\n", - " [0.2525, 0.7475],\n", - " [0.2493, 0.7507],\n", - " [0.3308, 0.6692],\n", - " [0.2088, 0.7912],\n", - " [0.4834, 0.5166],\n", - " [0.2363, 0.7637],\n", - " [0.4511, 0.5489],\n", - " [0.2282, 0.7718],\n", - " [0.3502, 0.6498]], device='cuda:0', grad_fn=)" + "tensor([[0.4698, 0.5302],\n", + " [0.3791, 0.6209],\n", + " [0.2715, 0.7285],\n", + " [0.3220, 0.6780],\n", + " [0.3979, 0.6021],\n", + " [0.4197, 0.5803],\n", + " [0.3409, 0.6591],\n", + " [0.2695, 0.7305],\n", + " [0.4400, 0.5600],\n", + " [0.4209, 0.5791],\n", + " [0.4640, 0.5360],\n", + " [0.4475, 0.5525],\n", + " [0.4261, 0.5739],\n", + " [0.3032, 0.6968],\n", + " [0.3452, 0.6548],\n", + " [0.3803, 0.6197],\n", + " [0.3741, 0.6259],\n", + " [0.3796, 0.6204],\n", + " [0.5005, 0.4995],\n", + " [0.3706, 0.6294],\n", + " [0.3142, 0.6858],\n", + " [0.3772, 0.6228],\n", + " [0.3281, 0.6719],\n", + " [0.3190, 0.6810],\n", + " [0.3340, 0.6660],\n", + " [0.3948, 0.6052],\n", + " [0.2351, 0.7649],\n", + " [0.4538, 0.5462],\n", + " [0.2321, 0.7679],\n", + " [0.4226, 0.5774],\n", + " [0.2449, 0.7551],\n", + " [0.3471, 0.6529]], device='cuda:0', grad_fn=)" ] }, "execution_count": 15, @@ -352,8 +352,9 @@ ], "source": [ "# smoketest\n", - "model = CNN(pretrained_embeddings=vocab.vectors).to(device)\n", - "model(batch.text[0].to(device))" + "model = CNN(pretrained_embeddings=TEXT.vocab.vectors).to(device)\n", + "gpu_batch = batch.text[0].to(device)\n", + "model(gpu_batch)" ] }, { @@ -365,6 +366,24 @@ "del model" ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "del gpu_batch" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "torch.cuda.empty_cache()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -374,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -385,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -404,7 +423,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -423,7 +442,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -432,7 +451,7 @@ "(25000, 2470)" ] }, - "execution_count": 20, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -444,7 +463,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -453,7 +472,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -470,14 +489,14 @@ " module__n_filters=100,\n", " module__filter_sizes=(2,3,4),\n", " module__dropout=0.2,\n", - " module__pretrained_embeddings=vocab.vectors,\n", + " module__pretrained_embeddings=TEXT.vocab.vectors,\n", " batch_size=32,\n", " verbose=2)" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -486,8 +505,8 @@ "text": [ " epoch train_loss valid_acc valid_loss dur\n", "------- ------------ ----------- ------------ -------\n", - " 1 \u001b[36m0.6302\u001b[0m \u001b[32m0.7516\u001b[0m \u001b[35m0.5243\u001b[0m 66.5468\n", - " 2 \u001b[36m0.4797\u001b[0m \u001b[32m0.7994\u001b[0m \u001b[35m0.4413\u001b[0m 59.9177\n" + " 1 \u001b[36m0.4689\u001b[0m \u001b[32m0.8370\u001b[0m \u001b[35m0.3656\u001b[0m 60.5744\n", + " 2 \u001b[36m0.3466\u001b[0m \u001b[32m0.8524\u001b[0m \u001b[35m0.3413\u001b[0m 58.6526\n" ] }, { @@ -495,7 +514,7 @@ "text/plain": [ "[initialized](\n", " module_=CNN(\n", - " (embedding): Embedding(400000, 100)\n", + " (embedding): Embedding(25002, 100)\n", " (conv_0): Conv1d(1, 100, kernel_size=(2, 100), stride=(1,))\n", " (conv_1): Conv1d(1, 100, kernel_size=(3, 100), stride=(1,))\n", " (conv_2): Conv1d(1, 100, kernel_size=(4, 100), stride=(1,))\n", @@ -505,7 +524,7 @@ ")" ] }, - "execution_count": 23, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -516,16 +535,16 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.79112" + "0.85512" ] }, - "execution_count": 24, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -537,7 +556,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -546,7 +565,7 @@ "(array([0, 1]), array([12500, 12500]))" ] }, - "execution_count": 25, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -558,10 +577,13 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ + "# NB: this has no effect on GPU memory usage. If I keyboard interrupt, the workers get\n", + "# restarted and memory usage goes down. Deleting these \"handler\" objects doesn't delete\n", + "# GPU memory references on the workers. \n", "del skorch_model" ] }, @@ -574,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -591,7 +613,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -604,7 +626,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -613,7 +635,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -640,7 +662,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -652,7 +674,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -700,7 +722,7 @@ "dask.array" ] }, - "execution_count": 32, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -709,15 +731,6 @@ "X" ] }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "import torch.nn as nn" - ] - }, { "cell_type": "code", "execution_count": 35, @@ -735,7 +748,7 @@ " module__n_filters=100,\n", " module__filter_sizes=(2, 3, 4),\n", " module__dropout=0.2,\n", - " module__pretrained_embeddings=vocab.vectors,\n", + " module__pretrained_embeddings=TEXT.vocab.vectors,\n", " batch_size=32,\n", " verbose=2)" ] @@ -756,8 +769,8 @@ "outputs": [], "source": [ "# define parameter grid\n", - "params = {'module__filter_size': [(1,2,3), (2, 3, 4), (3, 4, 5)], \n", - " 'module__n_filters': [25,50,100],\n", + "params = {'module__filter_sizes': [(1, 2, 3), (2, 3, 4), (3, 4, 5)], \n", + " 'module__n_filters': [25, 50, 100],\n", " 'module__dropout': loguniform(1e-1, 3e-1),\n", " 'batch_size': [32, 64],\n", " }" @@ -811,6 +824,26 @@ "cell_type": "code", "execution_count": 41, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "search.metadata['n_models']" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, "outputs": [], "source": [ "import time" @@ -818,7 +851,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -833,7 +866,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -847,8 +880,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 160.00 MB detected in task graph: \n", - " [[u ... .1570]]),\n", + "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 10.00 MB detected in task graph: \n", + " [[u ... .0721]]),\n", "), 0]\n", "Consider scattering large objects ahead of time\n", "with client.scatter to reduce scheduler burden and \n", @@ -867,77 +900,13 @@ "text": [ "[CV, bracket=0] creating 2 models\n", "[CV, bracket=0] For training there are between 10000 and 10000 examples in each chunk\n", - "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "tornado.application - ERROR - Multiple exceptions in yield list\n", - "Traceback (most recent call last):\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 849, in callback\n", - " result_list.append(f.result())\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", - " yielded = self.gen.throw(*exc_info)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 625, in _fit\n", - " prefix=self.prefix,\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", - " value = future.result()\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", - " yielded = self.gen.throw(*exc_info)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 233, in _fit\n", - " metas = yield client.gather(new_scores)\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", - " value = future.result()\n", - " File \"/opt/conda/lib/python3.7/site-packages/distributed/client.py\", line 1826, in _gather\n", - " raise exception.with_traceback(traceback)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 116, in _create_model\n", - " return model, {\"model_id\": ident, \"params\": params, \"partial_fit_calls\": 0}\n", - " File \"/opt/conda/lib/python3.7/contextlib.py\", line 130, in __exit__\n", - " self.gen.throw(type, value, traceback)\n", - " File \"/opt/conda/lib/python3.7/site-packages/distributed/utils.py\", line 676, in log_errors\n", - " raise\n", - " File \"/opt/conda/lib/python3.7/site-packages/distributed/utils.py\", line 676, in log_errors\n", - " raise\n", - " File \"/opt/conda/lib/python3.7/bdb.py\", line 88, in trace_dispatch\n", - " return self.dispatch_line(frame)\n", - " File \"/opt/conda/lib/python3.7/bdb.py\", line 113, in dispatch_line\n", - " if self.quitting: raise BdbQuit\n", - "bdb.BdbQuit\n" - ] - }, - { - "ename": "BdbQuit", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mBdbQuit\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 673\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdefault_client\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mif_delegate_has_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"best_estimator_\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"estimator\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mf\u001b[0;34m()\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallback_timeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 330\u001b[0m \u001b[0mfuture\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0masyncio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait_for\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfuture\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 331\u001b[0;31m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 332\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_hyperband.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[0;31m# _fit is run in parallel because it's also a tornado coroutine\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 400\u001b[0;31m \u001b[0m_SHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mSHAs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_brackets_ids\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 401\u001b[0m \u001b[0mSHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_brackets_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_SHAs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 402\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mcallback\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 847\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mchildren\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 848\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 849\u001b[0;31m \u001b[0mresult_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 850\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 624\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 625\u001b[0;31m \u001b[0mprefix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprefix\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 626\u001b[0m )\n\u001b[1;32m 627\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_results\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(model, params, X_train, y_train, X_test, y_test, additional_calls, fit_params, scorer, random_state, verbose, prefix)\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0;31m# async for future, result in seq:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 233\u001b[0;31m \u001b[0mmetas\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_scores\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 234\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlog_delay\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlog_delay\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36m_gather\u001b[0;34m(self, futures, errors, direct, local_worker)\u001b[0m\n\u001b[1;32m 1824\u001b[0m \u001b[0mexc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1825\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1826\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1827\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1828\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"skip\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_create_model\u001b[0;34m()\u001b[0m\n\u001b[1;32m 114\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mlog_errors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpdb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_params\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 116\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"model_id\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mident\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"params\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"partial_fit_calls\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 117\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/contextlib.py\u001b[0m in \u001b[0;36m__exit__\u001b[0;34m()\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 130\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 131\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;31m# Suppress StopIteration *unless* it's the same exception that\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mlog_errors\u001b[0;34m()\u001b[0m\n\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0mpdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 676\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 677\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 678\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mlog_errors\u001b[0;34m()\u001b[0m\n\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0mpdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 676\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 677\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 678\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/bdb.py\u001b[0m in \u001b[0;36mtrace_dispatch\u001b[0;34m()\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;31m# None\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'line'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 88\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch_line\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 89\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'call'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/bdb.py\u001b[0m in \u001b[0;36mdispatch_line\u001b[0;34m()\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop_here\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbreak_here\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muser_line\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 113\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquitting\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mBdbQuit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 114\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrace_dispatch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mBdbQuit\u001b[0m: " + "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n", + "[CV, bracket=0] validation score of 0.8386 received after 1 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8306 received after 1 partial_fit calls\n", + "[CV, bracket=0] validation score of 0.8446 received after 8 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8430 received after 2 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8456 received after 6 partial_fit calls\n", + "Time to complete grid search: 3813.07 seconds\n" ] } ], @@ -945,7 +914,7 @@ "# it's been erroring out with a less than helpful error message. This started happening right around \n", "# when I started passing module__pretrained_embeddings=vocab.vectors. Unclear if this is the culprit.\n", "\n", - "# NB: this took ~900 seconds on a single Nvidia GTX 980 Ti\n", + "# NB: this took ~3800 seconds on a single Nvidia GTX 980 Ti\n", "# notice how the number of training datapoints relates to the chunk size and our test_size\n", "# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\n", "start = time.time()\n", @@ -955,6 +924,26 @@ "print(f'Time to complete grid search: {duration} seconds')" ] }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "63.333333333333336" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3800 / 60" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -971,25 +960,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.8456" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.best_score_" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[initialized](\n", + " module_=CNN(\n", + " (embedding): Embedding(25002, 100)\n", + " (conv_0): Conv1d(1, 50, kernel_size=(3, 100), stride=(1,))\n", + " (conv_1): Conv1d(1, 50, kernel_size=(4, 100), stride=(1,))\n", + " (conv_2): Conv1d(1, 50, kernel_size=(5, 100), stride=(1,))\n", + " (fc): Linear(in_features=150, out_features=2, bias=True)\n", + " (dropout): Dropout(p=0.22181138802671369, inplace=False)\n", + " ),\n", + ")" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.best_estimator_" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -998,18 +1018,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'param_module__n_filters': array([50, 50, 50, 25, 50]),\n", + " 'test_score': array([0.8456, 0.7982, 0.733 , 0.843 , 0.8446]),\n", + " 'std_score_time': array([0.06216696, 0.19731486, 0.56393194, 1.33936262, 0.06445384]),\n", + " 'rank_test_score': array([1, 2, 3, 2, 1]),\n", + " 'mean_score_time': array([3.82462454, 4.0282222 , 5.47523713, 4.41082978, 5.29884744]),\n", + " 'params': array([{'batch_size': 64, 'module__dropout': 0.22181138802671369, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", + " {'batch_size': 64, 'module__dropout': 0.19188105885296006, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", + " {'batch_size': 32, 'module__dropout': 0.11893575283135104, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", + " {'batch_size': 32, 'module__dropout': 0.10900910968190201, 'module__filter_sizes': (2, 3, 4), 'module__n_filters': 25},\n", + " {'batch_size': 32, 'module__dropout': 0.10009422737462631, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50}],\n", + " dtype=object),\n", + " 'partial_fit_calls': array([6, 2, 2, 8, 8]),\n", + " 'param_module__dropout': array([0.22181139, 0.19188106, 0.11893575, 0.10900911, 0.10009423]),\n", + " 'std_partial_fit_time': array([ 3.6288025 , 1.52035153, 11.09951091, 15.07569551, 5.98224938]),\n", + " 'mean_partial_fit_time': array([ 93.61417103, 96.36260712, 136.89576507, 143.69626164,\n", + " 130.64727747]),\n", + " 'model_id': array(['bracket=1-0', 'bracket=1-1', 'bracket=1-2', 'bracket=0-0',\n", + " 'bracket=0-1'], dtype='\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcv_results\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcv_results_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mcv_results\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[1;32m 409\u001b[0m )\n\u001b[1;32m 410\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 411\u001b[0;31m \u001b[0mmgr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minit_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 412\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMaskedArray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmrecords\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mmrecords\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36minit_dict\u001b[0;34m(data, index, columns, dtype)\u001b[0m\n\u001b[1;32m 255\u001b[0m \u001b[0marr\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mis_datetime64tz_dtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0marr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marrays\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 256\u001b[0m ]\n\u001b[0;32m--> 257\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0marrays_to_mgr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata_names\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 258\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 259\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36marrays_to_mgr\u001b[0;34m(arrays, arr_names, index, columns, dtype)\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;31m# don't force copy because getting jammed in an ndarray anyway\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 82\u001b[0;31m \u001b[0marrays\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_homogenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 83\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;31m# from BlockManager perspective\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36m_homogenize\u001b[0;34m(data, index, dtype)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[0mval\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfast_multiget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 322\u001b[0m val = sanitize_array(\n\u001b[0;32m--> 323\u001b[0;31m \u001b[0mval\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mraise_cast_failure\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 324\u001b[0m )\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36msanitize_array\u001b[0;34m(data, index, dtype, copy, raise_cast_failure)\u001b[0m\n\u001b[1;32m 727\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0msubarr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 728\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 729\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Data must be 1-dimensional\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 730\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 731\u001b[0m \u001b[0msubarr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masarray_tuplesafe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mException\u001b[0m: Data must be 1-dimensional" + ] + } + ], "source": [ "cv_results = pd.DataFrame(search.cv_results_)\n", "cv_results.head()" @@ -1017,27 +1089,287 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], + "source": [ + "# issue with numpy converting array of tuples into a 2d array\n", + "search.cv_results_['param_module__filter_sizes'] = search.cv_results_['param_module__filter_sizes'].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
param_module__n_filterstest_scorestd_score_timerank_test_scoremean_score_timeparamspartial_fit_callsparam_module__dropoutstd_partial_fit_timemean_partial_fit_timemodel_idbracketparam_batch_sizeparam_module__filter_sizes
0500.84560.06216713.824625{'batch_size': 64, 'module__dropout': 0.221811...60.2218113.62880293.614171bracket=1-0164[3, 4, 5]
1500.79820.19731524.028222{'batch_size': 64, 'module__dropout': 0.191881...20.1918811.52035296.362607bracket=1-1164[3, 4, 5]
2500.73300.56393235.475237{'batch_size': 32, 'module__dropout': 0.118935...20.11893611.099511136.895765bracket=1-2132[3, 4, 5]
3250.84301.33936324.410830{'batch_size': 32, 'module__dropout': 0.109009...80.10900915.075696143.696262bracket=0-0032[2, 3, 4]
4500.84460.06445415.298847{'batch_size': 32, 'module__dropout': 0.100094...80.1000945.982249130.647277bracket=0-1032[3, 4, 5]
\n", + "
" + ], + "text/plain": [ + " param_module__n_filters test_score std_score_time rank_test_score \\\n", + "0 50 0.8456 0.062167 1 \n", + "1 50 0.7982 0.197315 2 \n", + "2 50 0.7330 0.563932 3 \n", + "3 25 0.8430 1.339363 2 \n", + "4 50 0.8446 0.064454 1 \n", + "\n", + " mean_score_time params \\\n", + "0 3.824625 {'batch_size': 64, 'module__dropout': 0.221811... \n", + "1 4.028222 {'batch_size': 64, 'module__dropout': 0.191881... \n", + "2 5.475237 {'batch_size': 32, 'module__dropout': 0.118935... \n", + "3 4.410830 {'batch_size': 32, 'module__dropout': 0.109009... \n", + "4 5.298847 {'batch_size': 32, 'module__dropout': 0.100094... \n", + "\n", + " partial_fit_calls param_module__dropout std_partial_fit_time \\\n", + "0 6 0.221811 3.628802 \n", + "1 2 0.191881 1.520352 \n", + "2 2 0.118936 11.099511 \n", + "3 8 0.109009 15.075696 \n", + "4 8 0.100094 5.982249 \n", + "\n", + " mean_partial_fit_time model_id bracket param_batch_size \\\n", + "0 93.614171 bracket=1-0 1 64 \n", + "1 96.362607 bracket=1-1 1 64 \n", + "2 136.895765 bracket=1-2 1 32 \n", + "3 143.696262 bracket=0-0 0 32 \n", + "4 130.647277 bracket=0-1 0 32 \n", + "\n", + " param_module__filter_sizes \n", + "0 [3, 4, 5] \n", + "1 [3, 4, 5] \n", + "2 [3, 4, 5] \n", + "3 [2, 3, 4] \n", + "4 [3, 4, 5] " + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cv_results = pd.DataFrame(search.cv_results_)\n", + "cv_results.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.83816" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.score(X_test, y_test)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Array Chunk
Bytes 200.00 kB 200.00 kB
Shape (25000,) (25000,)
Count 2 Tasks 1 Chunks
Type int64 numpy.ndarray
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + " 25000\n", + " 1\n", + "\n", + "
" + ], + "text/plain": [ + "dask.array<_predict, shape=(25000,), dtype=int64, chunksize=(25000,), chunktype=numpy.ndarray>" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.predict(X_test)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 1, 1, ..., 0, 0, 0])" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.predict(X_test).compute()" ] @@ -1051,9 +1383,128 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
model_idparamspartial_fit_callspartial_fit_timescorescore_timeelapsed_wall_timebracket
0bracket=0-0{'batch_size': 32, 'module__dropout': 0.109009...1128.6205660.82723.071467358.5270120
1bracket=0-1{'batch_size': 32, 'module__dropout': 0.100094...1124.6650280.83865.234394358.5270180
2bracket=1-0{'batch_size': 64, 'module__dropout': 0.221811...195.6026390.75583.739039460.1802061
3bracket=1-1{'batch_size': 64, 'module__dropout': 0.191881...194.8422560.74964.225537460.1802121
4bracket=1-2{'batch_size': 32, 'module__dropout': 0.118935...1125.7962540.83066.039169460.1802151
\n", + "
" + ], + "text/plain": [ + " model_id params \\\n", + "0 bracket=0-0 {'batch_size': 32, 'module__dropout': 0.109009... \n", + "1 bracket=0-1 {'batch_size': 32, 'module__dropout': 0.100094... \n", + "2 bracket=1-0 {'batch_size': 64, 'module__dropout': 0.221811... \n", + "3 bracket=1-1 {'batch_size': 64, 'module__dropout': 0.191881... \n", + "4 bracket=1-2 {'batch_size': 32, 'module__dropout': 0.118935... \n", + "\n", + " partial_fit_calls partial_fit_time score score_time elapsed_wall_time \\\n", + "0 1 128.620566 0.8272 3.071467 358.527012 \n", + "1 1 124.665028 0.8386 5.234394 358.527018 \n", + "2 1 95.602639 0.7558 3.739039 460.180206 \n", + "3 1 94.842256 0.7496 4.225537 460.180212 \n", + "4 1 125.796254 0.8306 6.039169 460.180215 \n", + "\n", + " bracket \n", + "0 0 \n", + "1 0 \n", + "2 1 \n", + "3 1 \n", + "4 1 " + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "hist = pd.DataFrame(search.history_)\n", "hist.head()" From 1263e2c1ab759f6301488c4293eefb3830fa6095 Mon Sep 17 00:00:00 2001 From: Todd Morrill Date: Sat, 23 May 2020 21:54:07 -0400 Subject: [PATCH 3/6] implement custom DataLoader to reduce Skorch run time --- machine-learning/model.py | 7 +- machine-learning/skorch-hyperparam-opt.ipynb | 374 ++++++++++++++----- 2 files changed, 292 insertions(+), 89 deletions(-) diff --git a/machine-learning/model.py b/machine-learning/model.py index 55469aa5..7ad44ea4 100644 --- a/machine-learning/model.py +++ b/machine-learning/model.py @@ -2,6 +2,7 @@ import torch import torch.nn as nn import torch.nn.functional as F +from torch.nn.utils.rnn import pad_sequence import torchtext @@ -26,8 +27,10 @@ def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0. self.dropout = nn.Dropout(dropout) def forward(self, text): + # padding_value ought to be 1: TEXT.vocab.stoi[TEXT.pad_token] + padded_batch = pad_sequence(text, batch_first=True, padding_value=1) #text = [batch size, sent len] - embedded = self.embedding(text) + embedded = self.embedding(padded_batch) #embedded = [batch size, sent len, emb dim] embedded = embedded.unsqueeze(1) #embedded = [batch size, 1, sent len, emb dim] @@ -43,4 +46,4 @@ def forward(self, text): #cat = [batch size, n_filters * len(filter_sizes)] logits = self.fc(cat) #logits = [batch_size, output_dim] - return F.softmax(logits, dim=-1) \ No newline at end of file + return torch.log(F.softmax(logits, dim=-1)) \ No newline at end of file diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb index d80e4fd3..69f6d639 100644 --- a/machine-learning/skorch-hyperparam-opt.ipynb +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -37,7 +37,7 @@ "\n", "

Client

\n", "\n", "\n", @@ -53,10 +53,10 @@ "" ], "text/plain": [ - "" + "" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -114,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -123,14 +123,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# takes approx. 10 minutes to download data and embeddings (will be cached for re-use)\n", "\n", "# set up fields\n", - "TEXT = data.Field(lower=True, include_lengths=True, batch_first=True, )\n", + "TEXT = data.Field(lower=True, batch_first=True, )\n", "LABEL = data.Field(sequential=False, unk_token=None)\n", "\n", "# make splits for data\n", @@ -149,10 +149,131 @@ " (train, test), batch_sizes=(32, 64), device='cpu')" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "import torch.utils.data" + ] + }, { "cell_type": "code", "execution_count": 7, "metadata": {}, + "outputs": [], + "source": [ + "class TorchDataset(torch.utils.data.Dataset):\n", + " def __init__(self, dataset, TEXT, LABEL):\n", + " self.dataset = dataset\n", + " self.TEXT = TEXT\n", + " self.LABEL = LABEL\n", + " \n", + " def __getitem__(self, idx):\n", + " example = self.dataset.examples[idx]\n", + " X = TEXT.numericalize([example.text]).squeeze() # get rid of \"batch\" dimension\n", + " y = LABEL.numericalize([example.label])\n", + " return X, y\n", + " \n", + " def __len__(self):\n", + " return len(self.dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "train_dataset = TorchDataset(train, TEXT, LABEL)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "e1 = train_dataset[0]\n", + "e2 = train_dataset[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "from torch.nn.utils.rnn import pad_sequence" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "torch.Size([136])" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "e1[0].shape" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "torch.Size([143])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "e2[0].shape" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "torch.Size([2, 143])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# hoping skorch will unzip the tuple as follows\n", + "# padding_value ought to be 1: TEXT.vocab.stoi[TEXT.pad_token]\n", + "pad_sequence(list(zip(*[e1, e2]))[0], batch_first=True, padding_value=1).shape" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, "outputs": [ { "data": { @@ -160,7 +281,7 @@ "['', '', 'the', 'a', 'and']" ] }, - "execution_count": 7, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -173,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -182,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -204,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -215,46 +336,41 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 542, 5101, 41, ..., 1, 1, 1],\n", - " [ 10, 7, 31, ..., 1, 1, 1],\n", - " [ 0, 49, 15842, ..., 1, 1, 1],\n", + "tensor([[ 310, 9, 90, ..., 1, 1, 1],\n", + " [ 94, 1236, 10251, ..., 1, 1, 1],\n", + " [ 9, 297, 2432, ..., 1, 1, 1],\n", " ...,\n", - " [ 25, 86, 311, ..., 1, 1, 1],\n", - " [ 9, 157, 168, ..., 1, 1, 1],\n", - " [ 10, 49, 235, ..., 1, 1, 1]])\n", - "tensor([132, 121, 72, 343, 112, 90, 226, 982, 118, 341, 145, 64, 149, 87,\n", - " 244, 270, 122, 94, 141, 76, 154, 151, 429, 97, 104, 76, 120, 125,\n", - " 120, 118, 134, 154])\n" + " [ 46, 25, 37, ..., 1, 1, 1],\n", + " [ 10, 151, 37, ..., 1, 1, 1],\n", + " [ 9, 586, 7573, ..., 1, 1, 1]])\n" ] } ], "source": [ "# numericalized tokens\n", - "print(batch.text[0])\n", - "# sequence lengths\n", - "print(batch.text[1])" + "print(batch.text)" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "tensor([1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0,\n", - " 0, 1, 0, 1, 1, 0, 1, 1])" + "tensor([0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,\n", + " 0, 1, 1, 1, 0, 1, 0, 1])" ] }, - "execution_count": 12, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -265,7 +381,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -274,7 +390,7 @@ "defaultdict(None, {'neg': 0, 'pos': 1})" ] }, - "execution_count": 13, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -294,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -305,47 +421,47 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "tensor([[0.4698, 0.5302],\n", - " [0.3791, 0.6209],\n", - " [0.2715, 0.7285],\n", - " [0.3220, 0.6780],\n", - " [0.3979, 0.6021],\n", - " [0.4197, 0.5803],\n", - " [0.3409, 0.6591],\n", - " [0.2695, 0.7305],\n", - " [0.4400, 0.5600],\n", - " [0.4209, 0.5791],\n", - " [0.4640, 0.5360],\n", - " [0.4475, 0.5525],\n", - " [0.4261, 0.5739],\n", - " [0.3032, 0.6968],\n", - " [0.3452, 0.6548],\n", - " [0.3803, 0.6197],\n", - " [0.3741, 0.6259],\n", - " [0.3796, 0.6204],\n", - " [0.5005, 0.4995],\n", - " [0.3706, 0.6294],\n", - " [0.3142, 0.6858],\n", - " [0.3772, 0.6228],\n", - " [0.3281, 0.6719],\n", - " [0.3190, 0.6810],\n", - " [0.3340, 0.6660],\n", - " [0.3948, 0.6052],\n", - " [0.2351, 0.7649],\n", - " [0.4538, 0.5462],\n", - " [0.2321, 0.7679],\n", - " [0.4226, 0.5774],\n", - " [0.2449, 0.7551],\n", - " [0.3471, 0.6529]], device='cuda:0', grad_fn=)" + "tensor([[0.4948, 0.5052],\n", + " [0.3819, 0.6181],\n", + " [0.2845, 0.7155],\n", + " [0.3763, 0.6237],\n", + " [0.4416, 0.5584],\n", + " [0.4124, 0.5876],\n", + " [0.3489, 0.6511],\n", + " [0.3170, 0.6830],\n", + " [0.4920, 0.5080],\n", + " [0.4617, 0.5383],\n", + " [0.4359, 0.5641],\n", + " [0.3998, 0.6002],\n", + " [0.4126, 0.5874],\n", + " [0.3464, 0.6536],\n", + " [0.3516, 0.6484],\n", + " [0.3844, 0.6156],\n", + " [0.3831, 0.6169],\n", + " [0.3435, 0.6565],\n", + " [0.4960, 0.5040],\n", + " [0.3020, 0.6980],\n", + " [0.2781, 0.7219],\n", + " [0.3688, 0.6312],\n", + " [0.3789, 0.6211],\n", + " [0.2984, 0.7016],\n", + " [0.3126, 0.6874],\n", + " [0.4026, 0.5974],\n", + " [0.1881, 0.8119],\n", + " [0.4694, 0.5306],\n", + " [0.2728, 0.7272],\n", + " [0.5161, 0.4839],\n", + " [0.2169, 0.7831],\n", + " [0.4119, 0.5881]], device='cuda:0', grad_fn=)" ] }, - "execution_count": 15, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -353,13 +469,14 @@ "source": [ "# smoketest\n", "model = CNN(pretrained_embeddings=TEXT.vocab.vectors).to(device)\n", - "gpu_batch = batch.text[0].to(device)\n", - "model(gpu_batch)" + "gpu_batch = batch.text.to(device)\n", + "model_out = model(gpu_batch)\n", + "torch.exp(model_out)" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -368,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -377,7 +494,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -393,18 +510,18 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "import skorch\n", - "from skorch import NeuralNetClassifier\n", + "from skorch import NeuralNet, NeuralNetClassifier \n", "import torch.optim as optim" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -463,7 +580,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -472,47 +589,98 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "from torch.utils.data import Dataset, DataLoader" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "def pad_batch(batch):\n", + " text, label = list(zip(*batch))\n", + " padded_batch = pad_sequence(text, batch_first=True, padding_value=1)\n", + " return padded_batch, torch.cat(label)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ + "from skorch.callbacks import EpochScoring" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "accuracy = EpochScoring('accuracy', lower_is_better=False)\n", + "callbacks = [accuracy]" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "# if you want to use a custom DataLoader, you must use NeuralNet\n", + "# also, not immediately obvious that for NeuralNet you are responsible for applying the log function\n", + "# whereas for NeuralNetClassifier, you are not\n", + "\n", "# NB: not ideal to be using softmax + log + NLLLoss\n", "# see discussion: https://github.com/skorch-dev/skorch/issues/637\n", - "skorch_model = NeuralNetClassifier(\n", + "skorch_model = NeuralNet(\n", " CNN,\n", " device=device,\n", " max_epochs=2,\n", " lr=0.001,\n", " optimizer=optim.Adam,\n", " criterion=nn.NLLLoss,\n", + " iterator_train__collate_fn=pad_batch,\n", + " iterator_train__shuffle=True,\n", + " iterator_valid__collate_fn=pad_batch,\n", + " iterator_valid__shuffle=False,\n", " train_split=skorch.dataset.CVSplit(.2), # NB: this witholds 20% of the training data for validation\n", " module__n_filters=100,\n", " module__filter_sizes=(2,3,4),\n", " module__dropout=0.2,\n", " module__pretrained_embeddings=TEXT.vocab.vectors,\n", " batch_size=32,\n", - " verbose=2)" + " verbose=2)\n", + "# getting the following error when trying to compute accuracy\n", + "# ValueError: Classification metrics can't handle a mix of binary and continuous-multioutput targets\n", + "# callbacks=callbacks)" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " epoch train_loss valid_acc valid_loss dur\n", - "------- ------------ ----------- ------------ -------\n", - " 1 \u001b[36m0.4689\u001b[0m \u001b[32m0.8370\u001b[0m \u001b[35m0.3656\u001b[0m 60.5744\n", - " 2 \u001b[36m0.3466\u001b[0m \u001b[32m0.8524\u001b[0m \u001b[35m0.3413\u001b[0m 58.6526\n" + " epoch train_loss valid_loss dur\n", + "------- ------------ ------------ -------\n", + " 1 \u001b[36m0.4723\u001b[0m \u001b[32m0.3617\u001b[0m 20.1019\n", + " 2 \u001b[36m0.3534\u001b[0m \u001b[32m0.3248\u001b[0m 29.7210\n" ] }, { "data": { "text/plain": [ - "[initialized](\n", + "[initialized](\n", " module_=CNN(\n", " (embedding): Embedding(25002, 100)\n", " (conv_0): Conv1d(1, 100, kernel_size=(2, 100), stride=(1,))\n", @@ -524,13 +692,45 @@ ")" ] }, - "execution_count": 25, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# NB: now that we implemented our custom batching we reduced compute time from 60 seconds\n", + "# per epoch to 20 seconds per epoch. That's huge.\n", + "# ((60 - 20) / 60)*100 = ~66%\n", + "skorch_model.fit(train_dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "skorch_model.fit(X_train, y_train)" + "(60 - 20) / 60 " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "skorch_model." ] }, { From 8a15332c885dc7be9e38a8e066efd2f676dcc084 Mon Sep 17 00:00:00 2001 From: Todd Morrill Date: Mon, 25 May 2020 10:32:22 -0400 Subject: [PATCH 4/6] skorch running well, hyperband still throwing errors --- machine-learning/model.py | 14 +- machine-learning/skorch-hyperparam-opt.ipynb | 1542 ++++++++---------- 2 files changed, 723 insertions(+), 833 deletions(-) diff --git a/machine-learning/model.py b/machine-learning/model.py index 7ad44ea4..6f48270d 100644 --- a/machine-learning/model.py +++ b/machine-learning/model.py @@ -4,12 +4,14 @@ import torch.nn.functional as F from torch.nn.utils.rnn import pad_sequence import torchtext +import numpy as np class CNN(nn.Module): - def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0.2, pretrained_embeddings=None): + def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0.2, pretrained_embeddings=None, TEXT=None): super().__init__() + self.TEXT = TEXT # will be used to initialize model embeddings layer self.embedding = nn.Embedding.from_pretrained(pretrained_embeddings) self.embedding.weight.requires_grad = False # save some computation @@ -27,10 +29,12 @@ def __init__(self, n_filters=100, filter_sizes=(2,3,4), output_dim=2, dropout=0. self.dropout = nn.Dropout(dropout) def forward(self, text): - # padding_value ought to be 1: TEXT.vocab.stoi[TEXT.pad_token] - padded_batch = pad_sequence(text, batch_first=True, padding_value=1) +# # bit of a hack to preprocess data inside the network +# if isinstance(text, np.ndarray): +# text = self.TEXT.process(text) + #text = [batch size, sent len] - embedded = self.embedding(padded_batch) + embedded = self.embedding(text) #embedded = [batch size, sent len, emb dim] embedded = embedded.unsqueeze(1) #embedded = [batch size, 1, sent len, emb dim] @@ -46,4 +50,4 @@ def forward(self, text): #cat = [batch size, n_filters * len(filter_sizes)] logits = self.fc(cat) #logits = [batch_size, output_dim] - return torch.log(F.softmax(logits, dim=-1)) \ No newline at end of file + return F.softmax(logits, dim=-1) \ No newline at end of file diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb index 69f6d639..c06d1443 100644 --- a/machine-learning/skorch-hyperparam-opt.ipynb +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -37,7 +37,7 @@ "\n", "

Client

\n", "\n", "\n", @@ -53,10 +53,10 @@ "" ], "text/plain": [ - "" + "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -103,18 +103,20 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import torchtext\n", "from torchtext import data\n", - "from torchtext import datasets" + "from torchtext import datasets\n", + "from torch.utils.data import Dataset, DataLoader\n", + "from torch.nn.utils.rnn import pad_sequence" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -123,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -144,49 +146,54 @@ "TEXT.build_vocab(train, vectors=vocab, max_size=max_size)\n", "LABEL.build_vocab(train)\n", "\n", + "# sadly I don't think we can use this \n", "# make iterator for splits\n", - "train_iter, test_iter = data.BucketIterator.splits(\n", - " (train, test), batch_sizes=(32, 64), device='cpu')" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "import torch.utils.data" + "# train_iter, test_iter = data.BucketIterator.splits(\n", + "# (train, test), batch_sizes=(32, 64), device='cpu')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['', '', 'the', 'a', 'and']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "class TorchDataset(torch.utils.data.Dataset):\n", - " def __init__(self, dataset, TEXT, LABEL):\n", - " self.dataset = dataset\n", - " self.TEXT = TEXT\n", - " self.LABEL = LABEL\n", - " \n", - " def __getitem__(self, idx):\n", - " example = self.dataset.examples[idx]\n", - " X = TEXT.numericalize([example.text]).squeeze() # get rid of \"batch\" dimension\n", - " y = LABEL.numericalize([example.label])\n", - " return X, y\n", - " \n", - " def __len__(self):\n", - " return len(self.dataset)" + "# itos := index-to-string\n", + "# note the 2 extra tokens added for us: '', ''\n", + "TEXT.vocab.itos[:5]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "defaultdict(None, {'neg': 0, 'pos': 1})" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "train_dataset = TorchDataset(train, TEXT, LABEL)" + "# stoi := string-to-index\n", + "# check on the meaning of these zeroes and ones\n", + "LABEL.vocab.stoi" ] }, { @@ -195,37 +202,47 @@ "metadata": {}, "outputs": [], "source": [ - "e1 = train_dataset[0]\n", - "e2 = train_dataset[1]" + "assert (len(TEXT.vocab.itos) == max_size + 2)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.']\n", + "\n", + "pos\n" + ] + } + ], "source": [ - "from torch.nn.utils.rnn import pad_sequence" + "# peek at the data\n", + "print(train.examples[0].text)\n", + "print()\n", + "print(train.examples[0].label)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "torch.Size([136])" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "e1[0].shape" + "# if you could use data.BucketIterator.splits\n", + "\n", + "# sadly train_iter isn't actually an iter..\n", + "# peek at a batch of data\n", + "# batch = next(iter(train_iter))\n", + "\n", + "# numericalized tokens\n", + "# print(batch.text)\n", + "\n", + "# print(batch.label)" ] }, { @@ -236,7 +253,7 @@ { "data": { "text/plain": [ - "torch.Size([143])" + "torch.Size([2, 143])" ] }, "execution_count": 12, @@ -245,51 +262,49 @@ } ], "source": [ - "e2[0].shape" + "TEXT.process([train[0].text, train[1].text]).shape" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "torch.Size([2, 143])" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "# hoping skorch will unzip the tuple as follows\n", - "# padding_value ought to be 1: TEXT.vocab.stoi[TEXT.pad_token]\n", - "pad_sequence(list(zip(*[e1, e2]))[0], batch_first=True, padding_value=1).shape" + "# custom dataset class required to work with Skorch\n", + "class TorchDataset(Dataset):\n", + " def __init__(self, dataset):\n", + " self.dataset = dataset\n", + "\n", + " def __getitem__(self, idx):\n", + " example = self.dataset.examples[idx]\n", + " return example.text, example.label\n", + " \n", + " def __len__(self):\n", + " return len(self.dataset)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['', '', 'the', 'a', 'and']" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "# itos := index-to-string\n", - "# note the 2 extra tokens added for us: '', ''\n", - "TEXT.vocab.itos[:5]" + "# # custom dataset class required to work with Skorch\n", + "# class TorchDataset(torch.utils.data.Dataset):\n", + "# def __init__(self, dataset, TEXT, LABEL):\n", + "# self.dataset = dataset\n", + "# self.TEXT = TEXT\n", + "# self.LABEL = LABEL\n", + " \n", + "# def __getitem__(self, idx):\n", + "# example = self.dataset.examples[idx]\n", + "# X = TEXT.numericalize([example.text]).squeeze() # get rid of \"batch\" dimension\n", + "# y = LABEL.numericalize([example.label])\n", + "# return X, y\n", + " \n", + "# def __len__(self):\n", + "# return len(self.dataset)" ] }, { @@ -298,7 +313,7 @@ "metadata": {}, "outputs": [], "source": [ - "assert (len(TEXT.vocab.itos) == max_size + 2)" + "ex = train.examples[0]" ] }, { @@ -307,20 +322,18 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.']\n", - "\n", - "pos\n" - ] + "data": { + "text/plain": [ + "'a masterful treatment of james caine\\'s \"the postman always rings twice\" as luchino visconti\\'s first film shot primarily around ferrara in a soulless war-torn italy. the original negative was thought destroyed but visconti saved a print and fortunately we can see this early neo-realist work today. a ruggedly handsome massimo girotti and clara calamai (who had recently revealed her breasts in la cena delle beffe\" (1941), star as the sensually-charged and ill-fated lovers who plot to kill her husband. unusual ending in which, although crime does not pay, one pays in a way not directly linked to the crime. excellent direction, script, acting, and cinematography. reportedly not as good as the french \"le dernier tournant\\' (1939) but probably better than the us version (1946) featuring lana turner and john garfield in the lead roles. highly recommended.'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "# peek at the data\n", - "print(train.examples[0].text)\n", - "print()\n", - "print(train.examples[0].label)" + "' '.join(ex.text)" ] }, { @@ -329,9 +342,8 @@ "metadata": {}, "outputs": [], "source": [ - "# sadly train_iter isn't actually an iter..\n", - "# peek at a batch of data\n", - "batch = next(iter(train_iter))" + "train_dataset = TorchDataset(train)\n", + "test_dataset = TorchDataset(test)" ] }, { @@ -343,62 +355,48 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 310, 9, 90, ..., 1, 1, 1],\n", - " [ 94, 1236, 10251, ..., 1, 1, 1],\n", - " [ 9, 297, 2432, ..., 1, 1, 1],\n", - " ...,\n", - " [ 46, 25, 37, ..., 1, 1, 1],\n", - " [ 10, 151, 37, ..., 1, 1, 1],\n", - " [ 9, 586, 7573, ..., 1, 1, 1]])\n" + "(['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.'], 'pos')\n" ] } ], "source": [ - "# numericalized tokens\n", - "print(batch.text)" + "print(train_dataset[0])" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,\n", - " 0, 1, 1, 1, 0, 1, 0, 1])" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "batch.label" + "def pad_batch(batch, TEXT, LABEL):\n", + " text, label = list(zip(*batch))\n", + " # numericalized and padded text representation\n", + " text_processed = TEXT.process(text)\n", + " label_processed = LABEL.process(label)\n", + " return text_processed, label_processed\n", + "\n", + "from functools import partial\n", + "\n", + "pad_batch_partial = partial(pad_batch, TEXT=TEXT, LABEL=LABEL)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "defaultdict(None, {'neg': 0, 'pos': 1})" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "# stoi := string-to-index\n", - "# check on the meaning of these zeroes and ones\n", - "LABEL.vocab.stoi" + "train_dataloader = DataLoader(train_dataset, batch_size=32, shuffle=True, collate_fn=pad_batch_partial)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "batch = next(iter(train_dataloader))" ] }, { @@ -410,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -421,62 +419,59 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "tensor([[0.4948, 0.5052],\n", - " [0.3819, 0.6181],\n", - " [0.2845, 0.7155],\n", - " [0.3763, 0.6237],\n", - " [0.4416, 0.5584],\n", - " [0.4124, 0.5876],\n", - " [0.3489, 0.6511],\n", - " [0.3170, 0.6830],\n", - " [0.4920, 0.5080],\n", - " [0.4617, 0.5383],\n", - " [0.4359, 0.5641],\n", - " [0.3998, 0.6002],\n", - " [0.4126, 0.5874],\n", - " [0.3464, 0.6536],\n", - " [0.3516, 0.6484],\n", - " [0.3844, 0.6156],\n", - " [0.3831, 0.6169],\n", - " [0.3435, 0.6565],\n", - " [0.4960, 0.5040],\n", - " [0.3020, 0.6980],\n", - " [0.2781, 0.7219],\n", - " [0.3688, 0.6312],\n", - " [0.3789, 0.6211],\n", - " [0.2984, 0.7016],\n", - " [0.3126, 0.6874],\n", - " [0.4026, 0.5974],\n", - " [0.1881, 0.8119],\n", - " [0.4694, 0.5306],\n", - " [0.2728, 0.7272],\n", - " [0.5161, 0.4839],\n", - " [0.2169, 0.7831],\n", - " [0.4119, 0.5881]], device='cuda:0', grad_fn=)" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([[0.5732, 0.4268],\n", + " [0.5372, 0.4628],\n", + " [0.5615, 0.4385],\n", + " [0.6806, 0.3194],\n", + " [0.6352, 0.3648],\n", + " [0.5678, 0.4322],\n", + " [0.6505, 0.3495],\n", + " [0.4325, 0.5675],\n", + " [0.6019, 0.3981],\n", + " [0.5857, 0.4143],\n", + " [0.6010, 0.3990],\n", + " [0.5662, 0.4338],\n", + " [0.6494, 0.3506],\n", + " [0.4390, 0.5610],\n", + " [0.6041, 0.3959],\n", + " [0.7121, 0.2879],\n", + " [0.5781, 0.4219],\n", + " [0.5727, 0.4273],\n", + " [0.5169, 0.4831],\n", + " [0.6531, 0.3469],\n", + " [0.5080, 0.4920],\n", + " [0.5611, 0.4389],\n", + " [0.5560, 0.4440],\n", + " [0.6448, 0.3552],\n", + " [0.5697, 0.4303],\n", + " [0.5798, 0.4202],\n", + " [0.6656, 0.3344],\n", + " [0.4933, 0.5067],\n", + " [0.5143, 0.4857],\n", + " [0.5518, 0.4482],\n", + " [0.5806, 0.4194],\n", + " [0.6070, 0.3930]], device='cuda:0', grad_fn=)\n" + ] } ], "source": [ "# smoketest\n", "model = CNN(pretrained_embeddings=TEXT.vocab.vectors).to(device)\n", - "gpu_batch = batch.text.to(device)\n", + "gpu_batch = batch[0].to(device)\n", "model_out = model(gpu_batch)\n", - "torch.exp(model_out)" + "print(model_out)" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -485,7 +480,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -494,7 +489,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -510,186 +505,216 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "import skorch\n", - "from skorch import NeuralNet, NeuralNetClassifier \n", + "from skorch import NeuralNetClassifier \n", "import torch.optim as optim" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ - "# this is a really unfortunate hack to make torchtext batching semantics work with skorch and dask\n", - "# the downside here is that we're no longer padding to the longest sequence in the batch, rather\n", - "# we're padding to the longest sequence in the *dataset*, which results in signifcantly more\n", - "# computation and thus significantly more time to train a model\n", - "# of course, you could set a max sequence length but that's not an ideal solution\n", - "# another solution would be to create a different dataset object, but then you can't use torchtext,\n", - "# which really is quite handy\n", - "\n", - "# train=True shuffles the data\n", - "train_iter_skorch = torchtext.data.Iterator(train, batch_size=len(train), train=True, sort=False, device='cpu')\n", - "test_iter_skorch = torchtext.data.Iterator(test, batch_size=len(test), train=False, sort=False, device='cpu')" + "import torch.nn as nn" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ - "# takes some time to numericalize the whole dataset\n", - "\n", - "# also notice that skorch and dask expect numpy arrays, which isn't ideal since it ties you to the cpu.\n", - "# meanwhile, projects like https://rapids.ai/ are moving toward all GPU computation, avoiding the cpu altogether.\n", - "for batch in train_iter_skorch:\n", - " X_train = batch.text[0].numpy()\n", - " y_train = batch.label.numpy()\n", + "# if you want to use a custom DataLoader, you must use NeuralNet\n", + "# also, not immediately obvious that for NeuralNet you are responsible for applying the log function\n", + "# whereas for NeuralNetClassifier, you are not\n", "\n", - "for batch in test_iter_skorch:\n", - " X_test = batch.text[0].numpy()\n", - " y_test = batch.label.numpy()" + "# NB: not ideal to be using softmax + log + NLLLoss\n", + "# see discussion: https://github.com/skorch-dev/skorch/issues/637\n", + "skorch_model = NeuralNetClassifier(\n", + " CNN,\n", + " device=device,\n", + " max_epochs=2,\n", + " lr=0.001,\n", + " optimizer=optim.Adam,\n", + " criterion=nn.NLLLoss,\n", + " iterator_train=DataLoader,\n", + " iterator_train__shuffle=True,\n", + " iterator_train__batch_size=32,\n", + " iterator_train__collate_fn=pad_batch_partial,\n", + " iterator_train__num_workers=8,\n", + " iterator_valid=DataLoader,\n", + " iterator_valid__shuffle=False,\n", + " iterator_valid__batch_size=64,\n", + " iterator_valid__collate_fn=pad_batch_partial,\n", + " iterator_valid__num_workers=8,\n", + " train_split=skorch.dataset.CVSplit(.2), # NB: this witholds 20% of the training data for validation\n", + " module__n_filters=100,\n", + " module__filter_sizes=(2,3,4),\n", + " module__dropout=0.2,\n", + " module__pretrained_embeddings=TEXT.vocab.vectors,\n", + " verbose=2)\n", + "# getting the following error when trying to compute accuracy\n", + "# ValueError: Classification metrics can't handle a mix of binary and continuous-multioutput targets\n", + "# callbacks=callbacks)" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 30, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " epoch train_loss valid_acc valid_loss dur\n", + "------- ------------ ----------- ------------ -------\n", + " 1 \u001b[36m0.4630\u001b[0m \u001b[32m0.8312\u001b[0m \u001b[35m0.3808\u001b[0m 33.8281\n", + " 2 \u001b[36m0.3454\u001b[0m \u001b[32m0.8540\u001b[0m \u001b[35m0.3361\u001b[0m 34.1240\n" + ] + }, { "data": { "text/plain": [ - "(25000, 2470)" + "[initialized](\n", + " module_=CNN(\n", + " (embedding): Embedding(25002, 100)\n", + " (conv_0): Conv1d(1, 100, kernel_size=(2, 100), stride=(1,))\n", + " (conv_1): Conv1d(1, 100, kernel_size=(3, 100), stride=(1,))\n", + " (conv_2): Conv1d(1, 100, kernel_size=(4, 100), stride=(1,))\n", + " (fc): Linear(in_features=300, out_features=2, bias=True)\n", + " (dropout): Dropout(p=0.2, inplace=False)\n", + " ),\n", + ")" ] }, - "execution_count": 22, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# notice how awfully large the second dimension is\n", - "X_train.shape" + "# NB: now that we implemented our custom batching we reduced compute time from 60 seconds\n", + "# per epoch to 20 seconds per epoch. That's huge.\n", + "# ((60 - 20) / 60)*100 = ~66%\n", + "skorch_model.fit(train_dataset, y=None)" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "import torch.nn as nn" + "# this isn't working as expected\n", + "# skorch_model.score(test_dataset)\n", + "# TypeError: score() missing 1 required positional argument: 'y'\n", + "# skorch_model.score(test_dataset, y=None)\n", + "# ValueError: Expected array-like (array or non-string sequence), got None" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "from torch.utils.data import Dataset, DataLoader" + "# score manually\n", + "test_dataloader = DataLoader(test_dataset, batch_size=len(test_dataset), shuffle=False, collate_fn=pad_batch_partial, num_workers=8)" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "def pad_batch(batch):\n", - " text, label = list(zip(*batch))\n", - " padded_batch = pad_sequence(text, batch_first=True, padding_value=1)\n", - " return padded_batch, torch.cat(label)" + "# sadly processing the entire test set twice just to score the model\n", + "processed_test_data = next(iter(test_dataloader))" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ - "from skorch.callbacks import EpochScoring" + "# quick check on the test set accuracy\n", + "test_preds = skorch_model.predict(test_dataset)" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 1, 1, ..., 0, 0, 0])" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_preds" + ] + }, + { + "cell_type": "code", + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "accuracy = EpochScoring('accuracy', lower_is_better=False)\n", - "callbacks = [accuracy]" + "test_labels = processed_test_data[1].numpy()" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ - "# if you want to use a custom DataLoader, you must use NeuralNet\n", - "# also, not immediately obvious that for NeuralNet you are responsible for applying the log function\n", - "# whereas for NeuralNetClassifier, you are not\n", - "\n", - "# NB: not ideal to be using softmax + log + NLLLoss\n", - "# see discussion: https://github.com/skorch-dev/skorch/issues/637\n", - "skorch_model = NeuralNet(\n", - " CNN,\n", - " device=device,\n", - " max_epochs=2,\n", - " lr=0.001,\n", - " optimizer=optim.Adam,\n", - " criterion=nn.NLLLoss,\n", - " iterator_train__collate_fn=pad_batch,\n", - " iterator_train__shuffle=True,\n", - " iterator_valid__collate_fn=pad_batch,\n", - " iterator_valid__shuffle=False,\n", - " train_split=skorch.dataset.CVSplit(.2), # NB: this witholds 20% of the training data for validation\n", - " module__n_filters=100,\n", - " module__filter_sizes=(2,3,4),\n", - " module__dropout=0.2,\n", - " module__pretrained_embeddings=TEXT.vocab.vectors,\n", - " batch_size=32,\n", - " verbose=2)\n", - "# getting the following error when trying to compute accuracy\n", - "# ValueError: Classification metrics can't handle a mix of binary and continuous-multioutput targets\n", - "# callbacks=callbacks)" + "from sklearn.metrics import accuracy_score" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 38, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - " epoch train_loss valid_loss dur\n", - "------- ------------ ------------ -------\n", - " 1 \u001b[36m0.4723\u001b[0m \u001b[32m0.3617\u001b[0m 20.1019\n", - " 2 \u001b[36m0.3534\u001b[0m \u001b[32m0.3248\u001b[0m 29.7210\n" - ] - }, + "data": { + "text/plain": [ + "0.85048" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accuracy_score(test_labels, test_preds)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ { "data": { "text/plain": [ - "[initialized](\n", - " module_=CNN(\n", - " (embedding): Embedding(25002, 100)\n", - " (conv_0): Conv1d(1, 100, kernel_size=(2, 100), stride=(1,))\n", - " (conv_1): Conv1d(1, 100, kernel_size=(3, 100), stride=(1,))\n", - " (conv_2): Conv1d(1, 100, kernel_size=(4, 100), stride=(1,))\n", - " (fc): Linear(in_features=300, out_features=2, bias=True)\n", - " (dropout): Dropout(p=0.2, inplace=False)\n", - " ),\n", - ")" + "(array([0, 1]), array([12500, 12500]))" ] }, "execution_count": 39, @@ -698,105 +723,236 @@ } ], "source": [ - "# NB: now that we implemented our custom batching we reduced compute time from 60 seconds\n", - "# per epoch to 20 seconds per epoch. That's huge.\n", - "# ((60 - 20) / 60)*100 = ~66%\n", - "skorch_model.fit(train_dataset)" + "# random guessing would 50% accuracy so the model is indeed training\n", + "np.unique(test_labels, return_counts=True)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, + "outputs": [], + "source": [ + "# NB: this has no effect on GPU memory usage. If I keyboard interrupt, the workers get\n", + "# restarted and memory usage goes down. Deleting these \"handler\" objects doesn't delete\n", + "# GPU memory references on the workers. \n", + "del skorch_model" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Grid search with Hyperband" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "# try to store the raw text in dask arrays and handle preprocessing inside the network\n", + "# this isn't ideal because feature engineering really should be separate from modeling" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "# raw text\n", + "train_text = []\n", + "train_label = []\n", + "for e in train.examples:\n", + " tokenized_text = e.text\n", + " text_string = ' '.join(tokenized_text)\n", + " train_text.append(text_string)\n", + " label = e.label\n", + " # label = LABEL.process([e.label]).numpy()\n", + " train_label.append(label)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.6666666666666666" + "['a masterful treatment of james caine\\'s \"the postman always rings twice\" as luchino visconti\\'s first film shot primarily around ferrara in a soulless war-torn italy. the original negative was thought destroyed but visconti saved a print and fortunately we can see this early neo-realist work today. a ruggedly handsome massimo girotti and clara calamai (who had recently revealed her breasts in la cena delle beffe\" (1941), star as the sensually-charged and ill-fated lovers who plot to kill her husband. unusual ending in which, although crime does not pay, one pays in a way not directly linked to the crime. excellent direction, script, acting, and cinematography. reportedly not as good as the french \"le dernier tournant\\' (1939) but probably better than the us version (1946) featuring lana turner and john garfield in the lead roles. highly recommended.']" ] }, - "execution_count": 40, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "(60 - 20) / 60 " + "train_text[:1]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ - "skorch_model." + "train_text = np.array(train_text)" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "train_text = np.expand_dims(train_text, axis=-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "sample_batch = [train_text[0], train_text[10]]" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "sample_text_batch = [i[0] for i in sample_batch]" + ] + }, + { + "cell_type": "code", + "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.85512" + "tensor([[ 3, 0, 12500, ..., 1, 1, 1],\n", + " [ 1669, 3651, 9, ..., 9300, 6517, 411]])" ] }, - "execution_count": 26, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# quick check on the test set accuracy\n", - "skorch_model.score(X_test, y_test)" + "TEXT.process(sample_text_batch)" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(array([0, 1]), array([12500, 12500]))" + "torch.Size([2, 858])" ] }, - "execution_count": 27, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# random guessing would 50% accuracy so the model is indeed training\n", - "np.unique(y_test, return_counts=True)" + "TEXT.process([train_text[0][0], train_text[1][0]]).shape" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "isinstance(train_text[:10], np.ndarray)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ - "# NB: this has no effect on GPU memory usage. If I keyboard interrupt, the workers get\n", - "# restarted and memory usage goes down. Deleting these \"handler\" objects doesn't delete\n", - "# GPU memory references on the workers. \n", - "del skorch_model" + "# TEXT.process(train_text[0])" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 52, "metadata": {}, + "outputs": [], "source": [ - "## Grid search with Hyperband" + "train_label = np.array(train_label)" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "# # this is a really unfortunate hack to make torchtext batching semantics work with skorch and dask\n", + "# # the downside here is that we're no longer padding to the longest sequence in the batch, rather\n", + "# # we're padding to the longest sequence in the *dataset*, which results in signifcantly more\n", + "# # computation and thus significantly more time to train a model\n", + "# # of course, you could set a max sequence length but that's not an ideal solution\n", + "# # another solution would be to create a different dataset object, but then you can't use torchtext,\n", + "# # which really is quite handy\n", + "\n", + "# # train=True shuffles the data\n", + "# train_iter_skorch = torchtext.data.Iterator(train, batch_size=len(train), train=True, sort=False, device='cpu')\n", + "# test_iter_skorch = torchtext.data.Iterator(test, batch_size=len(test), train=False, sort=False, device='cpu')\n", + "\n", + "# # takes some time to numericalize the whole dataset\n", + "\n", + "# # also notice that skorch and dask expect numpy arrays, which isn't ideal since it ties you to the cpu.\n", + "# # meanwhile, projects like https://rapids.ai/ are moving toward all GPU computation, avoiding the cpu altogether.\n", + "# for batch in train_iter_skorch:\n", + "# X_train = batch.text[0].numpy()\n", + "# y_train = batch.label.numpy()\n", + "\n", + "# for batch in test_iter_skorch:\n", + "# X_test = batch.text[0].numpy()\n", + "# y_test = batch.label.numpy()" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# notice how awfully large the second dimension is\n", + "# X_train.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -813,7 +969,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ @@ -826,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ @@ -835,7 +991,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 58, "metadata": {}, "outputs": [ { @@ -851,30 +1007,30 @@ "source": [ "# choose chunk size so that the remainder is not a tiny number\n", "print(f'Chunk size: {chunk_size}')\n", - "print(f'Total chunks: {math.ceil(len(X_train) / chunk_size)}')\n", - "last_chunk_size = len(X_train) % chunk_size\n", + "print(f'Total chunks: {math.ceil(len(train) / chunk_size)}')\n", + "last_chunk_size = len(train) % chunk_size\n", "if last_chunk_size == 0: # i.e. chunk_size evenly divides X_train\n", " last_chunk_size = chunk_size\n", "print(f'Last chunk size: {last_chunk_size}')\n", "\n", - "assert (len(X_train) % chunk_size > 10 or len(X_train) % chunk_size == 0), 'Choose another chunk size'" + "assert (len(train) % chunk_size > 10 or len(train) % chunk_size == 0), 'Choose another chunk size'" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "import dask.array as da\n", "\n", - "X = da.from_array(X_train, chunks=(chunk_size, X_train.shape[-1]))\n", - "y = da.from_array(y_train, chunks=(chunk_size))" + "X = da.from_array(train_text, chunks=(chunk_size))\n", + "y = da.from_array(train_label, chunks=(chunk_size))" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -888,41 +1044,41 @@ " Array Chunk \n", " \n", " \n", - " Bytes 494.00 MB 247.00 MB \n", - " Shape (25000, 2470) (12500, 2470) \n", + " Bytes 1.37 GB 685.20 MB \n", + " Shape (25000, 1) (12500, 1) \n", " Count 3 Tasks 2 Chunks \n", - " Type int64 numpy.ndarray \n", + " Type numpy.ndarray \n", " \n", "\n", "\n", "\n", - "\n", + "\n", "\n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", "\n", " \n", " \n", - " \n", + " \n", "\n", " \n", - " \n", + " \n", "\n", " \n", - " 2470\n", - " 25000\n", + " 1\n", + " 25000\n", "\n", "\n", "\n", "" ], "text/plain": [ - "dask.array" + "dask.array" ] }, - "execution_count": 34, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -933,7 +1089,37 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "# need new collate_fn due to the following error\n", + "# ValueError: Expected 2D array, got 1D array instead:\n", + "# array=['1' '1' '1' ... '1' '1' '1'].\n", + "# Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample." + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "def pad_batch_hyperband(batch, TEXT, LABEL):\n", + " text, label = list(zip(*batch))\n", + " # unnecessary extra dimension\n", + " text = [i[0] for i in text]\n", + " # numericalized and padded text representation\n", + " text_processed = TEXT.process(text)\n", + " label_processed = LABEL.process(label)\n", + " return text_processed, label_processed\n", + "\n", + "pad_batch_hyperband_partial = partial(pad_batch_hyperband, TEXT=TEXT, LABEL=LABEL)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, "metadata": {}, "outputs": [], "source": [ @@ -944,18 +1130,27 @@ " lr=0.001,\n", " optimizer=optim.Adam,\n", " criterion=nn.NLLLoss,\n", + " iterator_train=DataLoader,\n", + " iterator_train__shuffle=True,\n", + " iterator_train__batch_size=32,\n", + " iterator_train__collate_fn=pad_batch_hyperband_partial,\n", + " iterator_valid=DataLoader,\n", + " iterator_valid__collate_fn=pad_batch_hyperband_partial,\n", + " iterator_valid__shuffle=False,\n", + " iterator_valid__batch_size=64,\n", " train_split=None, # let hyperband handle it\n", " module__n_filters=100,\n", " module__filter_sizes=(2, 3, 4),\n", " module__dropout=0.2,\n", " module__pretrained_embeddings=TEXT.vocab.vectors,\n", + " # module__TEXT=TEXT,\n", " batch_size=32,\n", " verbose=2)" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ @@ -964,7 +1159,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ @@ -978,7 +1173,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -987,7 +1182,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -1002,7 +1197,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -1011,7 +1206,7 @@ "26" ] }, - "execution_count": 40, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -1022,7 +1217,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -1031,7 +1226,7 @@ "5" ] }, - "execution_count": 41, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -1042,7 +1237,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ @@ -1051,7 +1246,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ @@ -1066,7 +1261,39 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 72, + "metadata": {}, + "outputs": [], + "source": [ + "# I feel like the GPU is spending a lot of time waiting for the CPU to preprocess data\n", + "# I've been watching GPU power consumption during training and it's not as high as during\n", + "# skorch training, so I tried to increase the number of workers the dataloader uses and\n", + "# got the following error: AssertionError: daemonic processes are not allowed to have children" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'pos'" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y[0].compute()" + ] + }, + { + "cell_type": "code", + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -1080,7 +1307,19 @@ "name": "stderr", "output_type": "stream", "text": [ - "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 10.00 MB detected in task graph: \n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/torch/storage.py:34: FutureWarning: pickle support for Storage will be removed in 1.5. Use `torch.save` instead\n", + " warnings.warn(\"pickle support for Storage will be removed in 1.5. Use `torch.save` instead\", FutureWarning)\n", + "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 23.79 MB detected in task graph: \n", " [[u ... .0721]]),\n", "), 0]\n", "Consider scattering large objects ahead of time\n", @@ -1098,21 +1337,123 @@ "name": "stdout", "output_type": "stream", "text": [ - "[CV, bracket=0] creating 2 models\n", + "[CV, bracket=0] creating 2 models\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", + " sk_validation.check_array(sample, *args, **kwargs)\n", + "/opt/conda/lib/python3.7/site-packages/torch/storage.py:34: FutureWarning: pickle support for Storage will be removed in 1.5. Use `torch.save` instead\n", + " warnings.warn(\"pickle support for Storage will be removed in 1.5. Use `torch.save` instead\", FutureWarning)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "[CV, bracket=0] For training there are between 10000 and 10000 examples in each chunk\n", - "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n", - "[CV, bracket=0] validation score of 0.8386 received after 1 partial_fit calls\n", - "[CV, bracket=1] validation score of 0.8306 received after 1 partial_fit calls\n", - "[CV, bracket=0] validation score of 0.8446 received after 8 partial_fit calls\n", - "[CV, bracket=1] validation score of 0.8430 received after 2 partial_fit calls\n", - "[CV, bracket=1] validation score of 0.8456 received after 6 partial_fit calls\n", - "Time to complete grid search: 3813.07 seconds\n" + "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "tornado.application - ERROR - Multiple exceptions in yield list\n", + "Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 849, in callback\n", + " result_list.append(f.result())\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", + " yielded = self.gen.throw(*exc_info)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 625, in _fit\n", + " prefix=self.prefix,\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", + " value = future.result()\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", + " yielded = self.gen.throw(*exc_info)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 233, in _fit\n", + " metas = yield client.gather(new_scores)\n", + " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", + " value = future.result()\n", + " File \"/opt/conda/lib/python3.7/site-packages/distributed/client.py\", line 1826, in _gather\n", + " raise exception.with_traceback(traceback)\n", + " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 103, in _score\n", + " score = scorer(model, X, y)\n", + " File \"/opt/conda/lib/python3.7/site-packages/sklearn/metrics/_scorer.py\", line 371, in _passthrough_scorer\n", + " return estimator.score(*args, **kwargs)\n", + " File \"/opt/conda/lib/python3.7/site-packages/sklearn/base.py\", line 369, in score\n", + " return accuracy_score(y, self.predict(X), sample_weight=sample_weight)\n", + " File \"/opt/conda/lib/python3.7/site-packages/skorch/classifier.py\", line 210, in predict\n", + " for yp in self.forward_iter(X, training=False):\n", + " File \"/opt/conda/lib/python3.7/site-packages/skorch/net.py\", line 917, in forward_iter\n", + " for data in iterator:\n", + " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\", line 345, in __next__\n", + " data = self._next_data()\n", + " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\", line 385, in _next_data\n", + " data = self._dataset_fetcher.fetch(index) # may raise StopIteration\n", + " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\", line 47, in fetch\n", + " return self.collate_fn(data)\n", + " File \"\", line 7, in pad_batch_hyperband\n", + " label_processed = LABEL.process(label)\n", + " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 237, in process\n", + " tensor = self.numericalize(padded, device=device)\n", + " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 338, in numericalize\n", + " arr = [self.vocab.stoi[x] for x in arr]\n", + " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 338, in \n", + " arr = [self.vocab.stoi[x] for x in arr]\n", + "KeyError: tensor([0.])\n" + ] + }, + { + "ename": "KeyError", + "evalue": "tensor([0.])", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 673\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdefault_client\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mif_delegate_has_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"best_estimator_\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"estimator\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mf\u001b[0;34m()\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallback_timeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 330\u001b[0m \u001b[0mfuture\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0masyncio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait_for\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfuture\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 331\u001b[0;31m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 332\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_hyperband.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[0;31m# _fit is run in parallel because it's also a tornado coroutine\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 400\u001b[0;31m \u001b[0m_SHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mSHAs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_brackets_ids\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 401\u001b[0m \u001b[0mSHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_brackets_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_SHAs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 402\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mcallback\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 847\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mchildren\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 848\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 849\u001b[0;31m \u001b[0mresult_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 850\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 624\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 625\u001b[0;31m \u001b[0mprefix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprefix\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 626\u001b[0m )\n\u001b[1;32m 627\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_results\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(model, params, X_train, y_train, X_test, y_test, additional_calls, fit_params, scorer, random_state, verbose, prefix)\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0;31m# async for future, result in seq:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 233\u001b[0;31m \u001b[0mmetas\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_scores\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 234\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlog_delay\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlog_delay\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36m_gather\u001b[0;34m(self, futures, errors, direct, local_worker)\u001b[0m\n\u001b[1;32m 1824\u001b[0m \u001b[0mexc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1825\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1826\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1827\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1828\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"skip\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_score\u001b[0;34m()\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeta\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel_and_meta\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mscorer\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mscorer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/sklearn/metrics/_scorer.py\u001b[0m in \u001b[0;36m_passthrough_scorer\u001b[0;34m()\u001b[0m\n\u001b[1;32m 369\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_passthrough_scorer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mestimator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0;34m\"\"\"Function that wraps estimator.score\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 371\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mestimator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 372\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36mscore\u001b[0;34m()\u001b[0m\n\u001b[1;32m 367\u001b[0m \"\"\"\n\u001b[1;32m 368\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mmetrics\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0maccuracy_score\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 369\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0maccuracy_score\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 370\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/skorch/classifier.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m()\u001b[0m\n\u001b[1;32m 208\u001b[0m \"\"\"\n\u001b[1;32m 209\u001b[0m \u001b[0my_preds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 210\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0myp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward_iter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 211\u001b[0m \u001b[0myp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0myp\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0myp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0myp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 212\u001b[0m \u001b[0my_preds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mto_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0myp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/skorch/net.py\u001b[0m in \u001b[0;36mforward_iter\u001b[0;34m()\u001b[0m\n\u001b[1;32m 915\u001b[0m \u001b[0mdataset\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_dataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 916\u001b[0m \u001b[0miterator\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_iterator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtraining\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 917\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;32min\u001b[0m \u001b[0miterator\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 918\u001b[0m \u001b[0mXi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0munpack_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 919\u001b[0m \u001b[0myp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevaluation_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mXi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtraining\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m__next__\u001b[0;34m()\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__next__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 345\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 346\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_num_yielded\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_kind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0m_DatasetKind\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mIterable\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m_next_data\u001b[0;34m()\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 385\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_fetcher\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 386\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pin_memory\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\u001b[0m in \u001b[0;36mfetch\u001b[0;34m()\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mpossibly_batched_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcollate_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mpad_batch_hyperband\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# numericalized and padded text representation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mtext_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTEXT\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mlabel_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLABEL\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtext_processed\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel_processed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mprocess\u001b[0;34m()\u001b[0m\n\u001b[1;32m 235\u001b[0m \"\"\"\n\u001b[1;32m 236\u001b[0m \u001b[0mpadded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpad\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 237\u001b[0;31m \u001b[0mtensor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumericalize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpadded\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 238\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtensor\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 239\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mnumericalize\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: tensor([0.])" ] } ], "source": [ - "# it's been erroring out with a less than helpful error message. This started happening right around \n", - "# when I started passing module__pretrained_embeddings=vocab.vectors. Unclear if this is the culprit.\n", + "# I think I'm getting yelled at for passing in text\n", + "# TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found [initialized](\n", - " module_=CNN(\n", - " (embedding): Embedding(25002, 100)\n", - " (conv_0): Conv1d(1, 50, kernel_size=(3, 100), stride=(1,))\n", - " (conv_1): Conv1d(1, 50, kernel_size=(4, 100), stride=(1,))\n", - " (conv_2): Conv1d(1, 50, kernel_size=(5, 100), stride=(1,))\n", - " (fc): Linear(in_features=150, out_features=2, bias=True)\n", - " (dropout): Dropout(p=0.22181138802671369, inplace=False)\n", - " ),\n", - ")" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "search.best_estimator_" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1218,70 +1515,18 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'param_module__n_filters': array([50, 50, 50, 25, 50]),\n", - " 'test_score': array([0.8456, 0.7982, 0.733 , 0.843 , 0.8446]),\n", - " 'std_score_time': array([0.06216696, 0.19731486, 0.56393194, 1.33936262, 0.06445384]),\n", - " 'rank_test_score': array([1, 2, 3, 2, 1]),\n", - " 'mean_score_time': array([3.82462454, 4.0282222 , 5.47523713, 4.41082978, 5.29884744]),\n", - " 'params': array([{'batch_size': 64, 'module__dropout': 0.22181138802671369, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", - " {'batch_size': 64, 'module__dropout': 0.19188105885296006, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", - " {'batch_size': 32, 'module__dropout': 0.11893575283135104, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50},\n", - " {'batch_size': 32, 'module__dropout': 0.10900910968190201, 'module__filter_sizes': (2, 3, 4), 'module__n_filters': 25},\n", - " {'batch_size': 32, 'module__dropout': 0.10009422737462631, 'module__filter_sizes': (3, 4, 5), 'module__n_filters': 50}],\n", - " dtype=object),\n", - " 'partial_fit_calls': array([6, 2, 2, 8, 8]),\n", - " 'param_module__dropout': array([0.22181139, 0.19188106, 0.11893575, 0.10900911, 0.10009423]),\n", - " 'std_partial_fit_time': array([ 3.6288025 , 1.52035153, 11.09951091, 15.07569551, 5.98224938]),\n", - " 'mean_partial_fit_time': array([ 93.61417103, 96.36260712, 136.89576507, 143.69626164,\n", - " 130.64727747]),\n", - " 'model_id': array(['bracket=1-0', 'bracket=1-1', 'bracket=1-2', 'bracket=0-0',\n", - " 'bracket=0-1'], dtype='\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcv_results\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcv_results_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mcv_results\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[1;32m 409\u001b[0m )\n\u001b[1;32m 410\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 411\u001b[0;31m \u001b[0mmgr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minit_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 412\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMaskedArray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmrecords\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mmrecords\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36minit_dict\u001b[0;34m(data, index, columns, dtype)\u001b[0m\n\u001b[1;32m 255\u001b[0m \u001b[0marr\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mis_datetime64tz_dtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0marr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marrays\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 256\u001b[0m ]\n\u001b[0;32m--> 257\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0marrays_to_mgr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata_names\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 258\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 259\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36marrays_to_mgr\u001b[0;34m(arrays, arr_names, index, columns, dtype)\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;31m# don't force copy because getting jammed in an ndarray anyway\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 82\u001b[0;31m \u001b[0marrays\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_homogenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 83\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;31m# from BlockManager perspective\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36m_homogenize\u001b[0;34m(data, index, dtype)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[0mval\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfast_multiget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 322\u001b[0m val = sanitize_array(\n\u001b[0;32m--> 323\u001b[0;31m \u001b[0mval\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mraise_cast_failure\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 324\u001b[0m )\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/internals/construction.py\u001b[0m in \u001b[0;36msanitize_array\u001b[0;34m(data, index, dtype, copy, raise_cast_failure)\u001b[0m\n\u001b[1;32m 727\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0msubarr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 728\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 729\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Data must be 1-dimensional\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 730\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 731\u001b[0m \u001b[0msubarr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masarray_tuplesafe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mException\u001b[0m: Data must be 1-dimensional" - ] - } - ], + "outputs": [], "source": [ "cv_results = pd.DataFrame(search.cv_results_)\n", "cv_results.head()" @@ -1289,7 +1534,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1299,178 +1544,9 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
param_module__n_filterstest_scorestd_score_timerank_test_scoremean_score_timeparamspartial_fit_callsparam_module__dropoutstd_partial_fit_timemean_partial_fit_timemodel_idbracketparam_batch_sizeparam_module__filter_sizes
0500.84560.06216713.824625{'batch_size': 64, 'module__dropout': 0.221811...60.2218113.62880293.614171bracket=1-0164[3, 4, 5]
1500.79820.19731524.028222{'batch_size': 64, 'module__dropout': 0.191881...20.1918811.52035296.362607bracket=1-1164[3, 4, 5]
2500.73300.56393235.475237{'batch_size': 32, 'module__dropout': 0.118935...20.11893611.099511136.895765bracket=1-2132[3, 4, 5]
3250.84301.33936324.410830{'batch_size': 32, 'module__dropout': 0.109009...80.10900915.075696143.696262bracket=0-0032[2, 3, 4]
4500.84460.06445415.298847{'batch_size': 32, 'module__dropout': 0.100094...80.1000945.982249130.647277bracket=0-1032[3, 4, 5]
\n", - "
" - ], - "text/plain": [ - " param_module__n_filters test_score std_score_time rank_test_score \\\n", - "0 50 0.8456 0.062167 1 \n", - "1 50 0.7982 0.197315 2 \n", - "2 50 0.7330 0.563932 3 \n", - "3 25 0.8430 1.339363 2 \n", - "4 50 0.8446 0.064454 1 \n", - "\n", - " mean_score_time params \\\n", - "0 3.824625 {'batch_size': 64, 'module__dropout': 0.221811... \n", - "1 4.028222 {'batch_size': 64, 'module__dropout': 0.191881... \n", - "2 5.475237 {'batch_size': 32, 'module__dropout': 0.118935... \n", - "3 4.410830 {'batch_size': 32, 'module__dropout': 0.109009... \n", - "4 5.298847 {'batch_size': 32, 'module__dropout': 0.100094... \n", - "\n", - " partial_fit_calls param_module__dropout std_partial_fit_time \\\n", - "0 6 0.221811 3.628802 \n", - "1 2 0.191881 1.520352 \n", - "2 2 0.118936 11.099511 \n", - "3 8 0.109009 15.075696 \n", - "4 8 0.100094 5.982249 \n", - "\n", - " mean_partial_fit_time model_id bracket param_batch_size \\\n", - "0 93.614171 bracket=1-0 1 64 \n", - "1 96.362607 bracket=1-1 1 64 \n", - "2 136.895765 bracket=1-2 1 32 \n", - "3 143.696262 bracket=0-0 0 32 \n", - "4 130.647277 bracket=0-1 0 32 \n", - "\n", - " param_module__filter_sizes \n", - "0 [3, 4, 5] \n", - "1 [3, 4, 5] \n", - "2 [3, 4, 5] \n", - "3 [2, 3, 4] \n", - "4 [3, 4, 5] " - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "cv_results = pd.DataFrame(search.cv_results_)\n", "cv_results.head()" @@ -1478,98 +1554,27 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.83816" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "search.score(X_test, y_test)" ] }, { "cell_type": "code", - "execution_count": 63, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Array Chunk
Bytes 200.00 kB 200.00 kB
Shape (25000,) (25000,)
Count 2 Tasks 1 Chunks
Type int64 numpy.ndarray
\n", - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - " \n", - " \n", - " \n", - "\n", - " \n", - " \n", - "\n", - " \n", - " 25000\n", - " 1\n", - "\n", - "
" - ], - "text/plain": [ - "dask.array<_predict, shape=(25000,), dtype=int64, chunksize=(25000,), chunktype=numpy.ndarray>" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "search.predict(X_test)" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0, 1, 1, ..., 0, 0, 0])" - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "search.predict(X_test).compute()" ] @@ -1583,128 +1588,9 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
model_idparamspartial_fit_callspartial_fit_timescorescore_timeelapsed_wall_timebracket
0bracket=0-0{'batch_size': 32, 'module__dropout': 0.109009...1128.6205660.82723.071467358.5270120
1bracket=0-1{'batch_size': 32, 'module__dropout': 0.100094...1124.6650280.83865.234394358.5270180
2bracket=1-0{'batch_size': 64, 'module__dropout': 0.221811...195.6026390.75583.739039460.1802061
3bracket=1-1{'batch_size': 64, 'module__dropout': 0.191881...194.8422560.74964.225537460.1802121
4bracket=1-2{'batch_size': 32, 'module__dropout': 0.118935...1125.7962540.83066.039169460.1802151
\n", - "
" - ], - "text/plain": [ - " model_id params \\\n", - "0 bracket=0-0 {'batch_size': 32, 'module__dropout': 0.109009... \n", - "1 bracket=0-1 {'batch_size': 32, 'module__dropout': 0.100094... \n", - "2 bracket=1-0 {'batch_size': 64, 'module__dropout': 0.221811... \n", - "3 bracket=1-1 {'batch_size': 64, 'module__dropout': 0.191881... \n", - "4 bracket=1-2 {'batch_size': 32, 'module__dropout': 0.118935... \n", - "\n", - " partial_fit_calls partial_fit_time score score_time elapsed_wall_time \\\n", - "0 1 128.620566 0.8272 3.071467 358.527012 \n", - "1 1 124.665028 0.8386 5.234394 358.527018 \n", - "2 1 95.602639 0.7558 3.739039 460.180206 \n", - "3 1 94.842256 0.7496 4.225537 460.180212 \n", - "4 1 125.796254 0.8306 6.039169 460.180215 \n", - "\n", - " bracket \n", - "0 0 \n", - "1 0 \n", - "2 1 \n", - "3 1 \n", - "4 1 " - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "hist = pd.DataFrame(search.history_)\n", "hist.head()" From 1e4ec4ba2547fd66e67dfb08b00eb04deb1b3e5d Mon Sep 17 00:00:00 2001 From: Todd Morrill Date: Mon, 25 May 2020 11:40:49 -0400 Subject: [PATCH 5/6] working through hyperband errors --- machine-learning/skorch-hyperparam-opt.ipynb | 439 ++++++++++++------- 1 file changed, 284 insertions(+), 155 deletions(-) diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb index c06d1443..82544bf9 100644 --- a/machine-learning/skorch-hyperparam-opt.ipynb +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -37,7 +37,7 @@ "\n", "

Client

\n", "\n", "\n", @@ -53,7 +53,7 @@ "" ], "text/plain": [ - "" + "" ] }, "execution_count": 2, @@ -83,15 +83,18 @@ "outputs": [], "source": [ "# for reproducibility\n", - "import random\n", - "import numpy as np\n", + "# NB: enabling reproducibility can significantly slow down runtimes\n", + "reproducible = True\n", + "if reproducible:\n", + " import random\n", + " import numpy as np\n", "\n", - "SEED = 42\n", + " SEED = 42\n", "\n", - "random.seed(SEED)\n", - "np.random.seed(SEED)\n", - "torch.manual_seed(SEED)\n", - "torch.backends.cudnn.deterministic = True" + " random.seed(SEED)\n", + " np.random.seed(SEED)\n", + " torch.manual_seed(SEED)\n", + " torch.backends.cudnn.deterministic = True" ] }, { @@ -138,6 +141,13 @@ "# make splits for data\n", "train, test = datasets.IMDB.splits(TEXT, LABEL)\n", "\n", + "# work with 5k datapoints for faster iteration times\n", + "split_ratio = 5_000 / len(train)\n", + "train, discard = train.split(split_ratio=split_ratio)\n", + "\n", + "split_ratio = 5_000 / len(test)\n", + "test, discard = test.split(split_ratio=split_ratio)\n", + "\n", "# will be used to initialize model embeddings layer\n", "vocab = torchtext.vocab.GloVe(name='6B', dim=100)\n", "\n", @@ -214,7 +224,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.']\n", + "['it', 'aired', 'on', 'tv', 'yesterday,', 'so', 'i', 'decided', 'to', 'check', 'it', 'out.', 'this', 'was', 'one', 'of', 'the', 'last', 'bruce', 'timm/paul', 'dini', 'dtv', 'projects', 'related', 'to', 'their', 'old', '1992', 'batman', 'the', 'animated', 'series,', 'after', 'that', 'jeff', 'matsuda', 'came', 'along', 'and', 're-imagined', 'batman', 'with', 'his', 'new', 'the', 'batman', 'series,', 'but', 'anyway,', 'the', 'story', 'of', 'this', 'new', 'batman', 'movie', 'centers', 'around', 'the', 'appearance', 'of', 'a', 'new', 'vigilante', 'known', 'as', 'batwoman,', 'however', 'batman', 'feels', 'the', 'need', 'to', 'stop', 'her', 'because', 'of', 'her', 'extreme', 'methods,', 'and', 'also', 'in', 'the', 'meantime', 'take', 'down', 'the', 'pengiun', 'and', 'ruphert', 'thorn', 'who', 'both', 'are', 'secretly', 'working', 'with', 'carlton', \"duquesne(who's\", 'having', 'family', 'troubles)', 'and', 'another', 'villain(which', 'is', 'later', 'revealed', 'in', 'the', 'movie)', 'on', 'a', 'weapons', 'smuggling', 'operation,they', 'also', 'put', 'a', 'bounty', 'on', 'the', 'batwoman.', 'the', 'question', 'is:', 'who', 'is', 'this', 'mysterious', 'batwoman', 'and', 'is', 'it', 'possible', 'that', 'they', 'could', 'be', 'more', 'then', 'one?', \"it's\", 'up', 'to', 'batman', 'to', 'solve', 'this', 'mystery', 'and', 'stop', \"penguin's\", 'latest', 'operation.', 'for', 'an', 'animated', 'movie,', 'it', 'has', 'a', 'fairly', 'complex', 'plot', 'and', 'a', 'serious', 'tone,', 'which', 'is', 'good.', 'another', 'plus', 'was', 'the', 'complete', 'redesign', 'of', 'the', 'penguin', 'who', 'looks', 'much', 'more', 'like', 'the', 'sophisticated', 'mob', 'boss', \"we're\", 'used', 'to', 'seeing', 'in', 'the', 'comics,', 'unlike', 'his', 'previous', 'designs', 'that', 'borrowed', 'elements', 'from', 'tim', 'burton', 'vision', 'of', 'pengium(sewer', 'rat', 'and', 'circus', 'freak).', 'even', 'though', 'the', 'movie', 'contains', 'a', 'love', 'subplot', \"it's\", 'never', 'carried', 'that', 'far', 'and', \"doesn't\", 'derail', 'the', 'movie', 'like', 'say,', 'batman', 'forever.', 'the', 'voice', 'acting', 'is', 'standard', 'quality', 'for', 'these', 'direct-to-video', 'projects(if', 'only', 'batman:', 'mask', 'of', 'phantasm', 'took', 'this', 'route),', 'kevin', 'conroy', 'still', 'shines', 'as', 'batman/bruce', 'wayne.', 'and', 'like', 'i', 'said', 'despite', 'running', 'for', 'some', 'very', 'short', '80', 'minutes,', 'it', 'manages', 'to', 'make', 'a', 'pretty', 'good(and', 'complex)', 'storyline', 'complete', 'with', 'a', 'few', 'minor', 'twists', 'and', 'bucket', 'loads', 'of', 'action.', 'there', 'are', 'a', 'few', 'downsides,', 'however,', 'nightwing', 'is', 'nowhere', 'to', 'be', 'seen,', 'and', \"i'm\", 'sure', 'barbara', 'gordon', 'and', 'bruce', 'wayne', \"don't\", 'click', 'as', 'a', 'couple,', 'even', 'though', 'is', 'just', 'referenced,', 'tim', 'drake(aka', 'robin)', 'does', 'very', 'little', 'in', 'the', 'movie', 'and', 'to', 'be', 'quite', 'frank,', 'i', 'was', 'never', 'a', 'big', 'fan', 'of', 'paul', 'dini', 'and', 'bruce', \"timm's\", 'batman', 'character', 'design(especially', 'in', 'their', 'batman', 'shows', 'post-btas),', 'this', 'the', 'new', 'adventures', 'of', 'batman', 'and', 'robin,', 'well,', 'it', 'kinda', 'makes', 'batman', 'look', 'fat', 'then', 'rather', 'a', 'well-built', 'bulked', 'up', 'individual(kinda', 'like', 'the', 'jeff', 'matsuda', 'character', 'model', 'from', 'the', 'batman).', 'bruce', 'wayne', 'seems', 'a', 'bit', 'awkward,', 'those', 'blue', 'eyes', 'make', 'him', 'look', 'more', 'like', 'clark', 'kent', 'then', 'bruce(though', \"it's\", 'true', 'they', 'do', 'look', 'very', 'much', 'alike).', 'another', 'downside', 'is', 'rupert', 'throne(no', 'explanation', 'as', 'to', 'why', 'he', 'is', 'in', 'this', 'deal,', 'but', \"it's\", 'safe', 'to', 'say', \"he's\", 'has', 'goons', 'and', \"what's\", 'a', 'cut', 'of', 'the', 'deal)', 'which', 'does', 'very', 'little', 'more', 'then', 'hang', 'out', 'with', 'the', 'penguim', 'or', 'get', 'himself', 'hurt', 'every', 'time', 'he', 'points', 'a', 'gun', 'at', 'someone(count', 'how', 'many', 'times', 'this', 'happens', 'in', 'the', 'movie', 'and', \"you'll\", 'be', 'surprised.', 'overall,', 'a', 'good', 'batman', 'animated', 'movie,', 'worth', 'at', 'least', 'a', 'rental.']\n", "\n", "pos\n" ] @@ -253,7 +263,7 @@ { "data": { "text/plain": [ - "torch.Size([2, 143])" + "torch.Size([2, 490])" ] }, "execution_count": 12, @@ -324,7 +334,7 @@ { "data": { "text/plain": [ - "'a masterful treatment of james caine\\'s \"the postman always rings twice\" as luchino visconti\\'s first film shot primarily around ferrara in a soulless war-torn italy. the original negative was thought destroyed but visconti saved a print and fortunately we can see this early neo-realist work today. a ruggedly handsome massimo girotti and clara calamai (who had recently revealed her breasts in la cena delle beffe\" (1941), star as the sensually-charged and ill-fated lovers who plot to kill her husband. unusual ending in which, although crime does not pay, one pays in a way not directly linked to the crime. excellent direction, script, acting, and cinematography. reportedly not as good as the french \"le dernier tournant\\' (1939) but probably better than the us version (1946) featuring lana turner and john garfield in the lead roles. highly recommended.'" + "\"it aired on tv yesterday, so i decided to check it out. this was one of the last bruce timm/paul dini dtv projects related to their old 1992 batman the animated series, after that jeff matsuda came along and re-imagined batman with his new the batman series, but anyway, the story of this new batman movie centers around the appearance of a new vigilante known as batwoman, however batman feels the need to stop her because of her extreme methods, and also in the meantime take down the pengiun and ruphert thorn who both are secretly working with carlton duquesne(who's having family troubles) and another villain(which is later revealed in the movie) on a weapons smuggling operation,they also put a bounty on the batwoman. the question is: who is this mysterious batwoman and is it possible that they could be more then one? it's up to batman to solve this mystery and stop penguin's latest operation. for an animated movie, it has a fairly complex plot and a serious tone, which is good. another plus was the complete redesign of the penguin who looks much more like the sophisticated mob boss we're used to seeing in the comics, unlike his previous designs that borrowed elements from tim burton vision of pengium(sewer rat and circus freak). even though the movie contains a love subplot it's never carried that far and doesn't derail the movie like say, batman forever. the voice acting is standard quality for these direct-to-video projects(if only batman: mask of phantasm took this route), kevin conroy still shines as batman/bruce wayne. and like i said despite running for some very short 80 minutes, it manages to make a pretty good(and complex) storyline complete with a few minor twists and bucket loads of action. there are a few downsides, however, nightwing is nowhere to be seen, and i'm sure barbara gordon and bruce wayne don't click as a couple, even though is just referenced, tim drake(aka robin) does very little in the movie and to be quite frank, i was never a big fan of paul dini and bruce timm's batman character design(especially in their batman shows post-btas), this the new adventures of batman and robin, well, it kinda makes batman look fat then rather a well-built bulked up individual(kinda like the jeff matsuda character model from the batman). bruce wayne seems a bit awkward, those blue eyes make him look more like clark kent then bruce(though it's true they do look very much alike). another downside is rupert throne(no explanation as to why he is in this deal, but it's safe to say he's has goons and what's a cut of the deal) which does very little more then hang out with the penguim or get himself hurt every time he points a gun at someone(count how many times this happens in the movie and you'll be surprised. overall, a good batman animated movie, worth at least a rental.\"" ] }, "execution_count": 16, @@ -355,7 +365,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "(['a', 'masterful', 'treatment', 'of', 'james', \"caine's\", '\"the', 'postman', 'always', 'rings', 'twice\"', 'as', 'luchino', \"visconti's\", 'first', 'film', 'shot', 'primarily', 'around', 'ferrara', 'in', 'a', 'soulless', 'war-torn', 'italy.', 'the', 'original', 'negative', 'was', 'thought', 'destroyed', 'but', 'visconti', 'saved', 'a', 'print', 'and', 'fortunately', 'we', 'can', 'see', 'this', 'early', 'neo-realist', 'work', 'today.', 'a', 'ruggedly', 'handsome', 'massimo', 'girotti', 'and', 'clara', 'calamai', '(who', 'had', 'recently', 'revealed', 'her', 'breasts', 'in', 'la', 'cena', 'delle', 'beffe\"', '(1941),', 'star', 'as', 'the', 'sensually-charged', 'and', 'ill-fated', 'lovers', 'who', 'plot', 'to', 'kill', 'her', 'husband.', 'unusual', 'ending', 'in', 'which,', 'although', 'crime', 'does', 'not', 'pay,', 'one', 'pays', 'in', 'a', 'way', 'not', 'directly', 'linked', 'to', 'the', 'crime.', 'excellent', 'direction,', 'script,', 'acting,', 'and', 'cinematography.', 'reportedly', 'not', 'as', 'good', 'as', 'the', 'french', '\"le', 'dernier', \"tournant'\", '(1939)', 'but', 'probably', 'better', 'than', 'the', 'us', 'version', '(1946)', 'featuring', 'lana', 'turner', 'and', 'john', 'garfield', 'in', 'the', 'lead', 'roles.', 'highly', 'recommended.'], 'pos')\n" + "(['it', 'aired', 'on', 'tv', 'yesterday,', 'so', 'i', 'decided', 'to', 'check', 'it', 'out.', 'this', 'was', 'one', 'of', 'the', 'last', 'bruce', 'timm/paul', 'dini', 'dtv', 'projects', 'related', 'to', 'their', 'old', '1992', 'batman', 'the', 'animated', 'series,', 'after', 'that', 'jeff', 'matsuda', 'came', 'along', 'and', 're-imagined', 'batman', 'with', 'his', 'new', 'the', 'batman', 'series,', 'but', 'anyway,', 'the', 'story', 'of', 'this', 'new', 'batman', 'movie', 'centers', 'around', 'the', 'appearance', 'of', 'a', 'new', 'vigilante', 'known', 'as', 'batwoman,', 'however', 'batman', 'feels', 'the', 'need', 'to', 'stop', 'her', 'because', 'of', 'her', 'extreme', 'methods,', 'and', 'also', 'in', 'the', 'meantime', 'take', 'down', 'the', 'pengiun', 'and', 'ruphert', 'thorn', 'who', 'both', 'are', 'secretly', 'working', 'with', 'carlton', \"duquesne(who's\", 'having', 'family', 'troubles)', 'and', 'another', 'villain(which', 'is', 'later', 'revealed', 'in', 'the', 'movie)', 'on', 'a', 'weapons', 'smuggling', 'operation,they', 'also', 'put', 'a', 'bounty', 'on', 'the', 'batwoman.', 'the', 'question', 'is:', 'who', 'is', 'this', 'mysterious', 'batwoman', 'and', 'is', 'it', 'possible', 'that', 'they', 'could', 'be', 'more', 'then', 'one?', \"it's\", 'up', 'to', 'batman', 'to', 'solve', 'this', 'mystery', 'and', 'stop', \"penguin's\", 'latest', 'operation.', 'for', 'an', 'animated', 'movie,', 'it', 'has', 'a', 'fairly', 'complex', 'plot', 'and', 'a', 'serious', 'tone,', 'which', 'is', 'good.', 'another', 'plus', 'was', 'the', 'complete', 'redesign', 'of', 'the', 'penguin', 'who', 'looks', 'much', 'more', 'like', 'the', 'sophisticated', 'mob', 'boss', \"we're\", 'used', 'to', 'seeing', 'in', 'the', 'comics,', 'unlike', 'his', 'previous', 'designs', 'that', 'borrowed', 'elements', 'from', 'tim', 'burton', 'vision', 'of', 'pengium(sewer', 'rat', 'and', 'circus', 'freak).', 'even', 'though', 'the', 'movie', 'contains', 'a', 'love', 'subplot', \"it's\", 'never', 'carried', 'that', 'far', 'and', \"doesn't\", 'derail', 'the', 'movie', 'like', 'say,', 'batman', 'forever.', 'the', 'voice', 'acting', 'is', 'standard', 'quality', 'for', 'these', 'direct-to-video', 'projects(if', 'only', 'batman:', 'mask', 'of', 'phantasm', 'took', 'this', 'route),', 'kevin', 'conroy', 'still', 'shines', 'as', 'batman/bruce', 'wayne.', 'and', 'like', 'i', 'said', 'despite', 'running', 'for', 'some', 'very', 'short', '80', 'minutes,', 'it', 'manages', 'to', 'make', 'a', 'pretty', 'good(and', 'complex)', 'storyline', 'complete', 'with', 'a', 'few', 'minor', 'twists', 'and', 'bucket', 'loads', 'of', 'action.', 'there', 'are', 'a', 'few', 'downsides,', 'however,', 'nightwing', 'is', 'nowhere', 'to', 'be', 'seen,', 'and', \"i'm\", 'sure', 'barbara', 'gordon', 'and', 'bruce', 'wayne', \"don't\", 'click', 'as', 'a', 'couple,', 'even', 'though', 'is', 'just', 'referenced,', 'tim', 'drake(aka', 'robin)', 'does', 'very', 'little', 'in', 'the', 'movie', 'and', 'to', 'be', 'quite', 'frank,', 'i', 'was', 'never', 'a', 'big', 'fan', 'of', 'paul', 'dini', 'and', 'bruce', \"timm's\", 'batman', 'character', 'design(especially', 'in', 'their', 'batman', 'shows', 'post-btas),', 'this', 'the', 'new', 'adventures', 'of', 'batman', 'and', 'robin,', 'well,', 'it', 'kinda', 'makes', 'batman', 'look', 'fat', 'then', 'rather', 'a', 'well-built', 'bulked', 'up', 'individual(kinda', 'like', 'the', 'jeff', 'matsuda', 'character', 'model', 'from', 'the', 'batman).', 'bruce', 'wayne', 'seems', 'a', 'bit', 'awkward,', 'those', 'blue', 'eyes', 'make', 'him', 'look', 'more', 'like', 'clark', 'kent', 'then', 'bruce(though', \"it's\", 'true', 'they', 'do', 'look', 'very', 'much', 'alike).', 'another', 'downside', 'is', 'rupert', 'throne(no', 'explanation', 'as', 'to', 'why', 'he', 'is', 'in', 'this', 'deal,', 'but', \"it's\", 'safe', 'to', 'say', \"he's\", 'has', 'goons', 'and', \"what's\", 'a', 'cut', 'of', 'the', 'deal)', 'which', 'does', 'very', 'little', 'more', 'then', 'hang', 'out', 'with', 'the', 'penguim', 'or', 'get', 'himself', 'hurt', 'every', 'time', 'he', 'points', 'a', 'gun', 'at', 'someone(count', 'how', 'many', 'times', 'this', 'happens', 'in', 'the', 'movie', 'and', \"you'll\", 'be', 'surprised.', 'overall,', 'a', 'good', 'batman', 'animated', 'movie,', 'worth', 'at', 'least', 'a', 'rental.'], 'pos')\n" ] } ], @@ -426,38 +436,38 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.5732, 0.4268],\n", - " [0.5372, 0.4628],\n", - " [0.5615, 0.4385],\n", - " [0.6806, 0.3194],\n", - " [0.6352, 0.3648],\n", - " [0.5678, 0.4322],\n", - " [0.6505, 0.3495],\n", - " [0.4325, 0.5675],\n", - " [0.6019, 0.3981],\n", - " [0.5857, 0.4143],\n", - " [0.6010, 0.3990],\n", - " [0.5662, 0.4338],\n", - " [0.6494, 0.3506],\n", - " [0.4390, 0.5610],\n", - " [0.6041, 0.3959],\n", - " [0.7121, 0.2879],\n", - " [0.5781, 0.4219],\n", - " [0.5727, 0.4273],\n", - " [0.5169, 0.4831],\n", - " [0.6531, 0.3469],\n", - " [0.5080, 0.4920],\n", - " [0.5611, 0.4389],\n", - " [0.5560, 0.4440],\n", - " [0.6448, 0.3552],\n", - " [0.5697, 0.4303],\n", - " [0.5798, 0.4202],\n", - " [0.6656, 0.3344],\n", - " [0.4933, 0.5067],\n", - " [0.5143, 0.4857],\n", - " [0.5518, 0.4482],\n", - " [0.5806, 0.4194],\n", - " [0.6070, 0.3930]], device='cuda:0', grad_fn=)\n" + "tensor([[0.1738, 0.8262],\n", + " [0.3462, 0.6538],\n", + " [0.3317, 0.6683],\n", + " [0.2430, 0.7570],\n", + " [0.3659, 0.6341],\n", + " [0.3846, 0.6154],\n", + " [0.3757, 0.6243],\n", + " [0.3713, 0.6287],\n", + " [0.3153, 0.6847],\n", + " [0.3656, 0.6344],\n", + " [0.4096, 0.5904],\n", + " [0.3088, 0.6912],\n", + " [0.2832, 0.7168],\n", + " [0.3461, 0.6539],\n", + " [0.2674, 0.7326],\n", + " [0.2894, 0.7106],\n", + " [0.3850, 0.6150],\n", + " [0.2820, 0.7180],\n", + " [0.3537, 0.6463],\n", + " [0.2389, 0.7611],\n", + " [0.4709, 0.5291],\n", + " [0.4199, 0.5801],\n", + " [0.4443, 0.5557],\n", + " [0.3591, 0.6409],\n", + " [0.3270, 0.6730],\n", + " [0.3097, 0.6903],\n", + " [0.3241, 0.6759],\n", + " [0.3594, 0.6406],\n", + " [0.3175, 0.6825],\n", + " [0.3447, 0.6553],\n", + " [0.4566, 0.5434],\n", + " [0.2943, 0.7057]], device='cuda:0', grad_fn=)\n" ] } ], @@ -574,8 +584,8 @@ "text": [ " epoch train_loss valid_acc valid_loss dur\n", "------- ------------ ----------- ------------ -------\n", - " 1 \u001b[36m0.4630\u001b[0m \u001b[32m0.8312\u001b[0m \u001b[35m0.3808\u001b[0m 33.8281\n", - " 2 \u001b[36m0.3454\u001b[0m \u001b[32m0.8540\u001b[0m \u001b[35m0.3361\u001b[0m 34.1240\n" + " 1 \u001b[36m0.6295\u001b[0m \u001b[32m0.7840\u001b[0m \u001b[35m0.5172\u001b[0m 12.0888\n", + " 2 \u001b[36m0.4530\u001b[0m \u001b[32m0.8170\u001b[0m \u001b[35m0.4310\u001b[0m 12.4245\n" ] }, { @@ -599,9 +609,6 @@ } ], "source": [ - "# NB: now that we implemented our custom batching we reduced compute time from 60 seconds\n", - "# per epoch to 20 seconds per epoch. That's huge.\n", - "# ((60 - 20) / 60)*100 = ~66%\n", "skorch_model.fit(train_dataset, y=None)" ] }, @@ -652,26 +659,6 @@ "cell_type": "code", "execution_count": 35, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0, 1, 1, ..., 0, 0, 0])" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "test_preds" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, "outputs": [], "source": [ "test_labels = processed_test_data[1].numpy()" @@ -679,7 +666,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -688,16 +675,16 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.85048" + "0.8066" ] }, - "execution_count": 38, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -708,16 +695,16 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(array([0, 1]), array([12500, 12500]))" + "(array([0, 1]), array([2521, 2479]))" ] }, - "execution_count": 39, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -729,7 +716,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -748,7 +735,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -758,7 +745,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -776,16 +763,16 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "['a masterful treatment of james caine\\'s \"the postman always rings twice\" as luchino visconti\\'s first film shot primarily around ferrara in a soulless war-torn italy. the original negative was thought destroyed but visconti saved a print and fortunately we can see this early neo-realist work today. a ruggedly handsome massimo girotti and clara calamai (who had recently revealed her breasts in la cena delle beffe\" (1941), star as the sensually-charged and ill-fated lovers who plot to kill her husband. unusual ending in which, although crime does not pay, one pays in a way not directly linked to the crime. excellent direction, script, acting, and cinematography. reportedly not as good as the french \"le dernier tournant\\' (1939) but probably better than the us version (1946) featuring lana turner and john garfield in the lead roles. highly recommended.']" + "[\"it aired on tv yesterday, so i decided to check it out. this was one of the last bruce timm/paul dini dtv projects related to their old 1992 batman the animated series, after that jeff matsuda came along and re-imagined batman with his new the batman series, but anyway, the story of this new batman movie centers around the appearance of a new vigilante known as batwoman, however batman feels the need to stop her because of her extreme methods, and also in the meantime take down the pengiun and ruphert thorn who both are secretly working with carlton duquesne(who's having family troubles) and another villain(which is later revealed in the movie) on a weapons smuggling operation,they also put a bounty on the batwoman. the question is: who is this mysterious batwoman and is it possible that they could be more then one? it's up to batman to solve this mystery and stop penguin's latest operation. for an animated movie, it has a fairly complex plot and a serious tone, which is good. another plus was the complete redesign of the penguin who looks much more like the sophisticated mob boss we're used to seeing in the comics, unlike his previous designs that borrowed elements from tim burton vision of pengium(sewer rat and circus freak). even though the movie contains a love subplot it's never carried that far and doesn't derail the movie like say, batman forever. the voice acting is standard quality for these direct-to-video projects(if only batman: mask of phantasm took this route), kevin conroy still shines as batman/bruce wayne. and like i said despite running for some very short 80 minutes, it manages to make a pretty good(and complex) storyline complete with a few minor twists and bucket loads of action. there are a few downsides, however, nightwing is nowhere to be seen, and i'm sure barbara gordon and bruce wayne don't click as a couple, even though is just referenced, tim drake(aka robin) does very little in the movie and to be quite frank, i was never a big fan of paul dini and bruce timm's batman character design(especially in their batman shows post-btas), this the new adventures of batman and robin, well, it kinda makes batman look fat then rather a well-built bulked up individual(kinda like the jeff matsuda character model from the batman). bruce wayne seems a bit awkward, those blue eyes make him look more like clark kent then bruce(though it's true they do look very much alike). another downside is rupert throne(no explanation as to why he is in this deal, but it's safe to say he's has goons and what's a cut of the deal) which does very little more then hang out with the penguim or get himself hurt every time he points a gun at someone(count how many times this happens in the movie and you'll be surprised. overall, a good batman animated movie, worth at least a rental.\"]" ] }, - "execution_count": 43, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -796,7 +783,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -805,7 +792,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -814,7 +801,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -823,7 +810,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -832,17 +819,17 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "tensor([[ 3, 0, 12500, ..., 1, 1, 1],\n", - " [ 1669, 3651, 9, ..., 9300, 6517, 411]])" + "tensor([[ 9, 12553, 0, ..., 3, 7166, 369],\n", + " [ 3, 7166, 12553, ..., 1, 1, 1]])" ] }, - "execution_count": 48, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -853,16 +840,16 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "torch.Size([2, 858])" + "torch.Size([2, 2825])" ] }, - "execution_count": 49, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -873,7 +860,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -882,7 +869,7 @@ "True" ] }, - "execution_count": 50, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -893,7 +880,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -902,7 +889,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ @@ -911,7 +898,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -942,7 +929,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ @@ -952,12 +939,12 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "# https://ml.dask.org/hyper-parameter-search.html#hyperband-parameters-rule-of-thumb\n", - "EPOCHS = 5\n", + "EPOCHS = 2\n", "NUM_TRAINING_EXAMPLES = len(train)*.8\n", "n_examples = EPOCHS * NUM_TRAINING_EXAMPLES\n", "n_params = 8\n", @@ -969,7 +956,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -982,7 +969,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ @@ -991,16 +978,16 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Chunk size: 12500.0\n", - "Total chunks: 2\n", - "Last chunk size: 12500.0\n" + "Chunk size: 1000.0\n", + "Total chunks: 5\n", + "Last chunk size: 1000.0\n" ] } ], @@ -1018,7 +1005,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ @@ -1030,7 +1017,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 59, "metadata": {}, "outputs": [ { @@ -1044,10 +1031,10 @@ " Array Chunk \n", " \n", " \n", - " Bytes 1.37 GB 685.20 MB \n", - " Shape (25000, 1) (12500, 1) \n", - " Count 3 Tasks 2 Chunks \n", - " Type numpy.ndarray \n", + " Bytes 207.26 MB 41.45 MB \n", + " Shape (5000, 1) (1000, 1) \n", + " Count 6 Tasks 5 Chunks \n", + " Type numpy.ndarray \n", " \n", "\n", "\n", @@ -1056,7 +1043,10 @@ "\n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", "\n", " \n", @@ -1068,17 +1058,17 @@ "\n", " \n", " 1\n", - " 25000\n", + " 5000\n", "\n", "\n", "\n", "" ], "text/plain": [ - "dask.array" + "dask.array" ] }, - "execution_count": 60, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1089,7 +1079,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -1101,7 +1091,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ @@ -1119,7 +1109,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ @@ -1150,7 +1140,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 63, "metadata": {}, "outputs": [], "source": [ @@ -1159,7 +1149,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ @@ -1173,7 +1163,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ @@ -1182,7 +1172,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -1197,7 +1187,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -1206,7 +1196,7 @@ "26" ] }, - "execution_count": 68, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -1217,7 +1207,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -1226,7 +1216,7 @@ "5" ] }, - "execution_count": 69, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -1237,7 +1227,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 69, "metadata": {}, "outputs": [], "source": [ @@ -1246,7 +1236,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ @@ -1261,7 +1251,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ @@ -1273,28 +1263,34 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 72, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'pos'" - ] - }, - "execution_count": 83, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "y[0].compute()" + "# seems like the validation set is getting preprocessed twice\n", + "# KeyError: tensor([0.])\n", + "\n", + "# but then if you remove the collate_fn from iterator_valid__collate_fn=pad_batch_hyperband_partial\n", + "# then you get the following error\n", + "# TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found [u ... .0721]]),\n", + "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3379: UserWarning: Large object of size 21.54 MB detected in task graph: \n", + " [[u ... .3232]]),\n", "), 0]\n", "Consider scattering large objects ahead of time\n", "with client.scatter to reduce scheduler burden and \n", @@ -1358,8 +1354,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "[CV, bracket=0] For training there are between 10000 and 10000 examples in each chunk\n", - "[CV, bracket=1] For training there are between 10000 and 10000 examples in each chunk\n" + "[CV, bracket=0] For training there are between 800 and 800 examples in each chunk\n", + "[CV, bracket=1] For training there are between 800 and 800 examples in each chunk\n" ] }, { @@ -1400,7 +1396,7 @@ " data = self._dataset_fetcher.fetch(index) # may raise StopIteration\n", " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\", line 47, in fetch\n", " return self.collate_fn(data)\n", - " File \"\", line 7, in pad_batch_hyperband\n", + " File \"\", line 7, in pad_batch_hyperband\n", " label_processed = LABEL.process(label)\n", " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 237, in process\n", " tensor = self.numericalize(padded, device=device)\n", @@ -1418,7 +1414,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 673\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdefault_client\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mif_delegate_has_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"best_estimator_\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"estimator\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", @@ -1443,7 +1439,7 @@ "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m__next__\u001b[0;34m()\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__next__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 345\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 346\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_num_yielded\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_kind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0m_DatasetKind\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mIterable\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m_next_data\u001b[0;34m()\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 385\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_fetcher\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 386\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pin_memory\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\u001b[0m in \u001b[0;36mfetch\u001b[0;34m()\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mpossibly_batched_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcollate_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m\u001b[0m in \u001b[0;36mpad_batch_hyperband\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# numericalized and padded text representation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mtext_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTEXT\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mlabel_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLABEL\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtext_processed\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel_processed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mpad_batch_hyperband\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# numericalized and padded text representation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mtext_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTEXT\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mlabel_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLABEL\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtext_processed\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel_processed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mprocess\u001b[0;34m()\u001b[0m\n\u001b[1;32m 235\u001b[0m \"\"\"\n\u001b[1;32m 236\u001b[0m \u001b[0mpadded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpad\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 237\u001b[0;31m \u001b[0mtensor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumericalize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpadded\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 238\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtensor\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 239\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mnumericalize\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", @@ -1467,10 +1463,143 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# what's going on here?\n", + "# train_label should be text data and then get handled appropriately by pad_batch_hyperband\n", + "# instead, by the time the label makes it into pad_batch_hyperband, it is already a float tensor\n", + "# hence the lookup error. I was expecting a text string like 'pos'" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['pos', 'pos'], dtype='\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Array Chunk
Bytes 24 B 24 B
Shape (2,) (2,)
Count 7 Tasks 1 Chunks
Type numpy.ndarray
\n", + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + " 2\n", + " 1\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "dask.array" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y[:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dtype('\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# why did this take so long and why is the GPU running?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0my\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask/base.py\u001b[0m in \u001b[0;36mcompute\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0mdask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbase\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 165\u001b[0m \"\"\"\n\u001b[0;32m--> 166\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraverse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 167\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 168\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask/base.py\u001b[0m in \u001b[0;36mcompute\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 442\u001b[0m \u001b[0mpostcomputes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__dask_postcompute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 443\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 444\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mschedule\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdsk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 445\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mrepack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpostcomputes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 446\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(self, dsk, keys, restrictions, loose_restrictions, resources, sync, asynchronous, direct, retries, priority, fifo_timeout, actors, **kwargs)\u001b[0m\n\u001b[1;32m 2664\u001b[0m \u001b[0mshould_rejoin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2665\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2666\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpacked\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0masynchronous\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0masynchronous\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdirect\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdirect\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2667\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2668\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfutures\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36mgather\u001b[0;34m(self, futures, errors, direct, asynchronous)\u001b[0m\n\u001b[1;32m 1965\u001b[0m \u001b[0mdirect\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdirect\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1966\u001b[0m \u001b[0mlocal_worker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlocal_worker\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1967\u001b[0;31m \u001b[0masynchronous\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0masynchronous\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1968\u001b[0m )\n\u001b[1;32m 1969\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_set\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 344\u001b[0;31m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_flag\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 551\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 552\u001b[0;31m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cond\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 553\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 554\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 298\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 299\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 300\u001b[0;31m \u001b[0mgotit\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 301\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 302\u001b[0m \u001b[0mgotit\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "# why isn't this responding and why is the GPU running?\n", + "y[:2].compute()" + ] }, { "cell_type": "markdown", From 236381fe8416711f2264bbd56f97aa88996befd3 Mon Sep 17 00:00:00 2001 From: ToddMorrill Date: Sat, 27 Jun 2020 16:58:48 +0000 Subject: [PATCH 6/6] working example --- machine-learning/skorch-hyperparam-opt.ipynb | 1613 +++++++++--------- 1 file changed, 807 insertions(+), 806 deletions(-) diff --git a/machine-learning/skorch-hyperparam-opt.ipynb b/machine-learning/skorch-hyperparam-opt.ipynb index 82544bf9..d551c689 100644 --- a/machine-learning/skorch-hyperparam-opt.ipynb +++ b/machine-learning/skorch-hyperparam-opt.ipynb @@ -6,8 +6,8 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -q dask_cuda torch torchtext skorch\n", - "!pip -q install dask[dataframe] --upgrade" + "# !pip install -q dask_cuda torch torchtext skorch\n", + "# !pip -q install dask[dataframe] --upgrade" ] }, { @@ -21,13 +21,45 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Dask" + "## Setup Dask Cluster" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "import random\n", + "import time\n", + "\n", + "import dask.array as da\n", + "from dask_cuda import LocalCUDACluster\n", + "from dask_ml.model_selection import HyperbandSearchCV\n", + "from distributed import Client\n", + "import numpy as np\n", + "import pandas as pd\n", + "from scipy.stats import loguniform\n", + "from sklearn.metrics import accuracy_score\n", + "from sklearn.model_selection import RandomizedSearchCV\n", + "import skorch\n", + "from skorch import NeuralNetClassifier\n", + "from skorch.helper import SliceDataset\n", + "import torch\n", + "import torch.nn as nn\n", + "import torch.nn.functional as F\n", + "import torch.optim as optim\n", + "from torch.utils.data import Dataset, DataLoader\n", + "import torchtext\n", + "from torchtext import data\n", + "from torchtext import datasets" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "data": { @@ -37,7 +69,7 @@ "\n", "

Client

\n", "\n", "\n", @@ -46,26 +78,22 @@ "
    \n", "
  • Workers: 1
  • \n", "
  • Cores: 1
  • \n", - "
  • Memory: 33.68 GB
  • \n", + "
  • Memory: 31.63 GB
  • \n", "
\n", "\n", "\n", "" ], "text/plain": [ - "" + "" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import torch\n", - "from dask_cuda import LocalCUDACluster\n", - "from distributed import Client\n", - "\n", "# if you have GPU(s), use dask_cuda to automatically make use of them in your dask cluster\n", "if torch.cuda.is_available():\n", " cluster = LocalCUDACluster()\n", @@ -78,19 +106,15 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# for reproducibility\n", "# NB: enabling reproducibility can significantly slow down runtimes\n", - "reproducible = True\n", + "reproducible = False\n", "if reproducible:\n", - " import random\n", - " import numpy as np\n", - "\n", " SEED = 42\n", - "\n", " random.seed(SEED)\n", " np.random.seed(SEED)\n", " torch.manual_seed(SEED)\n", @@ -106,36 +130,35 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "import torchtext\n", - "from torchtext import data\n", - "from torchtext import datasets\n", - "from torch.utils.data import Dataset, DataLoader\n", - "from torch.nn.utils.rnn import pad_sequence" + "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" + "# this solves many of our later problems but isn't an ideal solution\n", + "# accuracy will take a hit\n", + "FIX_LENGTH = 512" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# takes approx. 10 minutes to download data and embeddings (will be cached for re-use)\n", + "# a few seconds to download IMDB dataset (84Mb, will be cached)\n", + "# approx. 10 minutes to download glove embeddings (862Mb, will be cached)\n", "\n", "# set up fields\n", - "TEXT = data.Field(lower=True, batch_first=True, )\n", + "TEXT = data.Field(lower=True, batch_first=True, fix_length=FIX_LENGTH)\n", "LABEL = data.Field(sequential=False, unk_token=None)\n", "\n", "# make splits for data\n", @@ -154,26 +177,21 @@ "# build the vocabulary\n", "max_size = 25_000 # shorten for demonstrative purposes\n", "TEXT.build_vocab(train, vectors=vocab, max_size=max_size)\n", - "LABEL.build_vocab(train)\n", - "\n", - "# sadly I don't think we can use this \n", - "# make iterator for splits\n", - "# train_iter, test_iter = data.BucketIterator.splits(\n", - "# (train, test), batch_sizes=(32, 64), device='cpu')" + "LABEL.build_vocab(train)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "['', '', 'the', 'a', 'and']" + "['', '', 'the', 'and', 'a']" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -186,16 +204,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "defaultdict(None, {'neg': 0, 'pos': 1})" + "defaultdict(None, {'pos': 0, 'neg': 1})" ] }, - "execution_count": 8, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -208,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -217,14 +235,14 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['it', 'aired', 'on', 'tv', 'yesterday,', 'so', 'i', 'decided', 'to', 'check', 'it', 'out.', 'this', 'was', 'one', 'of', 'the', 'last', 'bruce', 'timm/paul', 'dini', 'dtv', 'projects', 'related', 'to', 'their', 'old', '1992', 'batman', 'the', 'animated', 'series,', 'after', 'that', 'jeff', 'matsuda', 'came', 'along', 'and', 're-imagined', 'batman', 'with', 'his', 'new', 'the', 'batman', 'series,', 'but', 'anyway,', 'the', 'story', 'of', 'this', 'new', 'batman', 'movie', 'centers', 'around', 'the', 'appearance', 'of', 'a', 'new', 'vigilante', 'known', 'as', 'batwoman,', 'however', 'batman', 'feels', 'the', 'need', 'to', 'stop', 'her', 'because', 'of', 'her', 'extreme', 'methods,', 'and', 'also', 'in', 'the', 'meantime', 'take', 'down', 'the', 'pengiun', 'and', 'ruphert', 'thorn', 'who', 'both', 'are', 'secretly', 'working', 'with', 'carlton', \"duquesne(who's\", 'having', 'family', 'troubles)', 'and', 'another', 'villain(which', 'is', 'later', 'revealed', 'in', 'the', 'movie)', 'on', 'a', 'weapons', 'smuggling', 'operation,they', 'also', 'put', 'a', 'bounty', 'on', 'the', 'batwoman.', 'the', 'question', 'is:', 'who', 'is', 'this', 'mysterious', 'batwoman', 'and', 'is', 'it', 'possible', 'that', 'they', 'could', 'be', 'more', 'then', 'one?', \"it's\", 'up', 'to', 'batman', 'to', 'solve', 'this', 'mystery', 'and', 'stop', \"penguin's\", 'latest', 'operation.', 'for', 'an', 'animated', 'movie,', 'it', 'has', 'a', 'fairly', 'complex', 'plot', 'and', 'a', 'serious', 'tone,', 'which', 'is', 'good.', 'another', 'plus', 'was', 'the', 'complete', 'redesign', 'of', 'the', 'penguin', 'who', 'looks', 'much', 'more', 'like', 'the', 'sophisticated', 'mob', 'boss', \"we're\", 'used', 'to', 'seeing', 'in', 'the', 'comics,', 'unlike', 'his', 'previous', 'designs', 'that', 'borrowed', 'elements', 'from', 'tim', 'burton', 'vision', 'of', 'pengium(sewer', 'rat', 'and', 'circus', 'freak).', 'even', 'though', 'the', 'movie', 'contains', 'a', 'love', 'subplot', \"it's\", 'never', 'carried', 'that', 'far', 'and', \"doesn't\", 'derail', 'the', 'movie', 'like', 'say,', 'batman', 'forever.', 'the', 'voice', 'acting', 'is', 'standard', 'quality', 'for', 'these', 'direct-to-video', 'projects(if', 'only', 'batman:', 'mask', 'of', 'phantasm', 'took', 'this', 'route),', 'kevin', 'conroy', 'still', 'shines', 'as', 'batman/bruce', 'wayne.', 'and', 'like', 'i', 'said', 'despite', 'running', 'for', 'some', 'very', 'short', '80', 'minutes,', 'it', 'manages', 'to', 'make', 'a', 'pretty', 'good(and', 'complex)', 'storyline', 'complete', 'with', 'a', 'few', 'minor', 'twists', 'and', 'bucket', 'loads', 'of', 'action.', 'there', 'are', 'a', 'few', 'downsides,', 'however,', 'nightwing', 'is', 'nowhere', 'to', 'be', 'seen,', 'and', \"i'm\", 'sure', 'barbara', 'gordon', 'and', 'bruce', 'wayne', \"don't\", 'click', 'as', 'a', 'couple,', 'even', 'though', 'is', 'just', 'referenced,', 'tim', 'drake(aka', 'robin)', 'does', 'very', 'little', 'in', 'the', 'movie', 'and', 'to', 'be', 'quite', 'frank,', 'i', 'was', 'never', 'a', 'big', 'fan', 'of', 'paul', 'dini', 'and', 'bruce', \"timm's\", 'batman', 'character', 'design(especially', 'in', 'their', 'batman', 'shows', 'post-btas),', 'this', 'the', 'new', 'adventures', 'of', 'batman', 'and', 'robin,', 'well,', 'it', 'kinda', 'makes', 'batman', 'look', 'fat', 'then', 'rather', 'a', 'well-built', 'bulked', 'up', 'individual(kinda', 'like', 'the', 'jeff', 'matsuda', 'character', 'model', 'from', 'the', 'batman).', 'bruce', 'wayne', 'seems', 'a', 'bit', 'awkward,', 'those', 'blue', 'eyes', 'make', 'him', 'look', 'more', 'like', 'clark', 'kent', 'then', 'bruce(though', \"it's\", 'true', 'they', 'do', 'look', 'very', 'much', 'alike).', 'another', 'downside', 'is', 'rupert', 'throne(no', 'explanation', 'as', 'to', 'why', 'he', 'is', 'in', 'this', 'deal,', 'but', \"it's\", 'safe', 'to', 'say', \"he's\", 'has', 'goons', 'and', \"what's\", 'a', 'cut', 'of', 'the', 'deal)', 'which', 'does', 'very', 'little', 'more', 'then', 'hang', 'out', 'with', 'the', 'penguim', 'or', 'get', 'himself', 'hurt', 'every', 'time', 'he', 'points', 'a', 'gun', 'at', 'someone(count', 'how', 'many', 'times', 'this', 'happens', 'in', 'the', 'movie', 'and', \"you'll\", 'be', 'surprised.', 'overall,', 'a', 'good', 'batman', 'animated', 'movie,', 'worth', 'at', 'least', 'a', 'rental.']\n", + "['i', \"couldn't\", 'hold', 'back', 'the', 'tears', 'when', 'i', 'watched', 'this'] ...\n", "\n", "pos\n" ] @@ -232,53 +250,15 @@ ], "source": [ "# peek at the data\n", - "print(train.examples[0].text)\n", + "print(train.examples[0].text[:10], '...')\n", "print()\n", "print(train.examples[0].label)" ] }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "# if you could use data.BucketIterator.splits\n", - "\n", - "# sadly train_iter isn't actually an iter..\n", - "# peek at a batch of data\n", - "# batch = next(iter(train_iter))\n", - "\n", - "# numericalized tokens\n", - "# print(batch.text)\n", - "\n", - "# print(batch.label)" - ] - }, { "cell_type": "code", "execution_count": 12, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "torch.Size([2, 490])" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "TEXT.process([train[0].text, train[1].text]).shape" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, "outputs": [], "source": [ "# custom dataset class required to work with Skorch\n", @@ -296,89 +276,51 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "# # custom dataset class required to work with Skorch\n", - "# class TorchDataset(torch.utils.data.Dataset):\n", - "# def __init__(self, dataset, TEXT, LABEL):\n", - "# self.dataset = dataset\n", - "# self.TEXT = TEXT\n", - "# self.LABEL = LABEL\n", - " \n", - "# def __getitem__(self, idx):\n", - "# example = self.dataset.examples[idx]\n", - "# X = TEXT.numericalize([example.text]).squeeze() # get rid of \"batch\" dimension\n", - "# y = LABEL.numericalize([example.label])\n", - "# return X, y\n", - " \n", - "# def __len__(self):\n", - "# return len(self.dataset)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "ex = train.examples[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\"it aired on tv yesterday, so i decided to check it out. this was one of the last bruce timm/paul dini dtv projects related to their old 1992 batman the animated series, after that jeff matsuda came along and re-imagined batman with his new the batman series, but anyway, the story of this new batman movie centers around the appearance of a new vigilante known as batwoman, however batman feels the need to stop her because of her extreme methods, and also in the meantime take down the pengiun and ruphert thorn who both are secretly working with carlton duquesne(who's having family troubles) and another villain(which is later revealed in the movie) on a weapons smuggling operation,they also put a bounty on the batwoman. the question is: who is this mysterious batwoman and is it possible that they could be more then one? it's up to batman to solve this mystery and stop penguin's latest operation. for an animated movie, it has a fairly complex plot and a serious tone, which is good. another plus was the complete redesign of the penguin who looks much more like the sophisticated mob boss we're used to seeing in the comics, unlike his previous designs that borrowed elements from tim burton vision of pengium(sewer rat and circus freak). even though the movie contains a love subplot it's never carried that far and doesn't derail the movie like say, batman forever. the voice acting is standard quality for these direct-to-video projects(if only batman: mask of phantasm took this route), kevin conroy still shines as batman/bruce wayne. and like i said despite running for some very short 80 minutes, it manages to make a pretty good(and complex) storyline complete with a few minor twists and bucket loads of action. there are a few downsides, however, nightwing is nowhere to be seen, and i'm sure barbara gordon and bruce wayne don't click as a couple, even though is just referenced, tim drake(aka robin) does very little in the movie and to be quite frank, i was never a big fan of paul dini and bruce timm's batman character design(especially in their batman shows post-btas), this the new adventures of batman and robin, well, it kinda makes batman look fat then rather a well-built bulked up individual(kinda like the jeff matsuda character model from the batman). bruce wayne seems a bit awkward, those blue eyes make him look more like clark kent then bruce(though it's true they do look very much alike). another downside is rupert throne(no explanation as to why he is in this deal, but it's safe to say he's has goons and what's a cut of the deal) which does very little more then hang out with the penguim or get himself hurt every time he points a gun at someone(count how many times this happens in the movie and you'll be surprised. overall, a good batman animated movie, worth at least a rental.\"" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "' '.join(ex.text)" + "train_dataset = TorchDataset(train)\n", + "test_dataset = TorchDataset(test)" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "train_dataset = TorchDataset(train)\n", - "test_dataset = TorchDataset(test)" + "tokens, label = train_dataset[0]" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "(['it', 'aired', 'on', 'tv', 'yesterday,', 'so', 'i', 'decided', 'to', 'check', 'it', 'out.', 'this', 'was', 'one', 'of', 'the', 'last', 'bruce', 'timm/paul', 'dini', 'dtv', 'projects', 'related', 'to', 'their', 'old', '1992', 'batman', 'the', 'animated', 'series,', 'after', 'that', 'jeff', 'matsuda', 'came', 'along', 'and', 're-imagined', 'batman', 'with', 'his', 'new', 'the', 'batman', 'series,', 'but', 'anyway,', 'the', 'story', 'of', 'this', 'new', 'batman', 'movie', 'centers', 'around', 'the', 'appearance', 'of', 'a', 'new', 'vigilante', 'known', 'as', 'batwoman,', 'however', 'batman', 'feels', 'the', 'need', 'to', 'stop', 'her', 'because', 'of', 'her', 'extreme', 'methods,', 'and', 'also', 'in', 'the', 'meantime', 'take', 'down', 'the', 'pengiun', 'and', 'ruphert', 'thorn', 'who', 'both', 'are', 'secretly', 'working', 'with', 'carlton', \"duquesne(who's\", 'having', 'family', 'troubles)', 'and', 'another', 'villain(which', 'is', 'later', 'revealed', 'in', 'the', 'movie)', 'on', 'a', 'weapons', 'smuggling', 'operation,they', 'also', 'put', 'a', 'bounty', 'on', 'the', 'batwoman.', 'the', 'question', 'is:', 'who', 'is', 'this', 'mysterious', 'batwoman', 'and', 'is', 'it', 'possible', 'that', 'they', 'could', 'be', 'more', 'then', 'one?', \"it's\", 'up', 'to', 'batman', 'to', 'solve', 'this', 'mystery', 'and', 'stop', \"penguin's\", 'latest', 'operation.', 'for', 'an', 'animated', 'movie,', 'it', 'has', 'a', 'fairly', 'complex', 'plot', 'and', 'a', 'serious', 'tone,', 'which', 'is', 'good.', 'another', 'plus', 'was', 'the', 'complete', 'redesign', 'of', 'the', 'penguin', 'who', 'looks', 'much', 'more', 'like', 'the', 'sophisticated', 'mob', 'boss', \"we're\", 'used', 'to', 'seeing', 'in', 'the', 'comics,', 'unlike', 'his', 'previous', 'designs', 'that', 'borrowed', 'elements', 'from', 'tim', 'burton', 'vision', 'of', 'pengium(sewer', 'rat', 'and', 'circus', 'freak).', 'even', 'though', 'the', 'movie', 'contains', 'a', 'love', 'subplot', \"it's\", 'never', 'carried', 'that', 'far', 'and', \"doesn't\", 'derail', 'the', 'movie', 'like', 'say,', 'batman', 'forever.', 'the', 'voice', 'acting', 'is', 'standard', 'quality', 'for', 'these', 'direct-to-video', 'projects(if', 'only', 'batman:', 'mask', 'of', 'phantasm', 'took', 'this', 'route),', 'kevin', 'conroy', 'still', 'shines', 'as', 'batman/bruce', 'wayne.', 'and', 'like', 'i', 'said', 'despite', 'running', 'for', 'some', 'very', 'short', '80', 'minutes,', 'it', 'manages', 'to', 'make', 'a', 'pretty', 'good(and', 'complex)', 'storyline', 'complete', 'with', 'a', 'few', 'minor', 'twists', 'and', 'bucket', 'loads', 'of', 'action.', 'there', 'are', 'a', 'few', 'downsides,', 'however,', 'nightwing', 'is', 'nowhere', 'to', 'be', 'seen,', 'and', \"i'm\", 'sure', 'barbara', 'gordon', 'and', 'bruce', 'wayne', \"don't\", 'click', 'as', 'a', 'couple,', 'even', 'though', 'is', 'just', 'referenced,', 'tim', 'drake(aka', 'robin)', 'does', 'very', 'little', 'in', 'the', 'movie', 'and', 'to', 'be', 'quite', 'frank,', 'i', 'was', 'never', 'a', 'big', 'fan', 'of', 'paul', 'dini', 'and', 'bruce', \"timm's\", 'batman', 'character', 'design(especially', 'in', 'their', 'batman', 'shows', 'post-btas),', 'this', 'the', 'new', 'adventures', 'of', 'batman', 'and', 'robin,', 'well,', 'it', 'kinda', 'makes', 'batman', 'look', 'fat', 'then', 'rather', 'a', 'well-built', 'bulked', 'up', 'individual(kinda', 'like', 'the', 'jeff', 'matsuda', 'character', 'model', 'from', 'the', 'batman).', 'bruce', 'wayne', 'seems', 'a', 'bit', 'awkward,', 'those', 'blue', 'eyes', 'make', 'him', 'look', 'more', 'like', 'clark', 'kent', 'then', 'bruce(though', \"it's\", 'true', 'they', 'do', 'look', 'very', 'much', 'alike).', 'another', 'downside', 'is', 'rupert', 'throne(no', 'explanation', 'as', 'to', 'why', 'he', 'is', 'in', 'this', 'deal,', 'but', \"it's\", 'safe', 'to', 'say', \"he's\", 'has', 'goons', 'and', \"what's\", 'a', 'cut', 'of', 'the', 'deal)', 'which', 'does', 'very', 'little', 'more', 'then', 'hang', 'out', 'with', 'the', 'penguim', 'or', 'get', 'himself', 'hurt', 'every', 'time', 'he', 'points', 'a', 'gun', 'at', 'someone(count', 'how', 'many', 'times', 'this', 'happens', 'in', 'the', 'movie', 'and', \"you'll\", 'be', 'surprised.', 'overall,', 'a', 'good', 'batman', 'animated', 'movie,', 'worth', 'at', 'least', 'a', 'rental.'], 'pos')\n" + "['i', \"couldn't\", 'hold', 'back', 'the', 'tears', 'when', 'i', 'watched', 'this'] ...\n", + "\n", + "pos\n" ] } ], "source": [ - "print(train_dataset[0])" + "print(tokens[:10], '...')\n", + "print()\n", + "print(label)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ + "# custom collate function for DataLoader\n", "def pad_batch(batch, TEXT, LABEL):\n", " text, label = list(zip(*batch))\n", " # numericalized and padded text representation\n", @@ -393,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -402,13 +344,43 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "batch = next(iter(train_dataloader))" ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "processed_examples, labels = batch" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([ 9, 20, 7, 3765, 23, 8, 54, 692, 2, 2384]) ...\n", + "\n", + "tensor(1)\n" + ] + } + ], + "source": [ + "print(processed_examples[0][:10], '...')\n", + "print()\n", + "print(labels[0])" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -418,56 +390,56 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ - "# was having trouble with when model was defined in the notebook\n", - "# Can't get attribute ‘CNN' on : attribute lookup CNN on __main__ failed\n", "from model import CNN" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.1738, 0.8262],\n", - " [0.3462, 0.6538],\n", - " [0.3317, 0.6683],\n", - " [0.2430, 0.7570],\n", - " [0.3659, 0.6341],\n", - " [0.3846, 0.6154],\n", - " [0.3757, 0.6243],\n", - " [0.3713, 0.6287],\n", - " [0.3153, 0.6847],\n", - " [0.3656, 0.6344],\n", - " [0.4096, 0.5904],\n", - " [0.3088, 0.6912],\n", - " [0.2832, 0.7168],\n", - " [0.3461, 0.6539],\n", - " [0.2674, 0.7326],\n", - " [0.2894, 0.7106],\n", - " [0.3850, 0.6150],\n", - " [0.2820, 0.7180],\n", - " [0.3537, 0.6463],\n", - " [0.2389, 0.7611],\n", - " [0.4709, 0.5291],\n", - " [0.4199, 0.5801],\n", - " [0.4443, 0.5557],\n", - " [0.3591, 0.6409],\n", - " [0.3270, 0.6730],\n", - " [0.3097, 0.6903],\n", - " [0.3241, 0.6759],\n", - " [0.3594, 0.6406],\n", - " [0.3175, 0.6825],\n", - " [0.3447, 0.6553],\n", - " [0.4566, 0.5434],\n", - " [0.2943, 0.7057]], device='cuda:0', grad_fn=)\n" + "tensor([[0.5000, 0.5000],\n", + " [0.5174, 0.4826],\n", + " [0.4599, 0.5401],\n", + " [0.3472, 0.6528],\n", + " [0.3888, 0.6112],\n", + " [0.4259, 0.5741],\n", + " [0.3734, 0.6266],\n", + " [0.3527, 0.6473],\n", + " [0.4275, 0.5725],\n", + " [0.4277, 0.5723],\n", + " [0.5281, 0.4719],\n", + " [0.4183, 0.5817],\n", + " [0.4409, 0.5591],\n", + " [0.4205, 0.5795],\n", + " [0.4820, 0.5180],\n", + " [0.3552, 0.6448],\n", + " [0.3843, 0.6157],\n", + " [0.3047, 0.6953],\n", + " [0.5312, 0.4688],\n", + " [0.4069, 0.5931],\n", + " [0.3691, 0.6309],\n", + " [0.3541, 0.6459],\n", + " [0.2763, 0.7237],\n", + " [0.4770, 0.5230],\n", + " [0.3749, 0.6251],\n", + " [0.4165, 0.5835],\n", + " [0.4208, 0.5792],\n", + " [0.5268, 0.4732],\n", + " [0.4046, 0.5954],\n", + " [0.5047, 0.4953],\n", + " [0.3795, 0.6205],\n", + " [0.4030, 0.5970]], device='cuda:0', grad_fn=)\n" ] } ], @@ -481,7 +453,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -490,7 +462,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -499,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -510,32 +482,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Quick attempt at model training" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], - "source": [ - "import skorch\n", - "from skorch import NeuralNetClassifier \n", - "import torch.optim as optim" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [], - "source": [ - "import torch.nn as nn" + "## Quick attempt at model training to debug any issues" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -575,17 +527,17 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " epoch train_loss valid_acc valid_loss dur\n", - "------- ------------ ----------- ------------ -------\n", - " 1 \u001b[36m0.6295\u001b[0m \u001b[32m0.7840\u001b[0m \u001b[35m0.5172\u001b[0m 12.0888\n", - " 2 \u001b[36m0.4530\u001b[0m \u001b[32m0.8170\u001b[0m \u001b[35m0.4310\u001b[0m 12.4245\n" + " epoch train_loss valid_acc valid_loss dur\n", + "------- ------------ ----------- ------------ ------\n", + " 1 \u001b[36m0.6258\u001b[0m \u001b[32m0.7930\u001b[0m \u001b[35m0.5002\u001b[0m 2.0929\n", + " 2 \u001b[36m0.4405\u001b[0m \u001b[32m0.8250\u001b[0m \u001b[35m0.3986\u001b[0m 1.9010\n" ] }, { @@ -603,7 +555,7 @@ ")" ] }, - "execution_count": 30, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -614,20 +566,31 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ - "# this isn't working as expected\n", + "# https://github.com/skorch-dev/skorch/issues/641\n", + "\n", "# skorch_model.score(test_dataset)\n", "# TypeError: score() missing 1 required positional argument: 'y'\n", "# skorch_model.score(test_dataset, y=None)\n", - "# ValueError: Expected array-like (array or non-string sequence), got None" + "# ValueError: Expected array-like (array or non-string sequence), got None\n", + "\n", + "# can monkey patch skorch_model to achieve native scoring\n", + "# def score(self, X, y=None): \n", + "# ds = self.get_dataset(X) \n", + "# target_iterator = self.get_iterator(ds, training=False) \n", + " \n", + "# y_true = np.concatenate([skorch.utils.to_numpy(y) for _, y in target_iterator]) \n", + "# y_pred = self.predict(X)\n", + " \n", + "# return accuracy_score(y_true, y_pred) " ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -637,317 +600,217 @@ }, { "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "# sadly processing the entire test set twice just to score the model\n", - "processed_test_data = next(iter(test_dataloader))" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "# quick check on the test set accuracy\n", - "test_preds = skorch_model.predict(test_dataset)" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], - "source": [ - "test_labels = processed_test_data[1].numpy()" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "from sklearn.metrics import accuracy_score" - ] - }, - { - "cell_type": "code", - "execution_count": 37, + "execution_count": 30, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "0.8066" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "0.8006\n" + ] } ], "source": [ - "accuracy_score(test_labels, test_preds)" + "# test set accuracy\n", + "test_preds = skorch_model.predict(test_dataset)\n", + "processed_test_data = next(iter(test_dataloader))\n", + "test_labels = processed_test_data[1].numpy()\n", + "print(accuracy_score(test_labels, test_preds))" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(array([0, 1]), array([2521, 2479]))" + "(array([0, 1]), array([2554, 2446]))" ] }, - "execution_count": 38, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# random guessing would 50% accuracy so the model is indeed training\n", + "# random guessing would 50% accuracy so the model is indeed training well\n", "np.unique(test_labels, return_counts=True)" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "# NB: this has no effect on GPU memory usage. If I keyboard interrupt, the workers get\n", "# restarted and memory usage goes down. Deleting these \"handler\" objects doesn't delete\n", "# GPU memory references on the workers. \n", - "del skorch_model" + "# del skorch_model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Grid search with Hyperband" + "### Grid search with Skorch" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "# try to store the raw text in dask arrays and handle preprocessing inside the network\n", - "# this isn't ideal because feature engineering really should be separate from modeling" + "# define parameter grid\n", + "params = {'module__filter_sizes': [(1, 2, 3), (2, 3, 4), (3, 4, 5)], \n", + " 'module__n_filters': [25, 50, 100],\n", + " 'module__dropout': loguniform(1e-1, 3e-1),\n", + " 'batch_size': [32, 64],\n", + " }\n", + "\n", + "skorch_search = RandomizedSearchCV(skorch_model, params, n_iter=2, cv=5)" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ - "# raw text\n", - "train_text = []\n", - "train_label = []\n", - "for e in train.examples:\n", - " tokenized_text = e.text\n", - " text_string = ' '.join(tokenized_text)\n", - " train_text.append(text_string)\n", - " label = e.label\n", - " # label = LABEL.process([e.label]).numpy()\n", - " train_label.append(label)" + "# This errors out with: TypeError: fit() missing 1 required positional argument: 'y'\n", + "# skorch_search.fit(train_dataset, y=None)" ] }, { "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[\"it aired on tv yesterday, so i decided to check it out. this was one of the last bruce timm/paul dini dtv projects related to their old 1992 batman the animated series, after that jeff matsuda came along and re-imagined batman with his new the batman series, but anyway, the story of this new batman movie centers around the appearance of a new vigilante known as batwoman, however batman feels the need to stop her because of her extreme methods, and also in the meantime take down the pengiun and ruphert thorn who both are secretly working with carlton duquesne(who's having family troubles) and another villain(which is later revealed in the movie) on a weapons smuggling operation,they also put a bounty on the batwoman. the question is: who is this mysterious batwoman and is it possible that they could be more then one? it's up to batman to solve this mystery and stop penguin's latest operation. for an animated movie, it has a fairly complex plot and a serious tone, which is good. another plus was the complete redesign of the penguin who looks much more like the sophisticated mob boss we're used to seeing in the comics, unlike his previous designs that borrowed elements from tim burton vision of pengium(sewer rat and circus freak). even though the movie contains a love subplot it's never carried that far and doesn't derail the movie like say, batman forever. the voice acting is standard quality for these direct-to-video projects(if only batman: mask of phantasm took this route), kevin conroy still shines as batman/bruce wayne. and like i said despite running for some very short 80 minutes, it manages to make a pretty good(and complex) storyline complete with a few minor twists and bucket loads of action. there are a few downsides, however, nightwing is nowhere to be seen, and i'm sure barbara gordon and bruce wayne don't click as a couple, even though is just referenced, tim drake(aka robin) does very little in the movie and to be quite frank, i was never a big fan of paul dini and bruce timm's batman character design(especially in their batman shows post-btas), this the new adventures of batman and robin, well, it kinda makes batman look fat then rather a well-built bulked up individual(kinda like the jeff matsuda character model from the batman). bruce wayne seems a bit awkward, those blue eyes make him look more like clark kent then bruce(though it's true they do look very much alike). another downside is rupert throne(no explanation as to why he is in this deal, but it's safe to say he's has goons and what's a cut of the deal) which does very little more then hang out with the penguim or get himself hurt every time he points a gun at someone(count how many times this happens in the movie and you'll be surprised. overall, a good batman animated movie, worth at least a rental.\"]" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "train_text[:1]" - ] - }, - { - "cell_type": "code", - "execution_count": 43, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ - "train_text = np.array(train_text)" + "# https://github.com/skorch-dev/skorch/issues/605#issuecomment-650580286" ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "train_text = np.expand_dims(train_text, axis=-1)" + "# ValueError: Dataset does not have consistent lengths.\n", + "# dummy_y = np.zeros((len(train_dataset)))\n", + "# skorch_search.fit(train_dataset, y=dummy_y)" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ - "sample_batch = [train_text[0], train_text[10]]" + "# ValueError: Dataset does not have consistent lengths.\n", + "# y = torch.cat([LABEL.process([pair[1]]) for pair in train_dataset]).numpy()\n", + "# skorch_search.fit(train_dataset, y=y)" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ - "sample_text_batch = [i[0] for i in sample_batch]" + "# ValueError: Dataset does not have consistent lengths.\n", + "# skorch_search.fit(train_dataset, y=SliceDataset(train_dataset, idx=1))" ] }, { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[ 9, 12553, 0, ..., 3, 7166, 369],\n", - " [ 3, 7166, 12553, ..., 1, 1, 1]])" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "TEXT.process(sample_text_batch)" - ] - }, - { - "cell_type": "code", - "execution_count": 48, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "torch.Size([2, 2825])" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "TEXT.process([train_text[0][0], train_text[1][0]]).shape" + "## Grid search with Hyperband" ] }, { - "cell_type": "code", - "execution_count": 49, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "isinstance(train_text[:10], np.ndarray)" + "This is a really unfortunate hack to make deep learning batching semantics work with `Skorch` and `Dask`. The downside here is that we're no longer padding to the longest sequence in the batch, rather we're padding to the longest sequence in the *dataset*, which results in signifcantly more computation and thus significantly more time to train a model.\n", + "\n", + "Our solution was to set a max sequence length but that's not an ideal solution since you're still performing extra computation and accuracy does suffer." ] }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "# TEXT.process(train_text[0])" + "# train=True shuffles the data\n", + "train_iter_skorch = torchtext.data.Iterator(train, batch_size=len(train), train=True, sort=False, device='cpu')\n", + "test_iter_skorch = torchtext.data.Iterator(test, batch_size=len(test), train=False, sort=False, device='cpu')" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ - "train_label = np.array(train_label)" + "# takes some time to numericalize the whole dataset\n", + "\n", + "# also notice that skorch and dask expect numpy arrays, which isn't ideal since it ties you to the cpu.\n", + "# meanwhile, projects like https://rapids.ai/ are moving toward all GPU computation, avoiding the cpu altogether.\n", + "for batch in train_iter_skorch:\n", + " X_train = batch.text.numpy()\n", + " y_train = batch.label.numpy()" ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ - "# # this is a really unfortunate hack to make torchtext batching semantics work with skorch and dask\n", - "# # the downside here is that we're no longer padding to the longest sequence in the batch, rather\n", - "# # we're padding to the longest sequence in the *dataset*, which results in signifcantly more\n", - "# # computation and thus significantly more time to train a model\n", - "# # of course, you could set a max sequence length but that's not an ideal solution\n", - "# # another solution would be to create a different dataset object, but then you can't use torchtext,\n", - "# # which really is quite handy\n", - "\n", - "# # train=True shuffles the data\n", - "# train_iter_skorch = torchtext.data.Iterator(train, batch_size=len(train), train=True, sort=False, device='cpu')\n", - "# test_iter_skorch = torchtext.data.Iterator(test, batch_size=len(test), train=False, sort=False, device='cpu')\n", - "\n", - "# # takes some time to numericalize the whole dataset\n", - "\n", - "# # also notice that skorch and dask expect numpy arrays, which isn't ideal since it ties you to the cpu.\n", - "# # meanwhile, projects like https://rapids.ai/ are moving toward all GPU computation, avoiding the cpu altogether.\n", - "# for batch in train_iter_skorch:\n", - "# X_train = batch.text[0].numpy()\n", - "# y_train = batch.label.numpy()\n", - "\n", - "# for batch in test_iter_skorch:\n", - "# X_test = batch.text[0].numpy()\n", - "# y_test = batch.label.numpy()" + "for batch in test_iter_skorch:\n", + " X_test = batch.text.numpy()\n", + " y_test = batch.label.numpy()" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(5000, 512)" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# notice how awfully large the second dimension is\n", - "# X_train.shape" + "X_train.shape" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "# https://ml.dask.org/hyper-parameter-search.html#hyperband-parameters-rule-of-thumb\n", - "EPOCHS = 2\n", + "EPOCHS = 10\n", "NUM_TRAINING_EXAMPLES = len(train)*.8\n", "n_examples = EPOCHS * NUM_TRAINING_EXAMPLES\n", - "n_params = 8\n", + "n_params = 12\n", "\n", "# it's not immediately obvious to beginners how all these parameters interact with each other\n", "max_iter = n_params\n", @@ -956,7 +819,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -969,25 +832,16 @@ }, { "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [], - "source": [ - "import math" - ] - }, - { - "cell_type": "code", - "execution_count": 57, + "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Chunk size: 1000.0\n", - "Total chunks: 5\n", - "Last chunk size: 1000.0\n" + "Chunk size: 3333.0\n", + "Total chunks: 2\n", + "Last chunk size: 1667.0\n" ] } ], @@ -1005,19 +859,17 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ - "import dask.array as da\n", - "\n", - "X = da.from_array(train_text, chunks=(chunk_size))\n", - "y = da.from_array(train_label, chunks=(chunk_size))" + "X = da.from_array(X_train, chunks=(chunk_size, X_train.shape[-1]))\n", + "y = da.from_array(y_train, chunks=(chunk_size))" ] }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -1031,44 +883,41 @@ " Array Chunk \n", " \n", " \n", - " Bytes 207.26 MB 41.45 MB \n", - " Shape (5000, 1) (1000, 1) \n", - " Count 6 Tasks 5 Chunks \n", - " Type numpy.ndarray \n", + " Bytes 20.48 MB 13.65 MB \n", + " Shape (5000, 512) (3333, 512) \n", + " Count 3 Tasks 2 Chunks \n", + " Type int64 numpy.ndarray \n", " \n", "\n", "\n", "\n", - "\n", + "\n", "\n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", "\n", " \n", " \n", - " \n", + " \n", "\n", " \n", - " \n", + " \n", "\n", " \n", - " 1\n", - " 5000\n", + " 512\n", + " 5000\n", "\n", "\n", "\n", "" ], "text/plain": [ - "dask.array" + "dask.array" ] }, - "execution_count": 59, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1078,38 +927,35 @@ ] }, { - "cell_type": "code", - "execution_count": 60, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# need new collate_fn due to the following error\n", - "# ValueError: Expected 2D array, got 1D array instead:\n", - "# array=['1' '1' '1' ... '1' '1' '1'].\n", - "# Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample." + "TLDR; you can't use dask arrays with `torch.utils.data.Dataloader`, which means you have to do all your data preparation ahead of time" ] }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ - "def pad_batch_hyperband(batch, TEXT, LABEL):\n", - " text, label = list(zip(*batch))\n", - " # unnecessary extra dimension\n", - " text = [i[0] for i in text]\n", - " # numericalized and padded text representation\n", - " text_processed = TEXT.process(text)\n", - " label_processed = LABEL.process(label)\n", - " return text_processed, label_processed\n", + "# raw_train_dataset = [x for x in train_dataset]\n", + "# raw_train_dataset_array = np.array(raw_train_dataset, dtype=object)\n", + "# dask_dataset = da.from_array(raw_train_dataset_array, chunks=(chunk_size))\n", + "# dask_dataset[0].compute()\n", "\n", - "pad_batch_hyperband_partial = partial(pad_batch_hyperband, TEXT=TEXT, LABEL=LABEL)" + "# TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found \n", + "# data_iter = DataLoader(dask_dataset)\n", + "# next(iter(data_iter))\n", + "\n", + "# # TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found object\n", + "# np_data_iter = DataLoader(raw_train_dataset_array)\n", + "# next(iter(np_data_iter))" ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -1120,13 +966,7 @@ " lr=0.001,\n", " optimizer=optim.Adam,\n", " criterion=nn.NLLLoss,\n", - " iterator_train=DataLoader,\n", - " iterator_train__shuffle=True,\n", " iterator_train__batch_size=32,\n", - " iterator_train__collate_fn=pad_batch_hyperband_partial,\n", - " iterator_valid=DataLoader,\n", - " iterator_valid__collate_fn=pad_batch_hyperband_partial,\n", - " iterator_valid__shuffle=False,\n", " iterator_valid__batch_size=64,\n", " train_split=None, # let hyperband handle it\n", " module__n_filters=100,\n", @@ -1140,16 +980,7 @@ }, { "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [], - "source": [ - "from scipy.stats import loguniform" - ] - }, - { - "cell_type": "code", - "execution_count": 64, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ @@ -1163,16 +994,7 @@ }, { "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [], - "source": [ - "from dask_ml.model_selection import HyperbandSearchCV" - ] - }, - { - "cell_type": "code", - "execution_count": 66, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ @@ -1187,16 +1009,16 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "26" + "85" ] }, - "execution_count": 67, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1207,16 +1029,16 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "5" + "17" ] }, - "execution_count": 68, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1227,16 +1049,7 @@ }, { "cell_type": "code", - "execution_count": 69, - "metadata": {}, - "outputs": [], - "source": [ - "import time" - ] - }, - { - "cell_type": "code", - "execution_count": 70, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -1250,73 +1063,31 @@ ] }, { - "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [], - "source": [ - "# I feel like the GPU is spending a lot of time waiting for the CPU to preprocess data\n", - "# I've been watching GPU power consumption during training and it's not as high as during\n", - "# skorch training, so I tried to increase the number of workers the dataloader uses and\n", - "# got the following error: AssertionError: daemonic processes are not allowed to have children" - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [], - "source": [ - "# seems like the validation set is getting preprocessed twice\n", - "# KeyError: tensor([0.])\n", - "\n", - "# but then if you remove the collate_fn from iterator_valid__collate_fn=pad_batch_hyperband_partial\n", - "# then you get the following error\n", - "# TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found [u ... .3232]]),\n", + "/opt/conda/lib/python3.7/site-packages/distributed/worker.py:3351: UserWarning: Large object of size 10.00 MB detected in task graph: \n", + " [[u ... .0000]]),\n", "), 0]\n", "Consider scattering large objects ahead of time\n", "with client.scatter to reduce scheduler burden and \n", @@ -1333,127 +1104,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "[CV, bracket=0] creating 2 models\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", - " sk_validation.check_array(sample, *args, **kwargs)\n", - "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", - " sk_validation.check_array(sample, *args, **kwargs)\n", - "/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py:175: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).\n", - " sk_validation.check_array(sample, *args, **kwargs)\n", - "/opt/conda/lib/python3.7/site-packages/torch/storage.py:34: FutureWarning: pickle support for Storage will be removed in 1.5. Use `torch.save` instead\n", - " warnings.warn(\"pickle support for Storage will be removed in 1.5. Use `torch.save` instead\", FutureWarning)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[CV, bracket=0] For training there are between 800 and 800 examples in each chunk\n", - "[CV, bracket=1] For training there are between 800 and 800 examples in each chunk\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "tornado.application - ERROR - Multiple exceptions in yield list\n", - "Traceback (most recent call last):\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 849, in callback\n", - " result_list.append(f.result())\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", - " yielded = self.gen.throw(*exc_info)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 625, in _fit\n", - " prefix=self.prefix,\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", - " value = future.result()\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1107, in run\n", - " yielded = self.gen.throw(*exc_info)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 233, in _fit\n", - " metas = yield client.gather(new_scores)\n", - " File \"/opt/conda/lib/python3.7/site-packages/tornado/gen.py\", line 1099, in run\n", - " value = future.result()\n", - " File \"/opt/conda/lib/python3.7/site-packages/distributed/client.py\", line 1826, in _gather\n", - " raise exception.with_traceback(traceback)\n", - " File \"/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\", line 103, in _score\n", - " score = scorer(model, X, y)\n", - " File \"/opt/conda/lib/python3.7/site-packages/sklearn/metrics/_scorer.py\", line 371, in _passthrough_scorer\n", - " return estimator.score(*args, **kwargs)\n", - " File \"/opt/conda/lib/python3.7/site-packages/sklearn/base.py\", line 369, in score\n", - " return accuracy_score(y, self.predict(X), sample_weight=sample_weight)\n", - " File \"/opt/conda/lib/python3.7/site-packages/skorch/classifier.py\", line 210, in predict\n", - " for yp in self.forward_iter(X, training=False):\n", - " File \"/opt/conda/lib/python3.7/site-packages/skorch/net.py\", line 917, in forward_iter\n", - " for data in iterator:\n", - " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\", line 345, in __next__\n", - " data = self._next_data()\n", - " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\", line 385, in _next_data\n", - " data = self._dataset_fetcher.fetch(index) # may raise StopIteration\n", - " File \"/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\", line 47, in fetch\n", - " return self.collate_fn(data)\n", - " File \"\", line 7, in pad_batch_hyperband\n", - " label_processed = LABEL.process(label)\n", - " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 237, in process\n", - " tensor = self.numericalize(padded, device=device)\n", - " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 338, in numericalize\n", - " arr = [self.vocab.stoi[x] for x in arr]\n", - " File \"/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\", line 338, in \n", - " arr = [self.vocab.stoi[x] for x in arr]\n", - "KeyError: tensor([0.])\n" - ] - }, - { - "ename": "KeyError", - "evalue": "tensor([0.])", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# e.g. Validation set size: 2500 = 12500*.2, Train set size: 10000 = 12500 - 2500\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0msearch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mduration\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 673\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdefault_client\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 674\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 675\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mif_delegate_has_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"best_estimator_\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"estimator\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36mf\u001b[0;34m()\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallback_timeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 330\u001b[0m \u001b[0mfuture\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0masyncio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait_for\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfuture\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 331\u001b[0;31m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 332\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_hyperband.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[0;31m# _fit is run in parallel because it's also a tornado coroutine\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 400\u001b[0;31m \u001b[0m_SHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mSHAs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_brackets_ids\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 401\u001b[0m \u001b[0mSHAs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSHA\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_brackets_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_SHAs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 402\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mcallback\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 847\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mchildren\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 848\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 849\u001b[0;31m \u001b[0mresult_list\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 850\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdone\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 624\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 625\u001b[0;31m \u001b[0mprefix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprefix\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 626\u001b[0m )\n\u001b[1;32m 627\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_results\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexc_info\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0myielded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;31m# Break up a reference to itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_fit\u001b[0;34m(model, params, X_train, y_train, X_test, y_test, additional_calls, fit_params, scorer, random_state, verbose, prefix)\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0;31m# async for future, result in seq:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 233\u001b[0;31m \u001b[0mmetas\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32myield\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_scores\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 234\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlog_delay\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0m_i\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlog_delay\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/tornado/gen.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1099\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfuture\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1100\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhad_exception\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36m_gather\u001b[0;34m(self, futures, errors, direct, local_worker)\u001b[0m\n\u001b[1;32m 1824\u001b[0m \u001b[0mexc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1825\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1826\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1827\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1828\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"skip\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask_ml/model_selection/_incremental.py\u001b[0m in \u001b[0;36m_score\u001b[0;34m()\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeta\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel_and_meta\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mscorer\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mscorer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/sklearn/metrics/_scorer.py\u001b[0m in \u001b[0;36m_passthrough_scorer\u001b[0;34m()\u001b[0m\n\u001b[1;32m 369\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_passthrough_scorer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mestimator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0;34m\"\"\"Function that wraps estimator.score\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 371\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mestimator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 372\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36mscore\u001b[0;34m()\u001b[0m\n\u001b[1;32m 367\u001b[0m \"\"\"\n\u001b[1;32m 368\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mmetrics\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0maccuracy_score\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 369\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0maccuracy_score\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 370\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/skorch/classifier.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m()\u001b[0m\n\u001b[1;32m 208\u001b[0m \"\"\"\n\u001b[1;32m 209\u001b[0m \u001b[0my_preds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 210\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0myp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward_iter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 211\u001b[0m \u001b[0myp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0myp\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0myp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0myp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 212\u001b[0m \u001b[0my_preds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mto_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0myp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/skorch/net.py\u001b[0m in \u001b[0;36mforward_iter\u001b[0;34m()\u001b[0m\n\u001b[1;32m 915\u001b[0m \u001b[0mdataset\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_dataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 916\u001b[0m \u001b[0miterator\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_iterator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtraining\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 917\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;32min\u001b[0m \u001b[0miterator\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 918\u001b[0m \u001b[0mXi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0munpack_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 919\u001b[0m \u001b[0myp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevaluation_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mXi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtraining\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m__next__\u001b[0;34m()\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__next__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 345\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 346\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_num_yielded\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_kind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0m_DatasetKind\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mIterable\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py\u001b[0m in \u001b[0;36m_next_data\u001b[0;34m()\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_next_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_next_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 385\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dataset_fetcher\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# may raise StopIteration\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 386\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pin_memory\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpin_memory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py\u001b[0m in \u001b[0;36mfetch\u001b[0;34m()\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mpossibly_batched_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcollate_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m\u001b[0m in \u001b[0;36mpad_batch_hyperband\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# numericalized and padded text representation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mtext_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTEXT\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mlabel_processed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLABEL\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtext_processed\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel_processed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mprocess\u001b[0;34m()\u001b[0m\n\u001b[1;32m 235\u001b[0m \"\"\"\n\u001b[1;32m 236\u001b[0m \u001b[0mpadded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpad\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 237\u001b[0;31m \u001b[0mtensor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumericalize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpadded\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 238\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtensor\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 239\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36mnumericalize\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/torchtext/data/field.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mex\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mex\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0marr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvocab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstoi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocessing\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: tensor([0.])" + "[CV, bracket=0] creating 3 models\n", + "[CV, bracket=0] For training there are between 1333 and 2666 examples in each chunk\n", + "[CV, bracket=1] For training there are between 1333 and 2666 examples in each chunk\n", + "[CV, bracket=2] For training there are between 1333 and 2666 examples in each chunk\n", + "[CV, bracket=0] validation score of 0.7982 received after 1 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8032 received after 1 partial_fit calls\n", + "[CV, bracket=2] validation score of 0.7842 received after 1 partial_fit calls\n", + "[CV, bracket=0] validation score of 0.8551 received after 12 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8322 received after 4 partial_fit calls\n", + "[CV, bracket=2] validation score of 0.8212 received after 3 partial_fit calls\n", + "[CV, bracket=1] validation score of 0.8162 received after 12 partial_fit calls\n", + "[CV, bracket=2] validation score of 0.8062 received after 9 partial_fit calls\n", + "Time to complete grid search: 372.02 seconds\n" ] } ], "source": [ - "# I think I'm getting yelled at for passing in text\n", - "# TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found \n", - "
\n", - "\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Array Chunk
Bytes 24 B 24 B
Shape (2,) (2,)
Count 7 Tasks 1 Chunks
Type numpy.ndarray
\n", - "\n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - " \n", - " \n", - " \n", - "\n", - " \n", - " \n", - "\n", - " \n", - " 2\n", - " 1\n", - "\n", - "\n", - "\n", - "" - ], "text/plain": [ - "dask.array" + "[initialized](\n", + " module_=CNN(\n", + " (embedding): Embedding(25002, 100)\n", + " (conv_0): Conv1d(1, 50, kernel_size=(1, 100), stride=(1,))\n", + " (conv_1): Conv1d(1, 50, kernel_size=(2, 100), stride=(1,))\n", + " (conv_2): Conv1d(1, 50, kernel_size=(3, 100), stride=(1,))\n", + " (fc): Linear(in_features=150, out_features=2, bias=True)\n", + " (dropout): Dropout(p=0.12476236679704862, inplace=False)\n", + " ),\n", + ")" ] }, - "execution_count": 80, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "y[:2]" + "search.best_estimator_" ] }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "dtype('\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# why did this take so long and why is the GPU running?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0my\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask/base.py\u001b[0m in \u001b[0;36mcompute\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0mdask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbase\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 165\u001b[0m \"\"\"\n\u001b[0;32m--> 166\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraverse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 167\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 168\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/dask/base.py\u001b[0m in \u001b[0;36mcompute\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 442\u001b[0m \u001b[0mpostcomputes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__dask_postcompute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 443\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 444\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mschedule\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdsk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 445\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mrepack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpostcomputes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 446\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(self, dsk, keys, restrictions, loose_restrictions, resources, sync, asynchronous, direct, retries, priority, fifo_timeout, actors, **kwargs)\u001b[0m\n\u001b[1;32m 2664\u001b[0m \u001b[0mshould_rejoin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2665\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2666\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpacked\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0masynchronous\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0masynchronous\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdirect\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdirect\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2667\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2668\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfutures\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36mgather\u001b[0;34m(self, futures, errors, direct, asynchronous)\u001b[0m\n\u001b[1;32m 1965\u001b[0m \u001b[0mdirect\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdirect\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1966\u001b[0m \u001b[0mlocal_worker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlocal_worker\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1967\u001b[0;31m \u001b[0masynchronous\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0masynchronous\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1968\u001b[0m )\n\u001b[1;32m 1969\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/client.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(self, func, asynchronous, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 814\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m return sync(\n\u001b[0;32m--> 816\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback_timeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 817\u001b[0m )\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/distributed/utils.py\u001b[0m in \u001b[0;36msync\u001b[0;34m(loop, func, callback_timeout, *args, **kwargs)\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_set\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 344\u001b[0;31m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 345\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mtyp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_flag\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 551\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 552\u001b[0;31m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cond\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 553\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 554\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/conda/lib/python3.7/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 298\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 299\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 300\u001b[0;31m \u001b[0mgotit\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 301\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 302\u001b[0m \u001b[0mgotit\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + "name": "stdout", + "output_type": "stream", + "text": [ + "Data must be 1-dimensional\n" ] } ], "source": [ - "# why isn't this responding and why is the GPU running?\n", - "y[:2].compute()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Integration" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`HyperbandSearchCV` follows the Scikit-learn API and mirrors Scikit-learn's `RandomizedSearchCV`. This means that it \"just works\". All the Scikit-learn attributes and methods are available:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "search.best_score_" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "search.best_estimator_" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "search.cv_results_" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cv_results = pd.DataFrame(search.cv_results_)\n", - "cv_results.head()" + "# issue with numpy converting array of tuples into a 2d array\n", + "try: \n", + " cv_results = pd.DataFrame(search.cv_results_)\n", + " cv_results.head()\n", + "except Exception as e:\n", + " print(e)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -1673,9 +1317,178 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
param_module__n_filtersparam_batch_sizeparam_module__dropoutstd_partial_fit_timeparam_module__filter_sizestest_scoremodel_idbracketrank_test_scorestd_score_timeparamsmean_partial_fit_timemean_score_timepartial_fit_calls
0100320.1423330.000000[3, 4, 5]0.736264bracket=2-0290.000000{'batch_size': 32, 'module__dropout': 0.142332...3.0823130.1650041
1100640.1545501.427928[2, 3, 4]0.806194bracket=2-1210.003680{'batch_size': 64, 'module__dropout': 0.154549...4.2037690.1768669
225640.2735040.000000[1, 2, 3]0.778222bracket=2-2250.000000{'batch_size': 64, 'module__dropout': 0.273504...1.6137070.0537101
350320.2644420.000000[2, 3, 4]0.779221bracket=2-3240.000000{'batch_size': 32, 'module__dropout': 0.264442...1.7755650.0755161
425320.1340090.888979[2, 3, 4]0.806194bracket=2-4210.000247{'batch_size': 32, 'module__dropout': 0.134008...2.5506970.0629643
\n", + "
" + ], + "text/plain": [ + " param_module__n_filters param_batch_size param_module__dropout \\\n", + "0 100 32 0.142333 \n", + "1 100 64 0.154550 \n", + "2 25 64 0.273504 \n", + "3 50 32 0.264442 \n", + "4 25 32 0.134009 \n", + "\n", + " std_partial_fit_time param_module__filter_sizes test_score model_id \\\n", + "0 0.000000 [3, 4, 5] 0.736264 bracket=2-0 \n", + "1 1.427928 [2, 3, 4] 0.806194 bracket=2-1 \n", + "2 0.000000 [1, 2, 3] 0.778222 bracket=2-2 \n", + "3 0.000000 [2, 3, 4] 0.779221 bracket=2-3 \n", + "4 0.888979 [2, 3, 4] 0.806194 bracket=2-4 \n", + "\n", + " bracket rank_test_score std_score_time \\\n", + "0 2 9 0.000000 \n", + "1 2 1 0.003680 \n", + "2 2 5 0.000000 \n", + "3 2 4 0.000000 \n", + "4 2 1 0.000247 \n", + "\n", + " params mean_partial_fit_time \\\n", + "0 {'batch_size': 32, 'module__dropout': 0.142332... 3.082313 \n", + "1 {'batch_size': 64, 'module__dropout': 0.154549... 4.203769 \n", + "2 {'batch_size': 64, 'module__dropout': 0.273504... 1.613707 \n", + "3 {'batch_size': 32, 'module__dropout': 0.264442... 1.775565 \n", + "4 {'batch_size': 32, 'module__dropout': 0.134008... 2.550697 \n", + "\n", + " mean_score_time partial_fit_calls \n", + "0 0.165004 1 \n", + "1 0.176866 9 \n", + "2 0.053710 1 \n", + "3 0.075516 1 \n", + "4 0.062964 3 " + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cv_results = pd.DataFrame(search.cv_results_)\n", "cv_results.head()" @@ -1683,27 +1496,98 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.8106" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.score(X_test, y_test)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Array Chunk
Bytes 40.00 kB 40.00 kB
Shape (5000,) (5000,)
Count 2 Tasks 1 Chunks
Type int64 numpy.ndarray
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + " 5000\n", + " 1\n", + "\n", + "
" + ], + "text/plain": [ + "dask.array<_predict, shape=(5000,), dtype=int64, chunksize=(5000,), chunktype=numpy.ndarray>" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.predict(X_test)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 1, 0, ..., 1, 0, 1])" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search.predict(X_test).compute()" ] @@ -1717,9 +1601,128 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
model_idparamspartial_fit_callspartial_fit_timescorescore_timeelapsed_wall_timebracket
0bracket=0-0{'batch_size': 32, 'module__dropout': 0.124762...13.6796120.7982020.06916530.4306130
1bracket=0-1{'batch_size': 64, 'module__dropout': 0.145160...16.2695610.7912090.16742130.4306160
2bracket=0-2{'batch_size': 32, 'module__dropout': 0.104590...16.1930640.7892110.16652230.4306170
3bracket=1-0{'batch_size': 32, 'module__dropout': 0.153853...11.6835630.7872130.06264436.1044081
4bracket=1-1{'batch_size': 64, 'module__dropout': 0.181473...13.0025870.8031970.17163636.1044101
\n", + "
" + ], + "text/plain": [ + " model_id params \\\n", + "0 bracket=0-0 {'batch_size': 32, 'module__dropout': 0.124762... \n", + "1 bracket=0-1 {'batch_size': 64, 'module__dropout': 0.145160... \n", + "2 bracket=0-2 {'batch_size': 32, 'module__dropout': 0.104590... \n", + "3 bracket=1-0 {'batch_size': 32, 'module__dropout': 0.153853... \n", + "4 bracket=1-1 {'batch_size': 64, 'module__dropout': 0.181473... \n", + "\n", + " partial_fit_calls partial_fit_time score score_time \\\n", + "0 1 3.679612 0.798202 0.069165 \n", + "1 1 6.269561 0.791209 0.167421 \n", + "2 1 6.193064 0.789211 0.166522 \n", + "3 1 1.683563 0.787213 0.062644 \n", + "4 1 3.002587 0.803197 0.171636 \n", + "\n", + " elapsed_wall_time bracket \n", + "0 30.430613 0 \n", + "1 30.430616 0 \n", + "2 30.430617 0 \n", + "3 36.104408 1 \n", + "4 36.104410 1 " + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "hist = pd.DataFrame(search.history_)\n", "hist.head()" @@ -1750,16 +1753,14 @@ "\n", "Performance comparisons can be found in the SciPy 2019 talk/paper." ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { + "environment": { + "name": "pytorch-gpu.1-4.m46", + "type": "gcloud", + "uri": "gcr.io/deeplearning-platform-release/pytorch-gpu.1-4:m46" + }, "kernelspec": { "display_name": "Python 3", "language": "python", @@ -1775,7 +1776,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.7.6" } }, "nbformat": 4,