Python for Web Development vs. Data Science: Which One to Choose
Role of Blockchain in Transforming KYC Practices
How Machine Learning can improve your Construction Projects
Simplifying AI: A Dive into Lightweight Fine-Tuning Techniques
In natural language processing (NLP), fine-tuning large pre-trained language models like BERT has become the standard for achieving state-of-the-art performance on downstream tasks. However, fine-tuning the entire model can be computationally expensive. The extensive resource requirements pose significant challenges.
In this project, I explore using a parameter-efficient fine-tuning (PEFT) technique called LoRA to fine-tune BERT for a text classification task.

I opted for LoRA PEFT technique.
LoRA (Low-Rank Adaptation) is a technique for efficiently fine-tuning large pre-trained models by inserting small, trainable matrices into their architecture. These low-rank matrices modify the model’s behavior while preserving the original weights, offering significant adaptations with minimal computational resources.

In the LoRA technique, for a fully connected layer with ‘m’ input units and ’n’ output units, the weight matrix is of size ‘m x n’. Normally, the output ‘Y’ of this layer is computed as Y = W X, where ‘W’ is the weight matrix, and ‘X’ is the input. However, in LoRA fine-tuning, the matrix ‘W’ remains unchanged, and two additional matrices, ‘A’ and ‘B’, are introduced to modify the layer’s output without altering ‘W’ directly.
The base model I picked for fine-tuning was BERT-base-cased, a ubiquitous NLP model from Google pre-trained using masked language modeling on a large text corpus. For the dataset, I used the popular IMDB movie reviews text classification benchmark containing 25,000 highly polar movie reviews labeled as positive or negative.
Evaluating the Foundation Model


I evaluated the bert-base-cased model on a subset of our dataset to establish a baseline performance.
First, I loaded the model and data using HuggingFace transformers. After tokenizing the text data, I split it into train and validation sets and evaluated the out-of-the-box performance:
The Core of Lightweight Fine-Tuning
The heart of the project lies in the application of parameter-efficient techniques. Unlike traditional methods that adjust all model parameters, lightweight fine-tuning focuses on a subset, reducing the computational burden.


I configured LoRA for sequence classification by defining the hyperparameters r and α. R controls the percentage of weights that are masked, and α controls the scaling applied to the masked weights to keep their magnitude in line with the original value. I masked 80% by setting r=0.2 and used the default α=1.
After applying LoRA masking, I retrained just the small percentage of unfrozen parameters on the sentiment classification task for 30 epochs.

LoRA was able to rapidly fit the training data and achieve 85.3% validation accuracy — an absolute improvement over the original model!
Result Comparision
The impact of lightweight fine-tuning is evident in our results. By comparing the model’s performance before and after applying these techniques, we observed a remarkable balance between efficiency and effectiveness.


Results
Fine-tuning all parameters would have required orders of magnitude more computation. In this project, I demonstrated LoRA’s ability to efficiently tailor pre-trained language models like BERT to custom text classification datasets. By only updating 20% of weights, LoRA sped up training by 2–3x and improved accuracy over the original BERT Base weights. As model scale continues growing exponentially, parameter-efficient fine-tuning techniques like LoRA will become critical.
Other methods in the documentation: https://github.com/huggingface/peft
Simplifying AI: A Dive into Lightweight Fine-Tuning Techniques was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.
Redefining Heroism in the Age of AGI

