❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

OpenAI - Gibili Portrait Assistance: AI-Powered Image Generation Made Simple

By: angu10
31 March 2025 at 17:50

Introduction

Ever wished you could create stunning portraits with just a few clicks? Meet Gibili Portrait Assistance, an AI-powered tool that makes generating high-quality portraits effortless. Whether you’re an artist, designer, or simply someone who loves experimenting with AI, Gibili can help bring your ideas to life.

In this post, we’ll walk you through how to use Gibili Portrait Assistance and explore the OpenAI architecture behind it.

How to Use Gibili Portrait Assistance

Using Gibili is straightforward and requires no prior technical knowledge. Here’s a simple step-by-step guide:

1. Enter Your Description or Upload an Image
You can either type a text description of the portrait you want or upload an existing image to be enhanced or transformed by AI.

Text Prompt Example:

  • β€œA realistic portrait of a woman with curly brown hair, wearing a red scarf, in a cinematic lighting style.”

Image Upload:

  • If you have an image you want to modify or enhance, simply upload it, and Gibili will apply AI-powered enhancements or transformations.

2. Customize Your Preferences
You can fine-tune details such as:

  • Art Style: Realistic, digital painting, anime, etc.
  • Background: Solid color, blurred, natural scenery.
  • Facial Expressions: Smiling, neutral, surprised.
  • Additional Features: Glasses, hats, jewelry, etc.

3. Generate the Image
Press Enter, and within seconds, Gibili will produce a high-resolution portrait based on your input or uploaded image.

4. Refine and Download
If you want adjustments, you can tweak your input and regenerate until you’re satisfied. Once ready, download your portrait in high-quality format.

The OpenAI Architecture Behind Gibili

Gibili Portrait Assistance is powered by OpenAI’s advanced image generation models, leveraging diffusion models to create highly detailed and realistic portraits. Here’s a simplified breakdown:

1. Text-to-Image & Image-to-Image Generation
When you provide a text prompt, the AI model translates it into a visual representation using deep learning techniques. If you upload an image, the model can enhance, transform, or stylize it while maintaining its core structure.

2. Fine-Tuned on Portrait Data
The model has been trained on a vast dataset of portraits across different styles, ensuring high accuracy and creativity in generated images.

3. Iterative Refinement
Instead of creating the final image instantly, the AI gradually refines it through multiple steps, ensuring greater precision and quality.

4. User-Guided Adjustments
Users can modify parameters like style and background, and the model will intelligently adjust the portrait while maintaining coherence.

Why Use Gibili Portrait Assistance?

βœ… Easy to Use

No need for advanced design skills β€” just describe what you want or upload an image, and AI does the rest.

🎨 Customizable Output

From photorealistic portraits to artistic illustrations, you can tailor the results to your liking.

πŸš€ Fast & High-Quality

Generate high-resolution images within seconds.

πŸ–ŒοΈ Creative Freedom

Perfect for artists, marketers, and content creators looking for unique visuals.

Get Started with Gibili Today!

Ready to create amazing AI-generated portraits? Try Gibili Portrait Assistance now and explore the limitless possibilities of AI-powered creativity!

Prompting & my life

Source: BingΒ AI

In the AI Era, we all use AI in our daily lives. Prompting is an efficient way of using AI like ChatGPT, Perplexity, and others. Today, I would like to share the β€œPower of Prompting” in this blog. But to know the power of prompting, I would like to share my story. How the Prompting should change myΒ life.

As a small introduction, my name is Anand. I am a Front-End Developer, Tech & Finance Enthusiast and have a desire to work as an developer in Top ITΒ company.

Where do IΒ start???

Ok, I am pursuing my Higher Education in Government Aided School. A School filled with the teaching of discipline & education. Due to loosening of strict in school about language. I have no confidence in speaking in English. Even try to speak in English. We all know about the response of friends. How do they teaseΒ us?

Fast forward to 2022, I completed my schooling and joined BSc Computer Science. At that time, to be frank, I have no knowledge about tech, coding, hardware, and all. But I have that spark to learn. As we always know, the internet is filled with knowledge. But language is a big barrier to gaining knowledge.

Here is the intro of today’s AI war beginner or the reason for today’s AI warβ€Šβ€”β€ŠChatGPT. In November 2022, the ChatGPT was launched. Due to got an good roommates in my first year. I have know about the power of the internet. So, in that time, I gained the knowledge using only YouTube. Within one week of its release, I started usingΒ ChatGPT.

It helps to understand tech, education, and what I want using simple English or English filled with Grammar mistakes. After the lot of prompting I gained more knowledge about tech. Then move on to the courses in various platforms like Coursera, Udemy and other platform. Then move on to Blogs, Research Papers as little bit and moreΒ on.

Fast forward today, I have good foundational knowledge in various tech & finance. But the barrier of english and without knowledge of β€œHow search anything in internet deeply?” are broken and the AI acts as goodΒ mentor.

Nowadays even though I have gain knowledge through various things from youtube, blogs, AI, research papers, books. This all begin from that. Because without that beginning, now I amΒ nothing.

I think this blog is interesting in the way of denote the β€œPrompting & my life”. Stay tuned for my tech & financeΒ blogs.

Connect withΒ Me:

The Evolution & Backclash of Developers Using ChatGPT

ChatGPT made a revolution in human life, it changed many of their lives. Two Months ago I saw a great example of it. Using ChatGPT & LinkedIn, businessman Iwan Richardβ€Šβ€”β€ŠFounder & CEO of Reneonix should bring their business to the next level. To know more about their journey check the Being Scenius with Sriram Selvan Podcast the link is belowΒ πŸ‘‡

ChatGPT also plays an important role in my learning journey. So, I like to write a blog about β€œThe Evolution & Backclash of Developers Using ChatGPT”.

Note: Here I write the blog from my perspective, it may be changed forΒ you.

What makes the 100 Million People use the ChatGPT actively in just two months after their launching?

Source: ui42.com

Before the arrival of ChatGPT, the Internet plays a key role in learning anything. The process of visiting many websites and reading many things such as Blogs and articles is good for gaining knowledge. But it consumes more time and makes them tired. ChatGPT changes all things in time of arrival. It gives solutions for most things and explains easily in a way even understand by the children. But at the time of arrival, it does not give solutions for the present-day related questions. But that should be solved and made possible by using various methodologies and advancing theΒ ChatGPT.

But only that reason for using ChatGPT by a millionΒ users?

No, ChatGPT has been used by various people for various things. Like learning anything as easily, drafting mail professionally, more and more. Due to the tuning of the AI Model as perfect, they should not answer for bad things. Such a question is related to do crimes. That sounds interesting, right? It has done all things as good with the restrictions of helping bad things. So, it’s goodΒ only.

