← Prompts
Reference / Understand System Prompts Collection

.. currentmodule:: mlx.nn

.. _nn: .. currentmodule:: mlx.nn Neural Networks =============== Writing arbitrarily complex neural networks in MLX can be done using only :class:`mlx.core.array` and :meth:`mlx.core.value_and_gra

.. _nn:

.. currentmodule:: mlx.nn

Neural Networks
===============

Writing arbitrarily complex neural networks in MLX can be done using only
:class:`mlx.core.array` and :meth:`mlx.core.value_and_grad`. However, this requires the
user to write again and again the same simple neural network operations as well
as handle all the parameter state and initialization manually and explicitly.

The module :mod:`mlx.nn` solves this problem by providing an intuitive way of
composing neural network layers, initializing their parameters, freezing them
for finetuning and more.

Quick Start with Neural Networks
---------------------------------

.. code-block:: python

    import mlx.core as mx
    import mlx.nn as nn

    class MLP(nn.Module):

Sign in to view the full prompt.

Sign In

Classification

Reference Documentation, cheatsheets, setup guides
Reference Understand
Explain or analyze
Scope Project
This codebase
Manual Manually placed / Persistent