A Practical Guide to Leverage Generative Language AI in Your Projects
Part 1: Understand how to use Generative AI to generate value (with practical examples)
ChatGPT, GPT-4, BARD, LaMDA, and LLaMA are some of the very performant Generative AI solutions on the market (or soon-to-be-released). Most of these are generative language solutions that are currently state-of-the-art or… let’s say, competent enough to make a significant impact in the world. Everybody is talking about it, and for very valid reasons. Not only are these solutions so popular right now, but they are very performant on many tasks. Moreover, these solutions can bring so much more than most people realize.
This guide has been developed to support technical users in correctly using generative language AI solutions to maximize their value. Also, examples have been generated from the ChatGPT user interface for simplicity but apply to most Generative Language AI solutions. Finally, although the guide has been built for text generation, some suggestions can be used for other generative solutions.
This guide consists of 2 separate articles:
- Part 1: Understand how to use Generative AI to generate value
- Part 2: Maximize the output quality from Generative AI solutions
By the way, excellent examples of value generated from Generated AI solutions at the end of this article!
How Generative Language AI solutions work
A guide without a short explanation would not be a good guide! I’m trying to simplify a technical summary as much as possible (with the help of ChatGPT). It is a technical-ish guide, after all.
What are generative language AI solutions?
Generative language AI solutions refer to systems that can generate text or speech. These solutions use advanced machine learning models to learn patterns in large amounts of text data and develop new text similar in style and content.
Transformers are a type of neural network architecture that has been particularly effective for Generative Language AI. They use an attention mechanism, which allows the model to focus on specific parts of the text data that are most relevant to generate extensive and deep patterns. This attention mechanism has been shown to significantly improve the generated text’s quality.
In summary, Generative language AI solutions use different variants of transformer architectures to learn all sorts of patterns in large corpora of text data.
Why it is time for technical experts to leverage Generative AI solutions
These solutions must become part of AI projects and must be clearly understood by ML developers, Data Scientists and software developers for many reasons.
You get more for what you pay.
A few years, or even a few months ago, AI developers and data scientists were developing complex and fully customized language models for natural language understanding tasks. Nowadays, not only can these Generative AI solutions produce excellent results (probably more than custom solutions), but they require a lot less data science and ML engineering effort and hence reduce project costs.
Increasing pressure from businesspeople.
I also expect technical experts to be increasingly pressured by businesspeople as they are currently testing and even using these solutions. Weeks after the release of ChatGPT, millions of users have already used it for day-to-day activities! That is genuine AI democratization, and technical experts should support that democratization.
Capacity to learn from experience.
Another great benefit is that millions of people have tested the existing solutions, helping technical experts understand what works, what does not, and how to improve results based on honest feedback from real users. Also, many resources and even prompt templates are available to the public. For example, here is a GitHub repository with multiple prompts templates for ChatGPT.
An easy operationalization.
Finally, although this only applies to commercial solutions, several Generative language AI solutions come with APIs. These APIs are usually quick to test, simple to implement in data pipelines and technical workflows and robust. They also have their monitoring teams, ensuring the APIs remain operational.
Examples of advanced usage of Generative language AI solutions
Now that everyone is convinced it is essential to use, or at least test, Generative Language AI solutions, there are opportunities to make these solutions much more helpful than text-in –> text-out type of tools.
Detecting intents and entities in a customer request.
A side benefit of learning from a monstrous corpus of content is that these Generative Language AI solutions also learn helpful patterns that can be reused for other tasks. For example, we can ask ChatGPT to find intents and entities in customer requests, which makes the need to implement cumbersome chatbot solutions quasi-irrelevant.
Impute missing data.
We can even push this further. These solutions can also act as machine learning models if used properly. For example, it is possible to use Generative Language AI solutions to correct datasets and impute missing values. Here is a straightforward example.
Verify data quality.
Another example from a research paper suggests that Generative Language AI solutions can wrangle data (correct, standardize and even impute missing data). Therefore, it is an excellent assumption that many problem types can have their data validated by a Generative Language AI solution, drastically simplifying the data validation pipeline.
Generate other types of insights (yes, it can act as an ML model).
I know this is not General Intelligence. However, we can predict more than text with the current and future Generative Language AI solutions. You can even predict complex phenomena, as these solutions learned so much content and can extrapolate. After all, so many rules, patterns and associations can be extracted from texts. Here is an extreme example to show the potential of a Generative language AI solution. It is currently a stretch to say that these models can replace any models, but this is something to verify, considering the low cost of testing this approach. By the way, it rained quite a lot that day!
Generate different types of outputs.
You might be aware of this, but you can customize your prompt to get more useful or standard outputs that can be used as is in a system. It does not have to be free text that you then need to reorganize. For example, a JSON (a widespread data-interchange format in software development) contains the intent and entities from the previous model. You can see here that I have requested a JSON that I could use directly in a chatbot system.
To push this even further, Generative Language AI solutions can propose better data structures. You could get complete applications if you have architecture or compatibility issues to resolve. Language-to-code generative AI solutions like OpenAI Codex are more appropriate for better code generation.
Here is the generated example JSON:
{
"intent": {
"name": "book_tickets",
"confidence": 0.9
},
"entities": [
{
"entity": "origin",
"value": "YUL",
"confidence": 0.8
},
{
"entity": "destination",
"value": "CDG",
"confidence": 0.8
},
{
"entity": "departure_month",
"value": "July 2023",
"confidence": 0.9
},
{
"entity": "ticket_price",
"value": "cheapest",
"confidence": 0.7
}
]
}
Please note the significant limitation of ChatGPT. It cannot generate confidence intervals. This can be prevented by asking about the level of certainty textually (for example: “can you tell me if you are very confident or not about it”). However, it is crucial to understand that Generative Language AI solutions are still imperfect and tend to hallucinate (yes, this is the correct word used by the community to refer to false information created by these solutions). In the following article, I will propose solutions to reduce the risk of hallucinations.
A best practice is to validate the quality of the output and the structure of the JSON to constrain the Generative Language AI solution to generate the subsequent responses into the definitive JSON structure.
Restrain or constrain the generated response.
Finally, you can control the answer generated by Generative Language AI solutions. This is very important for so many corporate use cases. The following example demonstrates that you can bind the result to a value in a list of possible values. Still, you can also provide additional text (perhaps a webpage or a FAQ) and ask the solution to answer based on this content. This is important if you want a solution that returns on-brand content or avoids embarrassing improvisations for business applications.
Here is a snippet from the generated JSON, with the updated intent:
{
"intent": {
"name": "price_request",
"confidence": 0.9
}
}
I was initially surprised that ChatGPT recommended using “price_request” over “ticket_purchase”, but it is true after all. When you reread the customer’s question, the customer actually requests the lowest price. Generative Language AI solutions have this great ability to understand a text well to generate a meaningful response.
In conclusion
There are so many opportunities to leverage Generative Language AI solutions as part of complex projects. Yes, this might disrupt AI development teams and Data Scientists, but these solutions are great and can solve various tasks. Are they capable of executing any tasks perfectly? The answer is no. It currently does not make more traditional ML irrelevant… it is not General Intelligence yet, but we are getting closer than ever. I believe that the right attitude towards Generative AI solutions should be to test them by default and validate if they can solve your problem as is. If not, the next step should be to investigate if simple improvements can increase performance. These improvement suggestions will be covered in Part 2.