To be frank no. ButΒ Why?

Because ChatGPT makes the work easy. For Developers, it gives the basic code and even gives good code then the beginner level developers. However, the developers need sufficient knowledge to explain that code and fix the bug given by ChatGPT. Even Foreign IT Companies are allowed to use ChatGPT and other AI for development. But they expect basic knowledge at the time of their entry into their company. They did not like to hire persons who just copied and pasted the code without the knowledge of how the codingΒ works.

The problem arises for the beginners. One who starts using ChatGPT in their earlier stage is affected in two ways. First, they change them as lazy to code. Due to laziness after some time they struggle to code without ChatGPT. So, they also lose their confidence themself. Like β€œI Should not code as well or I am not a good developer” and due to laziness, they lose their problem-solving skills. Even the person who has good knowledge in the time of going to the companies for an interview, due to their high dependence on ChatGPT in time of practice, lacks code at the selection round. Second, in time of start learning no one is perfect. No one should develop a website like β€œNetflix” as straightly. But the ChatGPT had been done that. Here they imagine the AI should replicate the Developer's work as soon. Maybe it is possible but for that also need humans as a main player and just AI as a tool. Because it works by pre-training and scraping data from theΒ web.

What is the Solution?

  1. Using AI such as ChatGPT as a tool makes no trouble. However using that as an overload makes the developers lazy, which makes them lose their problem-solving skills.
  2. Using ChatGPT at the time of beginning the journey in coding causes more trouble than expected. Why? Because it gives unnecessary thinking, does not help to gain knowledge & more. The Error makes the developer's life as good. So, trying to solve the error yourself in the beginning gives a healthyΒ journey.

In conclusion using AI in development as a tool makes life as more easier, helps debug easily, and is enormously helpful usage. But using it over time gives onlyΒ trouble.

When feel this content is valuable follow me for more upcomingΒ Blogs.

Connect withΒ Me:

ChatGPT & RLHF

Source: itknowledgezone.com

Today I am back with an interesting topic, which I would like to share with you guys. Nowadays we all use AI as normal in our life. But actually, the use of AI begins with one AI. Which is ChatGPT. Did you think about it? How does the ChatGPT give more and more data as it is mostly accurate?

The Blog is about that only. Come on guys, have a joyfulΒ dive.

Source: upcoretech.com

The ChatGPT uses the technique or methodology of Reinforcement Learning From Human Feedback(RLFH). It looks complex, right? It’s a simpleΒ concept.

In our childhood, when we play in the ground we eat the sand right like God Krishna. But we do not show the whole universe in our mouths like them. I just take that example here. When Mother saw that they had beaten us and said not to do? Likewise in our school, when we got the first mark our mother appreciated us.

Here we learn what to do? by the feedback.

Here the AI should Rewarded(Positive Feedback) when they have perfectly done that or Otherwise they get Penalties(Negative Feedback). As a result, they change as per the feedback. The same thing here is done by Reinforcement Learning. They try a lot of things. This means here they give various results and get a lot of Feedback. By that, they learned, what need to do andΒ don’t.

Now the question comes to your mind such as β€œHow is this used by ChatGPT?”

We all know ChatGPT is used by a lot of people in various ways. We also know that it’s just an AI that replies to us as per the pre-trained data or already existing data. But people should ask the real-time data. For example, the model should be trained and launched during Joe Biden’s presidency. At the time, the model was fine-tuned to provide accurate and contextually relevant information about policies, initiatives, and events related to Joe Biden. However, after the next election, Donald Trump became the president. But still, the ChatGPT should give the same result as Joe Biden it’s an incorrect and also an outdated response right? To prevent that the methodology of Reinforcement Learning isΒ used.

To give real-time data, they should not only use this RLHF method. They also use Web Scrapping to get data & more other things. But the RLHF is also an important thing to give Real-time data by the ChatGPT. Because now the ChatGPT is not only the Chatbot AI or just a text-based AI. Now the ChatGPT 4 is an Multimodal AI. To learn more about Multimodal AI check the link: https://cloud.google.com/use-cases/multimodal-ai

Source: https://medium.com/lansaar/understanding-multimodal-ai-6d71653994a2

For that, they should use various methodologies to tune the modal to give better results for the users. But this RLHF methodology is more interesting than others for me. So, I like to share it with youΒ guys.

Note: Even the ChatGPT uses the methodology of Reinforcement Learning it’s trying to give more accuracy. But the result is not 100% perfect till now. Which means till 07/01/2025.

When feel this content is valuable follow me for more upcomingΒ Blogs.

Connect withΒ Me:

The Intelligent Loop: A Guide to Modern LLM Agents

By: angu10
24 February 2025 at 06:07

Introduction

Large Language Model (LLM) based AI agents represent a new paradigm in artificial intelligence. Unlike traditional software agents, these systems leverage the powerful capabilities of LLMs to understand, reason, and interact with their environment in more sophisticated ways. This guide will introduce you to the basics of LLM agents and their think-act-observe cycle.

What is an LLM Agent?

An LLM agent is a system that uses a large language model as its core reasoning engine to:

  1. Process natural language instructions
  2. Make decisions based on context and goals
  3. Generate human-like responses and actions
  4. Interact with external tools and APIs
  5. Learn from interactions and feedback

Think of an LLM agent as an AI assistant who can understand, respond, and take actions in the digital world, like searching the web, writing code, or analyzing data.

Image description

The Think-Act-Observe Cycle in LLM Agents

Observe (Input Processing)

LLM agents observe their environment through:

  1. Direct user instructions and queries
  2. Context from previous conversations
  3. Data from connected tools and APIs
  4. System prompts and constraints
  5. Environmental feedback

Think (LLM Processing)

The thinking phase for LLM agents involves:

  1. Parsing and understanding input context
  2. Reasoning about the task and requirements
  3. Planning necessary steps to achieve goals
  4. Selecting appropriate tools or actions
  5. Generating natural language responses

The LLM is the "brain," using its trained knowledge to process information and make decisions.

Act (Execution)

LLM agents can take various actions:

  1. Generate text responses
  2. Call external APIs
  3. Execute code
  4. Use specialized tools
  5. Store and retrieve information
  6. Request clarification from users

Key Components of LLM Agents

Core LLM

  1. Serves as the primary reasoning engine
  2. Processes natural language input
  3. Generates responses and decisions
  4. Maintains conversation context

Working Memory

  1. Stores conversation history
  2. Maintains current context
  3. Tracks task progress
  4. Manages temporary information

Tool Use

  1. API integrations
  2. Code execution capabilities
  3. Data processing tools
  4. External knowledge bases
  5. File manipulation utilities

