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
Download doccompass/mediq.py from ssg1/doc-compass: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/ssg1/doc-compass/resolve/main/doccompass/mediq.py
- Command line
-
hf download hf://ssg1/doc-compass/doccompass/mediq.py
-
curl -L -o mediq.py https://huggingface.co/ssg1/doc-compass/resolve/main/doccompass/mediq.py
1.87 kB
| """The post pool: unique real posts from MediQ_AskDocs.""" | |
| import html | |
| import json | |
| import re | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| # Pinned so everyone builds the same pool. | |
| MEDIQ = {"repo_id": "stellalisy/MediQ_AskDocs", "revision": "f215fd4d70e15298d71ae56330ac349c5720e0bf"} | |
| MEDIQ_FILES = [f"original/{split}.jsonl" for split in ("train", "validation", "test")] # skips synthetic/ | |
| _HANDLE = re.compile(r"/?\bu/[\w-]+") | |
| _URL = re.compile(r"https?://\S+|www\.\S+") | |
| def clean_text(text: str) -> str: | |
| """Drop Reddit handles, links and HTML entities; tidy whitespace but keep line breaks.""" | |
| text = html.unescape(text).replace("", " ") | |
| text = _URL.sub(" ", _HANDLE.sub(" ", text)) | |
| text = re.sub(r"[ \t]+", " ", text) | |
| return re.sub(r"\s*\n\s*", "\n", text).strip() | |
| def dedupe_key(text: str) -> str: | |
| """Two posts are the same post if they match after lower-casing and dropping punctuation.""" | |
| return re.sub(r"\W+", " ", text.lower()).strip() | |
| def load_mediq_posts() -> pd.DataFrame: | |
| """Return unique posts as (id, text), sorted by id. | |
| MediQ repeats each post once per doctor question, and some posts carry several ids, | |
| so we keep one row per post text and its smallest id. | |
| """ | |
| posts: dict[str, tuple[str, str]] = {} | |
| for name in MEDIQ_FILES: | |
| path = hf_hub_download(repo_type="dataset", filename=name, **MEDIQ) | |
| with open(path, encoding="utf-8") as lines: | |
| for line in lines: | |
| row = json.loads(line) | |
| text = clean_text(row["messages"][0]["content"]) | |
| post_id = row["id"].split("-")[0] | |
| key = dedupe_key(text) | |
| if key not in posts or post_id < posts[key][0]: | |
| posts[key] = (post_id, text) | |
| return pd.DataFrame(sorted(posts.values()), columns=["id", "text"]) | |