Skip to main content

A simple wrapper to support drug detection in medical texts.

Project description

drugdetector

This project provides a simple wrapper for performant zero-shot drug detection using LLMs.

Install

pip install drugdetector

Demo

For this demo, we're using a 4-bit quantized Llama-3 8B, but you can use many LLMs available on huggingface. We recommend one of the following fine-tuned models for improved performance:

  • fabriceyhc/Meta-Llama-3-8B-Instruct-DrugDetection-v3
  • fabriceyhc/Meta-Llama-3-70B-Instruct-DrugDetection-v3
from drugdetector import DrugDetector

detector = DrugDetector(model_id="TechxGenus/Meta-Llama-3-8B-Instruct-GPTQ")

Detection on default substances

When no specific drugs are requested, default to the ones we've studied.

results = detector.detect("Patient denies using heroin but reports cocaine use.")
print(results)
{'Heroin': False,
 'Cocaine': True,
 'Methamphetamine': False,
 'Benzodiazepine': False,
 'Prescription Opioids': False,
 'Cannabis': False,
 'Injection Drugs': False,
 'General Drugs': True,
 'medical_text': 'Patient denies using heroin but reports cocaine use.',
 'time_taken': 9.533252477645874}

Detection with custom drug dict

Tests zero-shot accuracy on any substances provided in as a python dictionary in the form of:

new_substances = {
  "substance1":"description1",
  "substance2":"description2",
  ...
  "substanceN":"descriptionN",
}
new_substances = {
    "Alcohol": "Alcohol is a legal substance but can be abused and lead to addiction and various health issues.",
    "Fentanyl": "Fentanyl is a potent synthetic opioid that is highly addictive and can lead to overdose, especially when used illicitly."
}

results = detector.detect("Patient hx of ethl use.", drugs=new_substances)
print(results)
{'Alcohol': True,
 'Fentanyl': False,
 'medical_text': 'Patient hx of ethl use.',
 'time_taken': 2.379117965698242}

Detection with custom drug dict and explanations provided

Demonstrates the model's ability to explain its decisions.

new_drugs = {
    "Alcohol": "Alcohol is a legal substance but can be abused and lead to addiction and various health issues.",
    "Fentanyl": "Fentanyl is a potent synthetic opioid that is highly addictive and can lead to overdose, especially when used illicitly."
}

results = detector.detect("Patient hx of ethl use.", drugs=new_substances, explain=True)
print(results)
{'Alcohol': True,
 'Fentanyl': False,
 'medical_text': 'Patient hx of ethl use.',
 'time_taken': 45.255696296691895,
 'Alcohol_explanation': 'The medical note mentions "ethl use", which is likely referring to ethanol, the scientific name for alcohol.',
 'Fentanyl_explanation': 'There is no mention of Fentanyl use in the medical note.'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drugdetector-0.3.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

drugdetector-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file drugdetector-0.3.0.tar.gz.

File metadata

  • Download URL: drugdetector-0.3.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for drugdetector-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e7f1d4bc3673dd2d5424ff265f227d0ead1635f1b0484d49f50141a3142b6b0e
MD5 9b3deac685ad11bd1ffe9db748e32f32
BLAKE2b-256 f6f25e5e535d7208ebce4a922b2716038ec420ee5f8353f7f6b2ebfd0aac5596

See more details on using hashes here.

File details

Details for the file drugdetector-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: drugdetector-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for drugdetector-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b187b464f3ffe1294916b8973eaade9b4f58014ec4085bd0ed3cb5b4de05f1fc
MD5 683291508c60d7b6c8cc1aa05bd23919
BLAKE2b-256 4503147269aaa3288f6567d72d848b09cffa5ddab0a206e32f12791c926f2b96

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page