Planning System

  1. Task decomposition
  2. Step-by-step reasoning
  3. Goal tracking
  4. Error handling and recovery

Types of LLM Agent Architectures

Simple Agents

  1. Single LLM with basic tool access
  2. Direct input-output processing
  3. Limited memory and context
  4. Example: Basic chatbots with API access

ReAct Agents

  1. Reasoning and Acting framework
  2. Step-by-step thought process
  3. Explicit action planning
  4. Self-reflection capabilities

Chain-of-Thought Agents

  1. Detailed reasoning steps
  2. Complex problem decomposition
  3. Transparent decision-making
  4. Better error handling

Multi-Agent Systems

  1. Multiple LLM agents working together
  2. Specialized roles and capabilities
  3. Inter-agent communication
  4. Collaborative problem-solving

Common Applications

LLM agents are increasingly used for:

  1. Personal assistance and task automation
  2. Code generation and debugging
  3. Data analysis and research
  4. Content creation and editing
  5. Customer service and support
  6. Process automation and workflow management

Best Practices for LLM Agent Design

Clear Instructions

  1. Provide explicit system prompts
  2. Define constraints and limitations
  3. Specify available tools and capabilities
  4. Set clear success criteria

Effective Memory Management

  1. Implement efficient context tracking
  2. Prioritize relevant information
  3. Clean up unnecessary data
  4. Maintain conversation coherence

Robust Tool Integration

  1. Define clear tool interfaces
  2. Handle API errors gracefully
  3. Validate tool outputs
  4. Monitor resource usage

Safety and Control

  1. Implement ethical guidelines
  2. Add safety checks and filters
  3. Monitor agent behavior
  4. Maintain user control

Ever Wonder How AI "Sees" Like You Do? A Beginner's Guide to Attention

By: angu10
19 February 2025 at 02:05

Understanding Attention in Large Language Models: A Beginner's Guide

Have you ever wondered how ChatGPT or other AI models can understand and respond to your messages so well? The secret lies in a mechanism called ATTENTION - a crucial component that helps these models understand relationships between words and generate meaningful responses. Let's break it down in simple terms!

What is Attention?

Imagine you're reading a long sentence: "The cat sat on the mat because it was comfortable." When you read "it," your brain naturally connects back to either "the cat" or "the mat" to understand what "it" refers to. This is exactly what attention does in AI models - it helps the model figure out which words are related to each other.

How Does Attention Work?

The attention mechanism works like a spotlight that can focus on different words when processing each word in a sentence. Here's a simple breakdown:

  1. For each word, the model calculates how important every other word is in relation to it.
  2. It then uses these importance scores to create a weighted combination of all words.
  3. This helps the model understand context and relationships between words.

Let's visualize this with an example:

Image description

In this diagram, the word "it" is paying attention to all other words in the sentence. The thickness of the arrows could represent the attention weights. The model would likely assign higher attention weights to "cat" and "mat" to determine which one "it" refers to.

Multi-Head Attention: Looking at Things from Different Angles

In modern language models, we don't just use one attention mechanism - we use several in parallel! This is called Multi-Head Attention. Each "head" can focus on different types of relationships between words.

Let's consider the sentence: The chef who won the competition prepared a delicious meal.

  • Head 1 could focus on subject-verb relationships (chef - prepared)
  • Head 2 might attend to adjective-noun pairs (delicious - meal)
  • Head 3 could look at broader context (competition - meal)

Here's a diagram:

Image description

This multi-headed approach helps the model understand text from different perspectives, just like how we humans might read a sentence multiple times to understand different aspects of its meaning.

Why Attention Matters

Attention mechanisms have revolutionized natural language processing because they:

  1. Handle long-range dependencies better than previous methods.
  2. Can process input sequences in parallel.
  3. Create interpretable connections between words.
  4. Allow models to focus on relevant information while ignoring irrelevant parts.

Recent Developments and Research

The field of LLMs is rapidly evolving, with new techniques and insights emerging regularly. Here are a few areas of active research:

Contextual Hallucinations

Large language models (LLMs) can sometimes hallucinate details and respond with unsubstantiated answers that are inaccurate with respect to the input context.

The Lookback Lens technique analyzes attention patterns to detect when a model might be generating information not present in the input context.

Extending Context Window

Researchers are working on extending the context window sizes of LLMs, allowing them to process longer text sequences.

Conclusion

While the math behind attention mechanisms can be complex, the core idea is simple: help the model focus on the most relevant parts of the input when processing each word. This allows language models to understand the context and relationships between words better, leading to more accurate and coherent responses.

Remember, this is just a high-level overview - there's much more to learn about attention mechanisms! Hopefully, this will give you a good foundation for understanding how modern AI models process and understand text.

A Step-by-Step Guide to LLM Function Calling inΒ Python

By: angu10
12 February 2025 at 23:06

Function calling allows Claude to interact with external functions and tools in a structured way. This guide will walk you through implementing function calling with Claude using Python, complete with examples and best practices.

Prerequisites

To get started, you'll need:

  • Python 3.7+
  • anthropic Python package
  • A valid API key from Anthropic

Basic Setup

from anthropic import Anthropic
import json
# Initialize the client
anthropic = Anthropic(api_key='your-api-key')

Defining Functions

function_schema = {
    "name": "get_weather",
    "description": "Get the current weather for a specific location",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City name or coordinates"
            },
            "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit"
            }
        },
        "required": ["location"]
    }
}

Making FunctionΒ Calls

A Step-by-Step Guide to LLM Function Calling inΒ Python
Function calling allows Claude to interact with external functions and tools in a structured way. This guide will walk you through implementing function calling with Claude using Python, complete with examples and best practices.
Prerequisites
To get started, you'll need:
Python 3.7+
anthropic Python package
A valid API key from Anthropic

Basic Setup
from anthropic import Anthropic
import json
# Initialize the client
anthropic = Anthropic(api_key='your-api-key')
Defining Functions
function_schema = {
    "name": "get_weather",
    "description": "Get the current weather for a specific location",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City name or coordinates"
            },
            "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit"
            }
        },
        "required": ["location"]
    }
}
Making FunctionΒ Calls
def get_weather(location, unit="celsius"):
    # This is a mock implementation but you can all call your API
    return {
        "location": location,
        "temperature": 22 if unit == "celsius" else 72,
        "conditions": "sunny"
    }
def process_function_call(message):
    try:
        # Parse the function call parameters
        params = json.loads(message.content)
        # Call the appropriate function
        if message.name == "get_weather":
            result = get_weather(**params)
            return json.dumps(result)
        else:
            raise ValueError(f"Unknown function: {message.name}")
    except Exception as e:
        return json.dumps({"error": str(e)})
