Using large language models (LLMs) on our own (local) data
Compares fine-tuning and zero-shot learning for applying LLMs to private documents, with vendor links and reference projects.
What this file does
Compares fine-tuning and zero-shot learning for applying LLMs to private documents, with vendor links and reference projects.
When to use it
- Choosing between fine-tuning and RAG for internal document Q&A
- Evaluating Azure, Google, OpenAI, Haystack, or LangChain for local data
- Starting a proof-of-concept for private document search with LLMs
- Understanding security and privacy considerations for enterprise LLM use
Assumes this stack
Using large language models (LLMs) on our own (local) data
Goal
Use large language models (LLMs) to extract information from our own (local) data.
Typical use case: a company has private documents that were never used to train the model. Therefore, we need to enhance the interaction with the model to get results from these documents.
Possible solutions:
- Fine-tuning: fine-tune a pre-trained model on our own data.
- Train the model on our own data.
- Zero-shot learning: use a pre-trained model without fine-tuning it on our own data.
- Extract information with a vector (embedding) of our own data.
- Feed that vector to the pre-trained model as part of the prompt.
What to consider when selecting a solution
Items to consider when selecting a solution:
- License
- Commercial vs. non-commercial use.
- GPLv3 vs. others.
- Time to make the solution available.
- Fine-tuning: time to train the model.
- Zero-shot learning: time to create a vector database that will be used to extract information from our own data.
- Time to update the solution.
- Fine-tuning: time to re-train the model on changed data.
- Zero-shot learning: time to update the vector database.
- Cost
- Fine-tuning: cost of training the model.
- Zero-shot learning: cost of creating the vector database and (potential) costs of larger prompts (pay per token).
- Accuracy
- Fine-tuning: potentially less accurate than zero-shot learning because the trained model is probabilistic, not deterministic.
- Zero-shot learning: accuracy of the model on our own data.
- Response time
- Fine-tuning: potentially faster response time because of smaller prompts.
- Zero-shot: Potentially larger response time because of vector database lookup and larger prompts.
- Data privacy
- Fine-tuning: data privacy is a concern because the model is trained on our own data.
- Zero-shot learning: data privacy is less of a concern because the model is not trained on our own data (but we still expose the prompt to the model).
- Security
- How to filter out private documents from the model?
- How to protect individuals' privacy?
- What regulations apply, e.g. GDPR, CCPA, HIPAA, etc.?
- What audit and compliance requirements apply?
- Resistance to poisoning attacks.
- Resistance to backdoor attacks.
- Resistance to model inversion attacks (extract data from the model).
- Resistance to membership inference attacks (determine if a data point was used to train the model).
- Resistance to offensive language attacks (generate offensive language).
- Resistance to model stealing attacks (steal the model).
Vendors, frameworks
Azure
Azure requires a corporate email to sign up for the service.
Technical references:
- ChatGPT + Enterprise data with Azure OpenAI and Cognitive Search
- Companion blog post.
- Unofficial implementation (refer to the blog post above).
OpenAI
NOTE: OpenAI removed all examples under the apps directory (explanation). The links below take you to the repository state before the apps directory was removed. Removing them also means they are no longer maintained. As they get older, newer techniques may appear, so use these examples as a starting point and look for newer ones.
- The "query your data" tutorial.
- See slides first.
- This is a good conceptual example - a good place to start learning (starting with slides, then code).
- Enterprise Knowledge Retrieval.
- "The notebook is the best place to start, and takes you through an end-to-end workflow for setting up and evaluating a simple back-end knowledge retrieval service"
- This is a very good notebook to start with. It shows not only the code but also the thought process of putting a good solution in place and evaluating it.
- It also covers agents, i.e. invoke external tools to complement the LLM.
- File Q&A: "[U]pload files and ask questions related to their content, and the app will use embeddings and GPT to generate answers from the most relevant files".
- Similar to the "query your data" and "enterprise knowledge retrieval" tutorials, but includes a front-end and backend.
- Seems to be older than the "knowledge retrieval" tutorial.
- Using Vector Databases for Embeddings Search.
- Shows how to use different embedding databases.
Haystack
- haystack: "Apply the latest NLP technology to your own data with the use of Haystack's pipeline architecture".
LangChain
- How-To Guides
- The ones related to answering questions on documents:
- Question Answering: "how to use LangChain for question answering over a list of documents. It covers four different types of chains: stuff, map_reduce, refine, map_rerank".
- Retrieval Question/Answering: "showcases question answering over an index."
- The ones related to answering questions on documents:
References
Projects that run GPT locally
- privateGPT. Based on GPT4All.
- Shows how to ingest data from different file formats with LangChain.
- Run ChatGPT-Style Questions Over Your Own Files Using the OpenAI API and LangChain!.
- GPT-4 & LangChain: "Create a ChatGPT Chatbot for Your PDF Files".
Projects that create/publish models
- GPT4All
- GPT-J
- MPT-7B: "provide a commercially-usable, open-source model that matches (and - in many ways - surpasses) LLaMA-7B."
Other projects with LLMs
- AutoGPT: Similar to "agents" in LangChain. It may be interesting to see how it is implemented behind the scenes (LangChain is also open source, but it has a lot more than agents -- this one is more focused).
Vector database and similarity search
- Faiss: the missing manual: Covers the basic concepts in the context of Faiss.
Fine-tuning
Prompt techniques to improve information retrieval
- OpenAI's Techniques to improve reliability: Illustrates techniques to improve answers, including "Let's think step by step" (Large Language Models are Zero-Shot Reasoners - zero shot) and "chain of thought" (Language Models Perform Reasoning via Chain of Thought - few shot).
- Unit test writing using a multi-step prompt: Shows how to use a sequence of prompts to get a response.
Document parsers/loaders
- Llama Hub
- LangChain Document Loaders
- Some loaders seem to be based on the ones from Llama Hub.
Improving search results
- Question answering using a search API and re-ranking (OpenAI)
- Search re-ranking in more details (OpenAI)
- Hypothetical Document Embeddings: Using hallucinations productively (OpenAI): demonstrates how to use HyDE to improve retrieval
- Fine-tuning a Classifier to Improve Truthfulness (OpenAI): Discusses how to fine-tune a classifier to remove false results.
- Dynamically chosing prompts and retrievers.
- Moderating the results.
Other
- Reddit: The best way to train an LLM on company data (March 2023): open-ended discussion.
- psychic: "extract and transform unstructured data from SaaS applications like Notion, Slack, Zendesk, Confluence, and Google Drive".
- MLC LLM: "a universal solution that allows any language models to be deployed natively on a diverse set of hardware backends and native applications".
- Prompt auto-evaluator: Use GPT-4 to evaluate prompts.
- How write prompts that invoke external tools (agents): This is the same as the link added above for OpenAI knowledge retrieval. I added it here again to remmeber it also has this interesting piece about agents.
What's inside
Goal, comparison table, vendor sections, and 10 reference categories with links
Change this for your project
- Replace
fau-masters-collected-works-cgarbin/gpt-all-localwith your own repository name - Replace
https://github.com/Azure-Samples/azure-search-openai-demo/with your own Azure sample if used - Replace
https://github.com/imartinez/privateGPTwith your own fork or alternative
Where it goes
Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.
Worth borrowing
- Decision matrix comparing fine-tuning vs zero-shot across 8 criteria
- Curated list of reference projects and tutorials for each approach
Related Documents
SUMMARY
Proposes three on-prem AI architectures, modular, hybrid, and fully local RAG, with hardware specs and vendor lists.
Retrieval & Prompts
Explains how CharMemory's extraction prompt and Vector Storage settings determine memory retrieval quality in SillyTavern.
App Review Support Guide — Switch2Go
Explains an AAC app's accessibility permissions, hardware needs, and reviewer walkthrough to pass App Store review.
RFC-BLite: High-Performance Embedded Document Database for .NET
Specifies an embedded document database for.NET with zero-allocation I/O, C-BSON format, and ACID transactions.