Run this model with HF Jobs
Run ssg1/doc-compass on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ssg1/doc-compass. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ssg1/doc-compass on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ssg1/doc-compass with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ssg1/doc-compass with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ssg1/doc-compass")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ssg1/doc-compass", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload the Doc Compass app bundle
Browse filesFiles changed (4)
123version https://git-lfs.github.com/spec/v1oid sha256:fb339f36161c91408385df4fecbb5385f98ca73432aa0bba2fce6ada94088331size 1111084123version https://git-lfs.github.com/spec/v1oid sha256:ba1b5886d760898f605968d3d1fd194db2f6caac588cdf0d1c7cdf4e359a532fsize 1111084
5 unmodified lines6789101112131415165 unmodified lines# them would point ROOT at the cache's blob folder instead of the folder holding checkpoints/.ROOT = Path(__file__).absolute().parents[1]PUBLIC = ROOT / "data" / "public" # downloaded and derived public dataMANUAL = ROOT / "data" / "manual" # our pool and labelsMODELS = ROOT / "checkpoints"MEDIQ_POSTS = PUBLIC / "mediq_posts.csv"PATIENT_COMMENTS = PUBLIC / "patient_comments.csv"POOL_IDS = MANUAL / "pool.ids.csv" # committed: which posts we label, and who labels themPOOL = MANUAL / "pool.csv" # local only: the same posts with their textDRAFT_LABELS = MANUAL / "draft.labels.csv" # first-pass labels shown in the labelling tool5 unmodified lines678910111213141516175 unmodified lines# them would point ROOT at the cache's blob folder instead of the folder holding checkpoints/.ROOT = Path(__file__).absolute().parents[1]PUBLIC = ROOT / "data" / "public" # downloaded and derived public dataSYNTHETIC = ROOT / "data" / "synthetic" # generated or apparently generated data; never counted as oursMANUAL = ROOT / "data" / "manual" # our pool and labelsMODELS = ROOT / "checkpoints"MEDIQ_POSTS = PUBLIC / "mediq_posts.csv"PATIENT_COMMENTS = SYNTHETIC / "patient_comments.csv"POOL_IDS = MANUAL / "pool.ids.csv" # committed: which posts we label, and who labels themPOOL = MANUAL / "pool.csv" # local only: the same posts with their textDRAFT_LABELS = MANUAL / "draft.labels.csv" # first-pass labels shown in the labelling tool
1 unmodified line2345678 unmodified lines1617181920212260 unmodified lines838485868788891 unmodified lineSource: Mendeley Data, DOI 10.17632/2twgjzpn82.2, CC BY 4.0. Each comment has a symptomcategory; CATEGORY_MAP sends each category to one of our labels, or drops it.See docs/label-set.md for the reasoning behind each choice."""8 unmodified linesfrom .labels import GP, LABELSfrom .mediq import dedupe_keyfrom .paths import PUBLIC_URL = "https://data.mendeley.com/public-files/datasets/2twgjzpn82/files/{file_id}/file_downloaded"_FILES = { # name: (Mendeley file id, sha256). We ignore the source's own train/test split.60 unmodified linesdef load_patient_comments() -> pd.DataFrame:"""Return unique comments as (text, label) in our label set, with emoji removed."""folder = PUBLIC / "patient_comments_source"rows = pd.concat([pd.read_excel(_download(name, folder)) for name in _FILES], ignore_index=True)rows["label"] = rows["Patient_Category"].map(lambda category: _MAP_BY_KEY[_category_key(category)])rows = rows.dropna(subset=["label"])1 unmodified line2345678910118 unmodified lines2021222324252660 unmodified lines878889909192931 unmodified lineSource: Mendeley Data, DOI 10.17632/2twgjzpn82.2, CC BY 4.0. Each comment has a symptomcategory; CATEGORY_MAP sends each category to one of our labels, or drops it.The comments appear to be generated rather than written by real patients (emoji matched toeach symptom, inserted typos, repeated openings), so we store them under data/synthetic anduse them for stage-1 training only.See docs/label-set.md for the reasoning behind each choice."""8 unmodified linesfrom .labels import GP, LABELSfrom .mediq import dedupe_keyfrom .paths import SYNTHETIC_URL = "https://data.mendeley.com/public-files/datasets/2twgjzpn82/files/{file_id}/file_downloaded"_FILES = { # name: (Mendeley file id, sha256). We ignore the source's own train/test split.60 unmodified linesdef load_patient_comments() -> pd.DataFrame:"""Return unique comments as (text, label) in our label set, with emoji removed."""folder = SYNTHETIC / "patient_comments_source"rows = pd.concat([pd.read_excel(_download(name, folder)) for name in _FILES], ignore_index=True)rows["label"] = rows["Patient_Category"].map(lambda category: _MAP_BY_KEY[_category_key(category)])rows = rows.dropna(subset=["label"])
31 unmodified lines3233343536373839403 unmodified lines444546474849503 unmodified lines545556575859606162636465661 unmodified line6869707172737431 unmodified linesRULES = [_rule("chest pain", "Chest pain or discomfort lasting for two minutes or more", MEDLINEPLUS,r"\bchest (?:pain|pressure|tightness|discomfort)\b|\bpain in (?:my|the|his|her) chest\b"),_rule("breathing", "Breathing problems (difficulty breathing, shortness of breath)", MEDLINEPLUS,rf"\b(?:{_CANT}|struggling to|hard to|trouble|difficulty) breath(?:e|ing)\b|\bshort(?:ness)? of breath\b|\bgasping for (?:air|breath)\b"),_rule("stroke signs", "Sudden numbness or weakness in the face, arm, or leg; sudden confusion or trouble speaking", CDC_STROKE,rf"\bface (?:is |was )?drooping\b|\bslurred speech\b|\b(?:{_CANT}|trouble) (?:speak|speaking|talk|talking)\b"r"|\bsudden(?:ly)? (?:numb|weak|confus)\w*|\b(?:numb|weak)\w* on (?:one|the left|the right|my left|my right) side\b"),3 unmodified lines_rule("loss of consciousness", "Fainting or loss of consciousness", MEDLINEPLUS,r"\b(?:passed out|fainted|lost consciousness|unconscious|unresponsive)\b"),_rule("suicidal thoughts", "Feeling of committing suicide or murder", MEDLINEPLUS,r"\bsuicid\w*|\bkill(?:ing)? myself\b|\bend(?:ing)? my (?:own )?life\b|\bwant(?:ed)? to die\b|\bdon'?t want to (?:live|be alive)\b"),_rule("face or throat swelling", "Swelling of the face, eyes, or tongue", MEDLINEPLUS,r"\b(?:throat|tongue|lips?|face) (?:is |are |was |were )?(?:swelling|swollen|closing)\b"r"|\bswelling (?:of|in) (?:my |the )?(?:face|tongue|throat|lips?)\b|\banaphyla\w*"),3 unmodified linesr"\boverdos\w*|(?<!food )\bpoison(?:ed|ing)\b|\b(?:swallowed|drank|ingested) (?:bleach|poison|detergent|antifreeze)\b"),_rule("sudden severe pain", "Sudden, severe pain anywhere in the body; sudden severe headache with no known cause", MEDLINEPLUS,r"\bsudden(?:ly)?\b[^.!?]{0,40}\b(?:severe|excruciating|unbearable|worst)\b[^.!?]{0,25}\b(?:pain|headache)\b"r"|\bworst (?:headache|pain) of my life\b"),_rule("sudden vision change", "Sudden trouble seeing", CDC_STROKE,rf"\bsudden(?:ly)? (?:lost|loss of|blurred|blurry|double) vision\b|\bsuddenly {_CANT} see\b|\bsudden(?:ly)? (?:went )?blind\b"),]# A match is ignored when one of these appears just before it ("no chest pain")._NEGATION = re.compile(r"\b(?:no|not|never|without|denies|deny|didn'?t|don'?t have|doesn'?t have|haven'?t)\b[^.!?,;]{0,25}$", re.IGNORECASE)def find_flags(text: str) -> list[dict]:1 unmodified lineflags = []for rule in RULES:for match in rule.pattern.finditer(text):if _NEGATION.search(text[max(0, match.start() - 40):match.start()]):continueflags.append({"rule": rule.name, "matched": match.group(0), "sign": rule.sign,"source": rule.source[0], "url": rule.source[1]})31 unmodified lines323334353637383940413 unmodified lines45464748495051523 unmodified lines5657585960616263646566676869707172731 unmodified line7576777879808131 unmodified linesRULES = [_rule("chest pain", "Chest pain or discomfort lasting for two minutes or more", MEDLINEPLUS,r"\bchest (?:pain|pressure|tightness|discomfort)\b|\bpain in (?:my|the|his|her) chest\b"r"|\bchest (?:hurts|is hurting|feels tight|feels heavy)\b"),_rule("breathing", "Breathing problems (difficulty breathing, shortness of breath)", MEDLINEPLUS,rf"\b(?:{_CANT}|can barely|barely able to|struggling to|hard to|trouble|difficulty) breath(?:e|ing)\b|\bshort(?:ness)? of breath\b|\bgasping for (?:air|breath)\b"),_rule("stroke signs", "Sudden numbness or weakness in the face, arm, or leg; sudden confusion or trouble speaking", CDC_STROKE,rf"\bface (?:is |was )?drooping\b|\bslurred speech\b|\b(?:{_CANT}|trouble) (?:speak|speaking|talk|talking)\b"r"|\bsudden(?:ly)? (?:numb|weak|confus)\w*|\b(?:numb|weak)\w* on (?:one|the left|the right|my left|my right) side\b"),3 unmodified lines_rule("loss of consciousness", "Fainting or loss of consciousness", MEDLINEPLUS,r"\b(?:passed out|fainted|lost consciousness|unconscious|unresponsive)\b"),_rule("suicidal thoughts", "Feeling of committing suicide or murder", MEDLINEPLUS,r"\bsuicid\w*|\bkill(?:ing)? myself\b|\bend(?:ing)? my (?:own )?life\b|\bwant(?:ed)? to die\b|\bdon'?t want to (?:live|be alive)\b"r"|\bend(?:ing)? it all\b|\btake my (?:own )?life\b"),_rule("face or throat swelling", "Swelling of the face, eyes, or tongue", MEDLINEPLUS,r"\b(?:throat|tongue|lips?|face) (?:is |are |was |were )?(?:swelling|swollen|closing)\b"r"|\bswelling (?:of|in) (?:my |the )?(?:face|tongue|throat|lips?)\b|\banaphyla\w*"),3 unmodified linesr"\boverdos\w*|(?<!food )\bpoison(?:ed|ing)\b|\b(?:swallowed|drank|ingested) (?:bleach|poison|detergent|antifreeze)\b"),_rule("sudden severe pain", "Sudden, severe pain anywhere in the body; sudden severe headache with no known cause", MEDLINEPLUS,r"\bsudden(?:ly)?\b[^.!?]{0,40}\b(?:severe|excruciating|unbearable|worst)\b[^.!?]{0,25}\b(?:pain|headache)\b"r"|\bworst (?:headache|pain) (?:of my life|ever)\b"),_rule("sudden vision change", "Sudden trouble seeing", CDC_STROKE,rf"\bsudden(?:ly)? (?:lost|loss of|blurred|blurry|double) vision\b|\bsuddenly {_CANT} see\b|\bsudden(?:ly)? (?:went )?blind\b"),]# A match is ignored when a negation governs it: "no chest pain", "I don't want to die",# "never had any trouble breathing". Only short filler words may sit between the two, so# "not sure why my chest pain started" and "I don't know why but my chest hurts" still flag._NEGATION = re.compile(r"\b(?:no|not|never|without|denies|deny|didn'?t|don'?t|doesn'?t|haven'?t|hasn'?t|isn'?t|wasn'?t)"r"(?:\s+(?:have|had|has|having|got|get|getting|any|a|an|the|real|really|much|more|been|"r"experienced|experiencing|feel|felt|noticed|want|wanted|to|this|that|such)){0,4}\s*$", re.IGNORECASE)def find_flags(text: str) -> list[dict]:1 unmodified lineflags = []for rule in RULES:for match in rule.pattern.finditer(text):if _NEGATION.search(text[max(0, match.start() - 60):match.start()]):continueflags.append({"rule": rule.name, "matched": match.group(0), "sign": rule.sign,"source": rule.source[0], "url": rule.source[1]})
checkpoints/tfidf_stage1.joblib+1-1
doccompass/paths.py+2-1
doccompass/patient_comments.py+6-2
doccompass/redflags.py+14-7