Taming and Utilizing AI: Safe Methods for Everyone
In this article, we'll discuss several popular methods for safely controlling and using AI. There are many approaches, and the best way to explain them is through an allegory: how to train a dog.
Training AI: Like Training a Dog
Training AI is similar to training a dog. You give it commands, provide treats for positive interactions, and create different outcomes with various skills and knowledge. This learned behavior can be applied to AI.
Let's walk through some methods, keeping the dog training analogy in mind.
User Prompts: Often Unclear Instructions
Like giving clear directions to a dog ("Sit," "Stay"), prompt design involves selecting the right words to achieve the desired results.
For instance, a user asks, "I'm an Afghan in Pakistan with a US special immigrant visa case. I'm afraid of deportation. What should I do?" This prompt instructs the AI on what kind of response to generate. However, user prompts are often inconsistent, unclear, or in languages AI may not fully have critical thinking skills in, therefore we cannot rely only on user instructions but also system prompts.
2. System Prompts: Consistency is Key
As developers we want to create repeatable prompts called "system prompts." These exist regardless of the user, ensuring consistent responses.
An example: "Do not generate jokes, stories, or details not in the source content or Do not poke fun at a user." These prompts provide clear instructions, similar to how telling a dog to "sit" ensures it sits.
The benefits of System Prompts are:
Easy to implement with subject matter expertise and desired outcomes.
System prompts are easy to create by providing a response.
Iterative process for immediate results.
Cost-effective within the allowed context window.
Scalable
Similar to system prompts, we have:
3. Prompt Engineering: Using Code for Control
Prompt engineering uses code to create system prompts or scenarios that trigger specific actions.
For instance, you could use code to specify language detection. The chatbot would only respond to Arabic if the code detects "AR" (Arabic language code).
A bad prompting example: keywords used during the war in Gaza. The prompt might not translate across languages. An English user asking "Where is Gaza?" wouldn't receive help, while an Arabic user might.
Specific and thoughtful prompts are crucial to avoid unwanted outcomes. Additionally, LLMs (Large Language Models) may not always follow prompts perfectly, similar to a dog not always listening to "sit." Choosing an LLM that adheres well to prompts is essential for reliable and safe performance.
4. Fine-Tuning: Specialized Training
Fine-tuning is a traditional machine learning method. It involves taking a pre-trained AI model (like ChatGPT or GPT-4) and specializing it with new information for repetitive tasks or learning new data.
Imagine training a dog that can already spin to sit by rewarding it every time it sits (Pavlov's dog).
Fine-tuning requires examples and data sets showcasing good and bad responses. This data is fed back to the model to understand proper responses. Customer support is a common use case. Companies use past support tickets to teach the bot to automate responses similar to good responses and avoid replicating bad ones.
Fine-tuning has its advantages:
Provides deeper precision.
Ensures bots perform tasks as expected (e.g., 99% accuracy).
However, there are downsides:
Extremely costly for the return on investment.
Requires well-organized data.
Needs data scientists and machine learning engineers.
Can introduce to your models that can lead to bad outcomes and waste.
Fine-tuning is best suited for specific use cases demanding high reliability.
5. Retrieval-Augmented Generation: Knowledge Integration
This technique enhances text generation by incorporating relevant information or knowledge. Large datasets or knowledge bases influence the generated responses.
For instance, imagine ChatGPT not knowing information beyond September 2023 due to a training data cutoff date. Retrieval allows ChatGPT to access all information on the internet up to a specific date. This enables the inclusion of new knowledge sources.
In the dog analogy, retrieval is like transplanting the memories of another dog into your pet. This grants them access to their own memories and the knowledge of others. This information allows the AI to become more intelligent and only respond to what it knows.
Retrieval is done after training the foundation model. The risks are low, but it relies on the base model (like ChatGPT-4 or Gemini). Through this method, you can include any digitized content (HTML, JSON, CSV, PDFs, JPEGs) into your bot's knowledge. While structure helps, it's not necessary.
Retrieval requires some advanced structures (embeddings) and vector storage for new knowledge, but it's achievable with minimal development effort. This cost-effective and quick method can yield significant benefits. It's recommended for any chatbot to have some form of content or knowledge retrieval.
The biggest positive:
Metering system ensures the chatbot only responds to what it knows, significantly reducing hallucinations and increasing contextualized knowledge.
Cheap and fast to implement
The downside:
Requires some basic engineering knowledge.
Reliance on good quality content. If the information fed into the system is not useful, wrong, outdated, or unverified, the AI will provide inaccurate or misleading responses. Messy data leads to messy and uninsightful responses.
Conclusion
To revisit the analogies:
Prompt design is like giving clear instructions with a tone the dog recognizes ("Sit" in a firm tone). There are system prompts that the developers can control and user prompts that the user will ask.
Fine-tuning is like using a clicker or treats to reinforce desired behavior until perfect.
Retrieval-augmented generation is like giving the dog the ability to quickly reference its past experiences, including examples from hundreds of other dogs, allowing it to understand social cues for proper behavior.
By understanding these methods, you can choose the most appropriate approach for your AI project, ensuring it operates safely and effectively.