How goldstraw/rust_transformer works
Main Components
• Data Ingestion & Preprocessing: Represent the dataset components (imdb_dataset.csv and word_embeddings.json). This includes the modules responsible for loading the IMDb reviews and the pre-trained word embeddings.
• Embedding Layer (src/embedding.rs): Transforms input tokens into vector representations.
• Positional Encoding (src/positional_encoder.rs): Adds sequence information to embeddings.
• Self-Attention Mechanism (src/self_attention.rs and src/multi_headed_attention.rs): Computes attention scores.
• Encoder Block(s) (src/encoder_block.rs, src/block.rs): Composite block that contains the self-attention and subsequent processing (e.g., normalization, add-and-norm from src/add_and_norm.rs).
• Feedforward or Dense Layers (src/dense.rs): Applies further transformation.
• Transformer Integration (src/transformer.rs): Orchestrates the overall transformation process.
• Execution Flow: Show how the main entry point (src/main.rs) kicks off the overall process, with orchestration possibly extended in src/run.rs. Additionally, include the logger (src/logger.rs) that logs key events during training/testing.
• Dataset Handling: Incorporate the dataset processing logic (src/dataset.rs) which likely prepares and splits the movie review data for training and testing.
Relationships and Interactions
• Embedding Layer to the Positional Encoder, indicating sequential processing.
• Link the results from the encoder stacks back into an output layer or post-processing module that provides the sentiment classification output.
Architectural Patterns and Design Principles
• Modular Design: Emphasize that each component (attention, normalization, encoding, dense layers) is implemented in separate files, promoting separation of concerns.
• Layered Processing: The pipeline follows a sequential layered pattern where data flows from the input through embeddings, positional encoding, attention mechanisms, and finally the dense layers.
• Reusable Components: The transformer blocks are abstracted in dedicated modules, which can be represented as reusable and scalable building blocks.
Relevant Technologies/Frameworks
• Rust & Cargo: At the foundation, represent the Rust ecosystem enforcing performance and memory-safety.
• Custom Implementation: Note that the design avoids external machine learning libraries, underlining a ground-up implementation.
• File Dependencies: Mention that configuration files like Cargo.toml and Cargo.lock manage package dependencies, though they are not part of the runtime data flow.