BaşlayınÜcretsiz Başlayın

Generating text

LLMs have many capabilities with text generation being one of the most popular.

You need to generate a response to a customer review found in text; it contains the same customer review for the Riverview Hotel you've seen before.

The pipeline module has been loaded for you.

Bu egzersiz

Introduction to LLMs in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Instantiate the generator pipeline specifying an appropriate task for generating text.
  • Complete the prompt by including the text and response in the f-string.
  • Complete the model pipeline by specifying a maximum length of 150 tokens and setting the pad_token_id to the end-of-sequence token.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Instantiate the pipeline
generator = pipeline(____, model="gpt2")

response = "Dear valued customer, I am glad to hear you had a good stay with us."

# Complete the prompt
prompt = f"Customer review:\n{____}\n\nHotel reponse to the customer:\n{____}"

# Complete the model pipeline
outputs = generator(prompt, ____, pad_token_id=____, truncation=True)

print(outputs[0]["generated_text"])
Kodu Düzenle ve Çalıştır