TorchLean API

NN.Examples.Models.Sequence.Transformer

Transformer Text Example #

Runnable torchlean transformer example. It reads a local text corpus, builds a short sequence reconstruction sample, and trains one transformer encoder block on that real text window.

The reusable model wiring is exposed as TorchLean.nn.models.TransformerEncoder. This command stays small so attention, normalization, the optimizer, logging, and CUDA execution remain easy to test regularly.

python3 scripts/datasets/download_example_data.py --tiny-shakespeare
lake build -R -K cuda=true && lake exe torchlean transformer --cuda --tiny-shakespeare --steps 1

CLI subcommand name used in terminal banners and error messages.

Instances For

    Default JSON loss-curve path for this command.

    Instances For

      Number of rows in the typed encoder batch.

      Instances For

        Short reconstruction window for the quick encoder training run.

        Instances For

          Transformer feature width.

          Instances For

            Number of attention heads.

            Instances For

              Feed-forward hidden width inside the encoder block.

              Instances For

                API-level encoder configuration shared by shapes and the constructor.

                Instances For
                  @[reducible, inline]

                  Input shape: a batch of sequence rows with dModel features per token.

                  Instances For
                    @[reducible, inline]

                    Output shape matches the input because this command trains a reconstruction objective.

                    Instances For

                      One reusable transformer encoder block from the public model API.

                      Instances For

                        Build one reconstruction sample from the loaded corpus prefix.

                        Instances For

                          Train the Transformer encoder with the public Trainer surface.

                          Instances For

                            CLI entrypoint for the Transformer encoder text command.

                            Instances For