Skip to content

This repository implements a GPU-accelerated next-word prediction model using PyTorch and LSTM. It includes data preprocessing with NLTK, vocabulary creation, training on tokenized text, and generating text predictions, starting from a given input phrase.

Notifications You must be signed in to change notification settings

sebastian2005-RP/GPU-Accelerated-Next-Word-Prediction-Using-LSTM-and-PyTorch

Repository files navigation

GPU-Accelerated Next Word Prediction Using LSTM and PyTorch 🚀

Next Word Prediction

Welcome to the GPU-Accelerated Next Word Prediction Using LSTM and PyTorch repository! This project showcases an efficient model for predicting the next word in a sequence using Long Short-Term Memory (LSTM) networks. By leveraging the power of GPUs and the PyTorch framework, this implementation aims to enhance the speed and accuracy of next-word predictions.

Table of Contents

Introduction

In the age of digital communication, next-word prediction plays a crucial role in enhancing user experience. This repository implements a next-word prediction model using LSTM networks, optimized for GPU processing. The model takes a sequence of words as input and predicts the most likely next word based on the context provided.

Features

  • GPU Acceleration: Utilizes GPU for faster training and prediction.
  • LSTM Architecture: Implements Long Short-Term Memory networks for effective sequence modeling.
  • Data Preprocessing: Includes tokenization and vocabulary creation using NLTK.
  • Text Generation: Generates coherent text predictions based on input phrases.
  • Easy to Use: Simple API for generating predictions.

Getting Started

Prerequisites

To run this project, you need the following software installed on your machine:

  • Python 3.6 or higher
  • PyTorch (with GPU support)
  • NLTK
  • Other dependencies listed in requirements.txt

Installation

  1. Clone the repository:

    git clone https://github.com/sebastian2005-RP/GPU-Accelerated-Next-Word-Prediction-Using-LSTM-and-PyTorch.git
    cd GPU-Accelerated-Next-Word-Prediction-Using-LSTM-and-PyTorch
  2. Install the required packages:

    pip install -r requirements.txt

Data Preparation

Before training the model, you need to prepare your dataset. This involves tokenizing your text and creating a vocabulary. You can use the provided scripts in the data_preprocessing folder.

  1. Place your text data in the data folder.

  2. Run the data preprocessing script:

    python data_preprocessing/preprocess.py

This will generate the necessary tokenized data and vocabulary files.

Model Architecture

The model architecture consists of an LSTM layer followed by a fully connected layer. This setup allows the model to learn dependencies over long sequences of text.

LSTM Layer

  • Input Size: The size of the vocabulary.
  • Hidden Size: Number of features in the hidden state.
  • Number of Layers: Stacked LSTM layers for better learning.

Fully Connected Layer

  • Takes the output from the LSTM layer and predicts the next word based on the learned features.

Training the Model

To train the model, use the following command:

python train.py --epochs 10 --batch_size 64

Adjust the epochs and batch_size parameters as needed. The model will save the trained weights to the models directory.

Generating Predictions

Once the model is trained, you can generate predictions using the provided script:

python predict.py --input "Your input phrase here"

This will output the predicted next word based on the input phrase.

Usage

To utilize the model in your applications, follow these steps:

  1. Load the trained model.
  2. Preprocess your input text.
  3. Call the prediction function.

Example

import torch
from model import LSTMModel

# Load the model
model = LSTMModel()
model.load_state_dict(torch.load('models/model_weights.pth'))

# Prepare input
input_text = "The quick brown fox"
# Generate prediction
predicted_word = model.predict(input_text)
print(predicted_word)

Contributing

Contributions are welcome! If you have suggestions for improvements or features, feel free to open an issue or submit a pull request.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Make your changes and commit them (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or suggestions, you can reach out to the maintainer:

Releases

To download the latest release of this project, visit the Releases section.

You can also check for updates and new features regularly.


Thank you for checking out this project! We hope it helps you in your journey of exploring next-word prediction using deep learning techniques. Happy coding!

About

This repository implements a GPU-accelerated next-word prediction model using PyTorch and LSTM. It includes data preprocessing with NLTK, vocabulary creation, training on tokenized text, and generating text predictions, starting from a given input phrase.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •