I am using GPT2 for text generation.
However, for any given prompt, the response is always the same.
For example, for the prompt: “The answer to the universe is” … the response is always: "The answer to the universe is not in the right directions to set an orbit around, but instead on a flat platform with plenty of space to spread Earthly planets and other planets. You still find the answer here at the end of the article of life…
How can I change this each time I run my code?
import json
import requests
headers = {“Authorization”: f"Bearer MYAPI"}
API_URL = “https://api-inference.huggingface.co/models/gpt2”
def query(payload):
data = json.dumps(payload)
response = requests.request(“POST”, API_URL, headers=headers, data=data)
return json.loads(response.content.decode(“utf-8”))
data = query({“inputs”: “The answer to the universe is”})
print(data[0][‘generated_text’])