UBC · 临床文档的提取与分析 · 模块一第二课 / NLP010

NLP 在 BC 癌症登记处:从病理报告流水线到隐私保护

不列颠哥伦比亚省癌症登记处(BC Cancer Registry,简称 BCCR)每年要收到 100 多万份病理报告。靠人工读完不可能,原来依赖的规则软件又错得太多。在 UBC 课程“临床文档的提取与分析”的这一课里,BCCR 的研究科学家 Lovedeep Gondara 讲了登记处怎样搭起一条 NLP 流水线来读这些报告,以及为什么在用它们训练任何模型之前,必须先把病人的身份信息拿掉。这篇笔记是我对这个案例的整理。

NLP at the BC Cancer Registry: From Pathology Reports to Privacy

Every year more than a million pathology reports reach the British Columbia Cancer Registry (BCCR). Reading them by hand is impossible, and the rule-based software it relied on made too many mistakes. In this lesson of UBC's Extraction and Analysis of Clinical Documents, Lovedeep Gondara, a research scientist at the BCCR, shows how the registry built a chain of NLP pipelines to read those reports, and why, before any model is trained on them, the patients' identities have to come out. This note is my summary of that case.

  • 章节 / section
  • 关键概念 / key term
  • 阅读提示 / reading note
ELLE · 阅读向导 / READING COMPANION

把概念连起来,再往下读 / Take a moment to connect the ideas

和 Elle 一起理清基础概念 / A few foundations, with Elle

点开概念理清区别,再试三道小题;选错后可以重新选择。 / Tap a concept to explore it, then try three short questions. You can change any answer.

可报告肿瘤 / Reportable tumor

国家和国际登记规则要求登记处收集的肿瘤,比如乳腺癌、肺癌、结直肠癌。有些癌症不需要报告,比如长在小腿上的基底细胞癌。 / A tumor that national and international registry rules say the registry must collect, such as breast, lung or colorectal cancer. Some cancers are not reportable, for example a basal cell carcinoma on the shin.

集成模型与 LLM 裁决 / Ensemble with an LLM tie-breaker

几个小模型各读报告的一部分并投票。足够多的模型意见一致就采用;意见不一时,由大语言模型读完整份报告和各模型的判断,做最终决定。 / Several small models each read part of a report and vote. When enough agree, their answer stands; when they disagree, a large language model reads the whole report and the votes and decides.

差分隐私 / Differential privacy

训练时加入可控噪声,让数据里有没有某一个人,输出几乎没有差别。它有理论上的保证,代价是准确率会下降一些。 / Training with controlled noise so the output barely changes whether or not any one person is in the data. It gives a theoretical guarantee, at the cost of some accuracy.

数据匿名化 / Anonymization

训练前把身份信息(姓名、健康号、出生日期、电话等)从文本里去掉,模型就没有个人信息可记、可泄露。 / Removing identifiers (names, health numbers, dates of birth, phone numbers) from the text before training, so there is nothing personal left for a model to memorize or leak.

1 / 3 · 一份报告写着“未见癌症证据”。关键词表在里面找到了“cancer”。这份报告应该判为癌症吗? / A report says "There is no evidence of cancer." A keyword table finds the word "cancer". Should the report be flagged as cancer?

2 / 3 · 登记处已经有了大语言模型。是否应该每一步都用它,包括找电话号码和邮编? / The registry already has a large language model. Should it use the LLM for every step, including finding phone numbers and postal codes?

3 / 3 · 用原始病理报告训练了一个模型,只分享模型、不分享报告。它还可能泄露病人的名字吗? / A model is trained on raw pathology reports, and only the model, not the reports, is shared. Can it still leak patient names?

全景图:癌症登记处的 NLP 与隐私规则

从左上角开始:病理报告是登记处的主要来源,下面是 NLP 适合做的任务。绿色大括号说明旧的规则系统为什么出错,橙色大括号和小灯泡列出三条新流水线。左下角的紫色一行是我得到的实用思路:简单的方法先上。右半边讲隐私:大模型会记住并泄露训练数据,所以有两道防线,差分隐私和数据匿名化,蓝色的三层就是登记处给报告做匿名化的办法。右下角是我的思考。