# Example conversation with function calling
messages = [
    {
        "role": "user",
        "content": "What's the weather like in Paris?"
    }
]
while True:
    response = anthropic.messages.create(
        model="claude-3-5-haiku-latest",
        messages=messages,
        tools=[function_schema]
    )
    # Check if Claude wants to call a function
    if response.tool_calls:
        for tool_call in response.tool_calls:
            # Execute the function
            result = process_function_call(tool_call)
            # Add the function result to the conversation
            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "name": tool_call.name,
                "content": result
            })
    else:
        # Normal response - print and break
        print(response.content)
        break

Best Practices

  1. Clear Function Descriptions
  • Write detailed descriptions for your functions
  • Specify parameter types and constraints clearly
  • Include examples in the descriptions when helpful
  1. Input Validation
  • Validate all function inputs before processing
  • Return meaningful error messages
  • Handle edge cases gracefully
  1. Response Formatting
  • Return consistent JSON structures
  • Include status indicators in responses
  • Format error messages uniformly

4Β . Security Considerations

  • Validate and sanitize all inputs
  • Implement rate limiting if needed
  • Use appropriate authentication
  • Don't expose sensitive information in function descriptions

Conclusion

Function calling with Claude enables powerful integrations between the language model and external tools. By following these best practices and implementing proper error handling, you can create robust and reliable function-calling implementations.

Understanding RAGAS: A Comprehensive Framework for RAG System Evaluation

By: angu10
1 February 2025 at 01:40

In the rapidly evolving landscape of artificial intelligence, Retrieval Augmented Generation (RAG) systems have emerged as a crucial technology for enhancing Large Language Models with external knowledge. However, ensuring the quality and reliability of these systems requires robust evaluation methods. Enter RAGAS (Retrieval Augmented Generation Assessment System), a groundbreaking framework that provides comprehensive metrics for evaluating RAG systems.

The Importance of RAG Evaluation

RAG systems combine the power of retrieval mechanisms with generative AI to produce more accurate and contextually relevant responses. However, their complexity introduces multiple potential points of failure, from retrieval accuracy to answer generation quality. This is where RAGAS steps in, offering a structured approach to assessment that helps developers and organizations maintain high standards in their RAG implementations.

Core RAGAS Metrics

Context Precision

Context precision measures how relevant the retrieved information is to the given query. This metric evaluates whether the system is pulling in the right pieces of information from its knowledge base. A high context precision score indicates that the retrieval component is effectively identifying and selecting relevant content, while a low score might suggest that the system is retrieving tangentially related or irrelevant information.

Faithfulness

Faithfulness assesses the alignment between the generated answer and the provided context. This crucial metric ensures that the system's responses are grounded in the retrieved information rather than hallucinated or drawn from the model's pre-trained knowledge. A faithful response should be directly supported by the context, without introducing external or contradictory information.

Answer Relevancy

The answer relevancy metric evaluates how well the generated response addresses the original question. This goes beyond mere factual accuracy to assess whether the answer provides the information the user was seeking. A highly relevant answer should directly address the query's intent and provide appropriate detail level.

Context Recall

Context recall compares the retrieved contexts against ground truth information, measuring how much of the necessary information was successfully retrieved. This metric helps identify cases where critical information might be missing from the system's responses, even if what was retrieved was accurate.

Practical Implementation

RAGAS's implementation is designed to be straightforward while providing deep insights. The framework accepts evaluation datasets containing:

Questions posed to the system
Retrieved contexts for each question
Generated answers
Ground truth answers for comparison

This structured approach allows for automated evaluation across multiple dimensions of RAG system performance, providing a comprehensive view of system quality.

Benefits and Applications

Quality Assurance

RAGAS enables continuous monitoring of RAG system performance, helping teams identify degradation or improvements over time. This is particularly valuable when making changes to the retrieval mechanism or underlying models.

Development Guidance

The granular metrics provided by RAGAS help developers pinpoint specific areas needing improvement. For instance, low context precision scores might indicate the need to refine the retrieval strategy, while poor faithfulness scores might suggest issues with the generation parameters.

Comparative Analysis

Organizations can use RAGAS to compare different RAG implementations or configurations, making it easier to make data-driven decisions about system architecture and deployment.

Best Practices for RAGAS Implementation

  1. Regular Evaluation Implement RAGAS as part of your regular testing pipeline to catch potential issues early and maintain consistent quality.
  2. Diverse Test Sets Create evaluation datasets that cover various query types, complexities, and subject matters to ensure robust assessment.
  3. Metric Thresholds Establish minimum acceptable scores for each metric based on your application's requirements and use these as quality gates in your deployment process.
  4. Iterative Refinement Use RAGAS metrics to guide iterative improvements to your RAG system, focusing on the areas showing the lowest performance scores.

Practical CodeΒ Examples

Basic RAGAS Evaluation

Here's a simple example of how to implement RAGAS evaluation in your Python code:

from ragas import evaluate
from datasets import Dataset
from ragas.metrics import (
    faithfulness,
    answer_relevancy,
    context_precision
)

def evaluate_rag_system(questions, contexts, answers, references):
    """
    Simple function to evaluate a RAG system using RAGAS

    Args:
        questions (list): List of questions
        contexts (list): List of contexts for each question
        answers (list): List of generated answers
        references (list): List of reference answers (ground truth)

    Returns:
        EvaluationResult: RAGAS evaluation results
    """
    # First, let's make sure you have the required packages
    try:
        import ragas
        import datasets
    except ImportError:
        print("Please install required packages:")
        print("pip install ragas datasets")
        return None

    # Prepare evaluation dataset
    eval_data = {
        "question": questions,
        "contexts": [[ctx] for ctx in contexts],  # RAGAS expects list of lists
        "answer": answers,
        "reference": references
    }

    # Convert to Dataset format
    eval_dataset = Dataset.from_dict(eval_data)

    # Run evaluation with key metrics
    results = evaluate(
        eval_dataset,
        metrics=[
            faithfulness,      # Measures if answer is supported by context
            answer_relevancy,  # Measures if answer is relevant to question
            context_precision  # Measures if retrieved context is relevant
        ]
    )

    return results

# Example usage
if __name__ == "__main__":
    # Sample data
    questions = [
        "What are the key features of Python?",
        "How does Python handle memory management?"
    ]

    contexts = [
        "Python is a high-level programming language known for its simple syntax and readability. It supports multiple programming paradigms including object-oriented, imperative, and functional programming.",
        "Python uses automatic memory management through garbage collection. It employs reference counting as the primary mechanism and has a cycle-detecting garbage collector for handling circular references."
    ]

    answers = [
        "Python is known for its simple syntax and readability, and it supports multiple programming paradigms including OOP.",
        "Python handles memory management automatically through garbage collection, using reference counting and cycle detection."
    ]

    references = [
        "Python's key features include readable syntax and support for multiple programming paradigms like OOP, imperative, and functional programming.",
        "Python uses automatic garbage collection with reference counting and cycle detection for memory management."
    ]

    # Run evaluation
    results = evaluate_rag_system(
        questions=questions,
        contexts=contexts,
        answers=answers,
        references=references
    )

    if results:
        # Print results
        print("\nRAG System Evaluation Results:")
        print(results)  

Event Summary: FOSS United Chennai Meetup – 25-01-2025

26 January 2025 at 04:53

πŸš€ Attended the FOSS United Chennai Meetup Yesterday! πŸš€

After, attending Grafana & Friends Meetup, straightly went to FOSS United Chennai Meetup at YuniQ in Taramani.

Had a chance to meet my Friends face to face after a long time. Sakhil Ahamed E. , Dhanasekar T, Dhanasekar Chellamuthu, Thanga Ayyanar, Parameshwar Arunachalam, Guru Prasath S, Krisha, Gopinathan Asokan

Talks Summary,

1. Ansh Arora, Gave a tour on FOSS United, How its formed, Motto, FOSS Hack, FOSS Clubs.

2. Karthikeyan A K, Gave a talk on his open source product injee (The no configuration instant database for frontend developers.). It’s a great tool. He gave a personal demo for me. It’s a great tool with lot of potentials. Would like to contribute !.

3. Justin Benito, How they celebrated New Year with https://tamilnadu.tech
It’s single go to page for events in Tamil Nadu. If you are interested ,go to the repo https://lnkd.in/geKFqnFz and contribute.

From Kaniyam Foundation we are maintaining a Google Calendar for a long time on Tech Events happening in Tamil Nadu https://lnkd.in/gbmGMuaa.

4. Prasanth Baskar, gave a talk on Harbor, OSS Container Registry with SBOM and more functionalities. SBOM was new to me.

5. Thanga Ayyanar, gave a talk on Static Site Generation with Emacs.

At the end, we had a group photo and went for tea. Got to meet my Juniors from St. Joseph’s Institute of Technology in this meet. Had a discussion with Parameshwar Arunachalam on his BuildToLearn Experience. They started prototyping an Tinder app for Tamil Words. After that had a small discussion on our Feb 8th Glug Inauguration at St. Joseph’s Institute of Technology Dr. KARTHI M .

Happy to see, lot of minds travelling from different districts to attend this meet.

RAG vs GraphRAG

By: angu10
20 January 2025 at 04:47

Introduction to RAG and GraphRAG

What is RAG?

RAG, or Retrieval-Augmented Generation, is a technique that combines information retrieval with text generation to produce more accurate and contextually relevant responses. It works by retrieving relevant information from a knowledge base and then using that information to augment the input to a large language model (LLM).

What is GraphRAG?

GraphRAG is an extension of the RAG framework that incorporates graph-structured knowledge. Instead of using a flat document-based retrieval system, GraphRAG utilizes graph databases to represent and query complex relationships between entities and concepts.

Applications of RAG and GraphRAG

RAG Applications

  1. Question-answering systems
  2. Chatbots and virtual assistants
  3. Content summarization
  4. Fact-checking and information verification
  5. Personalized content generation

GraphRAG Applications

  1. Knowledge graph-based question answering
  2. Complex reasoning tasks
  3. Recommendation systems
  4. Fraud detection and financial analysis
  5. Scientific research and literature review

Pros and Cons of RAG

Pros of RAG

  1. Improved accuracy: By retrieving relevant information, RAG can provide more accurate and up-to-date responses.
  2. Reduced hallucinations: The retrieval step helps ground the model's responses in factual information.
  3. Scalability: Easy to update the knowledge base without retraining the entire model.
  4. Transparency: The retrieved documents can be used to explain the model's reasoning.
  5. Customizability: Can be tailored to specific domains or use cases.

Cons of RAG

  1. Latency: The retrieval step can introduce additional latency compared to pure generation models.
  2. Complexity: Implementing and maintaining a RAG system can be more complex than using a standalone LLM.
  3. Quality-dependent: The system's performance heavily relies on the quality and coverage of the knowledge base.
  4. Potential for irrelevant retrievals: If the retrieval system is not well-tuned, it may fetch irrelevant information.
  5. Storage requirements: Maintaining a large knowledge base can be resource-intensive.

Pros and Cons of GraphRAG

Pros of GraphRAG

  1. Complex relationship modeling: Can represent and query intricate relationships between entities.
  2. Improved context understanding: Graph structure allows for better capturing of contextual information.
  3. Multi-hop reasoning: Enables answering questions that require following multiple steps or connections.
  4. Flexibility: Can incorporate various types of information and relationships in a unified framework.
  5. Efficient querying: Graph databases can be more efficient for certain types of queries compared to traditional databases.

Cons of GraphRAG

  1. Increased complexity: Building and maintaining a knowledge graph is more complex than a document-based system.
  2. Higher computational requirements: Graph operations can be more computationally intensive.
  3. Data preparation challenges: Converting unstructured data into a graph format can be time-consuming and error-prone.
  4. Potential for overfitting: If the graph structure is too specific, it may not generalize well to new queries.
  5. Scalability concerns: As the graph grows, managing and querying it efficiently can become challenging.

Comparing RAG and GraphRAG

When to Use RAG

  • For general-purpose question-answering systems
  • When dealing with primarily textual information
  • In scenarios where quick implementation and simplicity are priorities
  • For applications that don't require complex relationship modeling

When to Use GraphRAG

  • For domain-specific applications with complex relationships (e.g., scientific research, financial analysis)
  • When multi-hop reasoning is crucial
  • In scenarios where understanding context and relationships is more important than raw text retrieval
  • For applications that can benefit from a structured knowledge representation

Future Directions and Challenges

Advancements in RAG

  1. Improved retrieval algorithms
  2. Better integration with LLMs
  3. Real-time knowledge base updates
  4. Multi-modal RAG (incorporating images, audio, etc.)

Advancements in GraphRAG

  1. More efficient graph embedding techniques
  2. Integration with other AI techniques (e.g., reinforcement learning)
  3. Automated graph construction and maintenance
  4. Explainable AI through graph structures

Common Challenges

  1. Ensuring data privacy and security
  2. Handling biases in knowledge bases
  3. Improving computational efficiency
  4. Enhancing the interpretability of results

Conclusion

