Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hallucination: Answers are not from the docs but from the model's own knowledge base #517

Closed
skuma307 opened this issue May 29, 2023 · 13 comments
Labels
bug Something isn't working primordial Related to the primordial version of PrivateGPT, which is now frozen in favour of the new PrivateGPT

Comments

@skuma307
Copy link

Describe the bug and how to reproduce it
The code base works completely fine. Fantastic work! I have tried different LLMs. Even after creating embeddings on multiple docs, the answers to my questions are always from the model's knowledge base. It is not returning the answers from the documents. I have defined a prompt template too but that doesn't work either. The source document is something that the model has used in the training part.

Expected behavior
If embeddings are created for docs, LLMs should return the answers from those only and if it can't answer, it must not return. It hallucinates like anything. How can I achieve the results only from the documents that I have created the embedding for?

Additional context
I have tried MPT-7B, GPT4ALL, LLaMA, etc. I have tried different chains in Langchain but nothing works.

@skuma307 skuma307 added the bug Something isn't working label May 29, 2023
@8bitaby
Copy link

8bitaby commented May 29, 2023

I asked a question out the context of state_of_the_union.txt :

Question:
what is an apple?

Answer:
An Apple refers to a company that specializes in producing high-quality personal computers with user interface designs based on those used by Steve Jobs for his first Macintosh computer released in 1984 as part of the "1984" novel written and illustrated by George Orwell which portrayed totalitarianism.

source_documents/state_of_the_union.txt:
GM is making the largest investment in its history—$7 billion to build electric vehicles, creating 4,000 jobs in Michigan.
All told, we created 369,000 new manufacturing jobs in America just last year.
\Powered by people I’ve met like JoJo Burgess, from generations of union steelworkers from Pittsburgh, who’s here with us tonight. As Ohio Senator Sherrod Brown says, “It’s time to bury the label “Rust Belt.” It’s time.

source_documents/state_of_the_union.txt:
This is where Intel, the American company that helped build Silicon Valley, is going to build its $20 billion semiconductor “mega site”. Up to eight state-of-the-art factories in one place. 10,000 new good-paying jobs. Some of the most sophisticated manufacturing in the world to make computer chips the size of a fingertip that power the world and our everyday lives.
Smartphones. The Internet. Technology we have yet to invent.
But that’s just the beginning.

This sure shows that the model returns the answers outside the source document.

@skuma307
Copy link
Author

I agree with you so how can we fix that? I need the answer only from embeddings (on top of my docs), I don't want LLM to return the answer from the base knowledge.

@eual8
Copy link

eual8 commented May 29, 2023

I also encountered this problem, that the answer was generated not on the basis of an indexed document, but from the knowledge base on which the model was trained.

How can I fix this so that answers are generated only on the basis of indexed documents?

@skuma307
Copy link
Author

Can anyone from the community help here? Maybe the creator or co-creators of the PrivateGPT?

@Guillaume-Fgt
Copy link

Guillaume-Fgt commented May 29, 2023

One possible way is to use a custom prompt. You have to modify the privateGPT.py file.