手写风格的 BC 癌症登记处 NLP 全景图。左边:病理报告是主要来源;NLP 适合做的任务(分类、问答、对话、合成数据生成);旧系统 eMaRC 把“No evidence of cancer”误判为癌症;可报告性、肿瘤分组和自动编码三条新流水线;实用思路是简单的方法先上,从正则表达式到 BERT 类小模型再到 LLM。右边:隐私保护 NLP;大模型会记住并可能泄露数据;差分隐私;三层数据匿名化,去掉固定格式、人名和漏掉的名字,同时保留病名

根据我的手写笔记整理,修正了几处术语,并补充了简短的例子。

The big picture: a cancer registry's NLP, and its privacy rules

Start at the top left: pathology reports are the registry's main source, and below them are the tasks NLP suits. The green brace shows why the old rule-based system failed, and the orange brace with the lightbulb lists the three new pipelines. The purple line at the bottom left is the practical idea I took away: simple methods go first. The right half is privacy: large models can memorize and leak their training data, so there are two defences, differential privacy and anonymization, and the blue tiers are how the registry anonymizes its reports. My takeaway is in the bottom-right corner.

Handwritten-style overview of NLP at the BC Cancer Registry. Left: pathology reports as the main source; tasks NLP suits (classification, question answering, chat, synthetic data generation); the old rule-based system eMaRC misreading 'no evidence of cancer'; three new pipelines for reportability, tumor group and auto-coding; the practical idea that simple methods go first, from regular expressions to BERT-type models to LLMs. Right: privacy-preserving NLP; large models memorize and can leak data; differential privacy; anonymization in three tiers that remove numbers, names and missed names while keeping disease names

Tidied up from my handwritten page, with a few terms corrected and short examples added.

看视频这一段 / Watch this part

登记处和它的病理报告

BCCR 是一个覆盖全省人口的集中式登记处:它的职责是收集 BC 省居民所有“可报告”肿瘤的数据,每年约 3 万个肿瘤,并随人口增长而增加。和世界上大多数癌症登记处一样,它确认病例的主要来源是病理报告:描述组织样本或体液特征的医疗文件,可能给出诊断,也可能不给。

一份病理报告有三种用途:

用途 谁来读 用来做什么
临床 开检查或做操作的医生 诊断和制定治疗方案
运营 登记处 收集数据,支持决策、规划未来需求
研究 研究人员 圈定研究人群,比如按雌激素受体(ER)、孕激素受体(PR)和 HER2 状态筛选乳腺癌患者

报告里还有大量个人信息:病人的姓名、个人健康号(PHN)、地址和电话,医生的姓名、注册号和联系方式。这一点和笔记的后半部分有关。

Gondara 把 NLP 定位为机器学习的一个分支,而机器学习又是 AI 的一部分。NLP 近几年的大进步主要来自预训练模型:先在海量通用文本上训练(想象一下整个维基百科加 PubMed),再用一小份领域数据为某个任务做微调,比如根据病理报告预测诊断。这种做法提升了很多任务:分类(这份报告有没有癌症信息?)、基于给定上下文的问答、对话,以及数据生成,比如为某种疾病特征生成合成的病理报告。

The registry and its pathology reports

The BCCR is a population-level, centralized registry: its mandate is to collect data on every reportable tumor among British Columbia residents, around 30,000 tumors a year, a number that grows with the population. Its main source of confirmation, as in most cancer registries, is the pathology report: a medical document describing a tissue sample or body fluid, which may or may not give a diagnosis.

A pathology report serves three uses:

Use Who reads it What for
Clinical The doctor who ordered the test or did the procedure Diagnosis and a treatment plan
Operational The registry Data that informs decisions and plans for future needs
Research Researchers Finding a cohort, such as breast cancer patients by estrogen receptor (ER), progesterone receptor (PR) and HER2 status

The report also carries a lot of personal information: the patient's name, personal health number (PHN), address and phone number, and the physician's name, registration number and contact details. That matters for the second half of this note.

Gondara places NLP as a subfield of machine learning, which is itself a subset of AI. Most of its recent progress comes from pre-trained models: models first trained on huge amounts of general text (think of all of Wikipedia and PubMed), then fine-tuned on a small domain-specific dataset for one task, such as predicting a diagnosis from pathology reports. The tasks this approach improved include classification (does this report contain cancer information?), question answering over a given context, chat, and data generation, for example generating synthetic pathology reports for a given disease.

看视频这一段 / Watch this part

为什么规则不够用

登记处接收全省的病理报告数据流:每年 100 多万份,癌症和非癌症的都有。从 2020 年起,它使用美国疾病控制与预防中心(CDC)的免费软件 eMaRC Plus。eMaRC 是基于规则的:它维护一张张术语表(腺癌、癌等),报告里出现表中的词,就判为癌症。

