资源算法keras-gpt-2

keras-gpt-2

2020-03-02 | |  58 |   0 |   0

Keras GPT-2

[中文|English]

Load pretrained weights and predict with GPT-2.

Install

pip install keras-gpt-2

Demo

import osfrom 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])


上一篇:gpt-2-cloud-run

下一篇:gpt-2-poetry

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...