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

Building a search completion system

Search completion, or auto-complete, is a common NLP application used in search engines and messaging apps. The goal is to suggest possible completions based on a user's partial input. Your task is to use Hugging Face's "text-generation" pipeline to implement a basic auto-complete system that generates relevant completions from the user's query.

Bu egzersiz

Natural Language Processing (NLP) in Python

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

Egzersiz talimatları

  • Create an autocomplete pipeline with the "distilgpt2" model.
  • Generate five search query suggestions for the given prompt, limiting each to a maximum of eight tokens.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

from transformers import pipeline

# Create the pipeline
autocomplete = pipeline(task="____", model="____")

prompt = "Best books to read for"

# Generate search query completions
suggestions = ____

for suggestion in suggestions:
    print(suggestion['generated_text'])
Kodu Düzenle ve Çalıştır