Package: gptj
GPT-JA GPT-J API to use with pythonInstalling gpt-jpip install gptjParametersprompt: the prompt you wish to give to the modeltokens: the number of tokens to generate (values 204 or less are recommended)temperature: controls the randomness of the model. higher values will be more random (suggestest to keep under 1.0 or less, something like 0.3 works)top_p: top probability will use the most likely tokenstop_k: Top k probabilityrep: The likely hood of the model repeating the same tokens lower values are more repetativeAdvanced Parametersuser: the speaker the person who is giving gpt-j a promptbot: an imaginary character of your choicecontext: the part of the prompt that explains what is happening in the dialogexamples: a dictionary of user intentions and how the bot should respondBasic UsageIn the prompt enter something you want to generatefromgpt_j.Basic_apiimportsimple_completionprompt="def perfect_square(num):"The maximum length of the output responsemax_length=100Temperature controls the creativity of the modelA low temperature means the model will take less changes when completing a promptA high temperature will make the model more creativeBoth temperature and top probability must be a floattemperature=0.09top probability is an alternative way to control the randomness of the modelIf you are using top probability set temperature oneIf you are using temperature set top probability to onetop_probability=1.0top k is an integer value that controls part of the modeltop_k=40Repetition penalty will result in less repetative resultsrepetition=0.216Initializing the SimpleCompletion classHere you set query equal to the desired valuesNote values higher than 512 tend to take more time to generatequery=simple_completion(prompt,length=max_length,temp=temperature,top_p=top_probability,top_k=top_k,rep=repetition)Finally run the function belowprint(query)Advanced UsageContext is a string that is a description of the conversationfromgpt_j.gptj_apiimportCompletioncontext="This is a calculator bot that will answer basic math questions"Examples should be a dictionary of {user query: the way the model should respond to the given query} list of examplesQueries are to the left while target responses should be to the rightHere we can see the user is asking the model math related questionsThe way the model should respond if given on the rightDO NOT USE PERIODS AT THE END OF USER EXAMPLE!examples={"5 + 5":"10","6 - 2":"4","4 * 15":"60","10 / 5":"2","144 / 24":"6","7 + 1":"8"}Here you pass in the context and the examplescontext_setting=Completion(context,examples)Enter a prompt relevant to previous defined user queriesprompt="48 / 6"Pick a name relevant to what you are doingBelow you can change student to "Task" for example and get similar resultsUser="Student"Name your imaginary friend anything you wantBot="Calculator"Max tokens is the maximum length of the output responsemax_tokens=50Temperature controls the randomness of the modelA low temperature means the model will take less changes when completing a promptA high temperature will make the model more creative and produce more random outputsA Note both temperature and top probability must be a floattemperature=0.09Top probability is an alternative way to control the randomness of the modelIf you are using it set temperature oneIf you are using temperature set top probability to onetop_probability=1.0top k is an integer value that controls part of the modeltop_k=40Repetition penalty will result in less repetative resultsrepetition=0.216Simply set all the give all the parametersUnfilled parameters will be default valuesI recommend all parameters are filled for better resultsOnce everything is done execute the code belowresponse=context_setting.completion(prompt,user=User,bot=Bot,max_tokens=max_tokens,temperature=temperature,top_p=top_probability,top_k=top_k,rep=reptition)Last but not least print the responsePlease be patient depending on the given parameters it will take longer sometimesFor quick responses just use the Basic API which is a simplified versionprint(response)Note: This a very small model of 6B parameters and won't always produce accurate resultsDisclaimerI have removed the security from the API, please don't use for unethical use!
I am not responsible for anything you do with the APILicense and copyrightCreditThis is all possible thanks tohttps://github.com/vicgalle/gpt-j-apiFeel free to check out the original APILicense© Michael D Aranalicensed under theMIT License.