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

Keras · Function

Input

keras.Input() creates a symbolic Keras tensor for defining model inputs. Its shape describes each sample, while optional arguments configure batching, dtype, sparse or ragged inputs, naming, wrapping an existing tensor, and optional inputs.

How it works

keras.Input() creates a symbolic Keras tensor that represents model input. Specify the per-example shape and optional properties such as dtype, batch size, sparsity, raggedness, name, or optionality, then connect the tensor to layers and use it when constructing a 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
shapetuple or NonePer-sample shape, excluding the batch dimension; dimensions may be integers or None.
batch_sizeint or NoneOptional fixed batch size.
dtypestring or NoneExpected input data type.
sparsebool or NoneWhether sparse tensors are expected.
raggedbool or NoneWhether ragged tensors are expected.
batch_shapetuple or NoneComplete shape including the batch dimension.
namestring or NoneOptional unique layer name.
tensortensor or NoneExisting tensor to wrap instead of creating a placeholder.
optionalboolWhether the input accepts None.
returnsKeras tensorA Keras tensor.

Returns

A Keras tensor.

Key points

  • Use keras.Input() as the symbolic starting point for a Functional API model.
  • Pass shape as the per-sample dimensions; integer values fix dimensions and None permits a variable dimension.
  • Use batch_size to declare a fixed batch size separately from the sample shape.
  • Use batch_shape when specifying the complete shape, including the batch dimension, in one argument.
  • Set dtype to control the expected input type, for example "float32" or "int32".
  • Set optional=True when the model input may receive None.

Common mistakes

  • The shape excludes the batch dimension; use batch_shape when the batch dimension must be included explicitly.
  • A supplied name must not be duplicated within the same model.
  • Setting sparse=False does not reject sparse inputs; they are converted to dense tensors with zero as the default value.

Example: Create a model input

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)

Creates a symbolic input tensor and connects it to a small Functional API model.

When to use it

Functional model construction

Build a Functional API graph by connecting an input tensor to layers and passing the endpoints to keras.Model.

Variable-size or variable-length inputs

Describe data whose dimensions vary between examples by using None in the input shape.

Structured tensor inputs

Define models that accept sparse or ragged tensor representations.

Optional model inputs

Create a model signature where a particular input may be absent by enabling optional inputs.

Interview questions

QWhat does keras.Input() create, and how is its shape interpreted?

keras.Input() instantiates a symbolic Keras tensor for defining a model graph. Its shape describes one sample and does not include the batch dimension unless batch_shape is used.

Follow-up: How would you represent variable-length sequences? Use a shape containing None, such as shape=(None,), and choose an appropriate dtype.

QWhat are the roles of dtype, sparse, and ragged?

The dtype declares the expected input data type, while sparse and ragged describe whether sparse or ragged tensors are expected. These options let the input specification match the data representation used by the model.

Follow-up: What happens if sparse data is passed while sparse=False? Keras densifies it using a default value of zero.

QWhat does the optional argument change?

The optional flag allows the input to receive None; by default, inputs are not optional. The function returns a Keras tensor that can be passed through layers and used as a model input.

Follow-up: When would optionality be useful? It can support model signatures where a particular input is allowed to be absent.

  • keras.Model
  • keras.layers.Dense
  • Functional API

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