2016-02-22 13 views
7

Tôi tự hỏi làm thế nào tôi có thể sử dụng các MIST library để de-xác định một văn bản, ví dụ, chuyểnTôi làm cách nào để sử dụng thư viện MIST để xác định văn bản?

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. 

Tôi đã lang thang qua các tài liệu nhưng không có may mắn cho đến nay.

+0

may mắn làm điều này thực tế trên dữ liệu bệnh nhân và đảm bảo 100% rằng bạn sẽ không "bỏ lỡ" một cái gì đó mà lẽ ra đã bị che khuất ... –

+0

@MarcB không sao tôi không nhắm tới 100% (tôi ước gì) :) Tôi không mong đợi ghi chú của bệnh nhân cũng sạch sẽ. –

+1

@MarcB Chúng tôi đã có một số kết quả khá mặc dù: * Franck Dernoncourt, Ji Young Lee, Ozlem Uzuner, Peter Szolovits. [De-xác định các ghi chú bệnh nhân với các mạng thần kinh tái phát] (http://arxiv.org/abs/1606.03475). arXiv preprint arXiv: 1606.03475, 2016. * –

Trả lời

3

Câu trả lời này đã được thử nghiệm trên Windows 7 SP1 x64 Ultimate với Anaconda Python 2.7.11 x64 và MIST 2.0.4. MIST 2.0.4 không hoạt động với Python 3.x (theo hướng dẫn, tôi chưa thử nghiệm nó).

MIST (Bộ công cụ đánh giá nhận dạng MITER) [1] là một tùy chỉnh của MAT (Bộ công cụ chú giải của MITER), là công cụ để tự động gắn thẻ tài liệu hoặc với con người. Trình gắn thẻ tự động được dựa trên Carafe (Trường điều kiện RAndom) [2], đây là việc triển khai OCaml các trường ngẫu nhiên có điều kiện (CRF).

MIST không đi kèm với bất kỳ mô hình được đào tạo nào và chỉ có 10 tài liệu ngắn, không y tế được chú thích với lớp NER điển hình (như tổ chức và cá nhân).

De-id (không xác định) là quá trình gắn thẻ PHI (Thông tin sức khỏe cá nhân) trong tài liệu và thay thế chúng bằng dữ liệu giả mạo. Hãy bỏ qua thay thế PHI ngay bây giờ và tập trung vào gắn thẻ. Để gắn thẻ tài liệu (ví dụ, ghi chú của bệnh nhân), MAT tuân theo lược đồ học máy điển hình: CRF cần được huấn luyện trên tập dữ liệu có nhãn (= một tập hợp các tài liệu có nhãn), sau đó chúng tôi sử dụng nó để gắn thẻ các tài liệu không dán nhãn.

Khái niệm kỹ thuật chính trong MAT là nhiệm vụ. Nhiệm vụ là một tập hợp các hoạt động, được gọi là quy trình công việc, có thể được chia thành các bước. Công nhận thực thể được đặt tên (NER) là một nhiệm vụ. De-id là một nhiệm vụ khác (chủ yếu là NER hướng tới các văn bản y khoa): nói cách khác, MIST chỉ là một nhiệm vụ của MAT (thực ra là 3: core, HIPAA và AMIA. Core là một nhiệm vụ phụ huynh, trong khi HIPAA và AMIA là hai các loại thẻ khác nhau). Các bước là ví dụ về mã thông báo, gắn thẻ hoặc làm sạch. Quy trình làm việc chỉ là danh sách các bước mà người ta có thể làm theo.

Với điều này trong tâm trí, đây là mã cho 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 hiện đang thực hiện.

Dưới đây là các hướng dẫn tương tự cho 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 

Để chạy de-id, không có cần phải cài đặt các nhiệm vụ de-id là họ trước -Cài đặt. Có 2 tác vụ vô danh (\MIST_2_0_4\src\tasks\HIPAA\task.xml\MIST_2_0_4\src\tasks\AMIA\task.xml). Chúng không đi kèm với bất kỳ mô hình được đào tạo nào cũng như tập dữ liệu có nhãn, vì vậy bạn có thể muốn lấy một số dữ liệu tại Physician notes with annotated PHI.

Đối Microsoft Windows (thử nghiệm với Windows 7 SP1 x64 Ultimate):

Đào tạo mô hình (bạn có thể thay HIPAA Deidentification với AMIA Deidentification tùy thuộc vào tagset bạn muốn sử dụng):

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" 

Để chạy mô hình được đào tạo trên một tệp:

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" 

Để chạy chương trình được đào tạo mô hình trên một thư mục:

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" 

Như thường lệ, người ta có thể xác định các định dạng tập tin đầu vào là 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" 

Đối Ubuntu 14.04.4 LTS x64:

Để đào tạo mô hình (bạn có thể thay thế HIPAA Deidentification bằng AMIA Deidentification tùy thuộc vào thẻ bạn muốn sử dụng):

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" 

Để chạy các mô hình đào tạo về một tập tin:

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" 

Để chạy các mô hình đào tạo trên một thư mục:

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" 

Như thường lệ, người ta có thể xác định các định dạng tập tin đầu vào là 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" 

Thông báo lỗi điển hình:

  • raise PluginError, "Carafe not configured properly for this task and workflow: " + str(e) (khi cố gắng gắn thẻ tài liệu): thường có nghĩa là không có mô hình nào được chỉ định. Bạn cần xác định mô hình mặc định hoặc sử dụng --tagger_model /path/to/model/.
  • Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded (khi đào tạo một mô hình): thật dễ dàng để vượt qua giới hạn heap_size (mặc định là 2GB). Bạn có thể tăng heap_size với tham số --heap_size. Ví dụ (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, Bến Wellner, Cheryl Clark, David Austropharm, Bradley Malin, Lynette Hirschman, The MITRE xác định chà sàn toolkit : thiết kế, đào tạo và đánh giá, Int. J. Med. Tin học 79 (12) (2010) 849–859, http://dx.doi.org/10.1016/j.ijmedinf.2010.09.007.

[2] B. Wellner, Mô hình trình tự và phương pháp xếp hạng cho Phân tích thảo luận [Ph.D. Luận án]. Đại học Brandeis, Waltham, MA, 2009.http://www.cs.brandeis.edu/~wellner/pubs/wellner_dissertation.pdf


Documentation cho 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. 

Documentation cho 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. 
Các vấn đề liên quan