|
44 | 44 | "source": [ |
45 | 45 | "import os\n", |
46 | 46 | "\n", |
47 | | - "os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"2\"\n", |
| 47 | + "os.environ[\"KERAS_BACKEND\"] = \"tensorflow\"\n", |
48 | 48 | "\n", |
| 49 | + "import keras\n", |
49 | 50 | "import matplotlib as mpl\n", |
50 | 51 | "import matplotlib.pyplot as plt\n", |
51 | 52 | "import numpy as np\n", |
52 | 53 | "import pandas as pd\n", |
53 | | - "import tensorflow as tf\n", |
54 | 54 | "from google.cloud import bigquery\n", |
55 | | - "from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard\n", |
56 | | - "from tensorflow.keras.layers import (\n", |
| 55 | + "from keras.layers import (\n", |
57 | 56 | " GRU,\n", |
58 | 57 | " LSTM,\n", |
59 | 58 | " RNN,\n", |
60 | 59 | " Bidirectional,\n", |
61 | 60 | " Conv1D,\n", |
62 | 61 | " Dense,\n", |
| 62 | + " Flatten,\n", |
63 | 63 | " MaxPool1D,\n", |
64 | 64 | " Reshape,\n", |
65 | 65 | ")\n", |
66 | | - "from tensorflow.keras.models import Sequential\n", |
67 | | - "from tensorflow.keras.optimizers import Adam\n", |
68 | | - "from tensorflow.keras.utils import to_categorical\n", |
| 66 | + "from keras.models import Sequential\n", |
| 67 | + "from keras.optimizers import Adam\n", |
| 68 | + "from keras.regularizers import L1\n", |
69 | 69 | "\n", |
70 | 70 | "# To plot pretty figures\n", |
71 | 71 | "%matplotlib inline\n", |
|
76 | 76 | "# For reproducible results.\n", |
77 | 77 | "from numpy.random import seed\n", |
78 | 78 | "\n", |
79 | | - "seed(1)\n", |
80 | | - "tf.random.set_seed(2)" |
| 79 | + "seed(1)" |
81 | 80 | ] |
82 | 81 | }, |
83 | 82 | { |
|
420 | 419 | "ytrain = Xtrain.pop(LABEL)\n", |
421 | 420 | "yvalid = Xvalid.pop(LABEL)\n", |
422 | 421 | "\n", |
423 | | - "ytrain_categorical = to_categorical(ytrain.values)\n", |
424 | | - "yvalid_categorical = to_categorical(yvalid.values)" |
| 422 | + "ytrain_categorical = keras.utils.to_categorical(ytrain.values)\n", |
| 423 | + "yvalid_categorical = keras.utils.to_categorical(yvalid.values)" |
425 | 424 | ] |
426 | 425 | }, |
427 | 426 | { |
|
504 | 503 | "cell_type": "markdown", |
505 | 504 | "metadata": {}, |
506 | 505 | "source": [ |
507 | | - "**Lab Task #1a:** In the cell below, create a linear model using the [keras sequential API](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential) which maps the sequential input to a single dense fully connected layer." |
| 506 | + "**Lab Task #1a:** In the cell below, create a linear model using the [keras sequential API](https://keras.io/api/models/sequential/) which maps the sequential input to a single dense fully connected layer." |
508 | 507 | ] |
509 | 508 | }, |
510 | 509 | { |
|
639 | 638 | "\n", |
640 | 639 | "The DNN does slightly better. Let's see how a convolutional neural network performs. \n", |
641 | 640 | "\n", |
642 | | - "A 1-dimensional convolutional can be useful for extracting features from sequential data or deriving features from shorter, fixed-length segments of the data set. Check out the documentation for how to implement a [Conv1d in Tensorflow](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv1D). Max pooling is a downsampling strategy commonly used in conjunction with convolutional neural networks. Next, we'll build a CNN model in keras using the `Conv1D` to create convolution layers and `MaxPool1D` to perform max pooling before passing to a fully connected dense layer. " |
| 641 | + "A 1-dimensional convolutional can be useful for extracting features from sequential data or deriving features from shorter, fixed-length segments of the data set. Check out the documentation for how to implement a [Conv1d in Keras](https://keras.io/api/layers/convolution_layers/convolution1d/). Max pooling is a downsampling strategy commonly used in conjunction with convolutional neural networks. Next, we'll build a CNN model in keras using the `Conv1D` to create convolution layers and `MaxPool1D` to perform max pooling before passing to a fully connected dense layer. " |
643 | 642 | ] |
644 | 643 | }, |
645 | 644 | { |
|
712 | 711 | "cell_type": "markdown", |
713 | 712 | "metadata": {}, |
714 | 713 | "source": [ |
715 | | - "**Lab Task #2a:** Create an RNN model in keras. You can try different types of RNN cells like [LSTMs](https://www.tensorflow.org/api_docs/python/tf/keras/layers/LSTM), \n", |
716 | | - "[GRUs](https://www.tensorflow.org/api_docs/python/tf/keras/layers/GRU) or basic [RNN cell](https://www.tensorflow.org/api_docs/python/tf/keras/layers/SimpleRNN). Experiment with different cell sizes, activation functions, regularization, etc." |
| 714 | + "**Lab Task #2a:** Create an RNN model in keras. You can try different types of RNN cells like [LSTMs](https://keras.io/api/layers/recurrent_layers/lstm/), \n", |
| 715 | + "[GRUs](https://keras.io/api/layers/recurrent_layers/gru/) or basic [RNN cell](https://keras.io/api/layers/recurrent_layers/simple_rnn_cell/). Experiment with different cell sizes, activation functions, regularization, etc." |
717 | 716 | ] |
718 | 717 | }, |
719 | 718 | { |
|
975 | 974 | "cell_type": "markdown", |
976 | 975 | "metadata": {}, |
977 | 976 | "source": [ |
978 | | - "Copyright 2019 Google Inc. Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License" |
| 977 | + "Copyright 2025 Google Inc. Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License" |
979 | 978 | ] |
| 979 | + }, |
| 980 | + { |
| 981 | + "cell_type": "code", |
| 982 | + "execution_count": null, |
| 983 | + "metadata": {}, |
| 984 | + "outputs": [], |
| 985 | + "source": [] |
980 | 986 | } |
981 | 987 | ], |
982 | 988 | "metadata": { |
983 | 989 | "environment": { |
984 | 990 | "kernel": "conda-base-py", |
985 | | - "name": "workbench-notebooks.m121", |
| 991 | + "name": "workbench-notebooks.m132", |
986 | 992 | "type": "gcloud", |
987 | | - "uri": "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/workbench-notebooks:m121" |
| 993 | + "uri": "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/workbench-notebooks:m132" |
988 | 994 | }, |
989 | 995 | "kernelspec": { |
990 | 996 | "display_name": "Python 3 (ipykernel) (Local)", |
|
1001 | 1007 | "name": "python", |
1002 | 1008 | "nbconvert_exporter": "python", |
1003 | 1009 | "pygments_lexer": "ipython3", |
1004 | | - "version": "3.10.14" |
| 1010 | + "version": "3.10.18" |
1005 | 1011 | } |
1006 | 1012 | }, |
1007 | 1013 | "nbformat": 4, |
|
0 commit comments