Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,65 +167,29 @@
"\n",
"Next, create the model. We will use the simplest possible model we can, a Dense network. Since the problem is straightforward, this network will require only a single layer, with a single neuron.\n",
"\n",
"### Build a layer\n",
"### Build a layer and Assemble it into the model\n",
"\n",
"We'll call the layer `l0` and create it by instantiating `tf.keras.layers.Dense` with the following configuration:\n",
"\n",
"* `input_shape=[1]` — This specifies that the input to this layer is a single value. That is, the shape is a one-dimensional array with one member. Since this is the first (and only) layer, that input shape is the input shape of the entire model. The single value is a floating point number, representing degrees Celsius.\n",
"\n",
"* `units=1` — This specifies the number of neurons in the layer. The number of neurons defines how many internal variables the layer has to try to learn how to solve the problem (more later). Since this is the final layer, it is also the size of the model's output — a single float value representing degrees Fahrenheit. (In a multi-layered network, the size and shape of the layer would need to match the `input_shape` of the next layer.)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "pRllo2HLfXiu"
},
"outputs": [],
"source": [
"l0 = tf.keras.layers.Dense(units=1, input_shape=[1])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_F00_J9duLBD"
},
"source": [
"### Assemble layers into the model\n",
"\n",
"Once layers are defined, they need to be assembled into a model. The Sequential model definition takes a list of layers as an argument, specifying the calculation order from the input to the output.\n",
"* `units=1` — This specifies the number of neurons in the layer. The number of neurons defines how many internal variables the layer has to try to learn how to solve the problem (more later). Since this is the final layer, it is also the size of the model's output — a single float value representing degrees Fahrenheit. (In a multi-layered network, the size and shape of the layer would need to match the `input_shape` of the next layer.)\n",
"\n",
"This model has just a single layer, l0."
"* Once layers are defined, they need to be assembled into a model. The Sequential model definition takes a list of layers as an argument, specifying the calculation order from the input to the output."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cSp-GpLSuMRq"
"id": "pRllo2HLfXiu"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential([l0])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "t7pfHfWxust0"
},
"source": [
"**Note**\n",
"\n",
"You will often see the layers defined inside the model definition, rather than beforehand:\n",
"\n",
"```python\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Dense(units=1, input_shape=[1])\n",
"])\n",
"```"
" tf.keras.Input(shape=(1,)),\n",
" tf.keras.layers.Dense(units=1)\n",
"])"
]
},
{
Expand Down
Loading