Skip to content

Commit

Permalink
NER and trial task
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Jul 13, 2023
1 parent d1f1376 commit 5db2416
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tutorials/llm_clinical_trials/configs/ner_openai.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[nlp]
lang = "en"
pipeline = ["llm"]
batch_size = 128

[components]

[components.llm]
factory = "llm"

[components.llm.model]
@llm_models = "spacy.GPT-3-5.v1"
name = "gpt-3.5-turbo"

[components.llm.task]
@llm_tasks = "spacy.NER.v2"
labels = "Drug,Dose"
15 changes: 12 additions & 3 deletions tutorials/llm_clinical_trials/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ title: 'Clinical trial results extraction with LLMs'
description: "Using an LLM in a spaCy pipeline to extract patient groups, treatments and outcomes in clinical trials."

vars:
config: "config_openai.cfg"
ner_config: "ner_openai.cfg"
trial_config: "trial_openai.cfg"
pmid: 27144689

# These are the directories that the project needs.
Expand All @@ -16,10 +17,18 @@ assets:

# Project commands
commands:
- name: zero_shot_ner
help: "Run an LLM pipeline with zero-shot NER"
script:
- "python ./scripts/visualise_entities.py ${vars.pmid} ./configs/${vars.ner_config}"
deps:
- "assets/${vars.pmid}.txt"
- "configs/${vars.ner_config}"

- name: summarize
help: "Run the LLM-powered spaCy pipeline"
script:
- "python ./scripts/run_pipeline.py ${vars.pmid} ./configs/${vars.config}"
- "python ./scripts/extract_results.py ${vars.pmid} ./configs/${vars.trial_config}"
deps:
- "assets/${vars.pmid}.txt"
- "configs/${vars.config}"
- "configs/${vars.trial_config}"
21 changes: 21 additions & 0 deletions tutorials/llm_clinical_trials/scripts/visualise_entities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path

import typer
from input_reader import read_trial
from spacy import displacy
from spacy_llm.util import assemble
from wasabi import msg


def visualise_entities(pmid: int, config_path: Path, verbose: bool = False):
msg.text(f"Processing PMID {pmid}", show=verbose)
msg.text(f"Loading config from {config_path}", show=verbose)
text = read_trial(pmid, verbose=verbose)
nlp = assemble(config_path)
doc = nlp(text)
options = {"ents": ["Drug", "Dose"], "colors": {"Drug": "pink", "Dose": "orange"}}
displacy.serve(doc, style="ent", options=options)


if __name__ == "__main__":
typer.run(visualise_entities)

0 comments on commit 5db2416

Please sign in to comment.