Completion Parameter – Temperature

Parameter Temperature berguna untuk mengatur randomness dari output. Value tinggi output akan semakin random, kebalikannya makin rendah maka output lebih deterministik. Semakin tinggi randomness, ouput akan lebih kreatif.

Parameter Temperature memiliki rentang nilai dari 0-2, namun biasanya digunakan dari 0-1 saja. Default value adalah 1. Angka yang digunakan adalah angka decimal, artinya bisa dimasukan nilai temperature=0.1, 0.2 dan seterusnya.

Jika Anda menggunakan prompt yang sama berulang-ulang, dengan temparature = 0, result yang diharapkan akan selalu sama. Sementara jika temperature >0, output akan lebih variatif.

Pada percobaan yang kami lakukan, untuk contoh prompt dibawah dengan temperature=1, result akan bervariasi dari dog, wolve dan monkey, namun dog akan lebih sering tampil.

Sementara jika temperature=0, hasil selalu sama, yaitu dog.

Silakan coba juga dengan temperature =2, hasilnya lebih random, pada percobaanya yang kami lakukan output adalah bervariasi mulai dari Labrador, Tiger dan selalu berbeda.

Perhatian, jika Anda menggunakan Playground, nilai temperature dibatasi hanya sampai 1. Anda harus menggunakan code Python jika ingin menggunakan nilai 2.

Contoh penggunaan dengan temperature.

prompt = "My favorite animal is a "
    
openai.Completion.create(
    model = "text-davinci-003",
    prompt = prompt,
    max_tokens= 200,
    temperature = 1
)

Anda bisa menggunakan code dibawah untuk melakukan testing perbedaan value temparature

import textwrap

def nice_print(dictionary):
    for key, value in dictionary.items():
        wrapped_text = "\n".join(textwrap.wrap(value, width=120))
        print(f"{key}:")
        print(wrapped_text)
        print("-"*100)

nice_print({
    f"Temperature {temperature}": openai.Completion.create(model="text-davinci-003", prompt="""My favorite food is""".strip(), max_tokens =75, temperature=temperature, echo=True)
    .choices[0]["text"]
    .strip()
    for temperature in [0, 0.5, 1, 1.5, 2]
})

Result yang dihasilkan seperti berikut:

Temperature 0:
My favorite food is pizza. I love the combination of the doughy crust, the tangy tomato sauce, and the melty cheese. I
also like to add different toppings like pepperoni, mushrooms, and olives. Pizza is a great meal for any occasion,
whether it's a casual night in or a special celebration.
----------------------------------------------------------------------------------------------------
Temperature 0.5:
My favorite food is pizza  Pizza is a classic favorite food for many people. It's a delicious and easy-to-make meal that
can be customized with a variety of toppings to suit everyone's tastes. Whether it's a classic margherita, a meat-
lover's special, or a veggie-packed delight, pizza is always a hit.
----------------------------------------------------------------------------------------------------
Temperature 1:
My favorite food is tacos. I love to make them with a variety of fresh ingredients, like salsa, lettuce, tomatoes,
cheese, onions, and sour cream - sometimes with a bit of beef or chicken. Tacos are very versatile and can be customized
according to individual tastes. They are a great meal for any occasion, as they can be served as a main dish or as a
snack.
----------------------------------------------------------------------------------------------------
Temperature 1.5:
My favorite food is lots of types of sandwiches. I have several favorites from different parts of the world including
Primanti-Style sandwiches, Cubanitanos, French Croque Monsieurs, and Greek Gyros%uh3djd7dooccl298so/. Sandwiches are
versatile, convenient, and definitely should get enough love amongst all of the meal types out there!
----------------------------------------------------------------------------------------------------
Temperature 2:
My favorite food is fried play cakes. ​ Fried plantains are circles of sliced green ￐メrasé cimonimes haiti countries
national cuisine bol basedee dipped antath frwen beåË in hot hot peanut shape oil as out iconicmanyhow
----------------------------------------------------------------------------------------------------

Dapat dilihat, semakin tinggi temperature semakin random.

Sharing is caring: