Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 11, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 11, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 11, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 11, 2025

      Triple 4K 144Hz displays from something this small blows my mind — CalDigit’s Element 5 Hub tested and reviewed

      May 11, 2025

      Ori and the Blind Forest studio head says they could be forced to “shut down” due to the impact of negative Steam reviews for ‘No Rest for the Wicked’

      May 11, 2025

      Windows Phone just got its first AI ChatGPT-style app. No, really.

      May 11, 2025

      New Xbox games launching this week, from May 12 through May 18 — DOOM: The Dark Ages arrives on Xbox Game Pass

      May 11, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Brisa v0.2.13

      May 11, 2025
      Recent

      Brisa v0.2.13

      May 11, 2025

      Build Digital Assets & Earn Through Referrals with Biela — A Genuine Opportunity for Entrepreneurs

      May 11, 2025

      Laravel Routing

      May 10, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Triple 4K 144Hz displays from something this small blows my mind — CalDigit’s Element 5 Hub tested and reviewed

      May 11, 2025
      Recent

      Triple 4K 144Hz displays from something this small blows my mind — CalDigit’s Element 5 Hub tested and reviewed

      May 11, 2025

      Ori and the Blind Forest studio head says they could be forced to “shut down” due to the impact of negative Steam reviews for ‘No Rest for the Wicked’

      May 11, 2025

      Windows Phone just got its first AI ChatGPT-style app. No, really.

      May 11, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»A Coding Implementation of Accelerating Active Learning Annotation with Adala and Google Gemini

    A Coding Implementation of Accelerating Active Learning Annotation with Adala and Google Gemini

    May 11, 2025

    In this tutorial, we’ll learn how to leverage the Adala framework to build a modular active learning pipeline for medical symptom classification. We begin by installing and verifying Adala alongside required dependencies, then integrate Google Gemini as a custom annotator to categorize symptoms into predefined medical domains. Through a simple three-iteration active learning loop, prioritizing critical symptoms such as chest pain, we’ll see how to select, annotate, and visualize classification confidence, gaining practical insights into model behavior and Adala’s extensible architecture.

    Copy CodeCopiedUse a different Browser
    !pip install -q git+https://github.com/HumanSignal/Adala.git
    !pip list | grep adala

    We install the latest Adala release directly from its GitHub repository. At the same time, the subsequent pip list | grep adala command scans your environment’s package list for any entries containing “adala,” providing a quick confirmation that the library was installed successfully.

    Copy CodeCopiedUse a different Browser
    import sys
    import os
    print("Python path:", sys.path)
    print("Checking if adala is in installed packages...")
    !find /usr/local -name "*adala*" -type d | grep -v "__pycache__"
    
    
    
    
    !git clone https://github.com/HumanSignal/Adala.git
    !ls -la Adala

    We print out your current Python module search paths and then search the /usr/local directory for any installed “adala” folders (excluding __pycache__) to verify the package is available. Next, it clones the Adala GitHub repository into your working directory and lists its contents so you can confirm that all source files have been fetched correctly.

    Copy CodeCopiedUse a different Browser
    import sys
    sys.path.append('/content/Adala')

    By appending the cloned Adala folder to sys.path, we’re telling Python to treat /content/Adala as an importable package directory. This ensures that subsequent import Adala… statements will load directly from your local clone rather than (or in addition to) any installed version.

    Copy CodeCopiedUse a different Browser
    !pip install -q google-generativeai pandas matplotlib
    
    
    import google.generativeai as genai
    import pandas as pd
    import json
    import re
    import numpy as np
    import matplotlib.pyplot as plt
    from getpass import getpass

    We install the Google Generative AI SDK alongside data-analysis and plotting libraries (pandas and matplotlib), then import key modules, genai for interacting with Gemini, pandas for tabular data, json and re for parsing, numpy for numerical operations, matplotlib.pyplot for visualization, and getpass to prompt the user for their API key securely.

    Copy CodeCopiedUse a different Browser
    try:
        from Adala.adala.annotators.base import BaseAnnotator
        from Adala.adala.strategies.random_strategy import RandomStrategy
        from Adala.adala.utils.custom_types import TextSample, LabeledSample
        print("Successfully imported Adala components")
    except Exception as e:
        print(f"Error importing: {e}")
        print("Falling back to simplified implementation...")

    This try/except block attempts to load Adala’s core classes, BaseAnnotator, RandomStrategy, TextSample, and LabeledSample so that we can leverage its built-in annotators and sampling strategies. On success, it confirms that the Adala components are available; if any import fails, it catches the error, prints the exception message, and gracefully falls back to a simpler implementation.

    Copy CodeCopiedUse a different Browser
    GEMINI_API_KEY = getpass("Enter your Gemini API Key: ")
    genai.configure(api_key=GEMINI_API_KEY)

    We securely prompt you to enter your Gemini API key without echoing it to the notebook. Then we configure the Google Generative AI client (genai) with that key to authenticate all subsequent calls.

    Copy CodeCopiedUse a different Browser
    CATEGORIES = ["Cardiovascular", "Respiratory", "Gastrointestinal", "Neurological"]
    
    
    class GeminiAnnotator:
        def __init__(self, model_name="models/gemini-2.0-flash-lite", categories=None):
            self.model = genai.GenerativeModel(model_name=model_name,
                                              generation_config={"temperature": 0.1})
            self.categories = categories
           
        def annotate(self, samples):
            results = []
            for sample in samples:
                prompt = f"""Classify this medical symptom into one of these categories:
                {', '.join(self.categories)}.
                Return JSON format: {{"category": "selected_category",
                "confidence": 0.XX, "explanation": "brief_reason"}}
               
                SYMPTOM: {sample.text}"""
               
                try:
                    response = self.model.generate_content(prompt).text
                    json_match = re.search(r'({.*})', response, re.DOTALL)
                    result = json.loads(json_match.group(1) if json_match else response)
                   
                    labeled_sample = type('LabeledSample', (), {
                        'text': sample.text,
                        'labels': result["category"],
                        'metadata': {
                            "confidence": result["confidence"],
                            "explanation": result["explanation"]
                        }
                    })
                except Exception as e:
                    labeled_sample = type('LabeledSample', (), {
                        'text': sample.text,
                        'labels': "unknown",
                        'metadata': {"error": str(e)}
                    })
                results.append(labeled_sample)
            return results

    We define a list of medical categories and implement a GeminiAnnotator class that wraps Google Gemini’s generative model for symptom classification. In its annotate method, it builds a JSON-returning prompt for each text sample, parses the model’s response into a structured label, confidence score, and explanation, and wraps those into lightweight LabeledSample objects, falling back to an “unknown” label if any errors occur.

    Copy CodeCopiedUse a different Browser
    sample_data = [
        "Chest pain radiating to left arm during exercise",
        "Persistent dry cough with occasional wheezing",
        "Severe headache with sensitivity to light",
        "Stomach cramps and nausea after eating",
        "Numbness in fingers of right hand",
        "Shortness of breath when climbing stairs"
    ]
    
    
    text_samples = [type('TextSample', (), {'text': text}) for text in sample_data]
    
    
    annotator = GeminiAnnotator(categories=CATEGORIES)
    labeled_samples = []

    We define a list of raw symptom strings and wrap each in a lightweight TextSample object to pass them to the annotator. It then instantiates your GeminiAnnotator with the predefined category set and prepares an empty labeled_samples list to store the results of the upcoming annotation iterations.

    Copy CodeCopiedUse a different Browser
    print("nRunning Active Learning Loop:")
    for i in range(3):  
        print(f"n--- Iteration {i+1} ---")
       
        remaining = [s for s in text_samples if s not in [getattr(l, '_sample', l) for l in labeled_samples]]
        if not remaining:
            break
           
        scores = np.zeros(len(remaining))
        for j, sample in enumerate(remaining):
            scores[j] = 0.1
            if any(term in sample.text.lower() for term in ["chest", "heart", "pain"]):
                scores[j] += 0.5  
       
        selected_idx = np.argmax(scores)
        selected = [remaining[selected_idx]]
       
        newly_labeled = annotator.annotate(selected)
        for sample in newly_labeled:
            sample._sample = selected[0]  
        labeled_samples.extend(newly_labeled)
       
        latest = labeled_samples[-1]
        print(f"Text: {latest.text}")
        print(f"Category: {latest.labels}")
        print(f"Confidence: {latest.metadata.get('confidence', 0)}")
        print(f"Explanation: {latest.metadata.get('explanation', '')[:100]}...")

    This active‐learning loop runs for three iterations, each time filtering out already‐labeled samples and assigning a base score of 0.1—boosted by 0.5 for keywords like “chest,” “heart,” or “pain”—to prioritize critical symptoms. It then selects the highest‐scoring sample, invokes the GeminiAnnotator to generate a category, confidence, and explanation, and prints those details for review.

    Copy CodeCopiedUse a different Browser
    categories = [s.labels for s in labeled_samples]
    confidence = [s.metadata.get("confidence", 0) for s in labeled_samples]
    
    
    plt.figure(figsize=(10, 5))
    plt.bar(range(len(categories)), confidence, color='skyblue')
    plt.xticks(range(len(categories)), categories, rotation=45)
    plt.title('Classification Confidence by Category')
    plt.tight_layout()
    plt.show()

    Finally, we extract the predicted category labels and their confidence scores and use Matplotlib to plot a vertical bar chart, where each bar’s height reflects the model’s confidence in that category. The category names are rotated for readability, a title is added, and tight_layout() ensures the chart elements are neatly arranged before display.

    In conclusion, by combining Adala’s plug-and-play annotators and sampling strategies with the generative power of Google Gemini, we’ve constructed a streamlined workflow that iteratively improves annotation quality on medical text. This tutorial walked you through installation, setup, and a bespoke GeminiAnnotator, and demonstrated how to implement priority-based sampling and confidence visualization. With this foundation, you can easily swap in other models, expand your category set, or integrate more advanced active learning strategies to tackle larger and more complex annotation tasks.


    Check out Colab Notebook here. All credit for this research goes to the researchers of this project. Also, feel free to follow us on Twitter and don’t forget to join our 90k+ ML SubReddit.

    Here’s a brief overview of what we’re building at Marktechpost:

    • ML News Community – r/machinelearningnews (92k+ members)
    • Newsletter– airesearchinsights.com/(30k+ subscribers)
    • miniCON AI Events – minicon.marktechpost.com
    • AI Reports & Magazines – magazine.marktechpost.com
    • AI Dev & Research News – marktechpost.com (1M+ monthly readers)
    • Partner with us

    The post A Coding Implementation of Accelerating Active Learning Annotation with Adala and Google Gemini appeared first on MarkTechPost.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleGrabber is an imageboard/booru downloader
    Next Article Tencent Released PrimitiveAnything: A New AI Framework That Reconstructs 3D Shapes Using Auto-Regressive Primitive Generation

    Related Posts

    Machine Learning

    How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    May 11, 2025
    Machine Learning

    LightOn AI Released GTE-ModernColBERT-v1: A Scalable Token-Level Semantic Search Model for Long-Document Retrieval and Benchmark-Leading Performance

    May 11, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Take the Annual State of Laravel 2024 Survey

    Development

    CVE-2025-23177 – Apache ShellShock Path Traversal

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-36546 – F5OS SSH Key-Based Authentication Privilege Escalation

    Common Vulnerabilities and Exposures (CVEs)

    Agents bring the role of AI in development from reactive to proactive

    Tech & Work

    Highlights

    VS meldt actief misbruik van beveiligingslek in Commvault-webserver

    April 29, 2025

    VS meldt actief misbruik van beveiligingslek in Commvault-webserver

    Aanvallers maken actief misbruik van een kwetsbaarheid in Commvault-webserver, zo meldt het Cybersecurity and Infrastructure Security Agency (CISA) van het Amerikaanse ministerie van Homeland Security …
    Read more

    Published Date:
    Apr 29, 2025 (2 hours, 47 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2025-3928

    From broke musician to working dev. How college drop-out Ryan Furrer taught himself to code [Podcast #166]

    March 28, 2025

    6 Slack tips I swear by to turn a chaotic workspace into a well-oiled machine

    February 3, 2025

    Rilasciata Manjaro 25 “Zetar” con GNOME 48, KDE Plasma 6.3 e il kernel Linux 6.12

    April 15, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.