Python Tutorial: Keras input and dense layers

Zach Dean Mayer teaches how to build Keras models using the Functional API, starting with Input and Dense layers. He uses college basketball datasets with features like team IDs and seed differences, then shows how to define an input layer with keras.layers.Input and create output tensors, emphasizing the distinction between layers as architecture and tensors as data flow.
Chapters
Hi, I'm Zach Dean Mayer, and in this course I'll be teaching you advanced deep learning concepts. Using the Keras Functional API. You will learn how to build functional Keras models, including advanced topics such as shared layers, categorical embeddings, multiple inputs and multiple outputs. The Keras Functional API is extremely simple, yet immensely powerful. By the end of this class you will build a model that is capable of solving a regression and a classification problem at the same time. Chapter one is a refresher on building simple models where you will learn how to use the Keras Functional API. In chapter two, you will build a Keras model with two inputs. In chapter three, you will learn how to generalize your two input model to three or more inputs. And finally in chapter four, you will build models with multiple outputs that can solve multiple problems. You will be using two data sets of college basketball games from American colleges. The first data set is from the regular season and has the following the IDs of the two teams that played, whether the first team was home or away, whether the first team won or lost the game, and by how many points the first team won or lost. For the tournament data set, you also have the tournament seed, which is a pre tournament ranking for each team. These seeds range from one to 16, where the best four teams get a seed of one and the worst four teams get a seed of 16. You will use the difference in the two team seeds as an input to your model. Here are the first five rows of both the data sets. You can see that the team variables are encoded as integers and the tournament data set has one additional column, the difference between the tournament seeds for both teams. Other than the seed difference, the two data sets have identical columns. Within a given year, a team's roster stays relatively constant, but between years it can change a lot as seniors graduate and freshmen start. Therefore, for every year, each school is given a unique integer id. Keras models at their simplest are fundamentally composed of two parts, an input layer and an output layer. To start, I'll define a very simple Keras model which only expects a single input. I'll specify this using the input function from the Keras Layers module. The number of columns in the input is specified using the shape parameter. This tells the model how much data to expect. Note that the shape argument expects a tuple. The input function returns a tensor. If you print this tensor, you'll see that it is a TF tensor object, which indicates it is ready to be used by our model as input. Now that we've defined our input layer let's define the output layer. Outputs in KERAS are most commonly a single dense layer which specifies the shape of the expected output. In this case, we are expecting our model to predict a single value, so we pass one unit to the dense layer. If you print the output layer, the result is not a tensorflow tensor. It is a function which takes a tensor as input and produces a tensor as output. The difference between layers and tensors is key to understanding the Keras functional API. Layers are used to construct a deep learning model, and tensors are used to define the data flow through the model. In this case, the input layer defines a tensor, which we then pass to the output layer function. The final output of our model is a tensor. It is time for you to build some layers.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







