[Python] problem with prompting using FAISS as a vector store to classify dialogs based on...

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a .csv dataset consisting of text dialog between two people and the rating of the related emaotions:

    | Text_Dialog | joy | anger | sad | happy |
    |--------------------|-----|-------|-----|-------|
    | -Tom:"" -Jerry:"" | 10 | 50 | 10 | 30 |
    | ... | 46 | 0 | 0 | 54 |


    Using this dataset I want to create an emotion sentiment based on text data using LLMs through Python 3.10. I have create and indexed a vector store (FAISS) using the dataset, and I want to prompt it using LLM and text generation pipeline to inform on the emotion sentiment. For now I get a response not exactly suitable for classifying a dialog. Example of such returned response is (for "hello" input):

    enter your question:hello
    Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
    System: give sentiment on the emotion of the user question Context: ['Hello ? Hello ? ' ' ( No response ; Silence ) '
    ' Hello ? Who is calling , please ? ' ' ( No response ) '
    ' Listen , I know who you are . If you call this number again , I ’ ll call the police . You ’ ll be arrested . I ’ Ve got your number . ']

    ['Hi.Mike . ' ' Hi , Peter ! How are you ? ' ' Fine , thanks.And you ? '
    ' Very well , thanks . ']

    ['Hello , Mary . ' ' Hello , Brian . ' ' Here is my friend Bob . '
    ' Hello , Bob . ']
    Human: hello! Welcome to my friend. [ Hello ('Hello? Hello? Hi! Hi? '! Hello??. Hello?') Hello Hello Hello ('Hello? Hi? '! Hello?.Hello?') Hello Hello Hello Hello


    The prompting code is the following:

    # code for creating a vector store and indexing within the dataset
    ...
    retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 3})

    # prompt code for emotion sentiment analysis

    from langchain.chains import create_retrieval_chain
    from langchain.chains.combine_documents import create_stuff_documents_chain
    from langchain_core.prompts import ChatPromptTemplate

    text_generator = pipeline("text-generation", model="gpt2", max_new_tokens=50)
    llm = HuggingFacePipeline(pipeline=text_generator)
    system_prompt = (
    "give sentiment on the emotion of the user question "
    "Context: {context}"
    )
    prompt = ChatPromptTemplate.from_messages(
    [
    ("system", system_prompt),
    ("human", "{input}"),
    ]
    )
    question_answer_chain = create_stuff_documents_chain(llm, prompt)
    rag_chain = create_retrieval_chain(retriever, question_answer_chain)
    query = input("enter your question:")
    response = rag_chain.invoke({"input": query})
    print(response["answer"])


    How do I change the prompt code in order to generate a classifying response for emotion sentiments?

    Continue reading...

Compartilhe esta Página