在癌症报告里,登记处还要分出可报告肿瘤,也就是国家和国际登记规则要求收集的肿瘤(乳腺癌、肺癌、结直肠癌等大多数主要肿瘤),和不可报告的肿瘤,比如长在小腿上的基底细胞癌。

规则读不懂上下文。病理医生可能写:“我复核了这份样本,未见癌症证据(no evidence of cancer)。”eMaRC 看到“cancer”就判为阳性,它没法把“no evidence”和后面的词连起来理解。后果一环扣一环:

  1. 复杂文本上错误率很高。
  2. 每个分类结果都要人工复核,登记处本就不多的专业人员压力很大。
  3. 数据出得晚:平均延迟 18 个月,2023 年的数据要到 2025 年中后期才能用,对研究来说太慢。

深度学习模型不依赖人工设计的规则,还能利用长得多的上下文。它们能做得更好吗?Gondara 的回答是:能。

Why rules were not enough

The registry receives the provincial feed of pathology reports: upwards of a million a year, both cancer and non-cancer. Since 2020 it has used eMaRC Plus, free software from the US Centers for Disease Control and Prevention (CDC). eMaRC is rule-based: it keeps tables of terms (adenocarcinoma, carcinoma and so on) and flags a report as cancer when one of those terms appears.

Among the cancer reports, the registry must then separate reportable tumors, the ones national and international registry rules say it collects (breast, lung, colorectal cancer and most major tumors), from non-reportable ones, such as a basal cell carcinoma on a person's shin.

Rules cannot read context. A pathologist may write "I have reviewed this sample and there is no evidence of cancer." eMaRC sees "cancer" and flags the report as positive; it cannot combine "no evidence" with the word after it. The consequences pile up:

  1. A high error rate on complex text.
  2. Every classification has to be checked by hand, straining the registry's few subject matter experts.
  3. Data arrive late: on average 18 months, so 2023 data become available in mid to late 2025, which is too slow for research.

Deep learning models do not rely on handcrafted rules, and they can use a much longer context. Could they do better? Gondara's answer: yes.

看视频这一段 / Watch this part

一份报告走过的流水线

BCCR 已经开发并部署了多条 NLP 流水线。一份报告依次经过:

  1. 第一道筛选,eMaRC:判断报告里有没有癌症信息。它在这一步表现还不错,因为它“宁可多报”:假阳性很多,以尽量少漏掉癌症。
  2. 预处理:去掉报告的页眉,那里主要是病人和医生的身份信息;根据项目需要,只保留有用的段落,比如诊断部分和标本部分。
  3. 匿名化:用语言模型和正则表达式去掉剩下的身份信息(见本文后半部分)。
  4. 可报告性判断:把 eMaRC 放过来的不可报告肿瘤和非癌症报告剔除。
  5. 肿瘤分组:给每份报告分配一个大致的肿瘤类别(肺、乳腺、前列腺、结直肠、黑色素瘤、神经内分泌肿瘤等),这样工作才能分给专攻该类肿瘤的登记编码员。
  6. 自动编码:从每份报告里抽取监测数据字段。
  7. 合并:一个人可能有多份报告指向同一个肿瘤,比如几个月内的多次活检和检查。上面每条流水线都是按报告做判断,但登记处收集的是肿瘤级数据,所以要把这些报告合并成一条肿瘤记录。
  8. 人工复核:模型可能做得不好的病例交给人来看,这是“人在回路”(human-in-the-loop)的设计,之后数据才进入登记库。
信息图:AI 赋能癌症监测,BC 癌症登记处的 NLP 智能流水线。左边是传统处理模式的瓶颈:每年超 100 万份病理报告、平均 18 个月的滞后、极度依赖人工核查、规则系统 eMaRC 误报率高。右边是多阶段流水线:预处理与去隐私化,双模型集成过滤与 19 类肿瘤分组(6 个小模型加大模型仲裁),结合正则与问答模型抽取监测指标并整合成单一肿瘤记录
信息图信息图:AI 赋能癌症监测,BC 癌症登记处的 NLP 智能流水线。左边是传统处理模式的瓶颈:每年超 100 万份病理报告、平均 18 个月的滞后、极度依赖人工核查、规则系统 eMaRC 误报率高。右边是多阶段流水线:预处理与去隐私化,双模型集成过滤与 19 类肿瘤分组(6 个小模型加大模型仲裁),结合正则与问答模型抽取监测指标并整合成单一肿瘤记录点击查看大图

