Skip to content

yiyang92/gpt2-shakespeare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gpt2 for Shakespeare

A simple fine-tuning of the GPT2 model on the Shakespeare's novels and FastAPI-based service.

Setup

The best way to use is to setup a conda environment for the project and install it.

For training:

conda env create -f requirements/conda-environment.yaml && conda clean -q -y -a 

Then install as:

pip install -e .

Train (fine-tune)

For fine-tuning a model with default parameters:

train_gpt2 -p gpt_finetune_shake_speare

Fine-tuned checkpoints can be found at OneDrive

Generate (locally)

For generation, use:

generate_gpt2 -p gpt_finetune_shake_speare -c gpt2s-4.pt -i "be or not to be?"

where gpt2s-4.pt is the name of the fine-tuned saved parameters dictionary.

Service

Download checkpoint and place it into checkpoints folder in the directory root. Launch service with:

serve_gpt2

If initialization was successfull, you can use curl to get the generated text as:

curl -d '{"text":"be or not to be"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:8000/generate

About

Test task for ML startup. Finetuning of GPT-2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published