Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TensorFlow · Function

keras.Input

Creates a symbolic Keras tensor that starts a Functional API graph. Specify sample shape, dtype, batching, sparsity, and optionally a name or existing tensor.

How it works

tf.keras.Input creates a symbolic Keras tensor that records the expected sample shape and dtype. Use that tensor as the starting node for Functional API graphs, then pass the input and resulting output to tf.keras.Model.

Syntax

tf.keras.Input(shape=None, batch_size=None, dtype=None, sparse=None, batch_shape=None, name=None, tensor=None)

Parameters

NameTypeDescription
shapetuple of integers or NonePer-sample shape tuple, excluding the batch dimension; dimensions may be None.
batch_sizeintegerOptional fixed batch size.
dtypestringExpected input data type, such as float32 or int32.
sparsebooleanWhether the expected input is sparse; defaults to False.
batch_shapetupleComplete input shape, including the batch dimension.
namestringOptional unique layer name; autogenerated if omitted.
tensortensorExisting tensor to wrap rather than creating a new placeholder.

Returns

A Keras tensor.

Key points

  • The function creates the symbolic starting tensor for a Keras Functional API model.
  • The returned object carries graph-building metadata, allowing model construction from connected symbolic tensors.
  • Provide per-sample dimensions in shape; for example, shape=(32,) declares 32 features per sample.
  • Use None in shape for dimensions that can vary, such as sequence length.
  • batch_size fixes the number of samples in each input batch when a static batch dimension is desired.
  • tensor lets the input layer wrap an existing tensor instead of creating a new placeholder.

Common mistakes

  • If supplying name, make it unique within the model.
  • The sparse-input option is backend-specific; do not assume it works with every Keras backend.

Example: Build a Functional API model

import tensorflow as tf

inputs = tf.keras.Input(shape=(4,), name="features")
x = tf.keras.layers.Dense(8, activation="relu")(inputs)
outputs = tf.keras.layers.Dense(1)(x)
model = tf.keras.Model(inputs, outputs)

print(model.input_shape)  # (None, 4)

Creates a symbolic four-feature input and connects it to a small Functional API model.

When to use it

Functional model construction

Define the entry node of a graph assembled from layers and models.

Variable-size inputs

Accept sequences or other data with a dimension determined at runtime.

Named and multi-input graphs

Build models whose inputs have explicit names or multiple feature branches.

Interview questions

QWhat does tf.keras.Input create, and why is it useful?

tf.keras.Input creates a symbolic Keras tensor used to define a Functional API graph. It describes the input structure without representing a concrete data batch.

Follow-up: How would you represent a variable-length sequence? Use shape=(None,), leaving the sequence-length dimension unknown.

QHow are shape and batch dimensions handled?

shape describes one sample and excludes the batch dimension. For shape=(32,), the model expects batches whose samples are 32-dimensional vectors, with an unspecified batch size by default.

Follow-up: How can you make the batch dimension static? Supply batch_size, or specify the complete shape with batch_shape.

QWhat do dtype and sparse control?

dtype sets the expected input data type, while sparse indicates whether the expected input is sparse. If sparse is False, sparse tensors may still be supplied, but they are densified with zeros.

Follow-up: What limitation applies to sparse=True? Sparse input support is documented as available only with the TensorFlow backend.

  • tf.keras.Model
  • tf.keras.layers.InputLayer
  • tf.keras.layers.Dense
  • tf.keras.InputSpec

Source: tf.keras.Input | TensorFlow v2.16.1. Checked 2026-10-15.