读图提示:左下角对话框下面那句话和右下角几个肿瘤文件夹的名称出现了乱码,可以忽略;“可报告分类准确率达 97%–99%”指的是可报告肿瘤,不可报告肿瘤的准确率在 90% 以上。

One report's path through the pipeline

The BCCR has now built and deployed several NLP pipelines. A report travels through them in this order:

  1. Stage one, eMaRC: decides whether the report contains any cancer information. It does a decent job here because it over-calls cancer: many false positives, so that few cancers are missed.
  2. Pre-processing: removes the report header, which mostly holds patient and physician identifiers, and, depending on the project, keeps only useful segments such as the diagnosis and specimen sections.
  3. Anonymization: language models and regular expressions remove the remaining identifiers (the last sections of this note).
  4. Reportability: weeds out the non-reportable tumors and non-cancers that eMaRC let through.
  5. Tumor group: assigns each report a broad tumor group (lung, breast, prostate, colorectal, melanoma, neuroendocrine and so on), so the work can go to the tumor registrars who specialize in that group.
  6. Auto-coding: extracts the surveillance data fields from each report.
  7. Consolidation: one person may have several reports about one tumor, such as biopsies and tests over a few months. Every pipeline above decides per report, but the registry collects data per tumor, so the reports are combined into a single tumor record.
  8. Manual review: cases where the models may not have done well go to people, a human-in-the-loop design, before the data enter the registry.
Infographic: modernizing cancer registries from legacy rules to applied NLP. Left: the bottleneck of legacy rule-based systems, with over a million reports a year, an 18-month data lag, manual reviews, and 'no evidence of cancer' flagged positive. Right: the multi-stage NLP solution, with ensemble language models sorting reports into 19 tumor groups, auto-coding with regular expressions, question answering and classifiers, and consolidation into tumor records
InfographicInfographic: modernizing cancer registries from legacy rules to applied NLP. Left: the bottleneck of legacy rule-based systems, with over a million reports a year, an 18-month data lag, manual reviews, and 'no evidence of cancer' flagged positive. Right: the multi-stage NLP solution, with ensemble language models sorting reports into 19 tumor groups, auto-coding with regular expressions, question answering and classifiers, and consolidation into tumor recordsClick to open full size

A reading note: in this picture "97–99% accuracy" sits next to "LLMs as final decision-makers", but they belong to two different pipelines. 97–99% is the reportability pipeline's accuracy on reportable tumors (a two-model ensemble, above 90% for non-reportable ones); the LLM is the tie-breaker in the tumor group pipeline. Rule-based keyword matching did not simply "fail" either: eMaRC is still the first filter.

看视频这一段 / Watch this part

每一步选对工具

这一课最打动我的,是每条流水线怎样挑工具。Gondara 用了一句俗语:手里只有锤子,看什么都像钉子。登记处可以用 LLM,但不想在不需要的地方滥用它。

流水线 任务 怎么做
可报告性 可报告还是不可报告(二分类) 两个微调过的语言模型,各读报告的不同部分。只要有一个判为可报告,就算可报告,确保不漏掉可报告肿瘤。准确率:可报告肿瘤约 97%–99%,不可报告肿瘤 90% 以上
肿瘤分组 19 个肿瘤类别之一 6 个 BERT 类小模型(每个只能读约 512 个 token):3 个读报告开头,3 个读结尾。它们投票,足够多的模型同意就采用这个类别;不然就请大语言模型读完整份报告和 6 个模型的判断,做最终决定
自动编码 肿瘤行为(良性、原位、浸润)、侧别、部位、组织学等;是否提到新辅助治疗;是否有补充报告(addendum) 一套组合:简单的模式用正则表达式(“right breast”“left lung”),报告提到了什么用问答模型(报告里有没有写 ER 状态?),更难的标签用语言模型分类器
合并 从报告级数据到肿瘤级数据 不用 NLP:用普通代码写的业务逻辑,比如两份报告落在某个时间窗内时,哪一项优先

肿瘤分组最能说明为什么要分层设计。报告在哪里写明肿瘤类别并不固定:开头、结尾、中间,或者写得很含糊。标本可能取自乳腺,检查的却是鳞状细胞癌或黑色素瘤,和乳腺癌毫无关系。上下文窗口短的小模型只能看到报告的一部分,所以能读完整份报告的大模型留给它们意见不一的情况。在发表的版本里,6 个模型中不到 5 个意见一致时,大模型才出场。

