Sequential Models

Overview


The sequential model is the basic model of a neural network, that is, it consists of layers of inputs, weights, an activation function, and a set of outputs, which feeds the next input.

Applying to Inputs


To run the model on a set of inputs to see the outputs, use the predict method.


let output = model.predict(tf.tensor([[4,6]]));
				
Try it!

This will return a tensor, which can be converted to an array using Tensor-Flow utility

Linear Example


The following example demonstrates calculating the value of a linear model
{% y = \beta_1 x_x + \beta_2 x_2 + \beta_3 x_3 + \beta_4 x_4 %}



//load tensor flow library
await $src('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest');
let ut = await import('/lib/tensor-flow/util/v1.0.0/util.mjs');
	
const model = tf.sequential({
  layers:[
    tf.layers.dense({
      inputShape:[4],
      units:1,
    }),
  ]
});
	
let input = tf.tensor([[1, 2, 1, 1]]);
let output = model.predict(input);
let weights = await ut.weights(model,0);
let matrix = await ut.toArray(output);
				
Try it!

Contents