Both RAG and GraphRAG represent significant advancements in augmenting language models with external knowledge. While RAG offers a more straightforward approach suitable for many general applications, GraphRAG provides a powerful framework for handling complex, relationship-rich domains. The choice between the two depends on the specific requirements of the application, the nature of the data, and the complexity of the reasoning tasks involved. As these technologies continue to evolve, we can expect to see even more sophisticated and efficient ways of combining retrieval, reasoning, and generation in AI systems.

Connect postman to salesforce

3 January 2025 at 16:27

Today, I want to capture notes that I learnt from trailhead academy on connecting postman to a salesforce org.

To make postman allow changes at Salesforce org, we have to enable CORS policy in Salesforce. See below what does CORS mean.

CORS- Cross Origin Resource Sharing

It is a browser feature that controls how resources are requested from one site to another site. By configuring CORS, it enables special permissions for other external websites to access our salesforce data. In this case, we are enabling CORS for postman to access salesforce.

  • From setup ==> search for CORS ==> Add https://*.postman.co and https://*.postman.com URL
  • After that, in postman desktop -Do below steps one by one.
  • Create a separate workspace for Salesforce APIs to play around.
  • Search for Salesforce APIs. It does list out all the available collections.
  • Fork β€œSalesforce Platform API” and it will available to your local postman workspace.
  • After that, go to β€œAuthorization” click on β€œGenerate token” and copy β€œinstance” URL.
  • Configure β€œ_endpoint” value from variable tab as β€œinstance” URL
  • All set and that’s it. You can play around whatever requests that are available.

Connect postman to salesforce

3 January 2025 at 16:27

Today, I want to capture notes that I learnt from trailhead academy on connecting postman to a salesforce org.

To make postman allow changes at Salesforce org, we have to enable CORS policy in Salesforce. See below what does CORS mean.

CORS- Cross Origin Resource Sharing

It is a browser feature that controls how resources are requested from one site to another site. By configuring CORS, it enables special permissions for other external websites to access our salesforce data. In this case, we are enabling CORS for postman to access salesforce.

  • From setup ==> search for CORS ==> Add https://*.postman.co and https://*.postman.com URL
  • After that, in postman desktop -Do below steps one by one.
  • Create a separate workspace for Salesforce APIs to play around.
  • Search for Salesforce APIs. It does list out all the available collections.
  • Fork β€œSalesforce Platform API” and it will available to your local postman workspace.
  • After that, go to β€œAuthorization” click on β€œGenerate token” and copy β€œinstance” URL.
  • Configure β€œ_endpoint” value from variable tab as β€œinstance” URL
  • All set and that’s it. You can play around whatever requests that are available.

Learning Notes #8 – SLI, SLA, SLO

25 December 2024 at 16:11

In this blog, i write about SLI, SLA, SLO . I got a refreshing session from a podcast https://open.spotify.com/episode/2Ags7x1WrxaFLRd3KBU50K?si=vbYtW_YVQpOi8HwT9AOM1g. This blog is about that.

In the world of service reliability and performance, the terms SLO, SLA, and SLI are often used interchangeably but have distinct meanings. This blog explains these terms in detail, their importance, and how they relate to each other with practical examples.

1. What are SLIs, SLOs, and SLAs?

Service Level Indicators (SLIs)

An SLI is a metric that quantifies the level of service provided by a system. It measures specific aspects of performance or reliability, such as response time, uptime, or error rate.

Example:

  • Percentage of successful HTTP requests over a time window.
  • Average latency of API responses.

Service Level Objectives (SLOs)

An SLO is a target value or range for an SLI. It defines what β€œacceptable” performance or reliability looks like from the perspective of the service provider or user.

Example:

  • β€œ99.9% of HTTP requests must succeed within 500ms.”
  • β€œThe application should have 99.95% uptime per quarter.”

Service Level Agreements (SLAs)

An SLA is a formal contract between a service provider and a customer that specifies the agreed-upon SLOs and the consequences of failing to meet them, such as penalties or compensations.

Example:

  • β€œIf the uptime drops below 99.5% in a calendar month, the customer will receive a 10% credit on their monthly bill.”

2. Relationship Between SLIs, SLOs, and SLAs

  • SLIs are the metrics measured.
  • SLOs are the goals or benchmarks derived from SLIs.
  • SLAs are agreements that formalize SLOs and include penalties or incentives.

SLI: Average latency of API requests.
SLO: 95% of API requests should have latency under 200ms.
SLA: If latency exceeds the SLO for two consecutive weeks, the provider will issue service credits.

3. Practical Examples

Example 1: Web Hosting Service

  • SLI: Percentage of time the website is available.
  • SLO: The website must be available 99.9% of the time per month.
  • SLA: If uptime falls below 99.9%, the customer will receive a refund of 20% of their monthly fee.

Example 2: Cloud Storage Service

  • SLI: Time taken to retrieve a file from storage.
  • SLO: 95% of retrieval requests must complete within 300ms.
  • SLA: If retrieval times exceed 300ms for more than 5% of requests in a billing cycle, customers will get free additional storage for the next month.

Example 3: API Service

  • SLI: Error rate of API responses.
  • SLO: Error rate must be below 0.1% for all requests in a day.
  • SLA: If the error rate exceeds 0.1% for more than three days in a row, the customer is entitled to a credit worth 5% of their monthly subscription fee.

Getting started with Django Basics

11 December 2024 at 12:07

Below listed are the high level steps involved to create a basic Django application.

  1. install python
  2. use venv before installing django =>python -m venv tutorial-env
  3. activate the venv: tutorial-env\Scripts\activate
  4. install django in the venv=> python -m pip install django
  5. check version =>django-admin –version
  6. Create a django project => django-admin startproject myApp
  7. To start the webserver =>python manage.py runserver
  8. From the myApp location, open cmd and type code .=> which will open vs code for this project from VSCode 1. init.py => when the proj receives a request it will understand that this is a package with the help of this init file 2.asgi & wsgi =>Both required during deployment 3.settings.py =>DB, Language, Timezone, Static, URL etc.,
  9. URLs.py => will contain the list of urls used for the project
  10. outside of myApp, db.sqlite3 will be used by default as a lite weight DB
  11. Manage.py =>Very important file
  12. Within the project myAPP, we can create multiple application. to create a new app => python manage.py startapp blog 1.migrations => DB related
    1. init => represent that it is a pkg
    2. admin => for admin purposes
    3. apps => app related config eg: name of the app etc.,
    4. models => contents 6.tests => used for testing the app 7.views 10.Register the app: from myApp->setting.py under Installed_Apps ->add the recently created app β€˜blog’ 11.Create the first View:(in general we will receive the request and send back the response) from blog->views.py 1.import HTTPResponse => from django.http import HttpRespose a. Create a python function which take request as a parameter and return the HttpResponse=>A static string output 2.under blog, create a python file by name β€œurls.py” a.within that file add the urlpatterns list similar to myApp->urls.pyb.in this file, import path, and view from the project->from . import views c.to the urlpatterns list add and entry to the python function created under views.py path(β€œβ€<β€œβ€ represents home directory>,views.index,name=”index”) 3.In myApp-> urls.py a. import path,include from django.urls b. under urlpatterns, add path(β€œβ€,include(β€œblog.urls”)) –> including the url from the blog->urls.py
      1. Time to test the changes. Go to the application url. it should show the content from views.py->index function
      2. Alternatively if we want to call the index with a seperate url a. from the myApp->urls.py-> in the urlpatterns.path -> instead of β€œβ€, provide β€œblogs/” b. Test the same with both default application url and url/blogs