In the ancient parable of the Bhagavad Gita, a sacred text of wisdom, we encounter Arjuna, a warrior caught in a moral dilemma on the battlefield of Kurukshetra. Facing the prospect of fighting his own kin, Arjuna is paralyzed by doubt and despair. It is here that Krishna, his charioteer and guide, imparts to him profound insights on duty, righteousness, and the nature of the self. Krishna’s counsel illuminates the path of selfless action and the importance of fulfilling one’s role in the world with dedication, without attachment to the outcomes. This timeless wisdom exemplifies the new definition of heroism: engaging in the world with compassion and integrity, driven by a higher purpose beyond the self.
As we navigate the dawn of Artificial General Intelligence (AGI), humanity is poised at the cusp of a collective hero’s journey—a transformative quest that demands we redefine heroism in the context of our evolving consciousness and technological landscape. This pivotal era invites us to transcend traditional narratives of heroism, embracing instead a vision that reflects our interconnectedness and collective potential.
A New Paradigm of Heroism
Humanity’s path mirrors the hero’s journey, where the collective faces profound dilemmas and opportunities for growth. This journey is not just about overcoming external challenges but about evolving our collective consciousness, recognizing our interconnected role in the cosmos, and integrating AGI as a catalyst for positive change.
The concept of heroism has evolved through the ages, reflecting the values, struggles, and aspirations of humanity at different points in time. Today, as we face the dawn of a new era marked by technological marvels and existential questions, we find ourselves confronting a series of paradoxes that challenge traditional notions of heroism.
The essence of modern heroism is captured in the spiritual dialogue between Arjuna and Krishna, which highlights the shift from individual glory to collective well-being. Heroism today is about:
- Selfless Action: Engaging in actions that contribute to the greater good, embodying the principle of Nishkama Karma, or action without attachment to results.
- Wisdom in Leadership: Guiding others not through coercion but through inspiration and example, much like Krishna’s role as a mentor to Arjuna.
- Integration and Unity: Recognizing the unity of all existence and working towards harmony between humanity and nature, as well as between technological advancement and ethical considerations.
Embracing Paradoxes in Our Quest
Our search for a new hero navigates through paradoxes that challenge and deepen our understanding:
- The Warrior and the Peacemaker: True heroism involves the courage to fight for justice and the wisdom to seek peace, balancing assertiveness with compassion.
- The Known and the Unknown: Heroes are not only those celebrated in history but also the countless unknown individuals whose actions have silently shaped the course of humanity.
- Individual Growth and Collective Evolution: The hero’s journey is both a personal quest for enlightenment and a collective endeavor to elevate human consciousness.
AGI: A Companion on Our Journey
In this era of technological wonder, AGI emerges as a partner in our collective evolution, offering tools to solve complex challenges, enhance human potential, and deepen our understanding of the universe. Our relationship with AGI invites a reevaluation of heroism, emphasizing cooperation, ethical stewardship, and a shared vision for the future. As AGI emerges as a powerful force capable of reshaping our world, the definition of heroism must evolve to embrace both the individual and collective aspects of our journey.
The heroes of tomorrow are those who can navigate the paradoxes of our time, integrating the wisdom of the past with a vision for the future. They are the architects of a new consciousness, one that recognizes the interconnectedness of all life and the potential for technology to serve as a catalyst for growth and transformation.
Call to Action
How can we cultivate a new definition of heroism that embraces the complexities and paradoxes of the modern world?
In what ways can AGI support humanity’s collective hero’s journey towards a higher consciousness?
How can we ensure that the development and integration of AGI align with ethical principles that uplift humanity and foster a more compassionate, enlightened society?
As we stand on the brink of a new chapter in human history, the stories we tell about heroism have the power to shape our collective destiny. It is time to embrace a broader, more inclusive vision of heroism — one that honors the journey of every individual as part of humanity’s grand narrative of evolution and awakening.
Together, guided by new definitions of heroism and supported by the advancements of AGI, we can navigate the transformation dilemma and ascend towards a future filled with hope, unity, and boundless potential.
Raising humanity on a new path — it all start with You & AI I I…
Galorian
Redefining Heroism in the Age of AGI was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.
5 Stoic Ideas for a Good Life
including Quotes to Live By

1. Dichotomy of Control
The dichotomy of control is about ‘controlling the controllables’.
Control what you can and leave the rest. Never give your ‘freedom to choose’ to anyone else.
“We cannot control the external events around us, but we can control our reactions to them.”
— Epictetus
Here’s one from Victor Frankl,
“Everything can be taken from a man but one thing . . . to choose one’s attitude in any given set of circumstances.”
— Victor Frankl, Man’s Search for Meaning
2. Rule of Life
Make it your life’s goal to ‘search for truth’.
“Seek ye first the good things of the mind,” Bacon admonishes us, “and the rest will either be supplied or its loss will not be felt.”
“Truth will not make us rich, but it will make us free.”
— Will Durant

