This repository provides a script and recipe to Inference the BioBERT DownStream Inference
This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.
Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure.
Conditions | Need |
---|---|
CANN Version | >=5.0.3 |
Chip Platform | Ascend310/Ascend310P3 |
3rd Party Requirements | Please follow the 'requirements.txt' |
git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git
cd Modelzoo-TensorFlow/ACL_TensorFlow/contrib/nlp/BioBERT_for_ACL
Download the dataset by yourself, more details see: [data] Download the vocab.txt and bert_config.json by yourself, more details see: config
Obtain the fine-tuned checkpoint files or pb model, more details see: ckpt or models
Build the inference application, more details see: xacl_fmk Put xacl to the current dictory.
BioBERT
Configure the env
export install_path=/usr/local/Ascend
export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH
export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH
export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH
export ASCEND_OPP_PATH=${install_path}/opp
PreProcess
python3 xnlp_fmk.py \
--data_dir=./data/NCBI \
--output_dir=./data/NCBI \
--vocab_file=./config/biobert_base/vocab.txt \
--bert_config_file=./config/biobert_base/bert_config.json \
--do_lower_case=False \
--model_name=biobert \
--task_name=ner \
--action_type=preprocess
Freeze pb model
python3 xnlp_fmk.py \
--output_dir=./save/model \
--bert_config_file=./config/biobert_base/bert_config.json \
--pb_model_file=./save/model/BIOBERT_BASE_NER_BatchSize_None.pb \
--checkpoint_dir=./save/ckpt/biobert_base_ner \
--model_name=biobert \
--task_name=ner \
--action_type=freeze
Convert pb to om
python3 xnlp_fmk.py \
--output_dir=./save/model \
--pb_model_file=./save/model/BIOBERT_BASE_NER_BatchSize_None.pb \
--om_model_file=./save/model/BIOBERT_BASE_NER_BatchSize_1.om \
--predict_batch_size=1 \
--soc_version="Ascend310" \
--in_nodes="\"input_ids:1,128;input_mask:1,128;segment_ids:1,128\"" \
--out_nodes="\"logits:0\"" \
--model_name=biobert \
--task_name=ner \
--action_type=atc
Run the inference
python3 xnlp_fmk.py \
--data_dir=./data/NCBI \
--output_dir=./save/output \
--om_model_file=./save/model/BIOBERT_BASE_NER_BatchSize_1.om \
--predict_batch_size=1 \
--model_name=biobert \
--task_name=ner \
--action_type=npu
PostProcess
python3 xnlp_fmk.py \
--data_dir=./data/NCBI \
--output_dir=./save/output \
--vocab_file=./config/biobert_base/vocab.txt \
--om_model_file=./save/model/BIOBERT_BASE_NER_BatchSize_1.om \
--predict_batch_size=1 \
--do_lower_case=False \
--model_name=biobert \
--task_name=ner \
--action_type=postprocess
Convert pb to pbtxt
python3 xnlp_fmk.py \
--output_dir=./save/model \
--pb_model_file=./save/model/BIOBERT_BASE_RE_BatchSize_None.pb \
--model_name=biobert \
--task_name=re \
--action_type=pbtxt
Run the inference by pb model
python3 xnlp_fmk.py \
--data_dir=./data/GAD \
--output_dir=./save/output \
--pb_model_file=./save/model/BIOBERT_BASE_RE_BatchSize_None.pb \
--predict_batch_size=1 \
--in_nodes="\"input_ids:1,128;input_mask:1,128;segment_ids:1,128\"" \
--out_nodes="\"logits:0\"" \
--model_name=biobert \
--task_name=re \
--action_type=cpu
[1] https://arxiv.org/abs/1810.04805
[2] https://github.com/google-research/bert
[3] https://github.com/kyzhouhzau/BERT-NER
[4] https://github.com/zjy-ucas/ChineseNER
[5] https://github.com/hanxiao/bert-as-service
[6] https://github.com/macanv/BERT-BiLSTM-CRF-NER
[7] https://github.com/tensorflow/tensor2tensor
[8] https://github.com/google-research/albert
[9] https://github.com/brightmart/albert_zh
[10] https://github.com/HqWei/Sentiment-Analysis
[11] https://gitee.com/wang-bain/xacl_fmk
[12] https://github.com/brightmart/roberta_zh
[13] https://github.com/dmis-lab/biobert
[14] https://github.com/Songweiping/GRU4Rec_TensorFlow
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。