我想知道我如何使用MIST library取消识别文字,例如转换
Patient ID: P89474
Mary Phillips is a 45-year-old woman with a history of diabetes.
She arrived at New Hope Medical Center on August 5 complaining
of abdominal pain. Dr. Gertrude Philippoussis diagnosed her
with appendicitis and admitted her at 10 PM.
到
Patient ID: [ID]
[NAME] is a [AGE]-year-old woman with a history of diabetes.
She arrived at [HOSPITAL] on [DATE] complaining
of abdominal pain. Dr. [PHYSICIAN] diagnosed her
with appendicitis and admitted her at 10 PM.
我已经浏览了文档但到目前为止没有运气。
答案 0 :(得分:5)
此答案在Windows 7 SP1 x64 Ultimate上使用Anaconda Python 2.7.11 x64和MIST 2.0.4进行了测试。 MIST 2.0.4不适用于Python 3.x(根据手册,我自己没有测试过。)
MIST(MITER Identification Scrubber Toolkit)[1]是MAT(MITRE Annotation Toolkit)的定制,它是一种自动或与人类标记文档的工具(后者通过网络服务器提供GUI)。自动标记器基于Carafe(ConditionAl RAndom Fields)[2],它是条件随机字段(CRF)的OCaml实现。
MIST没有任何经过培训的模型,并且只有大约10个简短的非医学文件,注明了典型的NER类(如组织和个人)。
De-id(去标识)是在文档中标记PHI(私人健康信息)并用伪数据替换它们的过程。我们暂时忽略PHI替换,并专注于标记。为了标记文档(例如,患者注释),MAT遵循典型的机器学习方案:CRF需要在标记的数据集(=一组标记的文档)上进行训练,然后我们使用它来标记未标记的文档。
MAT中的主要技术概念是任务。任务是一组称为工作流的活动,可以分解为多个步骤。命名实体识别(NER)是一项任务。 De-id是另一项任务(主要是NER面向医学文本):换句话说,MIST只是MAT的一项任务(实际上是3:核心,HIPAA和AMIA。核心是父任务,而HIPAA和AMIA是两个任务不同的tagets)。步骤例如是标记化,标记或清理。工作流程只是可以遵循的步骤列表。
考虑到这一点,以下是 Microsoft Windows 的代码:
#######
rem Instructions for Windows 7 SP1 x64 Ultimate
rem Installing MIST: set MAT_PKG_HOME depending on where you downloaded it
SET MAT_PKG_HOME=C:\Users\Francky\Downloads\MIST_2_0_4\MIST_2_0_4\src\MAT
SET TMP=C:\Users\Francky\Downloads\MIST_2_0_4\MIST_2_0_4\temp
cd C:\Users\Francky\Downloads\MIST_2_0_4\MIST_2_0_4
python install.py
# MAT is now installed. We'll show how to use it for NER.
# We will be taking snippets from some of the 8 tutorials.
# A lot of the tutorial content are about the annotation GUI,
# which we don't care here.
# Tuto 1: install task
cd %MAT_PKG_HOME%
bin\MATManagePluginDirs.cmd install %CD%\sample\ne
# Tuto 2: build model (i.e., train it on labeled dataset)
bin\MATModelBuilder.cmd --task "Named Entity" --model_file %TMP%\ne_model ^
--input_files "%CD%\sample\ne\resources\data\json\*.json"
# Tuto 2: Add trained model as the default model
bin\MATModelBuilder.cmd --task "Named Entity" --save_as_default_model ^
--input_files "%CD%\sample\ne\resources\data\json\*.json"
# Tudo 5: use CLI -> prepare the document
bin\MATEngine.cmd --task "Named Entity" --workflow Demo --steps "zone,tokenize" ^
--input_file %CD%\sample\ne\resources\data\raw\voa2.txt --input_file_type raw ^
--output_file %CD%\voa2_txt.json --output_file_type mat-json
# Tuto 5: use CLI -> tag the document
bin\MATEngine.cmd --task "Named Entity" --workflow Demo --steps "tag" ^
--input_file %CD%\voa2_txt.json --input_file_type mat-json ^
--output_file %CD%\voa2_txt.json --output_file_type mat-json ^
--tagger_local
NER现已完成。
以下是 Ubuntu 14.04.4 LTS x64 的相同说明:
#######
# Instructions for Ubuntu 14.04.4 LTS x64
# Installing MIST: set MAT_PKG_HOME depending on where you downloaded it
export MAT_PKG_HOME=/home/ubuntu/mist/MIST_2_0_4/MIST_2_0_4/src/MAT
export TMP=/home/ubuntu/mist/MIST_2_0_4/MIST_2_0_4/temp
mkdir $TMP
cd /home/ubuntu/mist/MIST_2_0_4/MIST_2_0_4/
python install.py
# MAT is now installed. We'll show how to use it for NER.
# We will be taking snippets from some of the 8 tutorials.
# A lot of the tutorial content are about the annotation GUI,
# which we don't care here.
# Tuto 1: install task
cd $MAT_PKG_HOME
bin/MATManagePluginDirs install $PWD/sample/ne
# Tuto 2: build model (i.e., train it on labeled dataset)
bin/MATModelBuilder --task "Named Entity" --model_file $TMP/ne_model \
--input_files "$PWD/sample/ne/resources/data/json/*.json"
# Tuto 2: Add trained model as the default model
bin/MATModelBuilder --task "Named Entity" --save_as_default_model \
--input_files "$PWD/sample/ne/resources/data/json/*.json"
# Tudo 5: use CLI -> prepare the document
bin/MATEngine --task "Named Entity" --workflow Demo --steps "zone,tokenize" \
--input_file $PWD/sample/ne/resources/data/raw/voa2.txt --input_file_type raw \
--output_file $PWD/voa2_txt.json --output_file_type mat-json
# Tuto 5: use CLI -> tag the document
bin/MATEngine --task "Named Entity" --workflow Demo --steps "tag" \
--input_file $PWD/voa2_txt.json --input_file_type mat-json \
--output_file $PWD/voa2_txt.json --output_file_type mat-json \
--tagger_local
要运行de-id,无需安装预先安装的de-id任务。有2个de-id任务(\MIST_2_0_4\src\tasks\HIPAA\task.xml
和\MIST_2_0_4\src\tasks\AMIA\task.xml
)。它们没有经过任何训练模型,也没有标记数据集,因此您可能希望在Physician notes with annotated PHI获得一些数据。
对于 Microsoft Windows (使用Windows 7 SP1 x64 Ultimate测试):
训练模型(您可以将HIPAA Deidentification
替换为AMIA Deidentification
,具体取决于您要使用的标记集):
bin\MATModelBuilder.cmd --task "HIPAA Deidentification" ^
--save_as_default_model --nthreads=3 --max_iterations=15 ^
--lexicon_dir="%CD%\sample\mist\gazetteers" ^
--input_files "%CD%\sample\mist\i2b2-60-00-40\train\*.json"
在一个文件上运行训练模型:
bin\MATEngine --task "HIPAA Deidentification" --workflow Demo ^
--input_file .\note.txt --input_file_type raw ^
--output_file .\note.json --output_file_type mat-json ^
--tagger_local ^
--steps "clean,zone,tag"
在一个目录上运行训练模型:
bin\MATEngine --task "HIPAA Deidentification" --workflow Demo ^
--input_dir "%CD%\sample\test" --input_file_type raw ^
--output_dir "%CD%\sample\test" --output_file_type mat-json ^
--tagger_local ^
--steps "clean,zone,tag"
像往常一样,可以将输入文件格式指定为JSON:
bin\MATEngine --task "HIPAA Deidentification" --workflow Demo ^
--input_dir "%CD%\sample\mist\i2b2-60-00-40\test" --input_file_type mat-json ^
--output_dir "%CD%\sample\mist\i2b2-60-00-40\test_out" --output_file_type mat-json ^
--tagger_local --steps "tag"
对于 Ubuntu 14.04.4 LTS x64 :
训练模型(您可以将HIPAA Deidentification
替换为AMIA Deidentification
,具体取决于您要使用的标记集):
bin/MATModelBuilder --task "HIPAA Deidentification" \
--save_as_default_model --nthreads=20 --max_iterations=15 \
--lexicon_dir="$PWD/sample/mist/gazetteers" \
--input_files "$PWD/sample/mist/i2b2-60-00-40/train/*.json"
在一个文件上运行训练模型:
bin/MATEngine --task "HIPAA Deidentification" --workflow Demo \
--input_file ./note.txt --input_file_type raw \
--output_file ./note.json --output_file_type mat-json \
--tagger_local \
--steps "clean,zone,tag"
在一个目录上运行训练模型:
bin/MATEngine --task "HIPAA Deidentification" --workflow Demo \
--input_dir "$PWD/sample/test" --input_file_type raw \
--output_dir "$PWD/sample/test" --output_file_type mat-json \
--tagger_local \
--steps "clean,zone,tag"
像往常一样,可以将输入文件格式指定为JSON:
bin/MATEngine --task "HIPAA Deidentification" --workflow Demo \
--input_dir "$PWD/sample/mist/i2b2-60-00-40/test" --input_file_type mat-json \
--output_dir "$PWD/sample/mist/i2b2-60-00-40/test_out" --output_file_type mat-json \
--tagger_local --steps "tag"
典型错误消息:
raise PluginError, "Carafe not configured properly for this task and workflow: " + str(e)
(尝试标记文档时):通常表示未指定任何模型。您需要定义默认模型,或使用--tagger_model /path/to/model/
。 Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
(训练模型时):很容易超过heap_size限制(默认值为2GB)。您可以使用--heap_size
参数增加heap_size。示例(Linux):
bin/MATModelBuilder --task "HIPAA Deidentification" \
--save_as_default_model --nthreads=20 --max_iterations=15 \
--lexicon_dir="$PWD/sample/mist/gazetteers" \
--heap_size=60G \
--input_files "$PWD/sample/mist/mimic-140-20-40/train/*.json"
[1] John Aberdeen,Samuel Bayer,Reyyan Yeniterzi,Ben Wellner,Cheryl Clark,David Hanauer,Bradley Malin,Lynette Hirschman,MITRE识别洗涤器工具包:设计,培训和评估,Int。 J. Med。 Informatics 79(12)(2010)849-859,http://dx.doi.org/10.1016/j.ijmedinf.2010.09.007。
[2] B. Wellner,序列模型和排序方法 话语解析[Ph.D.论文]。布兰代斯大学, Waltham,MA,2009。http://www.cs.brandeis.edu/~wellner/pubs/wellner_dissertation.pdf
MATModelBuilder.cmd
的文档:
Usage: MATModelBuilder.cmd [task option] [config name option] [other options]
Options:
-h, --help show this help message and exit
Task option:
--task=task name of the task to use. Must be the first argument,
if present. Obligatory if the system knows of more
than one task. Known tasks are: AMIA Deidentification,
Named Entity, HIPAA Deidentification, Enhanced Named
Entity
Config name option:
--config_name=name name of the model build config to use. Must be the
first argument after --task, if present. Optional.
Default model build config will be used if no config
is specified.
Control options:
--version Print version number and exit
--debug Enable debug output.
--subprocess_debug=int
Set the subprocess debug level to the value provided,
overriding the global setting. 0 disables, 1 shows
some subprocess activity, 2 shows all subprocess
activity.
--subprocess_statistics
Enable subprocess statistics (memory/time), if the
capability is available and it isn't globally enabled.
--tmpdir_root=dir Override the default system location for temporary
files. If the directory doesn't exist, it will be
created. Use this feature to control where temporary
files are created, for added security, or in
conjunction with --preserve_tempfiles, as a debugging
aid.
--preserve_tempfiles
Preserve the temporary files created, as a debugging
aid.
--verbose_config If specified, print to stderr the source of each MAT
configuration variable the first time it's accessed.
Options for model class creation:
--partial_training_on_gold_only
When the trainer is presented with partially tagged
documents, by default MAT will ask it to train on all
annotated segments, completed or not. If this flag is
specified, only completed segments should be used for
training.
--feature_spec=FEATURE_SPEC
path to the Carafe feature spec file to use. Optional
if feature_spec is set in the <build_settings> for the
relevant model config in the task.xml file for the
task.
--training_method=TRAINING_METHOD
If present, specify a training method other than the
standard method. Currently, the only recognized value
is psa. The psa method is noticeably faster, but may
result in somewhat poorer results. You can use a value
of '' to override a previously specified training
method (e.g., a default method in your task).
--max_iterations=MAX_ITERATIONS
number of iterations for the optimized PSA training
mechanism to use. A value between 6 and 10 is
appropriate. Overrides any possible default in
<build_settings> for the relevant model config in the
task.xml file for the task.
--lexicon_dir=LEXICON_DIR
If present, the name of a directory which contains a
Carafe training lexicon. This pathname should be an
absolute pathname, and should have a trailing slash.
The content of the directory should be a set of files,
each of which contains a sequence of tokens, one per
line. The name of the file will be used as a training
feature for the token. Overrides any possible default
in <build_settings> for the relevant model config in
the task.xml file for the task.
--parallel If present, parallelizes the feature expectation
computation, which reduces the clock time of model
building when multiple CPUs are available
--nthreads=NTHREADS
If --parallel is used, controls the number of threads
used for training.
--gaussian_prior=GAUSSIAN_PRIOR
A positive float, default is 10.0. See the jCarafe
docs for details.
--no_begin Don't introduce begin states during training. Useful
if you're certain that you won't have any adjacent
spans with the same label. See the jCarafe
documentation for more details.
--l1 Use L1 regularization for PSA training. See the
jCarafe docs for details.
--l1_c=L1_C Change the penalty factor for the L1 regularizer. See
the jCarafe docs for details.
--heap_size=HEAP_SIZE
If present, specifies the -Xmx argument for the Java
JVM
--stack_size=STACK_SIZE
If present, specifies the -Xss argument for the Java
JVM
--tags=TAGS if present, a comma-separated list of tags to pass to
the training engine instead of the full tag set for
the task (used to create per-tag pre-tagging models
for multi-stage training and tagging)
--pre_models=PRE_MODELS
if present, a comma-separated list of glob-style
patterns specifying the models to include as pre-
taggers.
--add_tokens_internally
If present, Carafe will use its internal tokenizer to
tokenize the document before training. If your
workflow doesn't tokenize the document, you must
provide this flag, or Carafe will have no tokens to
base its training on. We recommend strongly that you
tokenize your documents separately; you should not use
this flag.
--word_properties=WORD_PROPERTIES
See the jCarafe docs for --word-properties.
--word_scores=WORD_SCORES
See the jCarafe docs for --word-scores.
--learning_rate=LEARNING_RATE
See the jCarafe docs for --learning-rate.
--disk_cache=DISK_CACHE
See the jCarafe docs for --disk_cache.
Input options:
--input_dir=dir A directory, all of whose files will be used in the
model construction. Can be repeated. May be specified
with --input_files.
--input_files=re A glob-style pattern describing full pathnames to use
in the model construction. May be specified with
--input_dir. Can be repeated.
--file_type=fake-xml-inline | mat-json | xml-inline
The file type of the input. One of fake-xml-inline,
mat-json, xml-inline. Default is mat-json.
--encoding=encoding
The encoding of the input. The default is the
appropriate default for the file type.
Output options:
--model_file=file Location to save the created model. The directory must
already exist. Obligatory if --save_as_default_model
isn't specified.
--save_as_default_model
If the the task.xml file for the task specifies the
<default_model> element, save the model in the
specified location, possibly overriding any existing
model.
MATEngine
的文档:
Usage: MATEngine [core options] [input/output/task options] [other options]
Options:
-h, --help show this help message and exit
Core options:
--other_app_dir=dir
additional directory to load a task from. Optional and
repeatable.
--settings_file=file
a file of settings to use which overwrites existing
settings. The file should be a Python config file in
the style of the template in
etc/MAT_settings.config.in. Optional.
--task=task name of the task to use. Obligatory if the system
knows of more than one task. Known tasks are: AMIA
Deidentification, Named Entity, HIPAA
Deidentification, Enhanced Named Entity
--version Print version number and exit
--debug Enable debug output.
--subprocess_debug=int
Set the subprocess debug level to the value provided,
overriding the global setting. 0 disables, 1 shows
some subprocess activity, 2 shows all subprocess
activity.
--subprocess_statistics
Enable subprocess statistics (memory/time), if the
capability is available and it isn't globally enabled.
--tmpdir_root=dir Override the default system location for temporary
files. If the directory doesn't exist, it will be
created. Use this feature to control where temporary
files are created, for added security, or in
conjunction with --preserve_tempfiles, as a debugging
aid.
--preserve_tempfiles
Preserve the temporary files created, as a debugging
aid.
--verbose_config If specified, print to stderr the source of each MAT
configuration variable the first time it's accessed.