GPT-2
Project description
Keras GPT-2
"Power, give me more power."
Install
pip install keras-gpt-2
Demo
import os
from keras_gpt_2 import load_trained_model_from_checkpoint, get_bpe_from_files, generate
model_folder = 'xxx/yyy/117M'
config_path = os.path.join(model_folder, 'hparams.json')
checkpoint_path = os.path.join(model_folder, 'model.ckpt')
encoder_path = os.path.join(model_folder, 'encoder.json')
vocab_path = os.path.join(model_folder, 'vocab.bpe')
print('Load model from checkpoint...')
model = load_trained_model_from_checkpoint(config_path, checkpoint_path)
print('Load BPE from files...')
bpe = get_bpe_from_files(encoder_path, vocab_path)
print('Generate text...')
output = generate(model, bpe, ['From the day forth, my arm'], length=20, top_k=1)
# If you are using the 117M model and top_k equals to 1, then the result will be:
# "From the day forth, my arm was broken, and I was in a state of pain. I was in a state of pain,"
print(output[0])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
keras-gpt-2-0.8.0.tar.gz
(7.0 kB
view details)
File details
Details for the file keras-gpt-2-0.8.0.tar.gz.
File metadata
- Download URL: keras-gpt-2-0.8.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
504ff7be61ce37c2b252aa8f26bc0a472b4a1ba272e78f9280f16affd561ea39
|
|
| MD5 |
9086a075ec65c289bb2a9332a7c23bcc
|
|
| BLAKE2b-256 |
41450cbe1cc712bef761a4fd21d99e6c5967fdd46c8a0c89ed3e5264fbfff2b6
|