In my earlier articles, I delved into the potential of blockchain as a complement to AI, and how tuning can facilitate the customization of Language Models (LMs) for enterprise applications. As I persist in exploring the practical applications of machine learning, artificial neural networks, and Generative AI, I find the field to be expansive with limitless possibilities. The realm of Generative AI and machine learning is bifurcated into supervised and unsupervised learning. Generative AI has garnered significant attention, starting with Chat-GPT and now extending to a multitude of pre-trained transformers.
Retrieval Augmented Generation
A technique that stands out due to its straightforwardness is Retrieval Augmented Generation, or RAG. An abundance of articles, tutorials, and code on RAG and prompt engineering are available, making it a favored choice for Generative AI modeling. Frameworks like LangChain and LlamaIndex have simplified the process of crafting solutions.
At its core, RAG operates as follows:
In a standard setup involving a Language Model (LLM) and a Vector Database, in the initial step, enterprise data that is proprietary and trusted is curated, transformed and then loaded into a vector database with embeddings.
Once complete it is ready for use and the user’s prompt or query undergoes several stages:
Tokenization: The user’s input is initially segmented into smaller units, typically words or sub words. This is necessary as machine learning models work with numbers, not text. Each token is then associated with a unique number (or vector) in a process known as embedding.
Embedding: The tokens are subsequently passed through an embedding layer, which converts them into dense vectors of a fixed size. This is more efficient than working with sparse vectors. The embedding layer is typically a component of the LLM and is trained alongside it.
Language Model Processing: The embedded tokens are fed into the LLM. The LLM processes the sequence of vectors and generates a new sequence of vectors. Each vector in the output sequence represents the LLM’s interpretation of the corresponding input token in the context of all other tokens.
Vector Database Search: The output vectors from the LLM can be used to search a Vector Database for similar vectors. The similarity between vectors is typically measured using a metric like cosine similarity or Euclidean distance. The items in the database with vectors most similar to the input vector are returned as search results.
Decoding: Finally, the output vectors from the LLM (or the vectors retrieved from the Vector Database) are decoded back into human-readable text. This is typically achieved by mapping each output vector to the token it represents.
This is a high-level summary of the process. The actual implementation can vary depending on the specific LLM and Vector Database used. It’s also important to note that this process involves complex mathematics and computations, typically performed on high-powered computers or servers.
Generative Adversarial Networks, or GANs, have recently sparked my curiosity, despite being a well-researched topic for several years. Their capacity to process images and videos opens up a wealth of potential applications. What’s particularly fascinating is the adversarial relationship between two models within the GAN framework.
Generative Adversarial Network
GANs operate on the principle of unsupervised learning, where two AI models, namely a Generator Model (GM) and a Discriminator Model (DM), are set against each other. These models are based on Convolutional Neural Networks (CNNs), with each node within the convolution layers implementing linear regression and applying filters for pattern recognition.
The DM is trained to classify or predict objects, while the GM gradually learns to generate images that closely resemble real ones with minimal input. The DM receives input from two sources: the first source provides real data such as actual images or objects, while the second, the GM, supplies randomly generated fake images or objects.
During training, the generator is constantly trying to outsmart the discriminator by generating better and better fakes.The DM’s task is to distinguish and classify real objects from fakes, compute the loss, and appropriately backpropagate it. As the GM improves with training, the DM’s performance deteriorates because it struggles to differentiate between real and fake. Eventually, there’s a convergence point where the GM can produce realistic fakes. This results in two independently exploitable models that can be used.
Generative Adversarial Networks (GANs) come in a variety of forms, each differing based on the architecture of the two models involved. The most basic form is the Vanilla GAN, which serves as the foundation for other variations. However, researchers have continuously refined this framework.
Conditional GANs, for example, allow users to guide the generation process by providing additional information like labels or captions.
Super-Resolution GANs (SRGANs) excel at taking low-resolution images and breathing life into them by synthesizing realistic details.
Deep Convolutional GANs (DCGANs) leverage the power of convolutional neural networks (CNNs) to excel at image generation, particularly for tasks involving natural scenes.
Beyond these core variations, the world of GANs gets even more fascinating.
Cyclic GANs (CycleGANs) perform fancy things like translating images from one domain to another, enabling transformations of sketches to photorealistic portraits.
StyleGANs, a recent advancement, offer unparalleled control over the style of generated images. This opens doors for applications like editing the artistic style of existing photographs.
Generative Adversarial Networks (GANs) and their role in Enterprise Applications
GANs, in their various forms and enhancements, unlock a multitude of new applications.
GANs have shown impressive results in areas such as enhancing the resolution of medical images, transforming low-quality images and data into realistic visuals, converting medical data into visualizations, and distinguishing between healthy and diseased organs in both humans and plants. A notable example that caught my attention was presented by Zuleyka of Edureka, who demonstrated with images of healthy and diseased leaves to train GAN models.
Given the ability of GANS to augment data, they seem to have potential to assist with new drug discovery as described in this paper.
Combating Counterfeits and Protecting Consumers:
Advanced Fake Detection: Early GAN research explored differentiating real and fake currency. This concept can be extended to detect counterfeit luxury goods, protecting brands and consumers alike. Companies like Entrupy and Goat already leverage AI and computer vision to combat counterfeits. At Chainyard, we had developed a blockchain enabled solution called "Trust Your Product" to fight fraud in the #supply_chain, and GANs can further enhance these efforts, saving brands millions in losses.
Product Management
With just a handful of data points and images, GANs can enhance the image quality, thereby aiding applications in product searches, detailing, and tracking product availability.
Moreover, GANs can contribute significantly toproduct design. By leveraging existing images, they can generate new, unique images. This capability is anticipated to provide a significant impetus to industries that rely heavily on visual creativity and innovation, such as the fashion industry. The potential to create novel designs and patterns using GANs could revolutionize the way products are conceived and brought to life.
Enhancing Security and Safety:
Sharpening Security Footage: Blurry security camera footage often hinders investigations. GANs can be used to improve image resolution, providing law enforcement with clearer visuals for identification purposes.
Predictive Video Analytics: By predicting the next frame in a video sequence, GANs can potentially help prevent crimes before they happen. Imagine a system that alerts authorities of suspicious behavior based on what it predicts will happen next.
Missing Person Identification: Training GANs to understand facial aging allows them to reconstruct a missing person's face based on childhood photographs. This technology could prove invaluable in locating missing individuals.
Advanced Verification Systems: Similar to counterfeit detection, GANs can be used for face recognition, verifying passports and educational credentials, and even authenticating signatures on important documents.
Satellite and Military Imagery: GANS can help augment military and satellite images, and even help predict video frames, thus greatly augmenting the defense capability
Preserving History: Restoring the Past:
Breathing New Life into Old Photos and Videos: Imagine transforming grainy, black-and-white photographs from the 1800s and 1900s into clear and vibrant images. GANs hold immense potential for restoring historical photos and videos, preserving our past for future generations.
These are just a few examples of how GANs are transforming the enterprise landscape. As the technology continues to evolve, we can expect even more innovative applications to emerge, shaping the future of various industries.
GAN Discriminator and Generator in Code
In this simple example, we define a Generator and Discriminator. I run this model to recognize real images of Oscar, my Yorkshire-terrier, along with fakes generated by the Generator. This code was run on my local laptop using 32x32 images. Nothing fancy. Both the models could be handled by trained and tuned LMs, though there are very few examples available.
Generator Class:
__init__(self, z_dim): This is the constructor method that is called when you create a new instance of the Generator class. It takes one argument, z_dim, which represents the dimension of the input noise vector.
self.gen: This defines a sequential neural network architecture using the nn.Sequential module from PyTorch. The network consists of several linear layers (nn.Linear) with increasing dimensionality (number of neurons) starting from z_dim to 1024. Each layer is followed by an activation function:nn.ReLU(): This is the Rectified Linear Unit activation function, which introduces non-linearity into the network.nn.Tanh(): The final layer uses the Tanh activation function, which outputs values between -1 and 1. This is often used in the output layer of a generator when dealing with image data.
forward(self, x): This method defines the forward pass of the network. It takes an input vector x (presumably the noise vector) and passes it through the sequential layers defined in self.gen. The final output of the network is returned.
Discriminator Class:
__init__(self): Similar to the Generator, this is the constructor method. It doesn't take any arguments.
self.disc: This defines another sequential neural network architecture. This network takes an input with a dimension of 1024 (likely representing an image) and reduces it to a single output value between 0 and 1 using a sigmoid activation function.nn.LeakyReLU(0.2): This is the Leaky ReLU activation function, which is similar to ReLU but allows for a small non-zero gradient for negative values. This helps prevent the network from dying.nn.Dropout(0.3): This layer introduces dropout, a technique that randomly drops a certain percentage of neurons during training (0.3 in this case). This helps prevent overfitting.nn.Sigmoid(): The final layer uses the Sigmoid activation function, which squashes the output between 0 and 1. In a GAN, the discriminator tries to distinguish between real data and data generated by the generator. The sigmoid output represents the discriminator's probability of a given input being real data.
Key Points:
The code defines a basic vanilla architecture for a GAN.
The Generator takes random noise and tries to generate realistic data (likely images based on the output size).
The Discriminator takes data (either real or generated) and tries to classify it as real or fake.
During training, these two networks are pitted against each other. The Generator tries to improve its ability to fool the Discriminator, while the Discriminator tries to get better at identifying real from fake data. This adversarial training is what drives GANs to learn and produce realistic outputs.
I will post the full sample code and a variation of this article on "Medium" and update this article to point towards that.
I am the CTO of Chainyard. We are a global leader in blockchain solutions. We also have expertise to help clients explore their AI, machine and deep learning use cases. Our solutions group has built and operates the blockchain and AI enabled "Trust Your Supplier" platform. Please reach out for any questions or collaborative projects.
This is a good write up on GAN
We have Blockchain for Guardrails for AI, but this use case is interesting.
Also , I have had better success with ProGAN vs cyclic or style with much lesser GPU. Any thoughts on that?
Founder @ Uptek | Toptal Vetted Expert Shopify Dev | I Design & Build Shopify Stores that Boost Sales Upto 60% of Your Store!
5moInteresting take. But, GANs can inherit biases from the training data. Careful data selection and training methods are crucial to mitigate this.
This is a good write up on GAN We have Blockchain for Guardrails for AI, but this use case is interesting. Also , I have had better success with ProGAN vs cyclic or style with much lesser GPU. Any thoughts on that?