Locust EP 2: Understanding Locust Wait Times with Complete Examples

17 November 2024 at 07:43

Locust is an excellent load testing tool, enabling developers to simulate concurrent user traffic on their applications. One of its powerful features is wait times, which simulate the realistic user think time between consecutive tasks. By customizing wait times, you can emulate user behavior more effectively, making your tests reflect actual usage patterns.

In this blog, we’ll cover,

  1. What wait times are in Locust.
  2. Built-in wait time options.
  3. Creating custom wait times.
  4. A full example with instructions to run the test.

What Are Wait Times in Locust?

In real-world scenarios, users don’t interact with applications continuously. After performing an action (e.g., submitting a form), they often pause before the next action. This pause is called a wait time in Locust, and it plays a crucial role in mimicking real-life user behavior.

Locust provides several ways to define these wait times within your test scenarios.

FastAPI App Overview

Here’s the FastAPI app that we’ll test,


from fastapi import FastAPI

# Create a FastAPI app instance
app = FastAPI()

# Define a route with a GET method
@app.get("/")
def read_root():
    return {"message": "Welcome to FastAPI!"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

Locust Examples for FastAPI

1. Constant Wait Time Example

Here, we’ll simulate constant pauses between user requests


from locust import HttpUser, task, constant

class FastAPIUser(HttpUser):
    wait_time = constant(2)  # Wait for 2 seconds between requests

    @task
    def get_root(self):
        self.client.get("/")  # Simulates a GET request to the root endpoint

    @task
    def get_item(self):
        self.client.get("/items/42?q=test")  # Simulates a GET request with path and query parameters

2. Between wait time Example

Simulating random pauses between requests.


from locust import HttpUser, task, between

class FastAPIUser(HttpUser):
    wait_time = between(1, 5)  # Random wait time between 1 and 5 seconds

    @task(3)  # Weighted task: this runs 3 times more often
    def get_root(self):
        self.client.get("/")

    @task(1)
    def get_item(self):
        self.client.get("/items/10?q=locust")

3. Custom Wait Time Example

Using a custom wait time function to introduce more complex user behavior


import random
from locust import HttpUser, task

def custom_wait():
    return max(1, random.normalvariate(3, 1))  # Normal distribution (mean: 3s, stddev: 1s)

class FastAPIUser(HttpUser):
    wait_time = custom_wait

    @task
    def get_root(self):
        self.client.get("/")

    @task
    def get_item(self):
        self.client.get("/items/99?q=custom")


Full Test Example

Combining all the above elements, here’s a complete Locust test for your FastAPI app.


from locust import HttpUser, task, between
import random

# Custom wait time function
def custom_wait():
    return max(1, random.uniform(1, 3))  # Random wait time between 1 and 3 seconds

class FastAPIUser(HttpUser):
    wait_time = custom_wait  # Use the custom wait time

    @task(3)
    def browse_homepage(self):
        """Simulates browsing the root endpoint."""
        self.client.get("/")

    @task(1)
    def browse_item(self):
        """Simulates fetching an item with ID and query parameter."""
        item_id = random.randint(1, 100)
        self.client.get(f"/items/{item_id}?q=test")

Running Locust for FastAPI

  1. Run Your FastAPI App
    Save the FastAPI app code in a file (e.g., main.py) and start the server

uvicorn main:app --reload

By default, the app will run on http://127.0.0.1:8000.

2. Run Locust
Save the Locust file as locustfile.py and start Locust.


locust -f locustfile.py

3. Configure Locust
Open http://localhost:8089 in your browser and enter:

  • Host: http://127.0.0.1:8000
  • Number of users and spawn rate based on your testing requirements.

4. Run in Headless Mode (Optional)
Use the following command to run Locust in headless mode


locust -f locustfile.py --headless -u 50 -r 10 --host http://127.0.0.1:8000`

-u 50: Simulate 50 users.

-r 10: Spawn 10 users per second.

Docker Ep 4 : The Digital Tea Kadai – Client Server Architecture & Docker

12 August 2024 at 14:25

The Client-Server Architecture

Once upon a time in the electronic city of Banglore, there was a popular digital tea kadai. This cafe was unique because it didn’t serve traditional coffee or pastries. Instead, it served data and services to its customers developers, businesses, and tech enthusiasts who were hungry for information and resources.

The Client:

One day, a young developer named Dinesh walked into tea kadai. He was working on a new app and needed to fetch some data from the cafe’s servers. In this story, Dinesh represents the client. As a client, his role was to request specific services and data from the cafe. He approached the counter and handed over his order slip, detailing what he needed.

The Server:

Behind the counter was Syed, the tea master, representing the server. Syed’s job was to take Dinesh’s request, process it, and deliver the requested data back to him.

Syed had access to a vast array of resources stored in the cafe’s back room, where all the data was kept. When Dinesh made his request, Syed quickly went to the back, gathered the data, and handed it back to Dinesh.

The client-server architecture at Tea Kadai worked seamlessly.

Dinesh, as the client, could make requests whenever he needed, and

Syed, as the server, would respond by providing the requested data.

This interaction was efficient, allowing many clients to be served by a single server at the cafe.

Docker’s Client-Server Technology

As Tea Kadai grew in popularity, it decided to expand its services to deliver data more efficiently and flexibly. To do this, they adopted a new technology called Docker, which helped them manage their operations more effectively.

Docker Client:

In the world of Docker at Tea Kadai, Dinesh still played the role of the client. But now, instead of just making simple data requests, she could request entire environments where he could test and run his applications.

These environments, called containers, were like personalized booths in the cafe where Alice could have her own setup with everything she needed to work on her app.

Dinesh used a special tool called the Docker Client to place his order. With this tool, he could specify exactly what he wanted in his container like the operating system, libraries, and applications needed for his app. The Docker Client was her interface for communicating with the cafe’s new backend system.

Docker Server (Daemon):

Behind the scenes, Tea Kadai had installed a powerful system known as the Docker Daemon, which acted as the server in this setup. The Docker Daemon was responsible for creating, running, and managing the containers requested by clients like Dinesh.

When Dinesh sent his container request using the Docker Client, the Docker Daemon received it, built the container environment, and handed it back to Dinesh for use.

Docker Images:

The Tea Kadai had a collection of premade recipes called Docker Images. These images were like blueprints for creating containers, containing all the necessary ingredients and instructions.

When Dinesh requested a new container, the Docker Daemon used these images to quickly prepare the environment.

Flexibility and Isolation:

The beauty of Docker at Tea Kadai was that it allowed multiple clients like Dinesh to have their containers running simultaneously, each isolated from the others. This isolation ensured that one client’s work wouldn’t interfere with another’s, just like having separate booths in the cafe for each customer. Dinesh could run, test, and even destroy his environment without affecting anyone else.

At the end,

In the vibrant city of Banglore, Tea Kadai thrived by adopting client-server architecture and Docker’s client-server technology. This approach allowed them to efficiently serve data and services while providing flexible, isolated environments for their clients. Dinesh and many others continued to come to tea kadai, knowing they could always get what they needed in a reliable and innovative way.

Exploring TAPAS: Analyzing Clinical Trial Data with Transformers

By: angu10
25 September 2023 at 04:31

Introduction:

Welcome to the world of Transformers, where cutting-edge natural language processing models are revolutionizing the way I interact with data. In this series of blogs, I will embark on a journey to explore and understand the capabilities of the TAPAS (Tabular Pre-trained Language Model) model, which is designed to extract valuable insights from tabular data. To kick things off, I'll delve into the basics of TAPAS and see it in action on a real-world dataset.

Understanding TAPAS:

TAPAS is a powerful language model developed by Google that specializes in processing tabular data. Unlike traditional models, TAPAS can handle structured data seamlessly, making it a game-changer for tasks involving tables and spreadsheets. With a token size of 512k, TAPAS can process large datasets efficiently, making it a valuable tool for data analysts and scientists.

My Dataset:

For this introductory exploration, I will work with a clinical trial dataset [Clinicaltrails.gov]. To start, I load the dataset and create a data frame containing the "label" column. This column contains information about gender distribution in clinical trials. I'll be using this data to ask questions and obtain insights.

from transformers import pipeline,TapasTokenizer, TapasForQuestionAnswering
import pandas as pd
import datasets

# Load the dataset (only once)
dataset = datasets.load_dataset("Kira-Asimov/gender_clinical_trial")

# Create the clinical_trials_data DataFrame with just the "label" column (only once)
clinical_trials_data = pd.DataFrame({
    "id": dataset["train"]["id"],
    "label": dataset["train"]["label"],
})

clinical_trials_data = clinical_trials_data.head(100)


Asking Questions with TAPAS:

The magic of TAPAS begins when I start asking questions about our data. In this example, I want to know how many records are in the dataset and how many of them are gender-specific (Male and Female). I construct queries like:

"How many records are in total?"
"How many 'Male' only gender studies are in total?"
"How many 'Female' only gender studies are in total?"

Using TAPAS to Answer Questions:

I utilize the "google/tapas-base-finetuned-wtq" model and its associated tokenizer to process our questions and tabular data. TAPAS tokenizes the data, extracts answers, and even performs aggregations when necessary.

counts = {}
answers = []

def TAPAS_model_learning(clinical_trials_data):
    model_name = "google/tapas-base-finetuned-wtq"
    model = TapasForQuestionAnswering.from_pretrained(model_name)
    tokenizer = TapasTokenizer.from_pretrained(model_name)


    queries = [
        "How many records are in total ?",
        "How many 'Male' only gender studies are in total ?",
        "How many 'Female' only gender studies are in total ?",
    ]

    for query in queries:
            model_name = "google/tapas-base-finetuned-wtq"
            model = TapasForQuestionAnswering.from_pretrained(model_name)
            tokenizer = TapasTokenizer.from_pretrained(model_name)
            # Tokenize the query and table
            inputs = tokenizer(table=clinical_trials_data, queries=query, padding="max_length", return_tensors="pt", truncation=True)

            # Get the model's output
            outputs = model(**inputs)
            predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
                inputs, outputs.logits.detach(), outputs.logits_aggregation.detach()
            )

            # Initialize variables to store answers for the current query
            current_answers = []

            # Count the number of cells in the answer coordinates
            count = 0
            for coordinates in predicted_answer_coordinates:
                count += len(coordinates)
                # Collect the cell values for the current answer
                cell_values = []
                for coordinate in coordinates:
                    cell_values.append(clinical_trials_data.iat[coordinate])

                current_answers.append(", ".join(cell_values))

            # Check if there are no matching cells for the query
            if count == 0:
                current_answers = ["No matching cells"]
            counts[query] = count
            answers.append(current_answers)
    return counts,answers