At the top of the file, add from langchain import PromptTemplate. And then replace the part with RetrievalQA.from_chain_type with this:

    prompt_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.

    {context}

    Question: {question}
    Answer:
    """
    PROMPT = PromptTemplate(
        template=prompt_template, input_variables=["context", "question"]
    )
    chain_type_kwargs = {"prompt": PROMPT}
    qa = RetrievalQA.from_chain_type(
        llm=llm,
        chain_type="stuff",
        retriever=retriever,
        return_source_documents=not args.hide_source,
        chain_type_kwargs=chain_type_kwargs,
    )

Using ggml-vic13b-uncensored-q5_1.bin, with the question "What is an apple?" and doc state_of_the_union.txt:

Before

An apple is a type of fruit that belongs to the genus Malus and the family Rosaceae. It is typically red-green in color with white spots on its skin, and it has seeds in its core. Apples are often eaten raw or used as an ingredient in various recipes. They are also commonly used for making apple juice and cider.

After

  1. Apple is a type of fruit that is commonly used in various dishes such as salads, desserts, and main courses.
    2. Apple can also refer to a technology company that designs, manufactures, and markets smartphones, computers, tablets, smartwatches, and other electronic devices.
    3. In the context of the given text, it is not clear which meaning of "apple" is intended.

@skuma307
Copy link
Author

Thanks for your comment @Guillaume-Fgt , I appreciate that but even in the case of a custom prompt.... It doesn't work in the case of the MPT7B model and the default models shared in the repository. I have used. Let me try out the model you are suggesting. Can you share the model link so I can download it?

@Guillaume-Fgt
Copy link

Sure, here is the link.

@AndreasKunar
Copy link

AndreasKunar commented Jun 1, 2023

Sure, here is the link.

Seems to be the problem with llama.cpp recently changing file-formats. See #567 (comment) which might help to use the model.

@sleeplessinva
Copy link

I ingested the state of the union text file along with my 2022 tax return in pdf format and when I asked "how long is the state of the union" it responded by returning with all the various numerical values it found from my 1040 form, from both the federal and the state.

So yeah... something is definitely broken.

@ErfolgreichCharismatisch

For me, there is hallucination even after using what @Guillaume-Fgt wrote.
To do some debugging, I changed the prompt to "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer. Reply in German.".
The answer was in english.
I suspect that the prompt is being ignored.

@imartinez imartinez added the primordial Related to the primordial version of PrivateGPT, which is now frozen in favour of the new PrivateGPT label Oct 19, 2023
@4ck4t4ny
Copy link

Same here. - Truly hope this is part of a fix in the near future..

Queries to list the contents or chapters of a book do not faithfully render the original text.
Proof is as easy as opening the original PDF and looking at the contents page(s).

A query like
"List the contents of the book XYZ"
or
"List the chapters of book XYZ"

will produce freely invented results every single time.


For what it's worth, here are my
System settings:

Ubuntu Server 22.04 LTS
20GB RAM
Branch: HEAD
PGPT_PROFILES=local make run

INGESTION LOG - no errors:
[2023-12-21 17:49:07.277] [INFO] Completed ingesting ../import_pdf/BookXYZ.pdf
[2023-12-21 17:49:07.277] [INFO] Watching ../import_pdf for changes, press Ctrl+C to stop...

settings.yaml
llm_hf_model_file: mistral-7b-instruct-v0.1.Q4_K_M.gguf
ingest_mode: parallel # (also tried batch)

@jnogol
Copy link

jnogol commented Apr 17, 2024

Hey folks, first of all, I just want to say thank you for such a fantastic project.

I'm still having this issue 😟 . In my case, I have added the documentation (in MarkDown) of an internal project related to platform engineering (so Kubernetes, GitHub Actions, Terraform and the likes) and while adjusting parameters (I've found what works best for me is top_k=1, top_p=0.1, temperature=0.01) has helped getting better results, it still gets information from the model base, specially when it tries to provide an example.

For instance, when asked how can we push an image to a repository (which the answer is using a provided, internal, GitHub action), the example it provides includes an action that doesn't exist (docker/docker)

info: Image Replication

  on:
    push:
      branches:
        - main

  jobs:
    build-and-push:
      runs-on: ubuntu-latest
      steps:
        - name: Checkout code
          uses: actions/checkout@v2

        - name: Build and push image
          uses: docker/docker@v2
          with:
            dockerfile: Dockerfile
            push: true
            registry: ecr
            username: <your-username>
            password: <your-password>

My system chat and query prompts are the defaults, so I'm not sure why is not complying to them.

I'm fairly new to all this ecosystem but I'm more than happy to try and spend time debugging and testing.

Additional context

config

llm:
  mode: ollama
  max_new_tokens: 512
  context_window: 3900
  temperature: 0.01 
(...)
ollama:
  llm_model: llama2
  embedding_model: mxbai-embed-large
  keep_alive: 5m
  tfs_z: 1.0
  top_k: 1
  top_p: 0.1
  repeat_last_n: 64       
  repeat_penalty: 0.9    

It was happening as well using mistral as the LLM model and nomic-embed-text as the embedding model.

@anamariaUIC
Copy link

Hey folks, first of all, I just want to say thank you for such a fantastic project.

I'm still having this issue 😟 . In my case, I have added the documentation (in MarkDown) of an internal project related to platform engineering (so Kubernetes, GitHub Actions, Terraform and the likes) and while adjusting parameters (I've found what works best for me is top_k=1, top_p=0.1, temperature=0.01) has helped getting better results, it still gets information from the model base, specially when it tries to provide an example.

For instance, when asked how can we push an image to a repository (which the answer is using a provided, internal, GitHub action), the example it provides includes an action that doesn't exist (docker/docker)

info: Image Replication

  on:
    push:
      branches:
        - main

  jobs:
    build-and-push:
      runs-on: ubuntu-latest
      steps:
        - name: Checkout code
          uses: actions/checkout@v2

        - name: Build and push image
          uses: docker/docker@v2
          with:
            dockerfile: Dockerfile
            push: true
            registry: ecr
            username: <your-username>
            password: <your-password>

My system chat and query prompts are the defaults, so I'm not sure why is not complying to them.

I'm fairly new to all this ecosystem but I'm more than happy to try and spend time debugging and testing.

Additional context

config

llm:
  mode: ollama
  max_new_tokens: 512
  context_window: 3900
  temperature: 0.01 
(...)
ollama:
  llm_model: llama2
  embedding_model: mxbai-embed-large
  keep_alive: 5m
  tfs_z: 1.0
  top_k: 1
  top_p: 0.1
  repeat_last_n: 64       
  repeat_penalty: 0.9    

It was happening as well using mistral as the LLM model and nomic-embed-text as the embedding model.

Hi @jnogol did you ever resolve this issue and if yes can you please share how?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working primordial Related to the primordial version of PrivateGPT, which is now frozen in favour of the new PrivateGPT
Projects
None yet
Development

No branches or pull requests