Skip to main content

A simple Python package that wraps existing model fine-tuning and generation scripts for OpenAI GPT-2 text generation model (specifically the "small", 124M hyperparameter version). Additionally, this package allows easier generation of text, generating to a file for easy curation, allowing for prefixes to force the text to start with a given phrase.

Usage

An example for downloading the model to the local system, fineturning it on a dataset. and generating some text.

Warning: the pretrained model, and thus any finetuned model, is 500 MB!

import gpt_2_simple as gpt2

gpt2.download_gpt2()   # model is saved into current directory under /models/124M/

sess = gpt2.start_tf_sess()
gpt2.finetune(sess, 'shakespeare.txt', steps=1000)   # steps is max number of training steps

gpt2.generate(sess)

The generated model checkpoints are by default in /checkpoint/run1. If you want to load a model from that folder and generate text from it:

import gpt_2_simple as gpt2

sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess)

gpt2.generate(sess)

As with textgenrnn, you can generate and save text for later use (e.g. an API or a bot) by using the return_as_list parameter.

single_text = gpt2.generate(sess, return_as_list=True)[0]
print(single_text)

You can pass a run_name parameter to finetune and load_gpt2 if you want to store/load multiple models in a checkpoint folder.

NB: Restart the Python session first if you want to finetune on another dataset or load another model.

Metadata

Release files for gpt2-plot 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt2-plot 0.7.1
File Size Uploaded
gpt2-plot-0.7.1.tar.gz 25.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt2-plot 0.7.1
File Interpreter ABI Platform
gpt2_plot-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.6 kB

Release files / gpt2-plot-0.7.1.tar.gz

Download URL gpt2-plot-0.7.1.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6cd8e37f93c181e13a62a0a42d5cf6f4eae96fd7d1258b997339431724b0e8be
BLAKE2b-256 checksum
How to use checksums
766b280370dc7ef656837a2a40088cbbee0da9d3b60a9f111daebc568ef22c41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / gpt2_plot-0.7.1-py3-none-any.whl

Download URL gpt2_plot-0.7.1-py3-none-any.whl
Size 24.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08f4a4aa510b096242f1e401db1547ea4c62fdc499dfbb053d9e1620e0b9421c
BLAKE2b-256 checksum
How to use checksums
83af8fc116fda881da63d2f7f03e853eb72623e4fc0e22e382f5394274825776
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page