Skip to main content

GPT2 text generation with just two lines of code!

Project description

Chatting Transformer

Easy text generation using state of the art NLP models.

License Downloads

Chatting Transformer is a Python library for generating text using GPT2. GPT-2 is a language model that was developed by OpenAI that specializes in generating text. By using Chatting Transformer, you can implement and use this model with just two lines of code.

Installation

pip install chattingtransformer

Basic Usage

from chattingtransformer import ChattingGPT2


model_name = "gpt2" 
gpt2 = ChattingGPT2(model_name)

text = "In 10 years, AI will " 
result = gpt2.generate_text(text) 

print(result) # Outputs: In 10 years, AI will  have revolutionized the way we interact with the world...

Available Models

Model Parameters Size
gpt2 134 M 548 MB
gpt2-medium 335 M 1.52 GB
gpt2-large 774 M 3.25 GB
gpt2-xl 1.5 B 6.43 GB
from chattingtransformer import ChattingGPT2

gpt2 = ChattingGPT2("gpt2")
gpt2_medium = ChattingGPT2("gpt2-medium")
gpt2_large = ChattingGPT2("gpt2-large")
gpt2_xl = ChattingGPT2("gpt2-xl")

Predefined Methods

Below are predfined methods that may be used to determine the output. To learn more, about these methods, please visit this webpage.

  1. "greedy"
  2. "beam-search"
  3. "generic-sampling"
  4. "top-k-sampling"
  5. "top-p-nucleus-sampling"
from chattingtransformer import ChattingGPT2

gpt2 = ChattingGPT2("gpt2")
text = "I think therefore I "
greedy_output = gpt2.generate_text(text, method = "greedy")
beam_search_output= gpt2.generate_text(text, method = "beam-search")
generic_sampling_output = gpt2.generate_text(text, method = "generic-sampling")
top_k_sampling_output = gpt2.generate_text(text, method = "top-k-sampling")
top_p_nucleus_sampling_output = gpt2.generate_text(text, method = "top-p-nucleus-sampling")

Custom Method

Below are the default values for the parameters you may adjust to modify how the model generates text. For more information about the purpose of each parameter, please visit Hugging Face's Transformer documentation on this webpage.

max_length:
min_length:
do_sample: early_stopping: num_beams: temperature: top_k: top_p: repetition_penalty: length_penalty: no_repeat_ngram_size: bad_words_ids:

Modify All Settings

You have the ability to modify all of the default text generation parameters at once as shown below.

from chattingtransformer import ChattingGPT2

settings =  {  
  "do_sample": False,  
  "early_stopping": False,  
  "num_beams": 1,  
  "temperature": 1,  
  "top_k": 50,  
  "top_p": 1.0,  
  "repetition_penalty": 1,  
  "length_penalty": 1,  
  "no_repeat_ngram_size": 2,  
  'bad_words_ids': None,  
}
gpt2 = ChattingGPT2("gpt2")
text = "I think therefore I "

result = gpt2.generate_text(text, method = "custom", custom_settings = settings)

Modify Length

You may modify the min and max length of the output using parameters within the generate_text method.

from chattingtransformer import ChattingGPT2


gpt2 = ChattingGPT2("gpt2")
text = "I think therefore I "

result = gpt2.generate_text(text, min_length=5, max_length=500)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chattingtransformer-1.0.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

chattingtransformer-1.0.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file chattingtransformer-1.0.3.tar.gz.

File metadata

  • Download URL: chattingtransformer-1.0.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for chattingtransformer-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b9f33d91569349c6db2d918edab8613ac65918f1da43092bca1055445f0ef7fa
MD5 44457eed6aae60a77a7e9231054e01dc
BLAKE2b-256 9c173af43f5688795e58f6b83027627cdd14bc1ec2f0308db89eca2fa6936b4a

See more details on using hashes here.

File details

Details for the file chattingtransformer-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: chattingtransformer-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for chattingtransformer-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 13af181b2e4e5d64e488534fdfe167e9571035ddb3ade3549651d494104f8c10
MD5 92aa651ff0c2e2247e8194959d7b8c7c
BLAKE2b-256 dce586e080cd8ccef2d1f934d2d7245edfae9995e9faf9c8c209540ff2635c34

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page