2. Infering relations from annotations with Relation toolkit
In [ ]:
Copied!
# Install medcat
! pip install "medcat[spacy,rel-cat]~=2.4.0" # NOTE: VERSION-STRING
# Install medcat
! pip install "medcat[spacy,rel-cat]~=2.4.0" # NOTE: VERSION-STRING
Collecting medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2 (from medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) Cloning https://github.com/CogStack/cogstack-nlp (to revision medcat/v0.11.2) to /private/var/folders/h4/sklqg_zx1dbbbx76m2__zb8h0000gn/T/pip-install-75p8sxeh/medcat_046359d163014f2cb358c679f5a62eeb Running command git clone --filter=blob:none --quiet https://github.com/CogStack/cogstack-nlp /private/var/folders/h4/sklqg_zx1dbbbx76m2__zb8h0000gn/T/pip-install-75p8sxeh/medcat_046359d163014f2cb358c679f5a62eeb Running command git checkout -q b1ce30ba716ff7c1f3b912085ca02026b6de3f22 Resolved https://github.com/CogStack/cogstack-nlp to commit b1ce30ba716ff7c1f3b912085ca02026b6de3f22 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy>2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.3.1) Requirement already satisfied: dill in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.4.0) Requirement already satisfied: pandas<3.0,>=2.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.3.0) Requirement already satisfied: tqdm<5.0,>=4.64 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (4.67.1) Requirement already satisfied: xxhash<4.0,>=3.5.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.5.0) Requirement already satisfied: pydantic>2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.11.7) Requirement already satisfied: typing-extensions in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (4.14.0) Requirement already satisfied: spacy in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.8.7) Requirement already satisfied: transformers<5.0,>=4.41.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (4.53.0) Requirement already satisfied: peft<1.0,>0.8.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.15.2) Requirement already satisfied: torch<3.0,>=2.4.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.7.1) Requirement already satisfied: scikit-learn<2.0,>=1.1.3 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.7.0) Requirement already satisfied: scipy in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.16.0) Requirement already satisfied: python-dateutil>=2.8.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pandas<3.0,>=2.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.9.0.post0) Requirement already satisfied: pytz>=2020.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pandas<3.0,>=2.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2025.2) Requirement already satisfied: tzdata>=2022.7 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pandas<3.0,>=2.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2025.2) Requirement already satisfied: packaging>=20.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (25.0) Requirement already satisfied: psutil in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (7.0.0) Requirement already satisfied: pyyaml in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (6.0.2) Requirement already satisfied: accelerate>=0.21.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.8.1) Requirement already satisfied: safetensors in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.5.3) Requirement already satisfied: huggingface_hub>=0.25.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.33.1) Requirement already satisfied: joblib>=1.2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from scikit-learn<2.0,>=1.1.3->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.5.1) Requirement already satisfied: threadpoolctl>=3.1.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from scikit-learn<2.0,>=1.1.3->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.6.0) Requirement already satisfied: filelock in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.18.0) Requirement already satisfied: sympy>=1.13.3 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.14.0) Requirement already satisfied: networkx in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.5) Requirement already satisfied: jinja2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.1.6) Requirement already satisfied: fsspec in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2025.5.1) Requirement already satisfied: regex!=2019.12.17 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2024.11.6) Requirement already satisfied: requests in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.32.4) Requirement already satisfied: tokenizers<0.22,>=0.21 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.21.2) Requirement already satisfied: hf-xet<2.0.0,>=1.1.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from huggingface_hub>=0.25.0->peft<1.0,>0.8.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.1.5) Requirement already satisfied: annotated-types>=0.6.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pydantic>2.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.7.0) Requirement already satisfied: pydantic-core==2.33.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pydantic>2.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.33.2) Requirement already satisfied: typing-inspection>=0.4.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from pydantic>2.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.4.1) Requirement already satisfied: six>=1.5 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas<3.0,>=2.2->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.17.0) Requirement already satisfied: mpmath<1.4,>=1.1.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from sympy>=1.13.3->torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.3.0) Requirement already satisfied: MarkupSafe>=2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from jinja2->torch<3.0,>=2.4.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.0.2) Requirement already satisfied: charset_normalizer<4,>=2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from requests->transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.4.2) Requirement already satisfied: idna<4,>=2.5 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from requests->transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from requests->transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.5.0) Requirement already satisfied: certifi>=2017.4.17 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from requests->transformers<5.0,>=4.41.0->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2025.6.15) Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.0.12) Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.0.5) Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.0.13) Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.0.11) Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.0.10) Requirement already satisfied: thinc<8.4.0,>=8.3.4 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (8.3.6) Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.1.3) Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.5.1) Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.0.10) Requirement already satisfied: weasel<0.5.0,>=0.1.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.4.1) Requirement already satisfied: typer<1.0.0,>=0.3.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.16.0) Requirement already satisfied: setuptools in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (65.5.0) Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.5.0) Requirement already satisfied: language-data>=1.2 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from langcodes<4.0.0,>=3.2.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.3.0) Requirement already satisfied: blis<1.4.0,>=1.3.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from thinc<8.4.0,>=8.3.4->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.3.0) Requirement already satisfied: confection<1.0.0,>=0.0.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from thinc<8.4.0,>=8.3.4->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.1.5) Requirement already satisfied: click>=8.0.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (8.2.1) Requirement already satisfied: shellingham>=1.3.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.5.4) Requirement already satisfied: rich>=10.11.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (14.0.0) Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from weasel<0.5.0,>=0.1.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.21.1) Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from weasel<0.5.0,>=0.1.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (7.1.0) Requirement already satisfied: wrapt in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.1.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.17.2) Requirement already satisfied: marisa-trie>=1.1.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from language-data>=1.2->langcodes<4.0.0,>=3.2.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (1.2.1) Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from rich>=10.11.0->typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (3.0.0) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from rich>=10.11.0->typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (2.19.2) Requirement already satisfied: mdurl~=0.1 in /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0.0,>=0.3.0->spacy->medcat@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2->medcat[meta-cat,spacy]@ git+https://github.com/CogStack/cogstack-nlp@medcat/v0.11.2#subdirectory=medcat-v2) (0.1.2)
In [2]:
Copied!
! wget "https://drive.usercontent.google.com/download?id=1nGI3Igrd7V0fayUAMVafZU9C8GSgEmDS&export=download&confirm=t&uuid=da8b7d44-401a-40f4-8e16-f1adc0ff827f" -O part_6_2_ade_relcat_model.zip
! unzip part_6_2_ade_relcat_model.zip -d part_6_2
! wget "https://drive.usercontent.google.com/download?id=1nGI3Igrd7V0fayUAMVafZU9C8GSgEmDS&export=download&confirm=t&uuid=da8b7d44-401a-40f4-8e16-f1adc0ff827f" -O part_6_2_ade_relcat_model.zip
! unzip part_6_2_ade_relcat_model.zip -d part_6_2
--2025-07-01 14:29:39-- https://drive.usercontent.google.com/download?id=1nGI3Igrd7V0fayUAMVafZU9C8GSgEmDS&export=download&confirm=t&uuid=da8b7d44-401a-40f4-8e16-f1adc0ff827f Resolving drive.usercontent.google.com (drive.usercontent.google.com)... 142.250.180.1 Connecting to drive.usercontent.google.com (drive.usercontent.google.com)|142.250.180.1|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 409019548 (390M) [application/octet-stream] Saving to: ‘part_6_2_ade_relcat_model.zip’ part_6_2_ade_relcat 100%[===================>] 390.07M 65.4MB/s in 7.8s 2025-07-01 14:29:49 (50.0 MB/s) - ‘part_6_2_ade_relcat_model.zip’ saved [409019548/409019548] Archive: part_6_2_ade_relcat_model.zip creating: /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/medcat-v2-tutorials/notebooks/introductory/relcat/part_6_2/ade_relcat_model inflating: part_6_2/ade_relcat_model/model.dat inflating: part_6_2/ade_relcat_model/config.json inflating: part_6_2/ade_relcat_model/model_config.json creating: /Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/medcat-v2-tutorials/notebooks/introductory/relcat/part_6_2/ade_relcat_model/bert-tokenizer inflating: part_6_2/ade_relcat_model/bert-tokenizer/added_tokens.json inflating: part_6_2/ade_relcat_model/bert-tokenizer/tokenizer_config.json inflating: part_6_2/ade_relcat_model/bert-tokenizer/special_tokens_map.json inflating: part_6_2/ade_relcat_model/bert-tokenizer/tokenizer.json inflating: part_6_2/ade_relcat_model/bert-tokenizer/vocab.txt
In [4]:
Copied!
from medcat.components.addons.relation_extraction.rel_cat import RelCAT
from medcat.components.addons.relation_extraction.rel_cat import RelCAT
/Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
1. Load the model of your choice.
In [10]:
Copied!
import os
from medcat.config import Config
from medcat.cdb import CDB
from medcat.tokenizing.tokenizers import create_tokenizer
from medcat.utils.legacy.convert_rel_cat import get_rel_cat_from_old
try:
rc_path = "./part_6_2/ade_relcat_model"
relCAT = RelCAT.load(rc_path)
except Exception as e:
try:
gen_config = Config()
gen_config.general.nlp.provider = 'spacy'
cdb = CDB(gen_config)
base_tokenizer = create_tokenizer(gen_config.general.nlp.provider, gen_config)
relCAT = get_rel_cat_from_old(cdb, rc_path, base_tokenizer)._rel_cat
except Exception as e2:
raise ValueError(
f"Unable to load RelCAT model from '{rc_path}'. "
f"Exists? {os.path.exists(rc_path)}; isdir? {os.path.isdir(rc_path)} "
f"Stuff in dir: {os.listdir(rc_path) if os.path.isdir(rc_path) else ['NOT A DIR']}")
import os
from medcat.config import Config
from medcat.cdb import CDB
from medcat.tokenizing.tokenizers import create_tokenizer
from medcat.utils.legacy.convert_rel_cat import get_rel_cat_from_old
try:
rc_path = "./part_6_2/ade_relcat_model"
relCAT = RelCAT.load(rc_path)
except Exception as e:
try:
gen_config = Config()
gen_config.general.nlp.provider = 'spacy'
cdb = CDB(gen_config)
base_tokenizer = create_tokenizer(gen_config.general.nlp.provider, gen_config)
relCAT = get_rel_cat_from_old(cdb, rc_path, base_tokenizer)._rel_cat
except Exception as e2:
raise ValueError(
f"Unable to load RelCAT model from '{rc_path}'. "
f"Exists? {os.path.exists(rc_path)}; isdir? {os.path.isdir(rc_path)} "
f"Stuff in dir: {os.listdir(rc_path) if os.path.isdir(rc_path) else ['NOT A DIR']}")
INFO:medcat.components.addons.relation_extraction.rel_cat:The default CDB file name 'cdb.dat' doesn't exist in the specified path, you will need to load & set a CDB manually via rel_cat.cdb = CDB.load('path')
INFO:medcat.components.addons.relation_extraction.base_component:RelExtrBaseComponent initialized
INFO:medcat.components.addons.relation_extraction.base_component:RelExtrBaseComponent initialized
INFO:medcat.components.addons.relation_extraction.base_component:RelExtrBaseComponent initialized
You are using a model of type bert to instantiate a model of type . This is not supported for all configurations of models and can yield errors.
Some weights of BertModel were not initialized from the model checkpoint at bert-base-uncased and are newly initialized because the shapes did not match:
- embeddings.word_embeddings.weight: found shape torch.Size([30522, 768]) in the checkpoint and torch.Size([30526, 768]) in the model instantiated
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
INFO:medcat.components.addons.relation_extraction.base_component:RelExtrBaseComponent initialized
2. Prepare the text for relation extraction. We assume that there are annotations already present.
In [11]:
Copied!
docs_with_anns = {"text": "REASON FOR CONSULTATION: , Left hip fracture.,HISTORY OF PRESENT ILLNESS: , The patient is a pleasant 53-year-old female with a known history of sciatica, apparently presented to the emergency room due to severe pain in the left lower extremity and unable to bear weight. History was obtained from the patient. As per the history, she reported that she has been having back pain with left leg pain since past 4 weeks. She has been using a walker for ambulation due to disabling pain in her left thigh and lower back. She was seen by her primary care physician and was scheduled to go for MRI yesterday. However, she was walking and her right foot got caught on some type of rug leading to place excessive weight on her left lower extremity to prevent her fall. Since then, she was unable to ambulate. The patient called paramedics and was brought to the emergency room. She denied any history of fall. She reported that she stepped the wrong way causing the pain to become worse. She is complaining of severe pain in her lower extremity and back pain. Denies any tingling or numbness. Denies any neurological symptoms. Denies any bowel or bladder incontinence.,X-rays were obtained which were remarkable for left hip fracture. Orthopedic consultation was called for further evaluation and management. On further interview with the patient, it is noted that she has a history of malignant melanoma, which was diagnosed approximately 4 to 5 years ago. She underwent surgery at that time and subsequently, she was noted to have a spread to the lymphatic system and lymph nodes for which she underwent surgery in 3/2008.,PAST MEDICAL HISTORY: , Sciatica and melanoma.,PAST SURGICAL HISTORY: ,As discussed above, surgery for melanoma and hysterectomy.,ALLERGIES: , NONE.,SOCIAL HISTORY: , Denies any tobacco or alcohol use. She is divorced with 2 children. She lives with her son.,PHYSICAL EXAMINATION:,GENERAL: The patient is well developed, well nourished in mild distress secondary to left lower extremity and back pain.,MUSCULOSKELETAL: Examination of the left lower extremity, there is presence of apparent shortening and external rotation deformity. Tenderness to palpation is present. Leg rolling is positive for severe pain in the left proximal hip. Further examination of the spine is incomplete secondary to severe leg pain. She is unable to perform a straight leg raising. EHL/EDL 5/5. 2+ pulses are present distally. Calf is soft and nontender. Homans sign is negative. Sensation to light touch is intact.,IMAGING:, AP view of the hip is reviewed. Only 1 limited view is obtained. This is a poor quality x-ray with a lot of soft tissue shadow. This x-ray is significant for basicervical-type femoral neck fracture. Lesser trochanter is intact. This is a high intertrochanteric fracture/basicervical. There is presence of lytic lesion around the femoral neck, which is not well delineated on this particular x-ray. We need to order repeat x-rays including AP pelvis, femur, and knee.,LABS:, Have been reviewed.,ASSESSMENT: , The patient is a 53-year-old female with probable pathological fracture of the left proximal femur.,DISCUSSION AND PLAN: , Nature and course of the diagnosis has been discussed with the patient. Based on her presentation without any history of obvious fall or trauma and past history of malignant melanoma, this appears to be a pathological fracture of the left proximal hip. At the present time, I would recommend obtaining a bone scan and repeat x-rays, which will include AP pelvis, femur, hip including knee. She denies any pain elsewhere. She does have a past history of back pain and sciatica, but at the present time, this appears to be a metastatic bone lesion with pathological fracture. I have discussed the case with Dr. X and recommended oncology consultation.,With the above fracture and presentation, she needs a left hip hemiarthroplasty versus calcar hemiarthroplasty, cemented type. Indication, risk, and benefits of left hip hemiarthroplasty has been discussed with the patient, which includes, but not limited to bleeding, infection, nerve injury, blood vessel injury, dislocation early and late, persistent pain, leg length discrepancy, myositis ossificans, intraoperative fracture, prosthetic fracture, need for conversion to total hip replacement surgery, revision surgery, DVT, pulmonary embolism, risk of anesthesia, need for blood transfusion, and cardiac arrest. She understands above and is willing to undergo further procedure. The goal and the functional outcome have been explained. Further plan will be discussed with her once we obtain the bone scan and the radiographic studies. We will also await for the oncology feedback and clearance.,Thank you very much for allowing me to participate in the care of this patient. I will continue to follow up.",
"annotations": [{
"id": 1011,
"user": "admin",
"cui": "161432005",
"value": "history of malignant melanoma",
"start": 1382,
"end": 1411,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1012,
"user": "admin",
"cui": "161432005",
"value": "history of malignant melanoma",
"start": 3347,
"end": 3376,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1013,
"user": "admin",
"cui": "52734007",
"value": "total hip replacement surgery",
"start": 4323,
"end": 4352,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1014,
"user": "admin",
"cui": "127287001",
"value": "intertrochanteric fracture",
"start": 2802,
"end": 2828,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1015,
"user": "admin",
"cui": "213270002",
"value": "intraoperative fracture",
"start": 4254,
"end": 4277,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1016,
"user": "admin",
"cui": "446050000",
"value": "primary care physician",
"start": 541,
"end": 563,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1017,
"user": "admin",
"cui": "5913000",
"value": "femoral neck fracture",
"start": 2733,
"end": 2754,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1018,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3120,
"end": 3141,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1019,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3399,
"end": 3420,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1020,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3748,
"end": 3769,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1021,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 224,
"end": 244,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1022,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 724,
"end": 744,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1023,
"user": "admin",
"cui": "165232002",
"value": "bladder incontinence",
"start": 1152,
"end": 1172,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1024,
"user": "admin",
"cui": "5880005",
"value": "PHYSICAL EXAMINATION",
"start": 1895,
"end": 1915,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1025,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 2003,
"end": 2023,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1026,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 2076,
"end": 2096,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1027,
"user": "admin",
"cui": "57662003",
"value": "injury, blood vessel",
"start": 4135,
"end": 4155,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1028,
"user": "admin",
"cui": "44551007",
"value": "myositis ossificans",
"start": 4233,
"end": 4252,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1029,
"user": "admin",
"cui": "59282003",
"value": "pulmonary embolism",
"start": 4377,
"end": 4395,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1030,
"user": "admin",
"cui": "116859006",
"value": "blood transfusion",
"start": 4426,
"end": 4443,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1031,
"user": "admin",
"cui": "224994002",
"value": "excessive weight",
"start": 700,
"end": 716,
"meta_anns": {}
},
{
"id": 1032,
"user": "admin",
"cui": "89890002",
"value": "lymphatic system",
"start": 1557,
"end": 1573,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1033,
"user": "admin",
"cui": "261554009",
"value": "revision surgery",
"start": 4354,
"end": 4370,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1034,
"user": "admin",
"cui": "428942009",
"value": "history of fall",
"start": 893,
"end": 908,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1035,
"user": "admin",
"cui": "61685007",
"value": "lower extremity",
"start": 1031,
"end": 1046,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1036,
"user": "admin",
"cui": "392521001",
"value": "MEDICAL HISTORY",
"start": 1638,
"end": 1653,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1037,
"user": "admin",
"cui": "106028002",
"value": "MUSCULOSKELETAL",
"start": 2039,
"end": 2054,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1038,
"user": "admin",
"cui": "417662000",
"value": "past history of",
"start": 3634,
"end": 3649,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1039,
"user": "admin",
"cui": "225728007",
"value": "emergency room",
"start": 183,
"end": 197,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1040,
"user": "admin",
"cui": "225728007",
"value": "emergency room",
"start": 861,
"end": 875,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1041,
"user": "admin",
"cui": "160476009",
"value": "SOCIAL HISTORY",
"start": 1783,
"end": 1797,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1042,
"user": "admin",
"cui": "248324001",
"value": "well nourished",
"start": 1958,
"end": 1972,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1043,
"user": "admin",
"cui": "244696009",
"value": "proximal femur",
"start": 3154,
"end": 3168,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1044,
"user": "admin",
"cui": "410429000",
"value": "cardiac arrest",
"start": 4449,
"end": 4463,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1045,
"user": "admin",
"cui": "287047008",
"value": "left leg pain",
"start": 386,
"end": 399,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1046,
"user": "admin",
"cui": "161891005",
"value": "and back pain",
"start": 1047,
"end": 1060,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1047,
"user": "admin",
"cui": "26175008",
"value": "approximately",
"start": 1433,
"end": 1446,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1048,
"user": "admin",
"cui": "161891005",
"value": "and back pain",
"start": 2024,
"end": 2037,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1049,
"user": "admin",
"cui": "1199008",
"value": "neurological",
"start": 1108,
"end": 1120
}
]}
docs_with_anns = {"text": "REASON FOR CONSULTATION: , Left hip fracture.,HISTORY OF PRESENT ILLNESS: , The patient is a pleasant 53-year-old female with a known history of sciatica, apparently presented to the emergency room due to severe pain in the left lower extremity and unable to bear weight. History was obtained from the patient. As per the history, she reported that she has been having back pain with left leg pain since past 4 weeks. She has been using a walker for ambulation due to disabling pain in her left thigh and lower back. She was seen by her primary care physician and was scheduled to go for MRI yesterday. However, she was walking and her right foot got caught on some type of rug leading to place excessive weight on her left lower extremity to prevent her fall. Since then, she was unable to ambulate. The patient called paramedics and was brought to the emergency room. She denied any history of fall. She reported that she stepped the wrong way causing the pain to become worse. She is complaining of severe pain in her lower extremity and back pain. Denies any tingling or numbness. Denies any neurological symptoms. Denies any bowel or bladder incontinence.,X-rays were obtained which were remarkable for left hip fracture. Orthopedic consultation was called for further evaluation and management. On further interview with the patient, it is noted that she has a history of malignant melanoma, which was diagnosed approximately 4 to 5 years ago. She underwent surgery at that time and subsequently, she was noted to have a spread to the lymphatic system and lymph nodes for which she underwent surgery in 3/2008.,PAST MEDICAL HISTORY: , Sciatica and melanoma.,PAST SURGICAL HISTORY: ,As discussed above, surgery for melanoma and hysterectomy.,ALLERGIES: , NONE.,SOCIAL HISTORY: , Denies any tobacco or alcohol use. She is divorced with 2 children. She lives with her son.,PHYSICAL EXAMINATION:,GENERAL: The patient is well developed, well nourished in mild distress secondary to left lower extremity and back pain.,MUSCULOSKELETAL: Examination of the left lower extremity, there is presence of apparent shortening and external rotation deformity. Tenderness to palpation is present. Leg rolling is positive for severe pain in the left proximal hip. Further examination of the spine is incomplete secondary to severe leg pain. She is unable to perform a straight leg raising. EHL/EDL 5/5. 2+ pulses are present distally. Calf is soft and nontender. Homans sign is negative. Sensation to light touch is intact.,IMAGING:, AP view of the hip is reviewed. Only 1 limited view is obtained. This is a poor quality x-ray with a lot of soft tissue shadow. This x-ray is significant for basicervical-type femoral neck fracture. Lesser trochanter is intact. This is a high intertrochanteric fracture/basicervical. There is presence of lytic lesion around the femoral neck, which is not well delineated on this particular x-ray. We need to order repeat x-rays including AP pelvis, femur, and knee.,LABS:, Have been reviewed.,ASSESSMENT: , The patient is a 53-year-old female with probable pathological fracture of the left proximal femur.,DISCUSSION AND PLAN: , Nature and course of the diagnosis has been discussed with the patient. Based on her presentation without any history of obvious fall or trauma and past history of malignant melanoma, this appears to be a pathological fracture of the left proximal hip. At the present time, I would recommend obtaining a bone scan and repeat x-rays, which will include AP pelvis, femur, hip including knee. She denies any pain elsewhere. She does have a past history of back pain and sciatica, but at the present time, this appears to be a metastatic bone lesion with pathological fracture. I have discussed the case with Dr. X and recommended oncology consultation.,With the above fracture and presentation, she needs a left hip hemiarthroplasty versus calcar hemiarthroplasty, cemented type. Indication, risk, and benefits of left hip hemiarthroplasty has been discussed with the patient, which includes, but not limited to bleeding, infection, nerve injury, blood vessel injury, dislocation early and late, persistent pain, leg length discrepancy, myositis ossificans, intraoperative fracture, prosthetic fracture, need for conversion to total hip replacement surgery, revision surgery, DVT, pulmonary embolism, risk of anesthesia, need for blood transfusion, and cardiac arrest. She understands above and is willing to undergo further procedure. The goal and the functional outcome have been explained. Further plan will be discussed with her once we obtain the bone scan and the radiographic studies. We will also await for the oncology feedback and clearance.,Thank you very much for allowing me to participate in the care of this patient. I will continue to follow up.",
"annotations": [{
"id": 1011,
"user": "admin",
"cui": "161432005",
"value": "history of malignant melanoma",
"start": 1382,
"end": 1411,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1012,
"user": "admin",
"cui": "161432005",
"value": "history of malignant melanoma",
"start": 3347,
"end": 3376,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1013,
"user": "admin",
"cui": "52734007",
"value": "total hip replacement surgery",
"start": 4323,
"end": 4352,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1014,
"user": "admin",
"cui": "127287001",
"value": "intertrochanteric fracture",
"start": 2802,
"end": 2828,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1015,
"user": "admin",
"cui": "213270002",
"value": "intraoperative fracture",
"start": 4254,
"end": 4277,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1016,
"user": "admin",
"cui": "446050000",
"value": "primary care physician",
"start": 541,
"end": 563,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1017,
"user": "admin",
"cui": "5913000",
"value": "femoral neck fracture",
"start": 2733,
"end": 2754,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1018,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3120,
"end": 3141,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1019,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3399,
"end": 3420,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1020,
"user": "admin",
"cui": "268029009",
"value": "pathological fracture",
"start": 3748,
"end": 3769,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1021,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 224,
"end": 244,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1022,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 724,
"end": 744,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1023,
"user": "admin",
"cui": "165232002",
"value": "bladder incontinence",
"start": 1152,
"end": 1172,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1024,
"user": "admin",
"cui": "5880005",
"value": "PHYSICAL EXAMINATION",
"start": 1895,
"end": 1915,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1025,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 2003,
"end": 2023,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1026,
"user": "admin",
"cui": "32153003",
"value": "left lower extremity",
"start": 2076,
"end": 2096,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1027,
"user": "admin",
"cui": "57662003",
"value": "injury, blood vessel",
"start": 4135,
"end": 4155,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1028,
"user": "admin",
"cui": "44551007",
"value": "myositis ossificans",
"start": 4233,
"end": 4252,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1029,
"user": "admin",
"cui": "59282003",
"value": "pulmonary embolism",
"start": 4377,
"end": 4395,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1030,
"user": "admin",
"cui": "116859006",
"value": "blood transfusion",
"start": 4426,
"end": 4443,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1031,
"user": "admin",
"cui": "224994002",
"value": "excessive weight",
"start": 700,
"end": 716,
"meta_anns": {}
},
{
"id": 1032,
"user": "admin",
"cui": "89890002",
"value": "lymphatic system",
"start": 1557,
"end": 1573,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1033,
"user": "admin",
"cui": "261554009",
"value": "revision surgery",
"start": 4354,
"end": 4370,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1034,
"user": "admin",
"cui": "428942009",
"value": "history of fall",
"start": 893,
"end": 908,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1035,
"user": "admin",
"cui": "61685007",
"value": "lower extremity",
"start": 1031,
"end": 1046,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1036,
"user": "admin",
"cui": "392521001",
"value": "MEDICAL HISTORY",
"start": 1638,
"end": 1653,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1037,
"user": "admin",
"cui": "106028002",
"value": "MUSCULOSKELETAL",
"start": 2039,
"end": 2054,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1038,
"user": "admin",
"cui": "417662000",
"value": "past history of",
"start": 3634,
"end": 3649,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1039,
"user": "admin",
"cui": "225728007",
"value": "emergency room",
"start": 183,
"end": 197,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1040,
"user": "admin",
"cui": "225728007",
"value": "emergency room",
"start": 861,
"end": 875,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1041,
"user": "admin",
"cui": "160476009",
"value": "SOCIAL HISTORY",
"start": 1783,
"end": 1797,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1042,
"user": "admin",
"cui": "248324001",
"value": "well nourished",
"start": 1958,
"end": 1972,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1043,
"user": "admin",
"cui": "244696009",
"value": "proximal femur",
"start": 3154,
"end": 3168,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1044,
"user": "admin",
"cui": "410429000",
"value": "cardiac arrest",
"start": 4449,
"end": 4463,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1045,
"user": "admin",
"cui": "287047008",
"value": "left leg pain",
"start": 386,
"end": 399,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1046,
"user": "admin",
"cui": "161891005",
"value": "and back pain",
"start": 1047,
"end": 1060,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1047,
"user": "admin",
"cui": "26175008",
"value": "approximately",
"start": 1433,
"end": 1446,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1048,
"user": "admin",
"cui": "161891005",
"value": "and back pain",
"start": 2024,
"end": 2037,
"acc": 1.0,
"meta_anns": {}
},
{
"id": 1049,
"user": "admin",
"cui": "1199008",
"value": "neurological",
"start": 1108,
"end": 1120
}
]}
3. Predict relations
In [12]:
Copied!
output_doc_with_relations = relCAT.predict_text_with_anns(text=docs_with_anns["text"], annotations=docs_with_anns["annotations"])
output_doc_with_relations = relCAT.predict_text_with_anns(text=docs_with_anns["text"], annotations=docs_with_anns["annotations"])
Token indices sequence length is longer than the specified maximum sequence length for this model (1086 > 512). Running this sequence through the model will result in indexing errors INFO:medcat.components.addons.relation_extraction.rel_cat:total relations for doc: 68 INFO:medcat.components.addons.relation_extraction.rel_cat:processing... 0%| | 0/68 [00:00<?, ?it/s]/Users/martratas/Documents/CogStack/.MedCAT.nosync/monorepo-nlp/.venv_v2_tut/lib/python3.11/site-packages/torch/utils/data/dataloader.py:683: UserWarning: 'pin_memory' argument is set as true but not supported on MPS now, then device pinned memory won't be used. warnings.warn(warn_msg) 100%|██████████| 68/68 [00:02<00:00, 23.21it/s]
4. Examine relations
In [14]:
Copied!
output_doc_with_relations.get_addon_data('relations')
output_doc_with_relations.get_addon_data('relations')
Out[14]:
[{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'bladder incontinence',
'ent2_text': 'history of malignant melanoma',
'confidence': 0.548,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'history of malignant melanoma',
'ent2_text': 'lymphatic system',
'confidence': 0.525,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'history of malignant melanoma',
'ent2_text': 'MEDICAL HISTORY',
'confidence': 0.53,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'history of malignant melanoma',
'ent2_text': 'approximately',
'confidence': 0.525,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'pathological fracture',
'ent2_text': 'history of malignant melanoma',
'confidence': 0.51,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'history of malignant melanoma',
'ent2_text': 'pathological fracture',
'confidence': 0.537,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'history of malignant melanoma',
'ent2_text': 'past history of',
'confidence': 0.598,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'proximal femur',
'ent2_text': 'history of malignant melanoma',
'confidence': 0.51,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'intraoperative fracture',
'ent2_text': 'total hip replacement surgery',
'confidence': 0.548,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'total hip replacement surgery',
'confidence': 0.572,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'myositis ossificans',
'ent2_text': 'total hip replacement surgery',
'confidence': 0.507,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'total hip replacement surgery',
'ent2_text': 'pulmonary embolism',
'confidence': 0.505,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'total hip replacement surgery',
'ent2_text': 'blood transfusion',
'confidence': 0.551,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'total hip replacement surgery',
'ent2_text': 'revision surgery',
'confidence': 0.517,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'total hip replacement surgery',
'ent2_text': 'cardiac arrest',
'confidence': 0.564,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'femoral neck fracture',
'ent2_text': 'intertrochanteric fracture',
'confidence': 0.577,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'intraoperative fracture',
'confidence': 0.535,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'myositis ossificans',
'ent2_text': 'intraoperative fracture',
'confidence': 0.556,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'intraoperative fracture',
'ent2_text': 'pulmonary embolism',
'confidence': 0.557,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'intraoperative fracture',
'ent2_text': 'blood transfusion',
'confidence': 0.569,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'intraoperative fracture',
'ent2_text': 'revision surgery',
'confidence': 0.525,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'intraoperative fracture',
'ent2_text': 'cardiac arrest',
'confidence': 0.509,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'primary care physician',
'ent2_text': 'left lower extremity',
'confidence': 0.635,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'primary care physician',
'ent2_text': 'excessive weight',
'confidence': 0.585,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'left leg pain',
'ent2_text': 'primary care physician',
'confidence': 0.591,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'pathological fracture',
'ent2_text': 'proximal femur',
'confidence': 0.548,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'pathological fracture',
'ent2_text': 'past history of',
'confidence': 0.601,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'proximal femur',
'ent2_text': 'pathological fracture',
'confidence': 0.51,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'past history of',
'ent2_text': 'pathological fracture',
'confidence': 0.57,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'left lower extremity',
'ent2_text': 'left leg pain',
'confidence': 0.505,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'excessive weight',
'ent2_text': 'left lower extremity',
'confidence': 0.508,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'left lower extremity',
'ent2_text': 'history of fall',
'confidence': 0.597,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'left lower extremity',
'ent2_text': 'emergency room',
'confidence': 0.531,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'lower extremity',
'ent2_text': 'bladder incontinence',
'confidence': 0.538,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'and back pain',
'ent2_text': 'bladder incontinence',
'confidence': 0.564,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'PHYSICAL EXAMINATION',
'ent2_text': 'left lower extremity',
'confidence': 0.506,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'PHYSICAL EXAMINATION',
'ent2_text': 'left lower extremity',
'confidence': 0.528,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'MEDICAL HISTORY',
'ent2_text': 'PHYSICAL EXAMINATION',
'confidence': 0.56,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'PHYSICAL EXAMINATION',
'ent2_text': 'MUSCULOSKELETAL',
'confidence': 0.533,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'SOCIAL HISTORY',
'ent2_text': 'PHYSICAL EXAMINATION',
'confidence': 0.521,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'PHYSICAL EXAMINATION',
'ent2_text': 'well nourished',
'confidence': 0.544,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'PHYSICAL EXAMINATION',
'ent2_text': 'and back pain',
'confidence': 0.51,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'left lower extremity',
'ent2_text': 'MUSCULOSKELETAL',
'confidence': 0.563,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'SOCIAL HISTORY',
'ent2_text': 'left lower extremity',
'confidence': 0.568,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'well nourished',
'ent2_text': 'left lower extremity',
'confidence': 0.527,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'left lower extremity',
'ent2_text': 'and back pain',
'confidence': 0.514,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'MUSCULOSKELETAL',
'ent2_text': 'left lower extremity',
'confidence': 0.508,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'SOCIAL HISTORY',
'ent2_text': 'left lower extremity',
'confidence': 0.562,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'and back pain',
'ent2_text': 'left lower extremity',
'confidence': 0.56,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'myositis ossificans',
'confidence': 0.505,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'pulmonary embolism',
'confidence': 0.529,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'blood transfusion',
'confidence': 0.508,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'injury, blood vessel',
'ent2_text': 'revision surgery',
'confidence': 0.545,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'myositis ossificans',
'ent2_text': 'pulmonary embolism',
'confidence': 0.59,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'myositis ossificans',
'ent2_text': 'revision surgery',
'confidence': 0.574,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'myositis ossificans',
'ent2_text': 'cardiac arrest',
'confidence': 0.569,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'pulmonary embolism',
'ent2_text': 'blood transfusion',
'confidence': 0.513,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'revision surgery',
'ent2_text': 'pulmonary embolism',
'confidence': 0.544,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'blood transfusion',
'ent2_text': 'cardiac arrest',
'confidence': 0.62,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'excessive weight',
'ent2_text': 'history of fall',
'confidence': 0.57,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'lymphatic system',
'ent2_text': 'SOCIAL HISTORY',
'confidence': 0.598,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'approximately',
'ent2_text': 'lymphatic system',
'confidence': 0.506,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'emergency room',
'ent2_text': 'history of fall',
'confidence': 0.509,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'history of fall',
'ent2_text': 'and back pain',
'confidence': 0.508,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-AE',
'label_id': 1,
'ent1_text': 'approximately',
'ent2_text': 'MEDICAL HISTORY',
'confidence': 0.504,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'SOCIAL HISTORY',
'ent2_text': 'MUSCULOSKELETAL',
'confidence': 0.525,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'well nourished',
'ent2_text': 'MUSCULOSKELETAL',
'confidence': 0.507,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None},
{'relation': 'DRUG-DOSE',
'label_id': 0,
'ent1_text': 'emergency room',
'ent2_text': 'and back pain',
'confidence': 0.508,
'start_ent_pos': '',
'end_ent_pos': '',
'start_entity_id': None,
'end_entity_id': None}]
Most relations in our case make no sense as we only have two classes that relate to drug and adverse effects and drug-dosage. It is recommended that you apply a TUI/CUI filter to the NER config step first to only focus on relevant concepts.
In [ ]:
Copied!