[Python] How to replace the deprecated 'conversational' pipeline in Hugging Face Transformers?

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a chatbot using Hugging Face's Transformers library. I was previously using the conversational pipeline, but it seems that it has been deprecated. Here is the code I was using:

    # Initialize the conversational pipeline
    conversation = pipeline("conversational", model=model, tokenizer=tokenizer)

    # Define the chat history
    chat_history = [
    {"role": "system", "content": "You are a smart chatbot"},
    {"role": "user", "content": "What is the capital of France?"},
    ]

    # Generate a response
    response = conversation(chat_history)
    print(response)


    raise this error:

    KeyError: "Unknown task conversational, available tasks are ['audio-classification', 'automatic-speech-recognition', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-feature-extraction', 'image-segmentation', 'image-to-image', 'image-to-text', 'mask-generation', 'ner', 'object-detection', 'question-answering', 'sentiment-analysis', 'summarization', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'text2text-generation', 'token-classification', 'translation', 'video-classification', 'visual-question-answering', 'vqa', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection', 'translation_XX_to_YY']"


    Now that the conversational pipeline is deprecated, I'm unsure how to achieve the same functionality. I've read that I might need to use the text-generation pipeline or the model's generate method directly, but I'm not sure how to implement this with my existing chat history structure.

    So, What is the recommended way to create a conversational chatbot using the latest version of Transformers?

    Any guidance or code examples would be greatly appreciated!

    Continue reading...

Compartilhe esta Página