• Stars
    star
    963
  • Rank 47,492 (Top 1.0 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Text-Generator with OpenAI gpt-2 Pytorch Implementation

GPT2-Pytorch with Text-Generator

Better Language Models and Their Implications

Our model, called GPT-2 (a successor to GPT), was trained simply to predict the next word in 40GB of Internet text. Due to our concerns about malicious applications of the technology, we are not releasing the trained model. As an experiment in responsible disclosure, we are instead releasing a much smaller model for researchers to experiment with, as well as a technical paper. from openAI Blog

This repository is simple implementation GPT-2 about text-generator in Pytorch with compress code

Quick Start

  1. download GPT2 pre-trained model in Pytorch which huggingface/pytorch-pretrained-BERT already made! (Thanks for sharing! it's help my problem transferring tensorflow(ckpt) file to Pytorch Model!)
$ git clone https://github.com/graykode/gpt-2-Pytorch && cd gpt-2-Pytorch
# download huggingface's pytorch model 
$ curl --output gpt2-pytorch_model.bin https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-pytorch_model.bin
# setup requirements, if using mac os, then run additional setup as descibed below
$ pip install -r requirements.txt
  1. Now, You can run like this.
  • Text from Book 1984, George Orwell
$ python main.py --text "It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him."
  1. Also You can Quick Starting in Google Colab

Option

  • --text : sentence to begin with.
  • --quiet : not print all of the extraneous stuff like the "================"
  • --nsamples : number of sample sampled in batch when multinomial function use
  • --unconditional : If true, unconditional generation.
  • --batch_size : number of batch size
  • --length : sentence length (< number of context)
  • --temperature: the thermodynamic temperature in distribution (default 0.7)
  • --top_k : Returns the top k largest elements of the given input tensor along a given dimension. (default 40)

See more detail option about temperature and top_k in here

Dependencies

  • Pytorch 0.41+
  • regex 2017.4.5

Mac OS Setup

$ python3 -m venv venv
$ source venv/bin/activate
$ pip install torch tqdm
$ brew install libomp
$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ pip install -r requirements.txt

Author

License

  • OpenAi/GPT2 follow MIT license, huggingface/pytorch-pretrained-BERT is Apache license.
  • I follow MIT license with original GPT2 repository

Acknowledgement

Jeff Wu(@WuTheFWasThat), Thomas Wolf(@thomwolf) for allowing referring code.

More Repositories

1

nlp-tutorial

Natural Language Processing Tutorial for Deep Learning Researchers
Jupyter Notebook
14,066
star
2

nlp-roadmap

ROADMAP(Mind Map) and KEYWORD for students those who have interest in learning NLP
3,216
star
3

distribution-is-all-you-need

The basic distribution probability Tutorial for Deep Learning Researchers
Python
1,620
star
4

xlnet-Pytorch

Simple XLNet implementation with Pytorch Wrapper
Jupyter Notebook
576
star
5

commit-autosuggestions

A tool that AI automatically recommends commit messages.
Python
383
star
6

toeicbert

TOEIC(Test of English for International Communication) solving using pytorch-pretrained-BERT model.
Python
119
star
7

modelsummary

All Model summary in PyTorch similar to `model.summary()` in Keras
Python
86
star
8

matorage

Matorage is tensor(multidimensional matrix) object storage manager for deep learning framework(Pytorch, Tensorflow V2, Keras)
Python
73
star
9

KorQuAD-beginner

Guide KorQuAD upload to leaderboard (EM 68.947 / F1 88.468) model which only use BERT-multilingual(single)
Python
41
star
10

aws-kubeflow

A guideline for basic use and installation of kubeflow in AWS.
Jupyter Notebook
38
star
11

vision-tutorial

Computer Vision Tutorial for Deep Learning Researchers
Python
33
star
12

DeepLearning-Study

This is repository for DeepLearning Study in Kyung Hee University
Python
28
star
13

DAC

Deep Adaptive Image Clustering Paper Implementation
Jupyter Notebook
28
star
14

horovod-ansible

Create Horovod cluster easily using Ansible
HCL
22
star
15

aws-kubeadm-terraform

create kubernetes cluster on AWS only typing 'terraform apply' on 3 minutes.
HCL
16
star
16

kubernetes-glusterfs-aws

file system clustering as glusterfs in kubernetes environment on aws platform
Shell
13
star
17

mlm-pipeline

mlm-pipeline is a cloud architecture that preprocesses the masked language model (mlm)
Python
10
star
18

linux0.11-kernel-code-review

The old Linux kernel source ver 0.11 review with line by line for OS lecture.
C
10
star
19

khuthon2018

λ”₯λŸ¬λ‹μ„ μ‚¬μš©ν•œ 맛집 뢄석 - 2018λ…„ 쿠톀(해컀톀)
JavaScript
8
star
20

projects

MY PROJECT LIST AT A GLANCE πŸŒˆπŸš€πŸ¦„
7
star
21

graykode.github.io

graykode's blog
Shell
4
star
22

ALGORITHM-MASTER

I LOVE ALGORITHM
C++
4
star
23

nlpblock

Use Abstractions Level Block for NLP with Pytorch
Python
3
star
24

intellij-foundry

Kotlin
3
star
25

ml-kubernetes-tutorial

very basic tutorial for who interesting in Machine Learning Serving with Docker, Kubernetes, Kubeflow
3
star
26

mnist-flow

This Project is only repository for solving AI Engineer Party
Python
3
star
27

modelaverage

tf-keras, make the average of model weight in same model.
Python
3
star
28

nonce-python

2019 github seminar in D.COM
HTML
2
star
29

nlp-advance

Simple Paper Implementation Code about all model after Attention is all you need(Transformer)
2
star
30

graykode

1
star
31

ohora

Jupyter Notebook
1
star