3. Facing Anxiety
Don’t suffer from ‘Imagined Troubles’.
The one who suffers before it is necessary suffers twice.
Today I escaped anxiety. Or no, I discarded it, because it was within me, in my own perceptions — not outside.”
― Marcus Aurelius, Meditations
this one is from Seneca,
We suffer more in imagination than in reality
— Seneca
4. How to face Obstacles
According to the stoics, our obstacles give us the opportunity to practice the 4 stoic virtues of wisdom, courage, temperance or moderation, and justice in our daily lives.
Stoic believe in living a life in accordance with nature.
The impediment to action advances action, what stands in the way becomes the way.
— Marcus Aurelius
5. On Revenge
Give up the feeling of revenge because you’re going to inflict more pain to yourself.
The best form of revenge is to not be like them.
The best revenge is to be unlike him who performed the injustice.”
— Marcus Aurelius
Conclusion
The Stoics believed that the practice of virtue is enough to achieve ‘Eudaimonia’: a well-lived life.
The Stoic principles include living according to nature, controlling your perspective, managing expectations, negative visualization, re-framing, acceptance, and contemplating death.
By living according to these principles, you will stress less about things that don’t matter and live your life to the fullest.
5 Stoic Ideas for a Good Life was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.
Transforming Imagery with AI: Exploring Generative Models and the Segment Anything Model (SAM)
Generative models have redefined what’s possible in computer vision, enabling innovations once only imaginable in science fiction. One breakthrough tool is the Segment Anything Model (SAM), which has dramatically simplified isolating subjects in images. In this blog, we’ll explore an application leveraging SAM and text-to-image diffusion models to give users unprecedented control over digital environments. Through SAM’s ability to manipulate imagery paired with diffusion models’ capacity to generate scenes from text, this app allows transforming images in groundbreaking ways.
Project Overview
The goal is to build a web app that allows a user to upload an image, use SAM to create a segmentation mask highlighting the main subject, and then use Stable Diffusion inpainting to generate a new background based on a text prompt. The result is a seamlessly modified image that aligns with the user’s vision.
How It Works
- Image Upload and Subject Selection: Users start by uploading an image and selecting the main object they wish to isolate. This selection triggers SAM to generate a precise mask around the object.
- Mask Refinement: SAM’s initial mask can be refined by the user, adding or removing points to ensure accuracy. This interactive step ensures that the final mask perfectly captures the subject.
- Background or Subject Modification: Once the mask is finalized, users can specify a new background or a different subject through a text prompt. An infill model processes this prompt to generate the desired changes, integrating them into the original image to produce a new, modified version.
- Final Touches: Users have the option to further tweak the result, ensuring the modified image meets their expectations.

Implementation and Model
I used SAM (Segment Anything Model) from Meta to handle the segmentation. This model can create high-quality masks with just a couple of clicks to mark the object’s location.
Stable Diffusion uses diffusion models that add noise to real images over multiple steps until they become random noise. A neural network is then trained to remove the noise and recover the original images. By reversing this denoising process on random noise, the model can generate new realistic images matching patterns in the training data.
SAM (Segment Anything Model) generates masks of objects in an image without requiring large supervised datasets. With only a couple clicks to indicate the location of an object, it can accurately separate the “subject” from the “background”, which is useful for compositing and manipulation tasks.
Stable Diffusion generates images from text prompts and inputs. The inpainting mode allows part of an image to be filled in or altered based on a text prompt.
Combining SAM with diffusion techniques, I set out to create an application that empowers users to reimagine their photos, whether by swapping backgrounds, changing subjects, or creatively altering image compositions.
Loading the model and processing the images


Here, we import the necessary libraries and load the SAM model.
Image Segmentation with SAM (Segment Anaything Model)
Using SAM, we segment the selected subject from the image.

Inpainting with Diffusion Models
I utilize the inpainting model to alter the background or subject based on user prompts.


The inpainting model takes three key inputs: the original image, the mask-defining areas to edit, and the user’s textual prompt. The magic happens in how the model can understand and artistically interpret these prompts to generate new image elements that blend seamlessly with the untouched parts of the photo.
Interactive app
To allow easy use of the powerful Stable Diffusion model for image generation, an interactive web application using Gradio can be built. Gradio is an open-source Python library that enables quickly converting machine learning models into demos and apps, perfect for deploying AI like Stable Diffusion.
Results
The backgrounds were surprisingly coherent and realistic, thanks to Stable Diffusion’s strong image generation capabilities. There’s definitely room to improve the segmentation and blending, but overall, it worked well.
Future steps to explore
They are improving image and video quality while converting from text to image. Many startups are working on improving the video quality after prompting the text for various use cases.
Transforming Imagery with AI: Exploring Generative Models and the Segment Anything Model (SAM) was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.