Format: application/octet-stream
⬇ Download File (5.1 KB)
   1  {
   2    "nbformat": 4,
   3    "nbformat_minor": 0,
   4    "metadata": {
   5      "accelerator": "GPU",
   6      "colab": {
   7        "name": "S+P Week 2 Lesson 1.ipynb",
   8        "provenance": [],
   9        "toc_visible": true
  10      },
  11      "kernelspec": {
  12        "display_name": "Python 3",
  13        "name": "python3"
  14      }
  15    },
  16    "cells": [
  17      {
  18        "cell_type": "code",
  19        "metadata": {
  20          "id": "zX4Kg8DUTKWO"
  21        },
  22        "source": [
  23          "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
  24          "# you may not use this file except in compliance with the License.\n",
  25          "# You may obtain a copy of the License at\n",
  26          "#\n",
  27          "# https://www.apache.org/licenses/LICENSE-2.0\n",
  28          "#\n",
  29          "# Unless required by applicable law or agreed to in writing, software\n",
  30          "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
  31          "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
  32          "# See the License for the specific language governing permissions and\n",
  33          "# limitations under the License."
  34        ],
  35        "execution_count": null,
  36        "outputs": []
  37      },
  38      {
  39        "cell_type": "code",
  40        "metadata": {
  41          "id": "s6eq-RBcQ_Zr"
  42        },
  43        "source": [
  44          "try:\n",
  45          "  # %tensorflow_version only exists in Colab.\n",
  46          "  %tensorflow_version 2.x\n",
  47          "except Exception:\n",
  48          "  pass"
  49        ],
  50        "execution_count": null,
  51        "outputs": []
  52      },
  53      {
  54        "cell_type": "code",
  55        "metadata": {
  56          "id": "BOjujz601HcS"
  57        },
  58        "source": [
  59          "import tensorflow as tf\n",
  60          "import numpy as np\n",
  61          "import matplotlib.pyplot as plt\n",
  62          "print(tf.__version__)"
  63        ],
  64        "execution_count": null,
  65        "outputs": []
  66      },
  67      {
  68        "cell_type": "code",
  69        "metadata": {
  70          "id": "asEdslR_05O_"
  71        },
  72        "source": [
  73          "dataset = tf.data.Dataset.range(10)\n",
  74          "for val in dataset:\n",
  75          "   print(val.numpy())"
  76        ],
  77        "execution_count": null,
  78        "outputs": []
  79      },
  80      {
  81        "cell_type": "code",
  82        "metadata": {
  83          "id": "Lrv_ghSt1lgQ"
  84        },
  85        "source": [
  86          "dataset = tf.data.Dataset.range(10)\n",
  87          "dataset = dataset.window(5, shift=1)\n",
  88          "for window_dataset in dataset:\n",
  89          "  for val in window_dataset:\n",
  90          "    print(val.numpy(), end=\" \")\n",
  91          "  print()"
  92        ],
  93        "execution_count": null,
  94        "outputs": []
  95      },
  96      {
  97        "cell_type": "code",
  98        "metadata": {
  99          "id": "QLEq6MG-2DN2"
 100        },
 101        "source": [
 102          "dataset = tf.data.Dataset.range(10)\n",
 103          "dataset = dataset.window(5, shift=1, drop_remainder=True)\n",
 104          "for window_dataset in dataset:\n",
 105          "  for val in window_dataset:\n",
 106          "    print(val.numpy(), end=\" \")\n",
 107          "  print()"
 108        ],
 109        "execution_count": null,
 110        "outputs": []
 111      },
 112      {
 113        "cell_type": "code",
 114        "metadata": {
 115          "id": "PJ9CAHlJ2ODe"
 116        },
 117        "source": [
 118          "dataset = tf.data.Dataset.range(10)\n",
 119          "dataset = dataset.window(5, shift=1, drop_remainder=True)\n",
 120          "dataset = dataset.flat_map(lambda window: window.batch(5))\n",
 121          "for window in dataset:\n",
 122          "  print(window.numpy())\n"
 123        ],
 124        "execution_count": null,
 125        "outputs": []
 126      },
 127      {
 128        "cell_type": "code",
 129        "metadata": {
 130          "id": "DryEZ2Mz2nNV"
 131        },
 132        "source": [
 133          "dataset = tf.data.Dataset.range(10)\n",
 134          "dataset = dataset.window(5, shift=1, drop_remainder=True)\n",
 135          "dataset = dataset.flat_map(lambda window: window.batch(5))\n",
 136          "dataset = dataset.map(lambda window: (window[:-1], window[-1:]))\n",
 137          "for x,y in dataset:\n",
 138          "  print(x.numpy(), y.numpy())"
 139        ],
 140        "execution_count": null,
 141        "outputs": []
 142      },
 143      {
 144        "cell_type": "code",
 145        "metadata": {
 146          "id": "1tl-0BOKkEtk"
 147        },
 148        "source": [
 149          "dataset = tf.data.Dataset.range(10)\n",
 150          "dataset = dataset.window(5, shift=1, drop_remainder=True)\n",
 151          "dataset = dataset.flat_map(lambda window: window.batch(5))\n",
 152          "dataset = dataset.map(lambda window: (window[:-1], window[-1:]))\n",
 153          "dataset = dataset.shuffle(buffer_size=10)\n",
 154          "for x,y in dataset:\n",
 155          "  print(x.numpy(), y.numpy())\n"
 156        ],
 157        "execution_count": null,
 158        "outputs": []
 159      },
 160      {
 161        "cell_type": "code",
 162        "metadata": {
 163          "id": "Wa0PNwxMGapy"
 164        },
 165        "source": [
 166          "dataset = tf.data.Dataset.range(10)\n",
 167          "dataset = dataset.window(5, shift=1, drop_remainder=True)\n",
 168          "dataset = dataset.flat_map(lambda window: window.batch(5))\n",
 169          "dataset = dataset.map(lambda window: (window[:-1], window[-1:]))\n",
 170          "dataset = dataset.shuffle(buffer_size=10)\n",
 171          "dataset = dataset.batch(2).prefetch(1)\n",
 172          "for x,y in dataset:\n",
 173          "  print(\"x = \", x.numpy())\n",
 174          "  print(\"y = \", y.numpy())\n"
 175        ],
 176        "execution_count": null,
 177        "outputs": []
 178      }
 179    ]
 180  }