|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "colab_type": "text", |
| 7 | + "id": "7yuytuIllsv1" |
| 8 | + }, |
| 9 | + "source": [ |
| 10 | + "# Trax Layers\n", |
| 11 | + "\n", |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": 1, |
| 17 | + "metadata": { |
| 18 | + "colab": { |
| 19 | + "height": 119 |
| 20 | + }, |
| 21 | + "colab_type": "code", |
| 22 | + "executionInfo": { |
| 23 | + "elapsed": 88481, |
| 24 | + "status": "ok", |
| 25 | + "timestamp": 1563927238895, |
| 26 | + "user": { |
| 27 | + "displayName": "Lukasz Kaiser", |
| 28 | + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mC8pChl87HbK_eOtVhtNPwUVx8btvfyYzH9UHn3=s64", |
| 29 | + "userId": "13267693649565518272" |
| 30 | + }, |
| 31 | + "user_tz": 420 |
| 32 | + }, |
| 33 | + "id": "oILRLCWN_16u", |
| 34 | + "outputId": "3f750014-c633-4162-ad07-f3c56c273304" |
| 35 | + }, |
| 36 | + "outputs": [ |
| 37 | + { |
| 38 | + "name": "stdout", |
| 39 | + "output_type": "stream", |
| 40 | + "text": [ |
| 41 | + "T2T: skipped importing 1 data_generators modules. OK if no other errors. Depend on _heavy or problem-specific py_binary targets if trying to use a module that was skipped.\n" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "name": "stderr", |
| 46 | + "output_type": "stream", |
| 47 | + "text": [ |
| 48 | + "matplotlib.use() must be called *before* pylab, matplotlib.pyplot,\n", |
| 49 | + "or matplotlib.backends is imported for the first time.\n", |
| 50 | + "\n" |
| 51 | + ] |
| 52 | + } |
| 53 | + ], |
| 54 | + "source": [ |
| 55 | + "#@title Licence and python imports.\n", |
| 56 | + "# Copyright 2018 Google LLC.\n", |
| 57 | + "\n", |
| 58 | + "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", |
| 59 | + "# you may not use this file except in compliance with the License.\n", |
| 60 | + "# You may obtain a copy of the License at\n", |
| 61 | + "\n", |
| 62 | + "# https://www.apache.org/licenses/LICENSE-2.0\n", |
| 63 | + "\n", |
| 64 | + "# Unless required by applicable law or agreed to in writing, software\n", |
| 65 | + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", |
| 66 | + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", |
| 67 | + "# See the License for the specific language governing permissions and\n", |
| 68 | + "# limitations under the License.\n", |
| 69 | + "\n", |
| 70 | + "import datetime\n", |
| 71 | + "import numpy as onp\n", |
| 72 | + "\n", |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + "cell_type": "code", |
| 77 | + "execution_count": 5, |
| 78 | + "metadata": { |
| 79 | + "cellView": "both", |
| 80 | + "colab": { |
| 81 | + "height": 51 |
| 82 | + }, |
| 83 | + "colab_type": "code", |
| 84 | + "executionInfo": { |
| 85 | + "elapsed": 2992, |
| 86 | + "status": "ok", |
| 87 | + "timestamp": 1563927313403, |
| 88 | + "user": { |
| 89 | + "displayName": "Lukasz Kaiser", |
| 90 | + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mC8pChl87HbK_eOtVhtNPwUVx8btvfyYzH9UHn3=s64", |
| 91 | + "userId": "13267693649565518272" |
| 92 | + }, |
| 93 | + "user_tz": 420 |
| 94 | + }, |
| 95 | + "id": "vlGjGoGMTt-D", |
| 96 | + "outputId": "7a7b5a1e-c01e-4a5e-eeb1-a88d9500aad4" |
| 97 | + }, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "name": "stdout", |
| 101 | + "output_type": "stream", |
| 102 | + "text": [ |
| 103 | + "/bin/sh: pip: command not found\n", |
| 104 | + "/bin/sh: pip: command not found\n" |
| 105 | + ] |
| 106 | + } |
| 107 | + ], |
| 108 | + "source": [ |
| 109 | + "#@title Install TensorFlow, Tensor2Tensor and Trax.\n", |
| 110 | + "\n", |
| 111 | + "! pip install -q tensorflow\n", |
| 112 | + "! pip install -q -U tensor2tensor\n", |
| 113 | + "\n", |
| 114 | + "from tensor2tensor.trax import trax\n", |
| 115 | + "from tensor2tensor.trax import backend\n", |
| 116 | + "from tensor2tensor.trax import layers as tl" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": 6, |
| 122 | + "metadata": { |
| 123 | + "colab": { |
| 124 | + "height": 68 |
| 125 | + }, |
| 126 | + "colab_type": "code", |
| 127 | + "executionInfo": { |
| 128 | + "elapsed": 434, |
| 129 | + "status": "ok", |
| 130 | + "timestamp": 1563927323194, |
| 131 | + "user": { |
| 132 | + "displayName": "Lukasz Kaiser", |
| 133 | + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mC8pChl87HbK_eOtVhtNPwUVx8btvfyYzH9UHn3=s64", |
| 134 | + "userId": "13267693649565518272" |
| 135 | + }, |
| 136 | + "user_tz": 420 |
| 137 | + }, |
| 138 | + "id": "V09viOSEQvQe", |
| 139 | + "outputId": "822ec44b-1e2e-4b6e-9fc7-9fc29f5d3783" |
| 140 | + }, |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "name": "stdout", |
| 144 | + "output_type": "stream", |
| 145 | + "text": [ |
| 146 | + "[[-7 -6 -5 -4 -3]\n", |
| 147 | + " [-2 -1 0 1 2]\n", |
| 148 | + " [ 3 4 5 6 7]]\n", |
| 149 | + "[[0 0 0 0 0]\n", |
| 150 | + " [0 0 0 1 2]\n", |
| 151 | + " [3 4 5 6 7]]\n" |
| 152 | + ] |
| 153 | + } |
| 154 | + ], |
| 155 | + "source": [ |
| 156 | + "x = onp.arange(-7, 8).reshape(3, -1)\n", |
| 157 | + "rng = backend.random.get_prng(0)\n", |
| 158 | + "layer = tl.Relu()\n", |
| 159 | + "params = layer.initialize(x.shape, x.dtype, rng)\n", |
| 160 | + "output = layer(x, params, rng=rng)\n", |
| 161 | + "print(x)\n", |
| 162 | + "print(output)" |
| 163 | + ] |
| 164 | + } |
| 165 | + ], |
| 166 | + "metadata": { |
| 167 | + "colab": { |
| 168 | + "collapsed_sections": [], |
| 169 | + "last_runtime": { |
| 170 | + "build_target": "//learning/deepmind/dm_python:dm_notebook", |
| 171 | + "kind": "private" |
| 172 | + }, |
| 173 | + "name": "Trax Layers", |
| 174 | + "provenance": [ |
| 175 | + { |
| 176 | + "file_id": "1EH76AWQ_pvT4i8ZXfkv-SCV4MrmllEl5", |
| 177 | + "timestamp": 1563927451951 |
| 178 | + } |
| 179 | + ], |
| 180 | + "version": "0.3.2" |
| 181 | + }, |
| 182 | + "kernelspec": { |
| 183 | + "display_name": "Python 2", |
| 184 | + "name": "python2" |
| 185 | + } |
| 186 | + }, |
| 187 | + "nbformat": 4, |
| 188 | + "nbformat_minor": 0 |
| 189 | +} |
0 commit comments