├── 1. First steps with Tensorflow Julia.ipynb ├── 10. Multi-class Classification of Handwritten Digits Julia.ipynb ├── 11. Intro to Sparse Data and Embeddings Julia.ipynb ├── 2. Synthetic Features and Outliers Julia.ipynb ├── 3. Validation Julia.ipynb ├── 4. Feature Sets Julia.ipynb ├── 5. Feature Crosses Julia.ipynb ├── 6. Logistic Regression Julia.ipynb ├── 8. Intro to Neural Nets Julia.ipynb ├── 9. Improving Neural Net Performance Julia.ipynb ├── Conversion of Movie-review data to one-hot encoding.ipynb ├── LICENSE ├── MNIST.jl ├── README.md └── TFrecord Extraction.ipynb /8. Intro to Neural Nets Julia.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "colab_type": "text", 7 | "id": "JndnmDMp66FL" 8 | }, 9 | "source": [ 10 | "This notebook is based on the file [Intro to Neural Nets programming exercise](https://colab.research.google.com/notebooks/mlcc/intro_to_neural_nets.ipynb?utm_source=mlcc&utm_campaign=colab-external&utm_medium=referral&utm_content=introneuralnets-colab&hl=en), which is part of Google's [Machine Learning Crash Course](https://developers.google.com/machine-learning/crash-course/)." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "metadata": { 17 | "cellView": "both", 18 | "colab": { 19 | "autoexec": { 20 | "startup": false, 21 | "wait_interval": 0 22 | } 23 | }, 24 | "colab_type": "code", 25 | "id": "hMqWDc_m6rUC" 26 | }, 27 | "outputs": [], 28 | "source": [ 29 | "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", 30 | "# you may not use this file except in compliance with the License.\n", 31 | "# You may obtain a copy of the License at\n", 32 | "#\n", 33 | "# https://www.apache.org/licenses/LICENSE-2.0\n", 34 | "#\n", 35 | "# Unless required by applicable law or agreed to in writing, software\n", 36 | "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", 37 | "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", 38 | "# See the License for the specific language governing permissions and\n", 39 | "# limitations under the License." 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "colab_type": "text", 46 | "id": "eV16J6oUY-HN", 47 | "slideshow": { 48 | "slide_type": "slide" 49 | } 50 | }, 51 | "source": [ 52 | "# Intro to Neural Networks" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": { 58 | "colab_type": "text", 59 | "id": "_wIcUFLSKNdx" 60 | }, 61 | "source": [ 62 | "**Learning Objectives:**\n", 63 | " * Define a neural network (NN) and its hidden layers \n", 64 | " * Train a neural network to learn nonlinearities in a dataset and achieve better performance than a linear regression model" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "colab_type": "text", 71 | "id": "_ZZ7f7prKNdy" 72 | }, 73 | "source": [ 74 | "In the previous exercises, we used synthetic features to help our model incorporate nonlinearities.\n", 75 | "\n", 76 | "One important set of nonlinearities was around latitude and longitude, but there may be others.\n", 77 | "\n", 78 | "We'll also switch back, for now, to a standard regression task, rather than the logistic regression task from the previous exercise. That is, we'll be predicting `median_house_value` directly." 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "colab_type": "text", 85 | "id": "J2kqX6VZTHUy" 86 | }, 87 | "source": [ 88 | "## Setup\n", 89 | "\n", 90 | "First, let's load and prepare the data." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 2, 96 | "metadata": { 97 | "colab": { 98 | "autoexec": { 99 | "startup": false, 100 | "wait_interval": 0 101 | } 102 | }, 103 | "colab_type": "code", 104 | "id": "AGOM1TUiKNdz" 105 | }, 106 | "outputs": [ 107 | { 108 | "name": "stderr", 109 | "output_type": "stream", 110 | "text": [ 111 | "2019-02-24 14:37:13.958387: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "using Plots\n", 117 | "using Distributions\n", 118 | "gr(fmt=:png)\n", 119 | "using DataFrames\n", 120 | "using TensorFlow\n", 121 | "import CSV\n", 122 | "import StatsBase\n", 123 | "using PyCall\n", 124 | "using Random\n", 125 | "using Statistics\n", 126 | "\n", 127 | "sess=Session(Graph())\n", 128 | "california_housing_dataframe = CSV.read(\"california_housing_train.csv\", delim=\",\");\n", 129 | "california_housing_dataframe = california_housing_dataframe[shuffle(1:size(california_housing_dataframe, 1)),:];" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 3, 135 | "metadata": { 136 | "colab": { 137 | "autoexec": { 138 | "startup": false, 139 | "wait_interval": 0 140 | } 141 | }, 142 | "colab_type": "code", 143 | "id": "2I8E2qhyKNd4" 144 | }, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "preprocess_targets (generic function with 1 method)" 150 | ] 151 | }, 152 | "execution_count": 3, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "function preprocess_features(california_housing_dataframe)\n", 159 | " \"\"\"Prepares input features from California housing data set.\n", 160 | "\n", 161 | " Args:\n", 162 | " california_housing_dataframe: A DataFrame expected to contain data\n", 163 | " from the California housing data set.\n", 164 | " Returns:\n", 165 | " A DataFrame that contains the features to be used for the model, including\n", 166 | " synthetic features.\n", 167 | " \"\"\"\n", 168 | " selected_features = california_housing_dataframe[\n", 169 | " [:latitude,\n", 170 | " :longitude,\n", 171 | " :housing_median_age,\n", 172 | " :total_rooms,\n", 173 | " :total_bedrooms,\n", 174 | " :population,\n", 175 | " :households,\n", 176 | " :median_income]]\n", 177 | " processed_features = selected_features\n", 178 | " # Create a synthetic feature.\n", 179 | " processed_features[:rooms_per_person] = (\n", 180 | " california_housing_dataframe[:total_rooms] ./\n", 181 | " california_housing_dataframe[:population])\n", 182 | " return processed_features\n", 183 | "end\n", 184 | " \n", 185 | "function preprocess_targets(california_housing_dataframe)\n", 186 | " \"\"\"Prepares target features (i.e., labels) from California housing data set.\n", 187 | "\n", 188 | " Args:\n", 189 | " california_housing_dataframe: A DataFrame expected to contain data\n", 190 | " from the California housing data set.\n", 191 | " Returns:\n", 192 | " A DataFrame that contains the target feature.\n", 193 | " \"\"\"\n", 194 | " output_targets = DataFrame()\n", 195 | " # Scale the target to be in units of thousands of dollars.\n", 196 | " output_targets[:median_house_value] = (\n", 197 | " california_housing_dataframe[:median_house_value] ./ 1000.0)\n", 198 | " return output_targets\n", 199 | "end" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 4, 205 | "metadata": { 206 | "colab": { 207 | "autoexec": { 208 | "startup": false, 209 | "wait_interval": 0 210 | } 211 | }, 212 | "colab_type": "code", 213 | "id": "pQzcj2B1T5dA" 214 | }, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "Training examples summary:\n", 221 | "Validation examples summary:\n", 222 | "Training targets summary:\n", 223 | "Validation targets summary:\n" 224 | ] 225 | }, 226 | { 227 | "data": { 228 | "text/html": [ 229 | "

1 rows × 8 columns

variablemeanminmedianmaxnuniquenmissingeltype
SymbolFloat64Float64Float64Float64NothingNothingDataType
1median_house_value207.11414.999179.45500.001Float64
" 230 | ], 231 | "text/latex": [ 232 | "\\begin{tabular}{r|cccccccc}\n", 233 | "\t& variable & mean & min & median & max & nunique & nmissing & eltype\\\\\n", 234 | "\t\\hline\n", 235 | "\t& Symbol & Float64 & Float64 & Float64 & Float64 & Nothing & Nothing & DataType\\\\\n", 236 | "\t\\hline\n", 237 | "\t1 & median\\_house\\_value & 207.114 & 14.999 & 179.45 & 500.001 & & & Float64 \\\\\n", 238 | "\\end{tabular}\n" 239 | ], 240 | "text/plain": [ 241 | "1×8 DataFrame. Omitted printing of 2 columns\n", 242 | "│ Row │ variable │ mean │ min │ median │ max │ nunique │\n", 243 | "│ │ \u001b[90mSymbol\u001b[39m │ \u001b[90mFloat64\u001b[39m │ \u001b[90mFloat64\u001b[39m │ \u001b[90mFloat64\u001b[39m │ \u001b[90mFloat64\u001b[39m │ \u001b[90mNothing\u001b[39m │\n", 244 | "├─────┼────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┤\n", 245 | "│ 1 │ median_house_value │ 207.114 │ 14.999 │ 179.45 │ 500.001 │ │" 246 | ] 247 | }, 248 | "execution_count": 4, 249 | "metadata": {}, 250 | "output_type": "execute_result" 251 | } 252 | ], 253 | "source": [ 254 | "# Choose the first 12000 (out of 17000) examples for training.\n", 255 | "training_examples = preprocess_features(first(california_housing_dataframe,12000))\n", 256 | "training_targets = preprocess_targets(first(california_housing_dataframe,12000))\n", 257 | "\n", 258 | "# Choose the last 5000 (out of 17000) examples for validation.\n", 259 | "validation_examples = preprocess_features(last(california_housing_dataframe,5000))\n", 260 | "validation_targets = preprocess_targets(last(california_housing_dataframe,5000))\n", 261 | "\n", 262 | "# Double-check that we've done the right thing.\n", 263 | "println(\"Training examples summary:\")\n", 264 | "describe(training_examples)\n", 265 | "println(\"Validation examples summary:\")\n", 266 | "describe(validation_examples)\n", 267 | "\n", 268 | "println(\"Training targets summary:\")\n", 269 | "describe(training_targets)\n", 270 | "println(\"Validation targets summary:\")\n", 271 | "describe(validation_targets)" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": { 277 | "colab_type": "text", 278 | "id": "RWq0xecNKNeG" 279 | }, 280 | "source": [ 281 | "## Building a Neural Network\n", 282 | "\n", 283 | "Use **`hidden_units`** to define the structure of the NN. The `hidden_units` argument provides a list of ints, where each int corresponds to a hidden layer and indicates the number of nodes in it. For example, consider the following assignment:\n", 284 | "\n", 285 | "`hidden_units=[3,10]`\n", 286 | "\n", 287 | "The preceding assignment specifies a neural net with two hidden layers:\n", 288 | "\n", 289 | "* The first hidden layer contains 3 nodes.\n", 290 | "* The second hidden layer contains 10 nodes.\n", 291 | "\n", 292 | "If we wanted to add more layers, we'd add more ints to the list. For example, `hidden_units=[10,20,30,40]` would create four layers with ten, twenty, thirty, and forty units, respectively.\n", 293 | "\n", 294 | "By default, all hidden layers will use ReLu activation and will be fully connected." 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 5, 300 | "metadata": { 301 | "colab": { 302 | "autoexec": { 303 | "startup": false, 304 | "wait_interval": 0 305 | } 306 | }, 307 | "colab_type": "code", 308 | "id": "ni0S6zHcTb04" 309 | }, 310 | "outputs": [ 311 | { 312 | "data": { 313 | "text/plain": [ 314 | "construct_columns (generic function with 1 method)" 315 | ] 316 | }, 317 | "execution_count": 5, 318 | "metadata": {}, 319 | "output_type": "execute_result" 320 | } 321 | ], 322 | "source": [ 323 | "function construct_columns(input_features)\n", 324 | " \"\"\"Construct the TensorFlow Feature Columns.\n", 325 | "\n", 326 | " Args:\n", 327 | " input_features: DataFrame of the numerical input features to use.\n", 328 | " Returns:\n", 329 | " A set of feature columns\n", 330 | " \"\"\" \n", 331 | " out=convert(Matrix, input_features[:,:])\n", 332 | " return convert(Matrix{Float64},out)\n", 333 | " \n", 334 | "end" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 6, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "data": { 344 | "text/plain": [ 345 | "create_batches (generic function with 3 methods)" 346 | ] 347 | }, 348 | "execution_count": 6, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "function create_batches(features, targets, steps, batch_size=5, num_epochs=0)\n", 355 | " \"\"\"Create batches.\n", 356 | "\n", 357 | " Args:\n", 358 | " features: Input features.\n", 359 | " targets: Target column.\n", 360 | " steps: Number of steps.\n", 361 | " batch_size: Batch size.\n", 362 | " num_epochs: Number of epochs, 0 will let TF automatically calculate the correct number\n", 363 | " Returns:\n", 364 | " An extended set of feature and target columns from which batches can be extracted.\n", 365 | " \"\"\" \n", 366 | " \n", 367 | " if(num_epochs==0)\n", 368 | " num_epochs=ceil(batch_size*steps/size(features,1))\n", 369 | " end\n", 370 | " \n", 371 | " names_features=names(features);\n", 372 | " names_targets=names(targets);\n", 373 | " \n", 374 | " features_batches=copy(features)\n", 375 | " target_batches=copy(targets)\n", 376 | "\n", 377 | " for i=1:num_epochs\n", 378 | " \n", 379 | " select=shuffle(1:size(features,1))\n", 380 | " \n", 381 | " if i==1\n", 382 | " features_batches=(features[select,:])\n", 383 | " target_batches=(targets[select,:])\n", 384 | " else\n", 385 | " \n", 386 | " append!(features_batches, features[select,:])\n", 387 | " append!(target_batches, targets[select,:])\n", 388 | " end\n", 389 | " end\n", 390 | " return features_batches, target_batches \n", 391 | "end" 392 | ] 393 | }, 394 | { 395 | "cell_type": "code", 396 | "execution_count": 7, 397 | "metadata": {}, 398 | "outputs": [ 399 | { 400 | "data": { 401 | "text/plain": [ 402 | "next_batch (generic function with 1 method)" 403 | ] 404 | }, 405 | "execution_count": 7, 406 | "metadata": {}, 407 | "output_type": "execute_result" 408 | } 409 | ], 410 | "source": [ 411 | "function next_batch(features_batches, targets_batches, batch_size, iter)\n", 412 | " \"\"\"Next batch.\n", 413 | "\n", 414 | " Args:\n", 415 | " features_batches: Features batches from create_batches.\n", 416 | " targets_batches: Target batches from create_batches.\n", 417 | " batch_size: Batch size.\n", 418 | " iter: Number of the current iteration\n", 419 | " Returns:\n", 420 | " An extended set of feature and target columns from which batches can be extracted.\n", 421 | " \"\"\" \n", 422 | " select=mod((iter-1)*batch_size+1, size(features_batches,1)):mod(iter*batch_size, size(features_batches,1));\n", 423 | "\n", 424 | " ds=features_batches[select,:];\n", 425 | " target=targets_batches[select,:];\n", 426 | " \n", 427 | " return ds, target\n", 428 | "end" 429 | ] 430 | }, 431 | { 432 | "cell_type": "code", 433 | "execution_count": 8, 434 | "metadata": {}, 435 | "outputs": [ 436 | { 437 | "data": { 438 | "text/plain": [ 439 | "my_input_fn (generic function with 3 methods)" 440 | ] 441 | }, 442 | "execution_count": 8, 443 | "metadata": {}, 444 | "output_type": "execute_result" 445 | } 446 | ], 447 | "source": [ 448 | "function my_input_fn(features_batches, targets_batches, iter, batch_size=5, shuffle_flag=1)\n", 449 | " \"\"\"Prepares a batch of features and labels for model training.\n", 450 | " \n", 451 | " Args:\n", 452 | " features_batches: Features batches from create_batches.\n", 453 | " targets_batches: Target batches from create_batches.\n", 454 | " iter: Number of the current iteration\n", 455 | " batch_size: Batch size.\n", 456 | " shuffle_flag: Determines wether data is shuffled before being returned\n", 457 | " Returns:\n", 458 | " Tuple of (features, labels) for next data batch\n", 459 | " \"\"\" \n", 460 | " \n", 461 | " # Construct a dataset, and configure batching/repeating.\n", 462 | " ds, target = next_batch(features_batches, targets_batches, batch_size, iter)\n", 463 | " \n", 464 | " # Shuffle the data, if specified.\n", 465 | " if shuffle_flag==1\n", 466 | " select=shuffle(1:size(ds, 1));\n", 467 | " ds = ds[select,:]\n", 468 | " target = target[select, :]\n", 469 | " end\n", 470 | " \n", 471 | " # Return the next batch of data.\n", 472 | " return ds, target\n", 473 | "end" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 9, 479 | "metadata": {}, 480 | "outputs": [ 481 | { 482 | "data": { 483 | "text/plain": [ 484 | "train_nn_regression_model (generic function with 1 method)" 485 | ] 486 | }, 487 | "execution_count": 9, 488 | "metadata": {}, 489 | "output_type": "execute_result" 490 | } 491 | ], 492 | "source": [ 493 | "function train_nn_regression_model(learning_rate,\n", 494 | " steps, \n", 495 | " batch_size, \n", 496 | " hidden_units,\n", 497 | " keep_probability,\n", 498 | " training_examples, \n", 499 | " training_targets, \n", 500 | " validation_examples, \n", 501 | " validation_targets)\n", 502 | " \"\"\"Trains a neural network model of one feature.\n", 503 | " \n", 504 | " Args:\n", 505 | " learning_rate: A `float`, the learning rate.\n", 506 | " steps: A non-zero `int`, the total number of training steps. A training step\n", 507 | " consists of a forward and backward pass using a single batch.\n", 508 | " batch_size: A non-zero `int`, the batch size.\n", 509 | " hidden_units: A vector describing the layout of the neural network\n", 510 | " keep_probability: A `float`, the probability of keeping a node active during one training step.\n", 511 | " \"\"\"\n", 512 | " \n", 513 | " periods = 10\n", 514 | " steps_per_period = steps / periods\n", 515 | "\n", 516 | " # Create feature columns.\n", 517 | " feature_columns = placeholder(Float32, shape=[-1, size(construct_columns(training_examples),2)])\n", 518 | " target_columns = placeholder(Float32, shape=[-1, size(construct_columns(training_targets),2)])\n", 519 | " \n", 520 | " # Network parameters\n", 521 | " push!(hidden_units,size(training_targets,2)) #create an output node that fits to the size of the targets\n", 522 | " activation_functions = Vector{Function}(undef, size(hidden_units,1))\n", 523 | " activation_functions[1:end-1] .= z->nn.dropout(nn.relu(z), keep_probability)\n", 524 | " activation_functions[end] = identity #Last function should be idenity as we need the logits \n", 525 | " \n", 526 | " # create network - professional template\n", 527 | " Zs = [feature_columns]\n", 528 | " for (ii,(hlsize, actfun)) in enumerate(zip(hidden_units, activation_functions))\n", 529 | " Wii = get_variable(\"W_$ii\"*randstring(4), [get_shape(Zs[end], 2), hlsize], Float32)\n", 530 | " bii = get_variable(\"b_$ii\"*randstring(4), [hlsize], Float32)\n", 531 | " Zii = actfun(Zs[end]*Wii + bii)\n", 532 | " push!(Zs, Zii)\n", 533 | " end\n", 534 | " \n", 535 | " y=Zs[end]\n", 536 | " loss=reduce_sum((target_columns - y).^2)\n", 537 | " \n", 538 | " features_batches, targets_batches = create_batches(training_examples, training_targets, steps, batch_size)\n", 539 | " \n", 540 | " # Advanced gradient decent with gradient clipping\n", 541 | " my_optimizer=(train.AdamOptimizer(learning_rate))\n", 542 | " gvs = train.compute_gradients(my_optimizer, loss)\n", 543 | " capped_gvs = [(clip_by_norm(grad, 5.), var) for (grad, var) in gvs]\n", 544 | " my_optimizer = train.apply_gradients(my_optimizer,capped_gvs)\n", 545 | " \n", 546 | " run(sess, global_variables_initializer())\n", 547 | " \n", 548 | " # Train the model, but do so inside a loop so that we can periodically assess\n", 549 | " # loss metrics.\n", 550 | " println(\"Training model...\")\n", 551 | " println(\"RMSE (on training data):\")\n", 552 | " training_rmse = []\n", 553 | " validation_rmse=[]\n", 554 | " \n", 555 | " for period in 1:periods\n", 556 | " # Train the model, starting from the prior state.\n", 557 | " for i=1:steps_per_period\n", 558 | " features, labels = my_input_fn(features_batches, targets_batches, convert(Int,(period-1)*steps_per_period+i), batch_size)\n", 559 | " run(sess, my_optimizer, Dict(feature_columns=>construct_columns(features), target_columns=>construct_columns(labels)))\n", 560 | " end\n", 561 | " # Take a break and compute predictions.\n", 562 | " training_predictions = run(sess, y, Dict(feature_columns=> construct_columns(training_examples))); \n", 563 | " validation_predictions = run(sess, y, Dict(feature_columns=> construct_columns(validation_examples))); \n", 564 | " \n", 565 | " # Compute loss.\n", 566 | " training_mean_squared_error = mean((training_predictions- construct_columns(training_targets)).^2)\n", 567 | " training_root_mean_squared_error = sqrt(training_mean_squared_error)\n", 568 | " validation_mean_squared_error = mean((validation_predictions- construct_columns(validation_targets)).^2)\n", 569 | " validation_root_mean_squared_error = sqrt(validation_mean_squared_error)\n", 570 | " # Occasionally print the current loss.\n", 571 | " println(\" period \", period, \": \", training_root_mean_squared_error)\n", 572 | " # Add the loss metrics from this period to our list.\n", 573 | " push!(training_rmse, training_root_mean_squared_error)\n", 574 | " push!(validation_rmse, validation_root_mean_squared_error)\n", 575 | " end\n", 576 | " \n", 577 | " println(\"Model training finished.\")\n", 578 | "\n", 579 | " # Output a graph of loss metrics over periods.\n", 580 | " p1=plot(training_rmse, label=\"training\", title=\"Root Mean Squared Error vs. Periods\", ylabel=\"RMSE\", xlabel=\"Periods\")\n", 581 | " p1=plot!(validation_rmse, label=\"validation\")\n", 582 | " \n", 583 | " #\n", 584 | " println(\"Final RMSE (on training data): \", training_rmse[end])\n", 585 | " println(\"Final RMSE (on validation data): \", validation_rmse[end])\n", 586 | " \n", 587 | " return y, feature_columns, p1 \n", 588 | "end" 589 | ] 590 | }, 591 | { 592 | "cell_type": "markdown", 593 | "metadata": { 594 | "colab_type": "text", 595 | "id": "2QhdcCy-Y8QR", 596 | "slideshow": { 597 | "slide_type": "slide" 598 | } 599 | }, 600 | "source": [ 601 | "## Task 1: Train a NN Model\n", 602 | "\n", 603 | "**Adjust hyperparameters, aiming to drop RMSE below 110.**\n", 604 | "\n", 605 | "Run the following block to train a NN model. \n", 606 | "\n", 607 | "Recall that in the linear regression exercise with many features, an RMSE of 110 or so was pretty good. We'll aim to beat that.\n", 608 | "\n", 609 | "Your task here is to modify various learning settings to improve accuracy on validation data.\n", 610 | "\n", 611 | "Overfitting is a real potential hazard for NNs. You can look at the gap between loss on training data and loss on validation data to help judge if your model is starting to overfit. If the gap starts to grow, that is usually a sure sign of overfitting.\n", 612 | "\n", 613 | "Because of the number of different possible settings, it's strongly recommended that you take notes on each trial to help guide your development process.\n", 614 | "\n", 615 | "Also, when you get a good setting, try running it multiple times and see how repeatable your result is. NN weights are typically initialized to small random values, so you should see differences from run to run.\n" 616 | ] 617 | }, 618 | { 619 | "cell_type": "code", 620 | "execution_count": 10, 621 | "metadata": {}, 622 | "outputs": [ 623 | { 624 | "name": "stdout", 625 | "output_type": "stream", 626 | "text": [ 627 | "Training model...\n", 628 | "RMSE (on training data):\n", 629 | " period 1: 159.5003388798359\n", 630 | " period 2: 146.17210524272318\n", 631 | " period 3: 115.86667616689647\n", 632 | " period 4: 103.41430171920487\n", 633 | " period 5: 101.759607509385\n", 634 | " period 6: 100.03529275063775\n", 635 | " period 7: 99.1696604548445\n", 636 | " period 8: 97.63196027126274\n", 637 | " period 9: 96.23186697214885\n", 638 | " period 10: 96.03693581788262\n", 639 | "Model training finished.\n", 640 | "Final RMSE (on training data): 96.03693581788262\n", 641 | "Final RMSE (on validation data): 95.03425708133081\n" 642 | ] 643 | }, 644 | { 645 | "data": { 646 | "text/plain": [ 647 | "(, , Plot{Plots.GRBackend() n=2})" 648 | ] 649 | }, 650 | "execution_count": 10, 651 | "metadata": {}, 652 | "output_type": "execute_result" 653 | } 654 | ], 655 | "source": [ 656 | " output_function, output_columns, p1 = train_nn_regression_model(\n", 657 | " # TWEAK THESE VALUES TO SEE HOW MUCH YOU CAN IMPROVE THE RMSE\n", 658 | " 0.001, #learning rate\n", 659 | " 2000, #steps\n", 660 | " 100, #batch_size\n", 661 | " [10, 10], #hidden_units\n", 662 | " 1.0, # keep probability\n", 663 | " training_examples,\n", 664 | " training_targets,\n", 665 | " validation_examples,\n", 666 | " validation_targets)" 667 | ] 668 | }, 669 | { 670 | "cell_type": "code", 671 | "execution_count": 11, 672 | "metadata": {}, 673 | "outputs": [ 674 | { 675 | "data": { 676 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQCAIAAAD9V4nPAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOzdeXwTZf4H8GdmcjRN2py9aQsF2nJf6kJBbkGRth6gIJccuq6yXj+8ORRUBNEF0d0VtIgoXgjCiiA3cimIHFKggFyl9EzTHG2OZjK/P6aG2DO0aaZpPu8XL17Jk8nMdyZpP52ZZ+ahOI4jAAAAwYoWugAAAAAhIQgBACCoIQgDCVUbqVSanJw8ZcqUc+fO+XyJdrvdZrN5WVinTp3qOtLeuXNnfhpfF9gk+/fvf/DBB7t27apQKHQ6XZ8+faZNm3by5Emh6/IZiqJSU1Prn6B+fitVQDXXOjQ0tGfPni+99JLFYmn6/FNTU321JRv8QKFxKJwjDCD8j+jtt9/ubuE4zmQy5eTkGAyGsLCw3377rUOHDj5cYmpqak5OToNfEvfP+e+//961a9dqr54+fbpLly7ugn1YXqNxHPfYY4+tWLGCoqjevXvHx8dbrdaLFy+eP3+eEDJ79uwFCxYIXaMPUBSVkpJy9uzZeiao9o2qZuvWrc1TWgtSbSNwHFdSUnL69GmbzdapU6fffvstJCSkKfP38ofIy1Lr/0ChkTgIHISQlJSUmu1Wq3XGjBmEkGnTpvl2iSkpKd58SQghCoWCEDJnzpyar7722mvuCXxbXqOtWrWKENK3b99Lly65G10u18GDB9u0aUMI+e6774Srzmfq+sJ4P0EwqHUj5OfnDxw4kBCyaNGiJs7fYrGYzeYmzoSHz6uZ4NBoaxASEjJ//nxCiICH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wgw0m7fvi02AoFAfX39rl271q5dq9FoxIknT54sKSnZuXPnhAkTqqurP/zwQ6/Xu2XLFvHd3NzcxMTE9evXD1rngQMH9uzZU1RUFB8fb7PZ1q1bV1lZ+e677169evXNN9/MzMz87rvvlEplZWXlypUrxUV4nl+xYkV6evrhw4cppSdOnPjggw9u3LgxIp8BwGhCAWAEDToAx48fv3HjxgcPHoRmmDdv3q1bt0Ivt2/fnpqaGlo2Pz9/4KoaGhoopYIgxMbGiueOosLCwrS0NEppenr6pk2bBgbIyckRD/yWlhZCyM2bN8XpnZ2dZWVlw76/AKMfOssAjKhHO8sMotfrBz1NYTKZ2traxGVtNltaWtqgVXV0dJhMpq6uLqPRKL515cqVzMxMh8NhNBqtVuuSJUtCa6uqqlq6dCmlVBCEjz76qLy8PD09fdGiRevXr588efLw7zDAqId7hACji1ar/f333xsGqKqqCr0bupX4dAqFgud5QsijPVFDDxEqFAqLxXLr1q233nqrpqZmzpw5BQUFw7MPAJKCQggwusydO/fevXtms9lsNr/66qslJSXHjx9/+iJxcXGxsbHnzp0LTTl79mx8fDwhJDEx8dixYwNnPnXqlNjo7u7evHmz0WjMy8srLy8vLy/Hs4wgT+gsAzC6bNu2bcOGDXv37p02bZrVai0rK/vll1+evgjHcTt27MjNzW1vb58zZ47NZvvqq68qKysJIXv27ElNTXU6nWvWrFGpVFar1WaziUtFR0efOXPG7XavXbu2t7fXYrEkJyeHffcARiHWNykB5IUEe7g8xZEjR8xms1arTU5OPn369JOWHfiS5/kDBw6ID10kJSVVVFSEZquurk5LSzMYDNOmTdu8eXNtbW3owL9+/XpKSopOp4uJicnMzLx79+6w7SeAdKCzDAAAyBruEQIAgKz9HzSwVhhkfgjcAAAAAElFTkSuQmCC" 677 | }, 678 | "execution_count": 11, 679 | "metadata": {}, 680 | "output_type": "execute_result" 681 | } 682 | ], 683 | "source": [ 684 | "plot(p1)" 685 | ] 686 | }, 687 | { 688 | "cell_type": "markdown", 689 | "metadata": { 690 | "colab_type": "text", 691 | "id": "c6diezCSeH4Y", 692 | "slideshow": { 693 | "slide_type": "slide" 694 | } 695 | }, 696 | "source": [ 697 | "## Task 2: Evaluate on Test Data\n", 698 | "\n", 699 | "**Confirm that your validation performance results hold up on test data.**\n", 700 | "\n", 701 | "Once you have a model you're happy with, evaluate it on test data to compare that to validation performance.\n", 702 | "\n", 703 | "Reminder, the test data set is located [here](https://storage.googleapis.com/mledu-datasets/california_housing_test.csv)." 704 | ] 705 | }, 706 | { 707 | "cell_type": "markdown", 708 | "metadata": { 709 | "colab_type": "text", 710 | "id": "FyDh7Qy6rQb0" 711 | }, 712 | "source": [ 713 | "Similar to what the code at the top does, we just need to load the appropriate data file, preprocess it and call predict and mean_squared_error.\n", 714 | "\n", 715 | "Note that we don't have to randomize the test data, since we will use all records." 716 | ] 717 | }, 718 | { 719 | "cell_type": "code", 720 | "execution_count": 12, 721 | "metadata": {}, 722 | "outputs": [ 723 | { 724 | "name": "stdout", 725 | "output_type": "stream", 726 | "text": [ 727 | "Final RMSE (on test data): 94.71009531508615" 728 | ] 729 | } 730 | ], 731 | "source": [ 732 | "california_housing_test_data = CSV.read(\"california_housing_test.csv\", delim=\",\");\n", 733 | "test_examples = preprocess_features(california_housing_test_data)\n", 734 | "test_targets = preprocess_targets(california_housing_test_data)\n", 735 | "\n", 736 | "test_predictions = run(sess, output_function, Dict(output_columns=> construct_columns(test_examples))); \n", 737 | "test_mean_squared_error = mean((test_predictions- construct_columns(test_targets)).^2)\n", 738 | "test_root_mean_squared_error = sqrt(test_mean_squared_error)\n", 739 | "\n", 740 | "print(\"Final RMSE (on test data): \", test_root_mean_squared_error)" 741 | ] 742 | }, 743 | { 744 | "cell_type": "code", 745 | "execution_count": 13, 746 | "metadata": {}, 747 | "outputs": [], 748 | "source": [ 749 | "#EOF" 750 | ] 751 | } 752 | ], 753 | "metadata": { 754 | "colab": { 755 | "collapsed_sections": [ 756 | "JndnmDMp66FL", 757 | "O2q5RRCKqYaU", 758 | "vvT2jDWjrKew" 759 | ], 760 | "default_view": {}, 761 | "name": "8. Intro to Neural Nets.ipynb", 762 | "provenance": [ 763 | { 764 | "file_id": "/v2/external/notebooks/mlcc/intro_to_neural_nets.ipynb", 765 | "timestamp": 1531038995036 766 | } 767 | ], 768 | "version": "0.3.2", 769 | "views": {} 770 | }, 771 | "kernelspec": { 772 | "display_name": "Julia 1.1.0", 773 | "language": "julia", 774 | "name": "julia-1.1" 775 | }, 776 | "language_info": { 777 | "file_extension": ".jl", 778 | "mimetype": "application/julia", 779 | "name": "julia", 780 | "version": "1.1.0" 781 | } 782 | }, 783 | "nbformat": 4, 784 | "nbformat_minor": 1 785 | } 786 | -------------------------------------------------------------------------------- /Conversion of Movie-review data to one-hot encoding.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", 10 | "# you may not use this file except in compliance with the License.\n", 11 | "# You may obtain a copy of the License at\n", 12 | "#\n", 13 | "# https://www.apache.org/licenses/LICENSE-2.0\n", 14 | "#\n", 15 | "# Unless required by applicable law or agreed to in writing, software\n", 16 | "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", 17 | "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", 18 | "# See the License for the specific language governing permissions and\n", 19 | "# limitations under the License." 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "# Conversion of Movie-review data to one-hot encoding" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "The final exercise of Google's [Machine Learning Crash Course](https://developers.google.com/machine-learning/crash-course/) uses the [ACL 2011 IMDB dataset](http://ai.stanford.edu/~amaas/data/sentiment/)) to train a Neural Network on movie review data. At this step, we are not concerned with building an input pipeline or implementing an effective handling and storage of the data. \n", 34 | "\n", 35 | "The following code converts the movie review data we extracted from a ``.tfrecord``-file in the [previous step](https://github.com/sdobber/MLCrashCourse/blob/master/TFrecord%20Extraction.ipynb) to a one-hot encoded matrix and stores it on the disk for later use:" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 1, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "using HDF5\n", 45 | "using JLD" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "The following function handles the conversion to a one-hot encoding:" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 6, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "create_data_columns (generic function with 1 method)" 64 | ] 65 | }, 66 | "execution_count": 6, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "# function for creating categorial colum from vocabulary list in one hot encoding\n", 73 | "function create_data_columns(data, informative_terms)\n", 74 | " onehotmat=zeros(length(data), length(informative_terms))\n", 75 | " \n", 76 | " for i=1:length(data)\n", 77 | " string=data[i]\n", 78 | " for j=1:length(informative_terms)\n", 79 | " if occursin(informative_terms[j], string)\n", 80 | " onehotmat[i,j]=1\n", 81 | " end\n", 82 | " end\n", 83 | " end\n", 84 | " return onehotmat\n", 85 | "end" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "Let's load the data from disk:" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 3, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "c = h5open(\"train_data.h5\", \"r\") do file\n", 102 | " global train_labels=read(file, \"output_labels\")\n", 103 | " global train_features=read(file, \"output_features\")\n", 104 | "end\n", 105 | "c = h5open(\"test_data.h5\", \"r\") do file\n", 106 | " global test_labels=read(file, \"output_labels\")\n", 107 | " global test_features=read(file, \"output_features\")\n", 108 | "end\n", 109 | "train_labels=train_labels'\n", 110 | "test_labels=test_labels';" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "We will use the full vocabulary file, which can be obtained [here](https://storage.googleapis.com/mledu-datasets/sparse-data-embedding/terms.txt). Put it in the same folder as the Jupyter-file and open it using" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 4, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "vocabulary=Array{String}(undef, 0)\n", 127 | "open(\"terms.txt\") do file\n", 128 | " for ln in eachline(file)\n", 129 | " push!(vocabulary, ln)\n", 130 | " end\n", 131 | "end" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "We will now create the test and training features matrices based on the full vocabulary file. This code does not create sparse matrices and takes a long time to run (about 2h on my laptop)." 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 7, 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "ename": "InterruptException", 148 | "evalue": "InterruptException:", 149 | "output_type": "error", 150 | "traceback": [ 151 | "InterruptException:", 152 | "", 153 | "Stacktrace:", 154 | " [1] unsafe_wrap at ./strings/string.jl:71 [inlined]", 155 | " [2] _searchindex(::String, ::String, ::Int64) at ./strings/search.jl:153", 156 | " [3] occursin at ./strings/search.jl:456 [inlined]", 157 | " [4] create_data_columns(::Array{String,1}, ::Array{String,1}) at ./In[6]:8", 158 | " [5] top-level scope at In[7]:3" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "# This takes a looong time. Only run it once and save the result\n", 164 | "train_features_full=create_data_columns(train_features, vocabulary)\n", 165 | "test_features_full=create_data_columns(test_features, vocabulary);" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "Save the data to disk. The data takes about 13GB of memory in uncompressed state." 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 8, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "save(\"IMDB_fullmatrix_datacolumns.jld\", \"train_features_full\", train_features_full, \"test_features_full\", test_features_full)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "metadata": {}, 188 | "outputs": [], 189 | "source": [] 190 | } 191 | ], 192 | "metadata": { 193 | "kernelspec": { 194 | "display_name": "Julia 0.7.0", 195 | "language": "julia", 196 | "name": "julia-0.7" 197 | }, 198 | "language_info": { 199 | "file_extension": ".jl", 200 | "mimetype": "application/julia", 201 | "name": "julia", 202 | "version": "0.7.0" 203 | } 204 | }, 205 | "nbformat": 4, 206 | "nbformat_minor": 2 207 | } 208 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MNIST.jl: -------------------------------------------------------------------------------- 1 | # This is a patched version of the latest MNIST.jl file (downloaded on Mar 6, 2019). 2 | # Please see the original contribution at https://github.com/johnmyleswhite/MNIST.jl 3 | 4 | 5 | module MNIST 6 | using Compat 7 | 8 | export trainfeatures, testfeatures, 9 | trainlabel, testlabel, 10 | traindata, testdata 11 | 12 | const IMAGEOFFSET = 16 13 | const LABELOFFSET = 8 14 | 15 | const NROWS = 28 16 | const NCOLS = 28 17 | 18 | const TRAINIMAGES = joinpath( 19 | dirname(@__FILE__), "..", "data", "train-images.idx3-ubyte" 20 | ) 21 | const TRAINLABELS = joinpath( 22 | dirname(@__FILE__), "..", "data", "train-labels.idx1-ubyte" 23 | ) 24 | const TESTIMAGES = joinpath( 25 | dirname(@__FILE__), "..", "data", "t10k-images.idx3-ubyte" 26 | ) 27 | const TESTLABELS = joinpath( 28 | dirname(@__FILE__), "..", "data", "t10k-labels.idx1-ubyte" 29 | ) 30 | 31 | function imageheader(@compat(filename::AbstractString)) 32 | io = open(filename, "r") 33 | magic_number = bswap(read!(io, Array{@compat(UInt32)})) 34 | total_items = bswap(read!(io, Array{@compat(UInt32)})) 35 | nrows = bswap(read!(io, Array{@compat(UInt32)})) 36 | ncols = bswap(read!(io, Array{@compat(UInt32)})) 37 | #magic_number = bswap(read(io, @compat(UInt32))) 38 | #total_items = bswap(read(io, @compat(UInt32))) 39 | #nrows = bswap(read(io, @compat(UInt32))) 40 | #ncols = bswap(read(io, @compat(UInt32))) 41 | close(io) 42 | return ( 43 | magic_number, 44 | @compat(Int(total_items)), 45 | @compat(Int(nrows)), 46 | @compat(Int(ncols)) 47 | ) 48 | end 49 | 50 | function labelheader(@compat(filename::AbstractString)) 51 | io = open(filename, "r") 52 | magic_number = bswap(read!(io, Array{@compat(UInt32)})) 53 | total_items = bswap(read!(io, Array{@compat(UInt32)})) 54 | #magic_number = bswap(read(io, @compat(UInt32))) 55 | #total_items = bswap(read(io, @compat(UInt32))) 56 | close(io) 57 | return magic_number, @compat(Int(total_items)) 58 | end 59 | 60 | function getimage(@compat(filename::AbstractString), index::Integer) 61 | io = open(filename, "r") 62 | seek(io, IMAGEOFFSET + NROWS * NCOLS * (index - 1)) 63 | image_t = read!(io, Array{@compat(UInt8)}(undef, MNIST.NROWS, MNIST.NCOLS)) 64 | #image_t = read(io, @compat(UInt8), (MNIST.NROWS, MNIST.NCOLS)) 65 | close(io) 66 | return image_t' 67 | end 68 | 69 | function getlabel(@compat(filename::AbstractString), index::Integer) 70 | io = open(filename, "r") 71 | seek(io, LABELOFFSET + (index - 1)) 72 | label = read!(io, Array{@compat(UInt8)}(undef,1)) 73 | #label = read(io, @compat(UInt8)) 74 | close(io) 75 | return label 76 | end 77 | 78 | function trainimage(index::Integer) 79 | convert(Array{Float64}, getimage(TRAINIMAGES, index)) 80 | end 81 | 82 | function testimage(index::Integer) 83 | convert(Array{Float64}, getimage(TESTIMAGES, index)) 84 | end 85 | 86 | function trainlabel(index::Integer) 87 | convert(Float64, getlabel(TRAINLABELS, index)[1]) 88 | end 89 | 90 | function testlabel(index::Integer) 91 | convert(Float64, getlabel(TESTLABELS, index)[1]) 92 | end 93 | 94 | trainfeatures(index::Integer) = vec(trainimage(index)) 95 | 96 | testfeatures(index::Integer) = vec(testimage(index)) 97 | 98 | function traindata() 99 | _, nimages, nrows, ncols = imageheader(TRAINIMAGES) 100 | features = Array(Float64, nrows * ncols, nimages) 101 | labels = Array(Float64, nimages) 102 | for index in 1:nimages 103 | features[:, index] = trainfeatures(index) 104 | labels[index] = trainlabel(index) 105 | end 106 | return features, labels 107 | end 108 | 109 | function testdata() 110 | _, nimages, nrows, ncols = imageheader(TESTIMAGES) 111 | features = Array(Float64, nrows * ncols, nimages) 112 | labels = Array(Float64, nimages) 113 | for index in 1:nimages 114 | features[:, index] = testfeatures(index) 115 | labels[index] = testlabel(index) 116 | end 117 | return features, labels 118 | end 119 | end # module 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MLCrashCourse 2 | Julia files inspired by Google's Machine Learning Crash Course 3 | 4 | The files in this repository reproduce most of the programming exercises in Google's Machine Learning Crash Course (https://developers.google.com/machine-learning/crash-course/) using Tensorflow.jl (https://github.com/malmaud/TensorFlow.jl). An accompanying blog can be found at https://sdobber.github.io/index.html. 5 | 6 | All files have been updated to work on Julia 1.1. At the time of writing (Mar 2019), this requires the developmental versions of the ``PyCall.jl`` and ``Tensorflow.jl``packages. 7 | -------------------------------------------------------------------------------- /TFrecord Extraction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "TFrecord Extraction Blog.ipynb", 7 | "version": "0.3.2", 8 | "provenance": [], 9 | "collapsed_sections": [] 10 | } 11 | }, 12 | "cells": [ 13 | { 14 | "metadata": { 15 | "id": "s9s_oLeydCiA", 16 | "colab_type": "code", 17 | "colab": {} 18 | }, 19 | "cell_type": "code", 20 | "source": [ 21 | "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", 22 | "# you may not use this file except in compliance with the License.\n", 23 | "# You may obtain a copy of the License at\n", 24 | "#\n", 25 | "# https://www.apache.org/licenses/LICENSE-2.0\n", 26 | "#\n", 27 | "# Unless required by applicable law or agreed to in writing, software\n", 28 | "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", 29 | "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", 30 | "# See the License for the specific language governing permissions and\n", 31 | "# limitations under the License." 32 | ], 33 | "execution_count": 0, 34 | "outputs": [] 35 | }, 36 | { 37 | "metadata": { 38 | "id": "b36C-FoMIM-u", 39 | "colab_type": "text" 40 | }, 41 | "cell_type": "markdown", 42 | "source": [ 43 | "# TFrecord Extraction\n", 44 | "\n", 45 | "\n", 46 | "We will load a tfrecord dataset and get the data out to use them with some other framework, for example TensorFlow on Julia.\n", 47 | "\n", 48 | "##Prepare Packages and Parse Function" 49 | ] 50 | }, 51 | { 52 | "metadata": { 53 | "id": "Z2vRJCmjIbPu", 54 | "colab_type": "code", 55 | "colab": { 56 | "base_uri": "https://localhost:8080/", 57 | "height": 119 58 | }, 59 | "outputId": "9afad190-3019-41e6-a6e8-fef6f6aa3d19" 60 | }, 61 | "cell_type": "code", 62 | "source": [ 63 | "from __future__ import print_function\n", 64 | "\n", 65 | "import collections\n", 66 | "import io\n", 67 | "import math\n", 68 | "\n", 69 | "import matplotlib.pyplot as plt\n", 70 | "import numpy as np\n", 71 | "import pandas as pd\n", 72 | "import tensorflow as tf\n", 73 | "from IPython import display\n", 74 | "from sklearn import metrics\n", 75 | "\n", 76 | "tf.logging.set_verbosity(tf.logging.ERROR)\n", 77 | "train_url = 'https://storage.googleapis.com/mledu-datasets/sparse-data-embedding/train.tfrecord'\n", 78 | "train_path = tf.keras.utils.get_file(train_url.split('/')[-1], train_url)\n", 79 | "test_url = 'https://storage.googleapis.com/mledu-datasets/sparse-data-embedding/test.tfrecord'\n", 80 | "test_path = tf.keras.utils.get_file(test_url.split('/')[-1], test_url)" 81 | ], 82 | "execution_count": 1, 83 | "outputs": [ 84 | { 85 | "output_type": "stream", 86 | "text": [ 87 | "Downloading data from https://storage.googleapis.com/mledu-datasets/sparse-data-embedding/train.tfrecord\n", 88 | "41631744/41625533 [==============================] - 0s 0us/step\n", 89 | "41639936/41625533 [==============================] - 0s 0us/step\n", 90 | "Downloading data from https://storage.googleapis.com/mledu-datasets/sparse-data-embedding/test.tfrecord\n", 91 | "40689664/40688441 [==============================] - 0s 0us/step\n", 92 | "40697856/40688441 [==============================] - 0s 0us/step\n" 93 | ], 94 | "name": "stdout" 95 | } 96 | ] 97 | }, 98 | { 99 | "metadata": { 100 | "id": "lNIsLhoMIhy3", 101 | "colab_type": "code", 102 | "colab": {} 103 | }, 104 | "cell_type": "code", 105 | "source": [ 106 | "def _parse_function(record):\n", 107 | " \"\"\"Extracts features and labels.\n", 108 | " \n", 109 | " Args:\n", 110 | " record: File path to a TFRecord file \n", 111 | " Returns:\n", 112 | " A `tuple` `(labels, features)`:\n", 113 | " features: A dict of tensors representing the features\n", 114 | " labels: A tensor with the corresponding labels.\n", 115 | " \"\"\"\n", 116 | " features = {\n", 117 | " \"terms\": tf.VarLenFeature(dtype=tf.string), # terms are strings of varying lengths\n", 118 | " \"labels\": tf.FixedLenFeature(shape=[1], dtype=tf.float32) # labels are 0 or 1\n", 119 | " }\n", 120 | " \n", 121 | " parsed_features = tf.parse_single_example(record, features)\n", 122 | " \n", 123 | " terms = parsed_features['terms'].values\n", 124 | " labels = parsed_features['labels']\n", 125 | "\n", 126 | " return {'terms':terms}, labels" 127 | ], 128 | "execution_count": 0, 129 | "outputs": [] 130 | }, 131 | { 132 | "metadata": { 133 | "id": "r0KG0RNkb2J8", 134 | "colab_type": "text" 135 | }, 136 | "cell_type": "markdown", 137 | "source": [ 138 | "## Training Data\n", 139 | "\n", 140 | "We start with the training data." 141 | ] 142 | }, 143 | { 144 | "metadata": { 145 | "id": "IjCsierOIlT_", 146 | "colab_type": "code", 147 | "colab": {} 148 | }, 149 | "cell_type": "code", 150 | "source": [ 151 | "# Create the Dataset object.\n", 152 | "ds = tf.data.TFRecordDataset(train_path)\n", 153 | "# Map features and labels with the parse function.\n", 154 | "ds = ds.map(_parse_function)" 155 | ], 156 | "execution_count": 0, 157 | "outputs": [] 158 | }, 159 | { 160 | "metadata": { 161 | "id": "KVwiTl5eInYd", 162 | "colab_type": "code", 163 | "colab": {} 164 | }, 165 | "cell_type": "code", 166 | "source": [ 167 | "# Make a one shot iterator\n", 168 | "n = ds.make_one_shot_iterator().get_next()\n", 169 | "sess = tf.Session()" 170 | ], 171 | "execution_count": 0, 172 | "outputs": [] 173 | }, 174 | { 175 | "metadata": { 176 | "id": "ILb2K8qznWfG", 177 | "colab_type": "text" 178 | }, 179 | "cell_type": "markdown", 180 | "source": [ 181 | "Direct meta-information on the number of datasets in a ``tfrecord`` file is unfortunately not available. We use the following nice hack to get the total number of entries by iterating over the whole dataset. " 182 | ] 183 | }, 184 | { 185 | "metadata": { 186 | "id": "J_1tXFDvnQLW", 187 | "colab_type": "code", 188 | "colab": { 189 | "base_uri": "https://localhost:8080/", 190 | "height": 34 191 | }, 192 | "outputId": "6dcf978d-9e62-4464-d112-a62429eeb9b7" 193 | }, 194 | "cell_type": "code", 195 | "source": [ 196 | "sum(1 for _ in tf.python_io.tf_record_iterator(train_path))" 197 | ], 198 | "execution_count": 6, 199 | "outputs": [ 200 | { 201 | "output_type": "execute_result", 202 | "data": { 203 | "text/plain": [ 204 | "25000" 205 | ] 206 | }, 207 | "metadata": { 208 | "tags": [] 209 | }, 210 | "execution_count": 6 211 | } 212 | ] 213 | }, 214 | { 215 | "metadata": { 216 | "id": "lG2OTnlxbdgi", 217 | "colab_type": "text" 218 | }, 219 | "cell_type": "markdown", 220 | "source": [ 221 | "Now, we create two vectors to store the output labels and features. Looping over the ``tfrecord``-dataset extracts the entries." 222 | ] 223 | }, 224 | { 225 | "metadata": { 226 | "id": "TCGFkmQdJjZ0", 227 | "colab_type": "code", 228 | "colab": {} 229 | }, 230 | "cell_type": "code", 231 | "source": [ 232 | "output_features=[]\n", 233 | "output_labels=[]\n", 234 | "\n", 235 | "for i in range(0,24999):\n", 236 | " value=sess.run(n)\n", 237 | " output_features.append(value[0]['terms'])\n", 238 | " output_labels.append(value[1])" 239 | ], 240 | "execution_count": 0, 241 | "outputs": [] 242 | }, 243 | { 244 | "metadata": { 245 | "id": "4QJINDWHSVPy", 246 | "colab_type": "text" 247 | }, 248 | "cell_type": "markdown", 249 | "source": [ 250 | "### Export to File\n", 251 | "\n", 252 | "We create a file to export using the h5py package." 253 | ] 254 | }, 255 | { 256 | "metadata": { 257 | "id": "crZXrT6KOPVD", 258 | "colab_type": "code", 259 | "colab": {} 260 | }, 261 | "cell_type": "code", 262 | "source": [ 263 | "import h5py" 264 | ], 265 | "execution_count": 0, 266 | "outputs": [] 267 | }, 268 | { 269 | "metadata": { 270 | "id": "ulLIGupVO-wM", 271 | "colab_type": "code", 272 | "colab": {} 273 | }, 274 | "cell_type": "code", 275 | "source": [ 276 | "dt = h5py.special_dtype(vlen=str)\n", 277 | "\n", 278 | "h5f = h5py.File('train_data.h5', 'w')\n", 279 | "h5f.create_dataset('output_features', data=output_features, dtype=dt)\n", 280 | "h5f.create_dataset('output_labels', data=output_labels)\n", 281 | "h5f.close()" 282 | ], 283 | "execution_count": 0, 284 | "outputs": [] 285 | }, 286 | { 287 | "metadata": { 288 | "id": "KupXUjS-b0NE", 289 | "colab_type": "text" 290 | }, 291 | "cell_type": "markdown", 292 | "source": [ 293 | "## Test Data\n", 294 | "\n", 295 | "We do a similar action on the test data." 296 | ] 297 | }, 298 | { 299 | "metadata": { 300 | "id": "tkxCqeH_bzqp", 301 | "colab_type": "code", 302 | "colab": {} 303 | }, 304 | "cell_type": "code", 305 | "source": [ 306 | "# Create the Dataset object.\n", 307 | "ds = tf.data.TFRecordDataset(test_path)\n", 308 | "# Map features and labels with the parse function.\n", 309 | "ds = ds.map(_parse_function)" 310 | ], 311 | "execution_count": 0, 312 | "outputs": [] 313 | }, 314 | { 315 | "metadata": { 316 | "id": "KKgsxkyIcNln", 317 | "colab_type": "code", 318 | "colab": {} 319 | }, 320 | "cell_type": "code", 321 | "source": [ 322 | "n = ds.make_one_shot_iterator().get_next()\n", 323 | "sess = tf.Session()" 324 | ], 325 | "execution_count": 0, 326 | "outputs": [] 327 | }, 328 | { 329 | "metadata": { 330 | "id": "13GV5BjzbV5k", 331 | "colab_type": "text" 332 | }, 333 | "cell_type": "markdown", 334 | "source": [ 335 | "The total number of datasets is" 336 | ] 337 | }, 338 | { 339 | "metadata": { 340 | "id": "WgoUMbt3bZKj", 341 | "colab_type": "code", 342 | "colab": { 343 | "base_uri": "https://localhost:8080/", 344 | "height": 34 345 | }, 346 | "outputId": "80173c90-4cf4-4a1b-f5a2-163d1a92f884" 347 | }, 348 | "cell_type": "code", 349 | "source": [ 350 | "sum(1 for _ in tf.python_io.tf_record_iterator(test_path))" 351 | ], 352 | "execution_count": 7, 353 | "outputs": [ 354 | { 355 | "output_type": "execute_result", 356 | "data": { 357 | "text/plain": [ 358 | "25000" 359 | ] 360 | }, 361 | "metadata": { 362 | "tags": [] 363 | }, 364 | "execution_count": 7 365 | } 366 | ] 367 | }, 368 | { 369 | "metadata": { 370 | "id": "8hqCiRuMbzZv", 371 | "colab_type": "code", 372 | "colab": {} 373 | }, 374 | "cell_type": "code", 375 | "source": [ 376 | "output_features=[]\n", 377 | "output_labels=[]\n", 378 | "\n", 379 | "for i in range(0,24999):\n", 380 | " value=sess.run(n)\n", 381 | " output_features.append(value[0]['terms'])\n", 382 | " output_labels.append(value[1])" 383 | ], 384 | "execution_count": 0, 385 | "outputs": [] 386 | }, 387 | { 388 | "metadata": { 389 | "id": "IOtz08uKcD-i", 390 | "colab_type": "text" 391 | }, 392 | "cell_type": "markdown", 393 | "source": [ 394 | "### Export to file" 395 | ] 396 | }, 397 | { 398 | "metadata": { 399 | "id": "XVhctiY-cOUz", 400 | "colab_type": "code", 401 | "colab": {} 402 | }, 403 | "cell_type": "code", 404 | "source": [ 405 | "dt = h5py.special_dtype(vlen=str)\n", 406 | "\n", 407 | "h5f = h5py.File('test_data.h5', 'w')\n", 408 | "h5f.create_dataset('output_features', data=output_features, dtype=dt)\n", 409 | "h5f.create_dataset('output_labels', data=output_labels)\n", 410 | "h5f.close()" 411 | ], 412 | "execution_count": 0, 413 | "outputs": [] 414 | }, 415 | { 416 | "metadata": { 417 | "id": "BpOaFRMRSXWa", 418 | "colab_type": "text" 419 | }, 420 | "cell_type": "markdown", 421 | "source": [ 422 | "## Google Drive Export\n", 423 | "\n", 424 | "Finally, we export the two files containing the training and test data to Google Drive. If necessary, intall the PyDrive package using ``!pip install -U -q PyDrive``. The folder-id is the string of letters and numbers that can be seen in your browser URL after ``https://drive.google.com/drive/u/0/folders/`` when accessing the desired folder." 425 | ] 426 | }, 427 | { 428 | "metadata": { 429 | "id": "5S4tUjTfTQHe", 430 | "colab_type": "code", 431 | "colab": {} 432 | }, 433 | "cell_type": "code", 434 | "source": [ 435 | "!pip install -U -q PyDrive" 436 | ], 437 | "execution_count": 0, 438 | "outputs": [] 439 | }, 440 | { 441 | "metadata": { 442 | "id": "2Q5uOqhlQJZE", 443 | "colab_type": "code", 444 | "colab": {} 445 | }, 446 | "cell_type": "code", 447 | "source": [ 448 | "from pydrive.auth import GoogleAuth\n", 449 | "from pydrive.drive import GoogleDrive\n", 450 | "from google.colab import auth\n", 451 | "from oauth2client.client import GoogleCredentials\n", 452 | "\n", 453 | "# Authenticate and create the PyDrive client.\n", 454 | "auth.authenticate_user()\n", 455 | "gauth = GoogleAuth()\n", 456 | "gauth.credentials = GoogleCredentials.get_application_default() \n", 457 | "drive = GoogleDrive(gauth)\n", 458 | "\n", 459 | "# PyDrive reference:\n", 460 | "# https://googledrive.github.io/PyDrive/docs/build/html/index.html" 461 | ], 462 | "execution_count": 0, 463 | "outputs": [] 464 | }, 465 | { 466 | "metadata": { 467 | "id": "REoT58sUS4Kw", 468 | "colab_type": "code", 469 | "colab": {} 470 | }, 471 | "cell_type": "code", 472 | "source": [ 473 | "# Adjust the id to the folder of your choice in Google Drive\n", 474 | "# Use `file = drive.CreateFile()` to write to root directory\n", 475 | "file = drive.CreateFile({'parents':[{\"id\": \"insert_folder_id\"}]})\n", 476 | "file.SetContentFile('train_data.h5')\n", 477 | "file.Upload()" 478 | ], 479 | "execution_count": 0, 480 | "outputs": [] 481 | }, 482 | { 483 | "metadata": { 484 | "id": "WGwibnA8TuDe", 485 | "colab_type": "code", 486 | "colab": {} 487 | }, 488 | "cell_type": "code", 489 | "source": [ 490 | "# Adjust the id to the folder of your choice in Google Drive\n", 491 | "# Use `file = drive.CreateFile()` to write to root directory\n", 492 | "file = drive.CreateFile({'parents':[{\"id\": \"insert_folder_id\"}]})\n", 493 | "file.SetContentFile('test_data.h5')\n", 494 | "file.Upload()" 495 | ], 496 | "execution_count": 0, 497 | "outputs": [] 498 | } 499 | ] 500 | } --------------------------------------------------------------------------------