Git Product home page Git Product logo

nlg's Introduction

GPT2 NLG

Overview

This repo provides the functionality for:

  1. app.py: A simple Flask web app that allows you to generate text with or without prompt based on a GPT2 model
  2. nlg.ipynb: Finetuning a 124M GPT2 model using Shakespeare's plays dataset. Code for CPU as well as GPU finetuning are provided.

Setup

# Create environment
mkdir ~/envs
cd ~/envs
python3 -m venv ~/envs/nlg_env

# Activate environment
source ~/envs/project_env/bin/activate

# Upgrade pip setuptools wheel
python -m pip install --upgrade pip setuptools wheel

# Install requirements
pip install -r requirements.txt

# Deactivate
deactivate
# Make the following modifications to files in the library so that GPU
# training works successfully

# ~/envs/nlg_env/lib/aitextgen/aitextgen.py
# add the line below relative to the 2 subsequent lines as
# a temporary fix regarding a "show_progress_bar" error
del train_params["show_progress_bar"]
trainer = pl.Trainer(**train_params)
trainer.fit(train_model)

# ~/envs/nlg_env/lib/transformers/tokenization_gpt2.py
def convert_tokens_to_string(self, tokens):
    """ Converts a sequence of tokens (string) in a single string. """
    # Add the line below at the start of convert_tokens_to_string to fix
    # error where instances of None occur in tokens.
    tokens = list(filter(lambda a: a is not None, tokens))
    text = "".join(tokens)
    text = bytearray([self.byte_decoder[c] for c in text]).decode("utf-8", errors=self.errors)
    return text
# Run Flask from the root directory
flask run

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.