我从这里得到的实用思路:简单的方法先上。模式能解决的用正则表达式,然后是 BERT 类分类器,LLM 留到最后,处理剩下的难题。每一步都比后一步更便宜、更快,也更容易检查。

The right tool for each step

What struck me most is how each pipeline picks its tools. Gondara put it with a proverb: if all you have is a hammer, every problem looks like a nail. The registry can use LLMs, but it does not want to overuse them where they are not needed.

Pipeline Task How it works
Reportability Reportable or not (two classes) Two fine-tuned language models, each reading a different section of the report. If either says reportable, the report is reportable, so that no reportable tumor is missed. Accuracy: about 97–99% for reportable tumors, above 90% for non-reportable ones
Tumor group One of 19 tumor groups Six small BERT-type models (each reads only about 512 tokens): three read the top of the report, three the bottom. They vote; if enough agree, that group wins. If not, a large language model reads the whole report plus the six votes and decides
Auto-coding Behavior (benign, in situ, invasive), laterality, site, histology and more; neoadjuvant therapy; whether an addendum is present A suite: regular expressions for simple patterns ("right breast", "left lung"), question answering for what a report mentions (does it give the ER status?), language-model classifiers for harder labels
Consolidation Report-level data to tumor-level data No NLP: business logic in ordinary code, such as which item takes priority when two reports fall within a time window

The tumor group task shows why the design is layered. Where a report names the tumor group varies: at the top, the bottom, the middle, or ambiguously. A specimen may be taken from the breast but tested for squamous cell carcinoma or melanoma, which has nothing to do with breast cancer. Small models with short context windows see only part of the report, so the large model, which can read all of it, is kept for the cases where they disagree. In the published version, the large model steps in when fewer than five of the six agree.

My practical idea from this: let the simple method go first. Use a regular expression when a pattern does the job, a BERT-type classifier next, and an LLM last, for what remains hard. Each step is cheaper, faster and easier to check than the one after it.

看视频这一段 / Watch this part

模型会泄露训练数据吗?

病理报告里满是个人身份信息。任何一项泄露都可能导致身份被盗用或伪造;未经授权获取这些信息,也违反隐私法,比如 BC 省的《个人信息保护法》(PIPA)和加拿大联邦的 PIPEDA,就像美国有 HIPAA。而诊断或预后模型根本不需要病人或医生的名字,它需要的是报告里描述样本、描述病理医生所见的那部分。

那么,如果我在自己的服务器上用未匿名化的原始报告训练模型,只把训练好的模型分享出去呢?模型不过是一堆矩阵、一堆数字而已。研究表明不是这样:大模型会泄露训练数据,有时是逐字泄露。用客服记录训练的模型可能吐出客户的姓名和电话;用健康档案训练的模型可能原样吐出病人的姓名、PHN 和地址。研究人员已经从 ChatGPT 这样的生产级模型里提取出了数 GB 的训练数据。把这样的模型开源,任何人都可以下载下来,用提问的方式把数据套出来。

为什么会这样?因为太大。生物统计里的一个逻辑回归模型可能只有四五个参数,超过十个就会有人质疑参数太多;而今天最大的模型参数超过一万亿。参数这么多,模型就能记住训练时见过的部分内容,包括敏感信息。

Can a model leak its training data?

Pathology reports are full of personal identifiers. Leaking any of them can lead to stolen or forged identity, and unauthorized access breaks privacy laws such as British Columbia's Personal Information Protection Act (PIPA) and Canada's PIPEDA, much as HIPAA does in the US. Yet a diagnostic or prognostic model does not need a patient's or physician's name at all; it needs the part of the report that describes the sample and what the pathologist saw.

So what if I train a model on raw, un-anonymized reports on my own servers and share only the trained model? It is just a set of matrices, a bunch of numbers. Studies say otherwise: large models can leak their training data, sometimes verbatim. A model trained on customer-service logs can reveal customer names and phone numbers; a model trained on health records can reveal a patient's name, PHN and address exactly as written. Researchers have extracted gigabytes of training data from production models such as ChatGPT. Releasing such a model as open source lets anyone query it for that data.

Why does this happen? Size. A logistic regression in biostatistics may have four or five parameters, and people start questioning anything over ten. Today's largest models have over a trillion. With that many parameters, a model can memorize parts of what it saw during training, including sensitive information.

