rish-16 / gpt2client

✍🏻 gpt2-client: Easy-to-use TensorFlow Wrapper for GPT-2 117M, 345M, 774M, and 1.5B Transformer Models 🤖 📝
MIT License
372 stars 74 forks source link

UnboundLocalError: local variable 'generated' referenced before assignment #12

Closed ghost closed 4 years ago

ghost commented 4 years ago

Describe the bug Trying to test on the Google Colab as per readme instructions.

To Reproduce Steps to reproduce the behavior:

  1. Executed
    pip install gpt2-client
  2. Executed
    from gpt2_client import GPT2Client
    gpt2 = GPT2Client('117M', save_dir='models')
    gpt2.load_model(force_download=False)
  3. Executed
    from gpt2_client import GPT2Client
    gpt2 = GPT2Client('117M')
    gpt2.generate(interactive=True)
    gpt2.generate(n_samples=4) 
    text = gpt.generate(return_text=True) 
    gpt2.generate(interactive=True, n_samples=3) 

Expected behavior Expected a prompt to return then some sort of generated text. Instead the script processes for a time then crashes returning gibberish along with:

UnboundLocalError                         Traceback (most recent call last)
<ipython-input-4-40d470866eb3> in <module>()
      5 
      6 gpt2.generate(interactive=True) # Asks user for prompt
----> 7 gpt2.generate(n_samples=4) # Generates 4 pieces of text
      8 text = gpt.generate(return_text=True) # Generates text and returns it in an array
      9 gpt2.generate(interactive=True, n_samples=3) # A different prompt each time

/usr/local/lib/python3.6/dist-packages/gpt2_client/gpt2_client.py in generate(self, interactive, n_samples, words, display, return_text)
    150                 print (colored('Generating sample...', 'yellow'))
    151 
--> 152                 while n_samples == 0 or generated < n_samples:
    153                     out = sess.run(output)
    154                     for i in range(batch_size):

UnboundLocalError: local variable 'generated' referenced before assignment

Screenshots image

ghost commented 4 years ago

Released the final segments in the readme are various commands not all meant to be executed.. sorry!