Close Menu
    Trending
    • TikTok to lay off hundreds of UK content moderators
    • People Really Only Care About These 3 Things at Work — Do You Offer Them?
    • Can Machines Really Recreate “You”?
    • Meet the researcher hosting a scientific conference by and for AI
    • Current Landscape of Artificial Intelligence Threats | by Kosiyae Yussuf | CodeToDeploy : The Tech Digest | Aug, 2025
    • Data Protection vs. Data Privacy: What’s the Real Difference?
    • Elon Musk and X reach settlement with axed Twitter workers
    • Labubu Could Reach $1B in Sales, According to Pop Mart CEO
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Artificial Intelligence»Can LangExtract Turn Messy Clinical Notes into Structured Data?
    Artificial Intelligence

    Can LangExtract Turn Messy Clinical Notes into Structured Data?

    Team_AIBS NewsBy Team_AIBS NewsAugust 19, 2025No Comments7 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email



    LangExtract is a from developers at Google that makes it straightforward to show messy, unstructured textual content into clear, structured knowledge by leveraging LLMs. Customers can present a number of few-shot examples together with a customized schema and get outcomes based mostly on that. It really works each with proprietary in addition to native LLMs (through Ollama). 

    A major quantity of knowledge in healthcare is unstructured, making it a really perfect space the place a software like this may be useful. Medical notes are lengthy and filled with abbreviations and inconsistencies. Vital particulars similar to drug names, dosages, and particularly adversarial drug reactions (ADRs) get buried within the textual content. Subsequently, for this text, I wished to see if LangExtract may deal with adversarial drug response (ADR) detection in scientific notes. Extra importantly, is it efficient? Let’s discover out on this article. Observe that whereas LangExtract is an open-source undertaking from builders at Google, it isn’t an formally supported Google product.

    Only a fast notice: I’m solely exhibiting how LanExtract works. I’m not a health care provider, and this isn’t medical recommendation.

    ▶️ Here’s a detailed Kaggle notebook to observe alongside.

    Why ADR Extraction Issues

    An Hostile Drug Response (ADR) is a dangerous, unintended end result brought on by taking a medicine. These can vary from delicate negative effects like nausea or dizziness to extreme outcomes that will require medical consideration. 

    Affected person takes drugs for headache however develops abdomen ache; a typical Hostile Drug Response (ADR) | Picture created by creator utilizing ChatGPT

    Detecting them shortly is crucial for affected person security and pharmacovigilance. The problem is that in scientific notes, ADRs are buried alongside previous situations, lab outcomes, and different context. Consequently, detecting them is hard. Utilizing LLMs to detect ADRs is an ongoing space of analysis. Some recent works have proven that LLMs are good at elevating pink flags however not dependable. So, ADR extraction is an effective stress check for LangExtract, because the objective right here is to see if this library can spot the adversarial reactions amongst different entities in scientific notes like drugs, dosages, severity, and so on.

    How LangExtract Works

    Earlier than we bounce into utilization, let’s break down LangExtract’s workflow. It’s a easy three-step course of:

    1. Outline your extraction process by writing a transparent immediate that specifies precisely what you need to extract. 
    2. Present a number of high-quality examples to information the mannequin in direction of the format and stage of element you anticipate.
    3. Submit your enter textual content, select the mannequin, and let LangExtract course of it. Customers can then evaluation the outcomes, visualize them, or cross them straight into their downstream pipeline.

    The official GitHub repository of the software has detailed examples spanning a number of domains, from entity extraction in Shakespeare’s Romeo & Juliet to treatment identification in scientific notes and structuring radiology experiences. Do examine them out.

    Set up

    First we have to set up the LangExtract library. It’s all the time a good suggestion to do that inside a virtual environment to maintain your undertaking dependencies remoted. 

    pip set up langextract

    Figuring out Hostile Drug Reactions in Medical Notes with LangExtract & Gemini

    Now let’s get to our use case. For this walkthrough, I’ll use Google’s Gemini 2.5 Flash mannequin. You possibly can additionally use Gemini Professional for extra complicated reasoning duties. You’ll must first set your API key:

    export LANGEXTRACT_API_KEY="your-api-key-here"

    ▶️ Here’s a detailed Kaggle notebook to observe alongside.

    Step 1: Outline the Extraction Job

    Let’s create our immediate for extracting drugs, dosages, adversarial reactions, and actions taken. We are able to additionally ask for severity the place talked about. 

    immediate = textwrap.dedent("""
    Extract treatment, dosage, adversarial response, and motion taken from the textual content.
    For every adversarial response, embrace its severity as an attribute if talked about.
    Use precise textual content spans from the unique textual content. Don't paraphrase.
    Return entities within the order they seem.""")
    The notice highlights ibuprofen (400 mg), the adversarial response (delicate abdomen ache), and the motion taken (stopping the drugs). That is what ADR extraction appears to be like like in apply. | Picture by Creator

    Subsequent, let’s present an instance to information the mannequin in direction of the right format:

    # 1) Outline the immediate
    immediate = textwrap.dedent("""
    Extract situation, treatment, dosage, adversarial response, and motion taken from the textual content.
    For every adversarial response, embrace its severity as an attribute if talked about.
    Use precise textual content spans from the unique textual content. Don't paraphrase.
    Return entities within the order they seem.""")
    
    # 2) Instance 
    examples = [
        lx.data.ExampleData(
            text=(
                "After taking ibuprofen 400 mg for a headache, "
                "the patient developed mild stomach pain. "
                "They stopped taking the medicine."
            ),
            extractions=[
                
                lx.data.Extraction(
                    extraction_class="condition",
                    extraction_text="headache"
                ),
            
                lx.data.Extraction(
                    extraction_class="medication",
                    extraction_text="ibuprofen"
                ),
                lx.data.Extraction(
                    extraction_class="dosage",
                    extraction_text="400 mg"
                ),
                lx.data.Extraction(
                    extraction_class="adverse_reaction",
                    extraction_text="mild stomach pain",
                    attributes={"severity": "mild"}
                ),
                lx.data.Extraction(
                    extraction_class="action_taken",
                    extraction_text="They stopped taking the medicine"
                )
            ]
        )
    ]

    Step 2: Present the Enter and Run the Extraction

    For the enter, I’m utilizing an actual scientific sentence from the ADE Corpus v2 dataset on Hugging Face.

    input_text = (
        "A 27-year-old man who had a historical past of bronchial bronchial asthma, "
        "eosinophilic enteritis, and eosinophilic pneumonia introduced with "
        "fever, pores and skin eruptions, cervical lymphadenopathy, hepatosplenomegaly, "
        "atypical lymphocytosis, and eosinophilia two weeks after receiving "
        "trimethoprim (TMP)-sulfamethoxazole (SMX) remedy."
    )

    Subsequent, let’s run LangExtract with the Gemini-2.5-Flash mannequin.

    end result = lx.extract(
        text_or_documents=input_text,
        prompt_description=immediate,
        examples=examples,
        model_id="gemini-2.5-flash",
        api_key=LANGEXTRACT_API_KEY 
    )

    Step 3: View the Outcomes

    You may show the extracted entities with positions

    print(f"Enter: {input_text}n")
    print("Extracted entities:")
    for entity in end result.extractions:
        position_info = ""
        if entity.char_interval:
            begin, finish = entity.char_interval.start_pos, entity.char_interval.end_pos
            position_info = f" (pos: {begin}-{finish})"
        print(f"• {entity.extraction_class.capitalize()}: {entity.extraction_text}{position_info}")

    LangExtract accurately identifies the adversarial drug response with out complicated it with the affected person’s pre-existing situations, which is a key problem in this kind of process.

    If you wish to visualize it, it’s going to create this .jsonl file. You may load that .jsonl file by calling the visualization perform, and it’ll create an HTML file for you.

    lx.io.save_annotated_documents(
        [result],
        output_name="adr_extraction.jsonl",
        output_dir="."
    )
    
    html_content = lx.visualize("adr_extraction.jsonl")
    
    # Show the HTML content material straight
    show((html_content))

    Working with longer scientific notes

    Actual scientific notes are sometimes for much longer than the instance proven above. As an example, right here is an precise notice from the ADE-Corpus-V2 dataset launched beneath the MIT License. You may entry it on Hugging Face or Zenodo. 

    Excerpt from a scientific notice from the ADE-Corpus-V2 dataset launched beneath the MIT License | Picture by the creator

    To course of longer texts with LangExtract, you retain the identical workflow however add three parameters:

    extraction_passes runs a number of passes over the textual content to catch extra particulars and enhance recall. 

    max_workers controls parallel processing so bigger paperwork may be dealt with sooner. 

    max_char_buffer splits the textual content into smaller chunks, which helps the mannequin keep correct even when the enter could be very lengthy.

    end result = lx.extract(
        text_or_documents=input_text,
        prompt_description=immediate,
        examples=examples,
        model_id="gemini-2.5-flash",
        extraction_passes=3,    
        max_workers=20,         
        max_char_buffer=1000   
    )

    Right here is the output. For brevity, I’m solely exhibiting a portion of the output right here.


    If you would like, you may also cross a doc’s URL on to the text_or_documents parameter.


    Utilizing LangExtract with Native fashions through Ollama

    LangExtract isn’t restricted to proprietary APIs. You may also run it with native fashions by means of Ollama. That is particularly helpful when working with privacy-sensitive scientific knowledge that may’t go away your safe setting. You may arrange Ollama regionally, pull your most well-liked mannequin, and level LangExtract to it. Full directions can be found within the official docs.

    Conclusion

    For those who’re constructing an info retrieval system or any software involving metadata extraction, LangExtract can prevent a big quantity of preprocessing effort. In my ADR experiments, LangExtract carried out effectively, accurately figuring out drugs, dosages, and reactions. What I observed is that the output straight is dependent upon the standard of the few-shot examples offered by the person, which suggests whereas LLMs do the heavy lifting, people nonetheless stay an essential a part of the loop. The outcomes have been encouraging, however since scientific knowledge is high-risk, broader and extra rigorous testing throughout numerous datasets continues to be wanted earlier than transferring towards manufacturing use.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleExplorando Estadísticas Descriptivas en Ciencia de Datos 📊 | by Gladys Choque Ulloa | Aug, 2025
    Next Article Average Ages to Make 6 Figures, Buy a House, Save for Retirement
    Team_AIBS News
    • Website

    Related Posts

    Artificial Intelligence

    Can Machines Really Recreate “You”?

    August 22, 2025
    Artificial Intelligence

    Unfiltered Roleplay AI Chatbots with Pictures – My Top Picks

    August 22, 2025
    Artificial Intelligence

    Roleplay AI Chatbot Apps with the Best Memory: Tested

    August 22, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    TikTok to lay off hundreds of UK content moderators

    August 22, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Melania Trump launches cryptocurrency on eve of inauguration

    January 20, 2025

    Torsten Hoefler Wins ACM Prize in Computing for Contributions to AI and HPC

    March 26, 2025

    Anthropic can now track the bizarre inner workings of a large language model

    March 27, 2025
    Our Picks

    TikTok to lay off hundreds of UK content moderators

    August 22, 2025

    People Really Only Care About These 3 Things at Work — Do You Offer Them?

    August 22, 2025

    Can Machines Really Recreate “You”?

    August 22, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

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