看视频这一段 / Watch this part

两道防线:差分隐私与数据匿名化

安全地分享模型,主要有两条路:

差分隐私(DP) 数据匿名化
思路 改变训练方式:加入可控的噪声,让任何一条记录都无法被认出 改变数据:训练前就去掉要保护的信息。什么都不留,就没有什么可泄露
优点 隐私程度可以调;保证是理论上的,无论攻击者算力多强都成立 现在就实用;对大多数任务来说,身份信息本来就帮不上诊断
代价 隐私与效用的权衡:隐私越强,噪声越多,模型越不准 必须找全每一个身份信息;没有理论保证

正式定义比较两个相邻数据集 D 和 D′,它们只差一条记录,也就是一个人。如果对任意一组输出 S,都有 P[M(D) ∈ S] ≤ eε · P[M(D′) ∈ S] + δ,就说机制 M 满足差分隐私。ε 和 δ 越小,两边的输出越相似,攻击者就越无法判断某一个人在不在数据里。差分隐私已经用在日常生活中:手机发回给苹果或谷歌的部分数据就是这样保护的。课上重点讲匿名化,因为它在今天更实用。

Two defences: differential privacy and anonymization

There are two main ways to share a model safely:

Differential privacy (DP) Anonymization
Idea Change how the model is trained: add controlled noise so no single record can be detected Change the data: remove what we want to protect before training. Nothing left, nothing to leak
Strength The amount of privacy is tunable, and the guarantee is theoretical: it holds whatever the attacker's computing power Practical today; for most tasks identifiers do not help the diagnosis anyway
Cost The privacy–utility trade-off: more privacy means more noise and a less accurate model Must find every identifier; no theoretical guarantee

The formal definition compares two neighboring datasets D and D′ that differ in one record, which means one person. A mechanism M is differentially private if, for any set of outputs S, P[M(D) ∈ S] ≤ eε · P[M(D′) ∈ S] + δ. The smaller ε and δ, the more alike the two outputs, so an attacker cannot tell whether any one person was in the data. DP is already in everyday use: some of the data that phones send back to Apple or Google is protected this way. The lecture focuses on anonymization because it is practical now.

看视频这一段 / Watch this part

BCCR Obscura:三层匿名化

要去掉的有:病人和医生的姓名、PHN、出生日期,以及任何单独或与其他信息组合后能认出一个人的数据,比如病例号、病历号。登记处自己开发的工具 BCCR Obscura 分三层来做:

层 方法 去掉什么
第 1 层 先做预处理(去掉特殊字符、转成小写),然后只用正则表达式 一切有固定格式的信息:PHN、医生编号、电话、邮编
第 2 层 微软的开源框架 Presidio(专门用来识别和移除敏感信息),配合 GLiNER 命名实体识别(NER)模型 大部分病人和医生的姓名
第 3 层 再用 spaCy(另一个基于深度学习的 NER 工具)兜底 第 2 层漏掉或只删了一部分的名字,比如很长的名字,或有两三个中间名的名字

有两个细节让它适合病理报告。Obscura 保留了一份以人名命名的疾病词典,比如 Paget 病、Kaposi 肉瘤,这样删人名时不会把诊断也删掉。它还保持报告的结构不变,因为下游的流水线要依赖这个结构。它能处理任何文本文件,包括登记处主要接收的 HL7(Health Level Seven)格式。

效果:病人标识信息去除率接近 99%,医生标识信息约 95%。这是由人工逐份检查几百份匿名化后的报告、记下残留了什么信息得出的。用一台带 RTX 4090 这类显卡的台式机,每小时能处理 1 万到 1.5 万份报告。

信息图:医疗 NLP 中的数据隐私保护,BCCR Obscura 脱敏方案。上半部分对比隐私风险与两条保护路径:大模型存在数据逐字泄露风险;差分隐私理论安全但降低准确率,数据脱敏直接移除标识符、更实用。下半部分是三级脱敏流水线:第一级用正则表达式匹配健康号、电话、邮编,第二、三级用 Presidio 加 GLiNER 和专用 NER 模型识别人名,并用字典保留病名;右侧是去除率、处理速度和数据延迟
信息图信息图:医疗 NLP 中的数据隐私保护,BCCR Obscura 脱敏方案。上半部分对比隐私风险与两条保护路径:大模型存在数据逐字泄露风险;差分隐私理论安全但降低准确率,数据脱敏直接移除标识符、更实用。下半部分是三级脱敏流水线:第一级用正则表达式匹配健康号、电话、邮编,第二、三级用 Presidio 加 GLiNER 和专用 NER 模型识别人名,并用字典保留病名;右侧是去除率、处理速度和数据延迟点击查看大图

