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
Optionally, but recommended is to install CUDA support for llama-cpp-python
(source).
pip install llama-cpp-python \
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/<cuda-version>
Where <cuda-version>
is one of the following:
cu121: CUDA 12.1 cu122: CUDA 12.2 cu123: CUDA 12.3 cu124: CUDA 12.4 cu125: CUDA 12.5
You can find what version of CUDA you support via nvidia-smi
and looking for the CUDA Version
in the top right corner.
Demo
For this demo, we're using our fine-tuned 8-bit quantized Llama-3 model (fabriceyhc/Llama-3-8B-DrugDetector
), but you can use many LLMs available on huggingface.
We recommend one of the following fine-tuned models for improved performance:
fabriceyhc/Llama-3-8B-DrugDetector
fabriceyhc/Llama-3-70B-DrugDetector
from drugdetector import DrugDetector
detector = DrugDetector(model_id="fabriceyhc/Llama-3-8B-DrugDetector")
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
Built Distribution
File details
Details for the file drugdetector-0.3.1.tar.gz
.
File metadata
- Download URL: drugdetector-0.3.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c54719f2ccacddcdb4a2b4029198aa1fea9472b8a7fa4eb054f0553a61e70c7 |
|
MD5 | 21fa8666ef8d08ec204c0a7ee93a93e4 |
|
BLAKE2b-256 | 6e862fcee0792bbe74b6e5a37342e416ec7068ab8221da9a3c4c3db370a7d8f4 |
File details
Details for the file drugdetector-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: drugdetector-0.3.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a48de11a58620bf3c3806fcd6fd93c64093446dc142544f94a9d8e1125accbc |
|
MD5 | 7be507aa4159840253fe91d4222813fe |
|
BLAKE2b-256 | 98d9751d93afd8fa0e07c8d48b7b86e9042adc317b9b2217716d14287f2f9c18 |