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

Keras · Function

keras.Input

keras.Input creates a symbolic Keras tensor that serves as the starting point for a model graph. Define its shape and related input properties, connect layers to it, and use the resulting tensors to build a Functional API model.

How it works

keras.Input creates a symbolic Keras tensor that describes the shape and type of data entering a model. Layers can consume that tensor to define a computation graph, after which the input and resulting output tensors are passed to keras.Model.

Syntax

keras.Input(shape=None, batch_size=None, dtype=None, sparse=None, ragged=None, batch_shape=None, name=None, tensor=None, optional=False)

Parameters

NameTypeDescription
shapetupleShape tuple excluding the batch size; dimensions may be integers or None.
batch_sizeintOptional fixed batch size.
dtypestrExpected input data type, such as float32 or int32.
sparseboolWhether the expected input is sparse; defaults to False.
raggedboolWhether the expected input is ragged.
batch_shapetupleOptional complete shape tuple including the batch size.
namestrOptional unique name for the input layer; autogenerated if omitted.
tensortensorOptional existing tensor to wrap.
optionalboolWhether the input may accept None values.

Returns

A Keras tensor.

Key points

  • Use keras.Input to create the symbolic starting tensor for a Functional API graph.
  • Specify feature or spatial dimensions with shape; None can represent an unknown dimension.
  • Use batch_size to declare a fixed batch dimension independently of the remaining input shape.
  • Set dtype to control the expected input data type, such as float32 or int32.
  • The tensor argument lets the input layer wrap an existing tensor instead of creating a new placeholder.
  • The function returns a Keras tensor that can be connected to subsequent layers.

Common mistakes

  • shape excludes the batch dimension; use batch_shape when the complete shape, including batch size, must be specified.
  • Give inputs distinct names within a model because duplicate names are not supported.
  • Sparse input support is backend-limited; it is documented for TensorFlow and JAX.
  • Set optional=True only when the model should accept a missing value for that input.

Example: Build a Functional API model

import keras
from keras import layers

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

model.summary()

Creates a symbolic input with 32 features, connects layers to it, and builds a Functional API model.

When to use it

Declare model inputs

Functional API graph construction

Specify a static batch size

Fixed-size data pipelines

Describe dtype, sparse, or ragged inputs

Multiple data representations

Wrap a supplied tensor

Integrating an existing symbolic tensor

Interview questions

QWhat does keras.Input create?

keras.Input creates a symbolic Keras tensor used to define a model graph. It describes properties such as shape and dtype without representing a concrete data batch.

Follow-up: How would you construct a model from it? Chain layers from the input tensor, then pass the input and final output tensors to keras.Model.

QHow do shape and batch_shape differ?

shape describes dimensions after the batch dimension, while batch_shape includes the batch dimension. For example, shape=(32,) describes batches of 32-dimensional vectors.

Follow-up: When would batch_size be useful? Use it when a fixed static batch size is required; otherwise leave it unspecified for flexible batches.

QWhich input-related options affect data representation?

The function accepts an optional dtype and can mark inputs as sparse or ragged. Sparse support is limited to the TensorFlow and JAX backends, and sparse inputs are densified when sparse=False.

Follow-up: What does optional=True change? It allows the input to accept None values.

  • keras.Model
  • keras.layers.Dense
  • keras.layers.InputLayer

Source: Input object - Keras. Checked 2026-10-15.