Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyTorch-based name generation model with dataset and training script #60

Merged
merged 3 commits into from
Nov 23, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Nov 23, 2024

Summary by Sourcery

New Features:

  • Introduce a PyTorch-based name generation system using LSTM architecture for character-level language modeling.

Copy link
Contributor

sourcery-ai bot commented Nov 23, 2024

Reviewer's Guide by Sourcery

This PR introduces a character-level name generation system using PyTorch. The implementation consists of a custom dataset class for processing name data and an LSTM-based neural network model for generating new names. The system includes comprehensive training and generation utilities with configurable parameters.

Sequence diagram for name generation process

sequenceDiagram
    participant User
    participant NameDataset
    participant NameGenerator
    participant Model
    User->>NameDataset: Initialize with names
    User->>NameGenerator: Initialize with vocab size
    User->>Model: Train model
    loop Generate names
        User->>Model: Generate name
        Model->>NameDataset: Get context
        Model->>NameGenerator: Predict next character
        NameGenerator-->>Model: Return prediction
        alt End token or max length
            Model-->>User: Return generated name
        end
    end
Loading

Class diagram for NameDataset and NameGenerator

classDiagram
    class NameDataset {
        -List~str~ names
        -int context_size
        -List~str~ chars
        -List~str~ special_tokens
        -Dict~str, int~ stoi
        -Dict~int, str~ itos
        -torch.Tensor X
        -torch.Tensor y
        +__init__(List~str~ names, int context_size=3)
        +_build_dataset() Tuple~torch.Tensor, torch.Tensor~
        +__len__() int
        +__getitem__(int idx) Tuple~torch.Tensor, torch.Tensor~
    }
    class NameGenerator {
        -nn.Embedding embedding
        -nn.LSTM lstm
        -nn.Linear fc
        +__init__(int vocab_size, int embedding_dim=24, int hidden_dim=128)
        +forward(torch.Tensor x) torch.Tensor
    }
Loading

File-Level Changes

Change Details Files
Implementation of a custom PyTorch Dataset for name processing
  • Created a dataset class that handles data cleaning and normalization
  • Implemented character-to-index and index-to-character mapping
  • Added special tokens handling for sequence start and end
  • Built sliding context window generation for training data
pocs/makemore_names.py
Development of an LSTM-based name generation model
  • Implemented character embedding layer
  • Added LSTM layer for sequence processing
  • Created final linear layer for character prediction
  • Implemented forward pass logic
pocs/makemore_names.py
Implementation of training and generation utilities
  • Created training loop with loss tracking and optimization
  • Implemented single name generation with sampling
  • Added batch generation of unique names
  • Included statistics and validation against training data
pocs/makemore_names.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leonvanbokhorst leonvanbokhorst self-assigned this Nov 23, 2024
@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Add PyTorch-based name generation model with dataset and training script Nov 23, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The NameDataset class is missing a call to _build_dataset() in init to initialize self.X and self.y. This will cause runtime errors when len or getitem are called.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@leonvanbokhorst leonvanbokhorst merged commit d7e6dc2 into main Nov 23, 2024
1 check failed
@leonvanbokhorst leonvanbokhorst deleted the kids-name-gen branch November 23, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant