{"id":5764,"date":"2025-08-19T11:07:22","date_gmt":"2025-08-19T11:07:22","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=5764"},"modified":"2025-08-19T11:07:22","modified_gmt":"2025-08-19T11:07:22","slug":"can-langextract-flip-messy-scientific-notes-into-structured-information","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=5764","title":{"rendered":"Can LangExtract Flip Messy Scientific Notes into Structured Information?"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dotted\"\/>\n<p class=\"wp-block-paragraph\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/google\/langextract\" target=\"_blank\" rel=\"noreferrer noopener\">LangExtract <\/a>is a  from <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/developers.googleblog.com\/en\/introducing-langextract-a-gemini-powered-information-extraction-library\/\" target=\"_blank\" rel=\"noreferrer noopener\">builders at Google<\/a> that makes it simple to show messy, unstructured textual content into clear, structured knowledge by leveraging LLMs. Customers can present just a few 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).\u00a0<\/p>\n<p class=\"wp-block-paragraph\">A big quantity of knowledge in healthcare is unstructured, making it an excellent space the place a instrument like this may be helpful. Scientific notes are lengthy and filled with abbreviations and inconsistencies. Necessary particulars reminiscent of drug names, dosages, and particularly hostile drug reactions (ADRs) get buried within the textual content. Subsequently, for this text, I needed to see if LangExtract might deal with hostile drug response (ADR) detection in medical notes. Extra importantly, is it efficient? Let\u2019s discover out on this article. Be aware that whereas LangExtract is an open-source challenge from builders at Google, it&#8217;s not an formally supported Google product.<\/p>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em><strong>Only a fast word: I\u2019m solely displaying how LanExtract works. I\u2019m not a physician, and this isn\u2019t medical recommendation.<\/strong><\/em><\/p>\n<\/blockquote>\n<p class=\"wp-block-paragraph\"><strong>\u25b6\ufe0f Here&#8217;s a detailed <\/strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.kaggle.com\/code\/parulpandey\/using-langextract-with-gemini\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Kaggle pocket book <\/strong><\/a><strong>to observe alongside.<\/strong><\/p>\n<h2 class=\"wp-block-heading\">Why ADR Extraction Issues<\/h2>\n<p class=\"wp-block-paragraph\">An <strong>Antagonistic Drug Response<\/strong> (ADR) is a dangerous, unintended outcome attributable to taking a drugs. These can vary from delicate uncomfortable side effects like nausea or dizziness to extreme outcomes which will require medical consideration.\u00a0<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/image-132.png\" alt=\"\" class=\"wp-image-615559\"\/><figcaption class=\"wp-element-caption\">Affected person takes drugs for headache however develops abdomen ache; a typical Antagonistic Drug Response (ADR) | Picture created by creator utilizing ChatGPT<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Detecting them shortly is vital for affected person security and <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.who.int\/teams\/regulation-prequalification\/regulation-and-safety\/pharmacovigilance\" target=\"_blank\" rel=\"noreferrer noopener\">pharmacovigilance<\/a>. The problem is that in medical notes, ADRs are buried alongside previous situations, lab outcomes, and different context. Because of this, detecting them is hard. Utilizing LLMs to detect ADRs is an ongoing space of analysis. Some <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/pmc.ncbi.nlm.nih.gov\/articles\/PMC12084699\/#section22-20420986251339358\" target=\"_blank\" rel=\"noreferrer noopener\">current works<\/a> have proven that LLMs are good at elevating crimson flags however not dependable. So, ADR extraction is an efficient stress take a look at for LangExtract, because the objective right here is to see if this library can spot the hostile reactions amongst different entities in medical notes like medicines, dosages, severity, and many others.<\/p>\n<h2 class=\"wp-block-heading\">How LangExtract Works<\/h2>\n<p class=\"wp-block-paragraph\">Earlier than we bounce into utilization, let\u2019s break down LangExtract\u2019s workflow. It\u2019s a easy three-step course of:<\/p>\n<ol class=\"wp-block-list\">\n<li class=\"wp-block-list-item\"><strong>Outline your extraction job<\/strong> by writing a transparent immediate that specifies precisely what you need to extract.\u00a0<\/li>\n<li class=\"wp-block-list-item\"><strong>Present just a few high-quality examples<\/strong> to information the mannequin in direction of the format and degree of element you anticipate.<\/li>\n<li class=\"wp-block-list-item\"><strong>Submit your enter textual content, select the mannequin, and let LangExtract course of it. <\/strong>Customers can<strong> <\/strong>then overview the outcomes, visualize them, or move them straight into their downstream pipeline.<\/li>\n<\/ol>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em>The official <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/google\/langextract\/tree\/main\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub repository<\/a> of the instrument has detailed examples spanning a number of domains, from entity extraction in Shakespeare\u2019s Romeo &amp; Juliet to remedy identification in medical notes and structuring radiology stories. Do test them out.<\/em><\/p>\n<\/blockquote>\n<h3 class=\"wp-block-heading\">Set up<\/h3>\n<p class=\"wp-block-paragraph\">First we have to set up the <code>LangExtract<\/code> library. It\u2019s at all times a good suggestion to do that inside a <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/venv.html\" rel=\"noreferrer noopener\" target=\"_blank\">digital atmosphere<\/a> to maintain your challenge dependencies remoted.\u00a0<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">pip set up langextract<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Figuring out Antagonistic Drug Reactions in Scientific Notes with LangExtract &amp;\u00a0Gemini<\/h2>\n<p class=\"wp-block-paragraph\">Now let\u2019s get to our use case. For this walkthrough, I\u2019ll use Google\u2019s <strong>Gemini 2.5 Flash<\/strong> mannequin. You can additionally use <strong>Gemini Professional<\/strong> for extra advanced reasoning duties. You\u2019ll must first set your API key:<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">export LANGEXTRACT_API_KEY=\"your-api-key-here\"<\/code><\/pre>\n<p class=\"wp-block-paragraph\"><strong>\u25b6\ufe0f Here&#8217;s a detailed <\/strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.kaggle.com\/code\/parulpandey\/using-langextract-with-gemini\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>Kaggle pocket book <\/strong><\/a><strong>to observe alongside.<\/strong><\/p>\n<h3 class=\"wp-block-heading\">Step 1: Outline the Extraction Process<\/h3>\n<p class=\"wp-block-paragraph\">Let\u2019s create our immediate for extracting medicines, dosages, hostile reactions, and actions taken. We will additionally ask for severity the place talked about.\u00a0<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">immediate = textwrap.dedent(\"\"\"\nExtract remedy, dosage, hostile response, and motion taken from the textual content.\nFor every hostile response, embody its severity as an attribute if talked about.\nUse precise textual content spans from the unique textual content. Don't paraphrase.\nReturn entities within the order they seem.\"\"\")<\/code><\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/image-133-1024x491.png\" alt=\"\" class=\"wp-image-615560\"\/><figcaption class=\"wp-element-caption\">The word highlights ibuprofen (400 mg), the hostile response (delicate abdomen ache), and the motion taken (stopping the medication). That is what ADR extraction seems to be like in follow. | Picture by\u00a0Creator<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Subsequent, let\u2019s present an instance to information the mannequin in direction of the right format:<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\"># 1) Outline the immediate\nimmediate = textwrap.dedent(\"\"\"\nExtract situation, remedy, dosage, hostile response, and motion taken from the textual content.\nFor every hostile response, embody its severity as an attribute if talked about.\nUse precise textual content spans from the unique textual content. Don't paraphrase.\nReturn entities within the order they seem.\"\"\")\n\n# 2) Instance \nexamples = [\n    lx.data.ExampleData(\n        text=(\n            \"After taking ibuprofen 400 mg for a headache, \"\n            \"the patient developed mild stomach pain. \"\n            \"They stopped taking the medicine.\"\n        ),\n        extractions=[\n            \n            lx.data.Extraction(\n                extraction_class=\"condition\",\n                extraction_text=\"headache\"\n            ),\n        \n            lx.data.Extraction(\n                extraction_class=\"medication\",\n                extraction_text=\"ibuprofen\"\n            ),\n            lx.data.Extraction(\n                extraction_class=\"dosage\",\n                extraction_text=\"400 mg\"\n            ),\n            lx.data.Extraction(\n                extraction_class=\"adverse_reaction\",\n                extraction_text=\"mild stomach pain\",\n                attributes={\"severity\": \"mild\"}\n            ),\n            lx.data.Extraction(\n                extraction_class=\"action_taken\",\n                extraction_text=\"They stopped taking the medicine\"\n            )\n        ]\n    )\n]<\/code><\/pre>\n<h3 class=\"wp-block-heading\">Step 2: Present the Enter and Run the Extraction<\/h3>\n<p class=\"wp-block-paragraph\">For the enter, I\u2019m utilizing an actual medical sentence from the <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/huggingface.co\/datasets\/SetFit\/ade_corpus_v2_classification\/viewer\/default\/train?f[label_text][value]=%27Related%27\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>ADE Corpus v2<\/strong><\/a> dataset on Hugging Face.<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">input_text = (\n    \"A 27-year-old man who had a historical past of bronchial bronchial asthma, \"\n    \"eosinophilic enteritis, and eosinophilic pneumonia introduced with \"\n    \"fever, pores and skin eruptions, cervical lymphadenopathy, hepatosplenomegaly, \"\n    \"atypical lymphocytosis, and eosinophilia two weeks after receiving \"\n    \"trimethoprim (TMP)-sulfamethoxazole (SMX) therapy.\"\n)<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Subsequent, let\u2019s run LangExtract with the Gemini-2.5-Flash mannequin.<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">outcome = lx.extract(\n    text_or_documents=input_text,\n    prompt_description=immediate,\n    examples=examples,\n    model_id=\"gemini-2.5-flash\",\n    api_key=LANGEXTRACT_API_KEY \n)<\/code><\/pre>\n<h3 class=\"wp-block-heading\">Step 3: View the\u00a0Outcomes<\/h3>\n<p class=\"wp-block-paragraph\">You may show the extracted entities with positions<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">print(f\"Enter: {input_text}n\")\nprint(\"Extracted entities:\")\nfor entity in outcome.extractions:\n    position_info = \"\"\n    if entity.char_interval:\n        begin, finish = entity.char_interval.start_pos, entity.char_interval.end_pos\n        position_info = f\" (pos: {begin}-{finish})\"\n    print(f\"\u2022 {entity.extraction_class.capitalize()}: {entity.extraction_text}{position_info}\")<\/code><\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-18-at-12.26.34-AM-1024x371.png\" alt=\"\" class=\"wp-image-615574\"\/><\/figure>\n<p class=\"wp-block-paragraph\">LangExtract accurately identifies the <strong>hostile drug response<\/strong> with out complicated it with the affected person\u2019s pre-existing situations, which is a key problem in one of these job.<\/p>\n<p class=\"wp-block-paragraph\">If you wish to visualize it, it\u2019s going to create this\u00a0<code>.jsonl<\/code> file. You may load that\u00a0<code>.jsonl<\/code> file by calling the visualization perform, and it&#8217;ll create an HTML file for you.<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">lx.io.save_annotated_documents(\n    [result],\n    output_name=\"adr_extraction.jsonl\",\n    output_dir=\".\"\n)\n\nhtml_content = lx.visualize(\"adr_extraction.jsonl\")\n\n# Show the HTML content material straight\nshow((html_content))<\/code><\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/ADR_final.gif\" alt=\"\" class=\"wp-image-615572\"\/><\/figure>\n<h2 class=\"wp-block-heading\">Working with longer medical\u00a0notes<\/h2>\n<p class=\"wp-block-paragraph\">Actual medical notes are sometimes for much longer than the instance proven above. As an example, right here is an precise word from the <strong><em>ADE-Corpus-V2<\/em> dataset<\/strong> launched below the <strong>MIT License<\/strong>. You may entry it on <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/huggingface.co\/datasets\/SetFit\/ade_corpus_v2_classification\" rel=\"noreferrer noopener\" target=\"_blank\">Hugging Face<\/a> or <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/zenodo.org\/records\/13889331\" rel=\"noreferrer noopener\" target=\"_blank\">Zenodo<\/a>.\u00a0<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/image-135-1024x759.png\" alt=\"\" class=\"wp-image-615563\"\/><figcaption class=\"wp-element-caption\">Excerpt from a medical word from the <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/zenodo.org\/records\/13889331\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>ADE-Corpus-V2<\/em> dataset<\/strong><\/a> launched below the <strong>MIT\u00a0License<\/strong> | Picture by the creator<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">To course of longer texts with LangExtract, you retain the identical workflow however add three parameters:<\/p>\n<p><strong>extraction_passes<\/strong> runs a number of passes over the textual content to catch extra particulars and enhance recall.\u00a0<\/p>\n<p><strong>max_workers<\/strong> controls parallel processing so bigger paperwork will be dealt with quicker.\u00a0<\/p>\n<p><strong>max_char_buffer<\/strong> splits the textual content into smaller chunks, which helps the mannequin keep correct even when the enter could be very lengthy.<\/p>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">outcome = lx.extract(\n    text_or_documents=input_text,\n    prompt_description=immediate,\n    examples=examples,\n    model_id=\"gemini-2.5-flash\",\n    extraction_passes=3,    \n    max_workers=20,         \n    max_char_buffer=1000   \n)<\/code><\/pre>\n<p class=\"has-text-align-left wp-block-paragraph\">Right here is the output. For brevity, I\u2019m solely displaying a portion of the output right here.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/contributor.insightmediagroup.io\/wp-content\/uploads\/2025\/08\/image-136-1024x481.png\" alt=\"\" class=\"wp-image-615564\"\/><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dotted\"\/>\n<p class=\"wp-block-paragraph\">If you&#8217;d like, you can too move a doc\u2019s URL on to the <code>text_or_documents<\/code> parameter.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dotted\"\/>\n<h2 class=\"wp-block-heading\">Utilizing LangExtract with Native fashions through\u00a0Ollama<\/h2>\n<p class=\"wp-block-paragraph\">LangExtract isn\u2019t restricted to proprietary APIs. You may as well run it with native fashions by way of <strong>Ollama<\/strong>. That is particularly helpful when working with privacy-sensitive medical knowledge that may\u2019t depart your safe atmosphere. You may arrange Ollama domestically, pull your most well-liked mannequin, and level LangExtract to it. Full directions can be found within the <a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/To%20use%20the%20`langextract`%20library,%20we%20need%20to%20authenticate%20with%20the%20service%20using%20an%20API%20key.%20This%20code%20cell%20retrieves%20the%20API%20key%20from%20the%20user%20data%20and%20sets%20it%20as%20an%20environment%20variable,%20making%20it%20accessible%20to%20the%20library.\" rel=\"noreferrer noopener\" target=\"_blank\">official docs<\/a>.<\/p>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p class=\"wp-block-paragraph\">For those who\u2019re constructing an data retrieval system or any software involving metadata extraction, LangExtract can prevent a major quantity of preprocessing effort. In my ADR experiments, LangExtract carried out nicely, accurately figuring out medicines, dosages, and reactions. What I observed is that the output straight relies on the standard of the few-shot examples supplied by the person, which implies whereas LLMs do the heavy lifting, people nonetheless stay an vital a part of the loop. The outcomes had been encouraging, however since medical knowledge is high-risk, broader and extra rigorous testing throughout numerous datasets remains to be wanted earlier than transferring towards manufacturing use.<\/p>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>LangExtract is a from builders at Google that makes it simple to show messy, unstructured textual content into clear, structured knowledge by leveraging LLMs. Customers can present just a few 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":5766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[4802,157,4556,4801,1531,1248,2416],"class_list":["post-5764","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-clinical","tag-data","tag-langextract","tag-messy","tag-notes","tag-structured","tag-turn"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5764"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5764\/revisions"}],"predecessor-version":[{"id":5765,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5764\/revisions\/5765"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/5766"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-06-15 10:03:30 UTC -->