读图提示:99% 是病人标识信息的去除率,医生标识信息约为 95%;数据延迟的缩短来自所有 NLP 流水线的共同作用,不只是匿名化这一步,课上给的原有延迟是平均 18 个月(总结时说 18 到 24 个月)。

这些流水线加在一起,正在提升登记处的数据质量、缩短数据采集的时间:原来 18 到 24 个月的延迟已经降到约 14 个月,目标是在未来一年到一年半内做到实时提供数据。

BCCR Obscura: anonymization in three tiers

What has to go: patient and physician names, the PHN, date of birth, and any item that alone or combined with others can identify a person, such as a case number or medical record number. The registry's in-house tool, BCCR Obscura, does it in three tiers:

Tier Method What it removes
Tier 1 Pre-processing (remove special characters, lowercase), then regular expressions only Anything with a fixed pattern: PHN, physician IDs, phone numbers, postal codes
Tier 2 Microsoft Presidio, an open-source framework for finding and removing sensitive information, running GLiNER named entity recognition (NER) models Most patient and physician names
Tier 3 spaCy, another NER library with deep-learning models, as a fail-safe Names tier 2 missed or removed only partly, such as long names or names with two or three middle names

Two details make it work for pathology. Obscura keeps a dictionary of eponymous diseases, conditions named after people, such as Paget's disease and Kaposi's sarcoma, so that removing names does not remove diagnoses. It also leaves the report's structure unchanged, because downstream pipelines rely on it. It works on any text file, including Health Level Seven (HL7) messages, the format the registry mostly receives.

The results: close to 99% of patient identifiers and about 95% of physician identifiers removed, measured by a person checking a few hundred anonymized reports by hand for anything left behind. On one desktop GPU such as an RTX 4090, it anonymizes 10,000 to 15,000 reports an hour.

Infographic: privacy-preserving NLP, protecting medical data in AI. Left: the threat, with massive models memorizing training data and leaking personal details verbatim, and compliance and identity-theft risks under HIPAA, PIPEDA and PIPA. Right: the BCCR Obscura three-tier pipeline, with tier 1 regular expressions removing phone numbers, postal codes and PHNs, and tiers 2 and 3 using Presidio with GLiNER and another NER model to remove names; accuracy, throughput and data delay
InfographicInfographic: privacy-preserving NLP, protecting medical data in AI. Left: the threat, with massive models memorizing training data and leaking personal details verbatim, and compliance and identity-theft risks under HIPAA, PIPEDA and PIPA. Right: the BCCR Obscura three-tier pipeline, with tier 1 regular expressions removing phone numbers, postal codes and PHNs, and tiers 2 and 3 using Presidio with GLiNER and another NER model to remove names; accuracy, throughput and data delayClick to open full size

A reading note: "99% accuracy" is for patient identifiers; physician identifiers are about 95%. The shorter data delay comes from all the NLP pipelines together, not from anonymization alone, and the lecture gave the earlier delay as 18 months on average (18 to 24 in its summary). The "StarPy" in the picture is spaCy, the tier 3 model.

Together, these pipelines are improving data quality and shortening data capture at the registry: the delay of 18 to 24 months has come down to about 14, with real-time data as the goal for the next year or year and a half.

看视频这一段 / Watch this part

我的思考

这个案例让我更贴近实际地感受到,NLP 能怎样提高医疗系统的效率。它也让我时刻记着一条规则:要考虑病人的隐私,在保护好隐私的同时提高效率。

但我认为 NLP 能做的不只是提高筛选疾病的效率,它在数据分析、随访和健康教育上也都能有所应用。

My thoughts

This case made the use of NLP to improve the efficiency of a health system feel much more real to me. It also kept one rule in front of me the whole time: patient privacy comes first, and efficiency has to be gained while that privacy is protected.

But I think NLP can do more than screen for disease faster. It can also help with data analysis, with patient follow-up, and with health education.

看视频这一段 / Watch this part

原始手写笔记

BC 癌症登记处 NLP 实战的手写笔记:主要来源是病理报告;NLP 适合的任务;旧系统识别不了“No evidence of cancer”;新系统的可报告性、肿瘤分组和监测数据自动编码三条流水线;紫色的实用思路,简单的模型先上,圈出了正则表达式;隐私保护 NLP,包括数据泄露、模型很大、差分隐私和三层匿名化;一行中文:清除人名,要保留病名

