Generative AI is currently one of the hottest topics in the AI space. In this blog we will have the following goals:
- What is Generative AI? And its use cases to revolutionize AI Applications.
- Describe how Generative AI models work and their potential business use cases.
- Describe how a data organization can find initial success with generative AI Applications.
- Potential risks and challenges of Generative AI.
- Learn LLM model wrappers and use cases with Open-AI.
In Generative AI people ask these questions very much:
- Is Generative AI a threat or an opportunity for my business?
- How can I use my data securely with Generative AI?
- How can I use Generative AI to gain a competitive advantage?
1. What is Generative AI?
Generative AI is the sub-field of Artificial Intelligence that focuses on generating new content such as Images, Text, Audio/Music, Video, Code, 3D Objects, and Synthetic data.
– Generative Models
Generative AI is built on deep learning, unsupervised or semi-supervised models that use large datasets to create new possible content. The main idea is to generate completely original artefacts that look real.
Factors making Generative AI possible now:
- Large Datasets: Availability of large and diverse datasets. AI models learn patterns, correlations, and characteristics of large datasets.
- Computational Power: Advancements in hardware; GPU. Access to cloud computing. Open-source software, Hugging face.
- Innovative DL Models: Generative Adversarial Networks (GANs), Transformer architecture, Reinforcement learning from human feedback (RLHF).
– Why should I care now about Generative AI?
AI/ML has been around for a while, why it matters now
- Generative AI model’s accuracy and effectiveness have hit a tipping point.
- Many models are openly available and customizable such as LLAMA2, Falcon, Dolly etc.
- Economical for use-case even for non-technical business users since Models like Chat GPT are available in the cloud as End API.
– Generative AI Use Cases
Generative AI can be used in various industries like Healthcare, Automotive, Architectural, Drugs, Chips, Education, Photography, etc. Some use cases are the following:
- Content Generation — Image, Video, Audio, Video
- Question/Answer
- Virtual Assistants
- Content Personalization
- Style Transfer
- Storytelling, poetry, creative writing
- Translation
- Code generation/ auto-completion
- Synthetic dataset generation
- Architecture design and urban planning etc.
– Some Trending Generative AI Models
- Text Generator Models: OpenAI API, Gopher, LLaMA, LLaMA2, Mixtral, Vicuna-13B, Bard etc.
- Image Generation Models: MidJourney, DALL-E2, Stable Diffusion, DragGAN, Imagen, Make-A-Scene, etc.
- Coding Generation Models: Github Copilot, OpenAI Codex, Ghostwriter, Amazon CodeWhisper, Code LLaMa, etc.
- Video: RunwayML, Synthesia, Rephrase AI, Fliki, Pictory, Pika etc.
- Audio — Speech: Eleven Labs, Resemble AI, podcast.ai, Vall-EX, TorToiSe, Bark, Coque etc.
- Audio — Music: Harmonai, MusicLM, AudioCraft, Stable Audio, Suno AI etc.
2. Generative AI: LLM
Generative AI & Large Language models are a once-in-a-generation shift in technology. LLM models are trained on massive datasets to achieve advanced language processing capabilities based on deep learning neural networks. LLM models use foundation models like GPT-4, Bard(Gemini), LLaMA, etc.
– LLM Working:
LLM models work on the principle of Transformer Deep Learning architecture which uses the Self-Attention technique for understanding long textual data. “Attention is all you need” — This Transformer paper brought a revolution in the Natural Language Processing(NLP) field by introducing Transformer Architecture which overcomes the drawbacks of RNN(Recurrent Neural Networks).
Transformer uses Encoder and Decoder- in which Encoders are designed to learn embedding that can be used for various predictive modeling tasks such as classification. While Decoders are designed to generate new text, for example, answering user queries.
These are the major advantages of Transformers over the RNN technique:
- Parallel Processing: Unlike RNN which process data sequentially, Transformers process text in parallel, making training faster and more efficient.
- Long-range dependency modelling: RNN struggles to capture long-range dependencies between words.
- Interpretability: By highlighting which part of the input sequence the model pays attention to, it’s possible to gain insights into its decision-making process.
- Flexibility: The transformer architecture is modular and can be easily adapted to different NLP tasks.
- State-of-the-art performance: Transformers have achieved state-of-the-art performance on many NLP benchmarks. This is due to their combination of parallel processing, long-range dependency modelling, and flexible architecture.
– LLMs Business use cases:
- Customer Engagement: LLM can be used to provide personalized product/content recommendations based on customer behaviour and preferences.
- Content Creation: LLM can be used for Creative writing, Technical writing, Translation and localization, PDF summarization, and Article writing for blogs/social media.
- Process automation and efficiency: Automated customer response, Sentiment analysis of reviews, prioritization.
- Code and developer productivity: Code completion, Error detection, debugging, Convert code between languages, Automated testing, Natural language to code generation.
– LLM Flavors:
If you are thinking of your own modern LLM Application. There are two types of Models:
- Open Source Models:
— Meta LLaMA 2, Dolly, Falcon, etc. - Proprietary Models:
— OpenAI ChatGPT, Google PaLM 2 etc.
There are various Pros and cons for both Flavors of LLM Models:
Using Proprietary Models (LLMs-as-a-Service)
Pros:
– Quick to get started and work. Only API calls are required which fit very easily into existing pipelines.
– Can offer state-of-the-art results.
Cons:
– Pay for each token sent/received
– Data Privacy/Security: You may not know how your data is being used.
– Vendor lock-in: Suspectable to vendor outages, deprecated, features, etc.
— Restrictive license for usage and modification.
Using Open Source Models(offline models)
Pros:
– Task-tailoring: Select and/or fine-tune a specific model for your use case.
– Inference Cost: More tailored models are often smaller, making them faster at inference time.
– Control: All of the data and model information stays entirely within your control.
– Commercial/Non-Commercial use.
– Provides flexibility for Customization.
– Meta LLAMA2, Dolly, Falcon etc.
Cons:
– Upfront time & Cost investments: Needs time to select, evaluate, and possibly tune. Also, pipeline building and deployment costs.
– Data Requirements: fine-tuning or larger models require larger datasets.
– Skills Sets: Require in-house expertise
– Fine-Tuned Models
Fine-tuning is the process of further training a pre-trained model on a specific task or dataset to adapt it for a particular application or domain.
Models can be fine-tuned for:
- Specific tasks: Such as Question Answering, Sentiment Analysis, etc,
- Domain Specific: Such as Science, Finance, Healthcare or Legal, etc.
3. Potential Risks and Challenges of Generative AI
Generative AI brings new risks and challenges for businesses and society. There are various news on various ChatGPT data leaking. There is a high risk of security for the various industries.
There are various data privacy and security challenges with Gen AI. Some of them are discussed below:
– Data Privacy:
- Current models don’t have a “forgetting” feature for personal data.
- Models are trained on personal information. This might violate a person’s privacy rights.
- Employee training based on Company policies, How can/can’t use GenAI tools.
- Attentive while using off-shelf Services. Prompt data can be collected, used for training, or shared with 3rd parties.
Data privacy: Best Practices
- Ensure proper data anonymization, encryption, and access controls.
- Implement safeguards to access or disclosure of sensitive data during training/storage/inference.
- Establish data and model governance. Version control, monitoring, auditing, data usage policy, etc.
– Data Security in Generative AI
Data Leakage
GenAI models have the potential to memorize and reproduce training data. What if training or prompt includes sensitive or confidential data?
E.g., One employee from XYZ company used the Proprietary LLM Model to get some answers to queries with the prompt “What is the solution for Problem using for ‘xyz’ client to deliver the project before the deadline of date-1”.
This data can be used for training a better version of the model. Another user can use some prompt to get confidential information.
Prompt Injection
Inserting specific instructions or prompts within the input text to manipulate the normal behaviour of LLM.
Prompt injection cases:
– Generating malicious code
– Instructing an agent to give the wrong information
– Revealing confidential information
– Easy access to content for planning attacks or violence
4. LLM Wrappers
This section will cover some technical things on the implementation and usage of LLMs in your application or developing an application from scratch. If you don’t want to go into technical we have covered the basics till section 3.
So, LLM wrappers are the high-level interface to various kinds of LLM models. There are various wrappers available:
- LangChain: Langchain provides an interface to different models from LLMs to Chat Models to Text Embedding Models like Hugging Face, OpenAI, Studio AI21, etc. Using langchain you can load offline available models also like LLaMa, Falcon etc. Langchain focuses on implementing ‘chaining’, for creating LLM-driven pipelines for streamlined operations.
- LLamaIndex: Llama index also provides an interface to LLM models as langchain. The main difference is Llama index specializes in supporting RAG(Retrieval-Augmented Generation) architecture.
LangChain
Let’s develop a small LLM application to create a Question question-answering bot to get answers. Before going into implementation first understand a bit on a few technical words.
- Tokens: Tokenization is the process of breaking a sequence of text into smaller parts known as tokens for easier machine analysis.
- Embeddings: Word embeddings are the numeric representation of words as real-valued vectors in a lower dimensional space and capture inter-word semantics.
- Prompts: Prompts are the input passed to LLM models based on which LLM will act.
- Prompt Template: Prompt Templates are formats or structures that guide users in providing input to a language model.
- Temperature: Temperature parameters control the creativity of text generated. Temperature is between 0 and 1. A high value will produce more creative text while a low value will produce more predictable text.
- Open-AI ChatGPT-4: OpenAI has various models available we will leverage OpenAI.
Now let’s get into some coding. For that, we will leverage Python programming language with some Python packages like:
- openai==0.28
- langchain
- streamlit — For front end.
- dotenv — For loading the Env file OpenAI API key
Code of Finance Bot using OpenAI
You can get OpenAI API key from https://openai.com . Put OpenAI key in a .env
file as OPENAI_API_KEY = "YOUR_KEY"
Output:
Run app by streamlit run app.py
. You can see a web page will open in the browser.
Conclusion
So, What do you think Generative AI is a Boon or Bane to the industry? In my understanding, Generative AI is a Boon to the industry but there are still various challenges for security that need to be overcome. And currently in my opinion Open Source Models like LLaMa2 etc can be used for developing LLM Applications if there is a risk to the security of data.
References:
[1]. Ashish Vaswani, Noam Shazeer, Attention Is All You Need arXiv: 1706.03762, 12Jun.2017
[2]. Langchain: https://www.langchain.com/
[3]. Llamaindex: https://www.llamaindex.ai/
[4]. Youliang Yuan, Wenxiang Jiao, GPT-4 Is Too Smart To Be Safe: Stealthy Chat with LLMs via Cipher. arXiv: 2308.06463, 12 Aug 2023.
[5]. Nicholas Carlini, Florian Tramer, Extracting Training Data from Large Language Models, arXiv: 2012.07805, 14 Dec 2020
[6]. OpenAI: https://openai.com/