gpt-2-simple | Python package to easily retrain OpenAI | Machine Learning library

 by   minimaxir Python Version: 0.8.1 License: Non-SPDX

kandi X-RAY | gpt-2-simple Summary

kandi X-RAY | gpt-2-simple Summary

gpt-2-simple is a Python library typically used in Telecommunications, Media, Media, Entertainment, Artificial Intelligence, Machine Learning, Deep Learning, Tensorflow applications. gpt-2-simple has no bugs, it has no vulnerabilities, it has build file available and it has medium support. However gpt-2-simple has a Non-SPDX License. You can install using 'pip install gpt-2-simple' or download it from GitHub, PyPI.

Python package to easily retrain OpenAI's GPT-2 text-generating model on new texts
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              gpt-2-simple has a medium active ecosystem.
              It has 3277 star(s) with 667 fork(s). There are 75 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 161 open issues and 100 have been closed. On average issues are closed in 98 days. There are 17 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of gpt-2-simple is 0.8.1

            kandi-Quality Quality

              gpt-2-simple has 0 bugs and 0 code smells.

            kandi-Security Security

              gpt-2-simple has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              gpt-2-simple code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              gpt-2-simple has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              gpt-2-simple releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              gpt-2-simple saves you 592 person hours of effort in developing the same functionality from scratch.
              It has 1384 lines of code, 85 functions and 10 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed gpt-2-simple and discovered the below as its top functions. This is intended to give you an instant insight into gpt-2-simple implemented functionality, and help decide if they suit your requirements.
            • Argument parser
            • Download the GPT2 model
            • Download file with progress bar
            • Finalize gpt2
            • Simulate the model
            • Attention layer
            • Compute the attention mask
            • Block block
            • Generate a sequence of tokens
            • Compute top - k logits
            • Compute the top - p logits for the given logits
            • Copy a checkpoint to gdrive
            • Returns the name of the tar file
            • Encodes a dataset into a numpy array
            • Copies a checkpoint from gdrive
            • Reset a TensorFlow session
            • Copies a file from the gdrive
            • Copy a file to gdrive
            Get all kandi verified functions for this library.

            gpt-2-simple Key Features

            No Key Features are available at this moment for gpt-2-simple.

            gpt-2-simple Examples and Code Snippets

            yourAI,Getting Started
            Pythondot img1Lines of Code : 10dot img1no licencesLicense : No License
            copy iconCopy
            git clone https://github.com/minimaxir/gpt-2-simple
            cd gpt-2-simple
            
            virtualenv .env
            # Wait for it to setup
            .env\Scripts\activate # On Windows
            source .env\bin\activate # On Unix
            pip install -r requirements.txt 
            # IF USING A GPU TO FINETUNE/GENERATE
            p  
            copy iconCopy
            gpt2.generate(sess,
                          length=200,
                          temperature=0.7,
                          prefix='<|startoftext|>',
                          truncate='<|endoftext|>',
                          include_prefix=False
                          )
              
            copy iconCopy
            $ pipenv shell # this take you to the virtual environment
            $ python -m ipykernel install --user --name= # change the kernel name as you see fit
            $ jupyter lab # run a jupyterlab instance on your localhost
              
            GPT-2 Continue training from checkpoint
            Pythondot img4Lines of Code : 16dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            sess = gpt2.start_tf_sess()
            
            gpt2.finetune(sess,
                file_name,
                model_name=model_name,
                checkpoint_dir=checkpoint_dir,
                run_name=run_name,
                steps=25,
            )
            
            Training...
            
            [26 | 7.48] loss=0.49 avg=0.49
            
            how can I get the logit values as probabilities from gpt-2?
            Pythondot img5Lines of Code : 6dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            enc = gpt_2_simple.src.encoder.get_encoder(checkpoint_path)
            N_token = len(enc.encoder)
            tokens_decoded = [enc.decode([token]) for token in range(N_token)]
            
            probs = tf.nn.softmax(logits)
            
            Generate text from input on default model gpt-2-simple python
            Pythondot img6Lines of Code : 7dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            gpt_2_simple --sample_every 50 finetune yourtext.txt
            
            gpt_2_simple generate --prefix "Once upon a time"  --nsamples 5
            
            mkdir -p checkpoint/
            cp -r models/345M checkpoint/run1
            

            Community Discussions

            QUESTION

            how can I get the logit values as probabilities from gpt-2?
            Asked 2020-Feb-03 at 01:53

            I'm using the gpt-2 simple package: https://github.com/minimaxir/gpt-2-simple

            I would like to get a probability for all possible next tokens as an output. something like:

            [ ['A', 0.25], ['B',0.25], ['C',0.25], ['D',0.25] ]

            I've modified the gpt_2_simple python code looks something like this:

            ...

            ANSWER

            Answered 2020-Feb-03 at 01:53

            1) get list of decoded tokens:

            Source https://stackoverflow.com/questions/60029211

            QUESTION

            Is there a GPT-2 implementation that allows me to fine-tune and prompt for text completion?
            Asked 2020-Jan-28 at 09:23

            I wish to to fine-tune a GPT-2 implementation on some text data. I then want to use this model to complete a text prompt. I can do the first part easily enough using Max Woolf's gpt-2-simple implementation. And Neil Shepherd's fork of OpenAI allows for GPT-2 to be trained on new data and completes text.

            However, my corpus is too small to train on and not get gibberish back. Is there any way I can combine the two functions? Ideally, I'd like to be able to do this via a python interface (as opposed to CLI), as I'd like to use pandas for data cleaning and what-have-you. Thanks.

            ...

            ANSWER

            Answered 2020-Jan-28 at 09:23

            Huggingface's Transformers package has a GPT-2 implementation (including pre-trained models) for PyTorch and TensorFlow. You can easily work with them in Python.

            Fine-tuning of GPT-2, however, requires a lot of memory and I am not sure is you will be able to do the full backpropagation on that. In that case, you fine-tune just a few highest layers.

            Source https://stackoverflow.com/questions/59944537

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install gpt-2-simple

            gpt-2-simple can be installed via PyPI:. You will also need to install the corresponding TensorFlow for your system (e.g. tensorflow or tensorflow-gpu). TensorFlow 2.0 is currently not supported and the package will throw an assertion if loaded, so TensorFlow 1.14/1.15 is recommended.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install gpt-2-simple

          • CLONE
          • HTTPS

            https://github.com/minimaxir/gpt-2-simple.git

          • CLI

            gh repo clone minimaxir/gpt-2-simple

          • sshUrl

            git@github.com:minimaxir/gpt-2-simple.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link