整理后的版本改了这些地方:拼错的“Suitbele”改为 suited;“Old system”写明是 eMaRC(规则加关键词表),“cannot identify”改为否定问题:“No evidence of cancer”仍被判为癌症,并补上它的后果(误报多、人工复核、平均延迟 18 个月);三条新流水线各补了一行做法(任一模型判可报告即保留、6 个小模型投票加 LLM 裁决、正则加问答加分类器),并补上合并和人工复核两步;“simple model go first”改为正则表达式 → BERT 类小模型 → LLM 最后;隐私部分按因果顺序排列(模型非常大 → 会记住训练数据 → 可能逐字泄露隐私数据),取代原来的“cannot memorize privacy data”;差分隐私补上了它的权衡(可控噪声、理论保证、准确率下降);第 1 层从“去掉数字”改为去掉固定格式(PHN、电话、邮编),第 2 层写明是 Presidio 加 GLiNER,去掉的是人名而不只是名(first name),第 3 层是兜底的 NER 模型,补删漏掉的名字,比如多个中间名;中文那一行补了两个以人名命名的疾病作例子;补上了去除率和我的思考。

Original handwritten notes

Handwritten notes on applied NLP at the BC Cancer Registry: the main source is pathology reports; tasks NLP is suited for; the old system cannot identify 'no evidence of cancer'; the new system with reportability, tumor group classification and surveillance data items auto-coding pipelines; a purple practical idea, simple models go first, with regular expressions circled; privacy-preserving NLP with leaking data, large models, differential privacy and three tiers of anonymization; a Chinese line on removing person names but keeping disease names

What changed in the tidied version: "Suitbele" is now "suited"; "Old system" is named (eMaRC, a rule-based keyword table), "cannot identify" now reads as a negation problem in which "no evidence of cancer" is still flagged as cancer, and its consequences (more errors, manual review, an 18-month delay) were added; each new pipeline gained one line on how it works (either-model rule, six small models with an LLM tie-breaker, regex + question answering + classifiers), and the consolidation and manual-review steps were added; "simple model go first" now runs regular expressions → BERT-type models → LLMs last; the privacy lines now run in cause-and-effect order (models are very large → they memorize training data → they can leak private data verbatim) in place of "cannot memorize privacy data"; differential privacy gained its trade-off (controlled noise, a theoretical guarantee, lower accuracy); Tier 1 now removes fixed patterns (PHN, phone numbers, postal codes) rather than just "numbers", Tier 2 names Presidio + GLiNER and removes names in general (not only first names), and Tier 3 is a fail-safe NER model for names that were missed, such as multiple middle names; the Chinese line now gives two eponymous diseases as examples; the removal rates and my takeaway were added.

学习来源与资源

这篇笔记基于我在不列颠哥伦比亚大学(UBC)微证书项目“用自然语言处理改善患者照护”(Natural Language Processing to Improve Patient Care)中的学习笔记,课程为临床文档的提取与分析(模块一第 1.2 课“BC 癌症登记处的 NLP 实战”,主讲 Lovedeep Gondara)。技术细节核对了以下资料:

动手试试

  • Microsoft Presidio:第 2 层用的开源框架。在它的在线演示里粘贴一段自己编的报告,看看它能识别出哪些姓名、电话和日期,又是怎样遮盖的。只用虚构的文本,不要用真实报告。
  • regex101:在自己编的文字上试一个第 1 层风格的模式,比如 10 位健康号或加拿大邮编。记得选择和你代码一致的正则风格(例如 Python)。

Learning sources and resources

This note is based on my study notes from the University of British Columbia (UBC) micro-certificate program "Natural Language Processing to Improve Patient Care," in the course Extraction and Analysis of Clinical Documents (Module 1, lesson 1.2, "Applied NLP at the BC Cancer Registry," by Lovedeep Gondara). Technical details were checked against:

Try it yourself

  • Microsoft Presidio: the open-source framework used in tier 2. Its online demo lets you paste a made-up report and see which names, phone numbers and dates it detects and how it masks them. Use only synthetic text, never a real report.
  • regex101: try a tier-1-style pattern, such as a 10-digit health number or a Canadian postal code, on your own made-up text. Choose the flavor that matches your code (for example Python).
原图 / Original ↗