Evaluating TAPAS Performance:

Now, let's see how well TAPAS performs in answering our questions. I have expected answers for each question variation, and I calculate the error percentage to assess the model's accuracy.

# Prepare your variations of the same question and their expected answers
question_variations = {
    "How many records are in total ?": 100,
    "How many 'Male' only gender studies are in total ?": 3,
    "How many 'Female' only gender studies are in total ?":9,
}



# Use TAPAS to predict the answer based on your tabular data and the question
predicted_count,predicted_answer = TAPAS_model_learning(clinical_trials_data)
print(predicted_count)
# Check if any predicted answer matches the expected answer
for key,value in predicted_count.items():
    error = question_variations[key] - value


    # Calculate the accuracy percentage
    error_percentage = (error / question_variations[key]) * 100

    # Print the results
    print(f"{key}: Model Value: {value}, Excepted Value: {question_variations[key]}, Error Percentage: {error_percentage :.2f}%")

Results and Insights:

The output reveals how TAPAS handled our queries:

For the question "How many records are in total?", TAPAS predicted 69 records, with an error percentage of 31.00% compared to the expected value of 100 records.

For the question "How many 'Male' only gender studies are in total?", TAPAS correctly predicted 3 records, with a perfect match to the expected value.

For the question "How many 'Female' only gender studies are in total?", TAPAS predicted 2 records, with a significant error percentage of 77.78% compared to the expected value of 9 records.

Conclusion and Future Exploration:

In this first blog of our TAPAS exploration series, I introduced you to the model's capabilities and showcased its performance on a real dataset. I observed both accurate and less accurate predictions, highlighting the importance of understanding and fine-tuning the model for specific tasks.

In our future blogs, I will delve deeper into TAPAS, exploring its architecture, fine-tuning techniques, and strategies for improving its accuracy on tabular data. Stay tuned as I unlock the full potential of TAPAS for data analysis and insights.

❌
❌