Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Punk-and-The-Monk committed Nov 29, 2019
1 parent f6b9c2f commit e9d1869
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ Targeting to release before Dec 5th. 目标是12月5日前发布。

## 模型

使用 [albert_zh_small](https://github.com/brightmart/albert_zh) 预训练模型,额外加上一层全连接做answer span预测
使用 [albert_zh_small](https://github.com/brightmart/albert_zh) 预训练模型,额外加上一层全连接做answer span预测

* 模型训练
* 在CMRC2018数据集的验证集上,max_seq_len为512的模型得分为F1:75.989, EM:52.097, Average:64.038,max_seq_len为384的模型得分为F1:74.781, EM:51.010, Average:62.895
* max_seq_len为512的模型使用tflite转换后大小为18M,经测试,该模型在4线程的安卓手机上推理延时为580ms左右,在单线程条件下为1.4s左右。
* max_seq_len为384的模型使用tflite转换后大小为18M,经测试,该模型在4线程的安卓手机上推理延时为390ms左右,在单线程条件下为930ms左右

​ 已完成,待提交

* 用tflite转换模型

​ 已完成,待提交
* 模型训练与模型转换过程见[bert_cn_finetune-master](https://github.com/CLUEbenchmark/MobileQA/tree/master/bert_cn_finetune-master)



## Android Demo

已完成第一版,详见 [tflite-android-transformers-master](https://github.com/CLUEbenchmark/MobileQA/tree/master/tflite-android-transformers-master)

效果示例:

![android demo](./media/example.gif)

## IOS Demo

Expand Down
46 changes: 28 additions & 18 deletions bert_cn_finetune-master/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
## 基于中文的机器阅读理解模型

代码引用自 https://github.com/ewrfcas/bert_cn_finetune
基于中文的机器阅读理解模型
1.下载albert_small_zh_google放入文件夹中。地址:https://storage.googleapis.com/albert_zh/albert_small_zh_google.zip
2.python cmrc2018_finetune_tf_albert.py (由于后期转tflite文件,训练过程中不要使用tf.float16)
3.将生成的模型转pb(在转pb以及tflite的过程中要确保tensorflow版本为1.15.0)
pip install tensorflow==1.15.0
freeze_graph --input_checkpoint albert_model.ckpt \
--output_graph albert_tiny_zh.pb \
--output_node_names finetune_mrc/truediv \
--checkpoint_version 1 --input_meta_graph albert_model.ckpt.meta --input_binary true
4.pb文件转tflite文件
pip install tf-nightly
tflite_convert --graph_def_file albert_tiny_zh.pb \
--input_arrays 'input_ids,input_masks,segment_ids' \
--output_arrays 'finetune_mrc/add, finetune_mrc/add_1'\
--input_shapes 1,512:1,512:1,512 \
--output_file saved_model.tflite \
--enable_v1_converter --experimental_new_converter


## 模型训练

1. 下载albert_small_zh_google放入文件夹中。地址:https://storage.googleapis.com/albert_zh/albert_small_zh_google.zip

2. python cmrc2018_finetune_tf_albert.py

(注意:由于后期转tflite文件,训练过程中不要使用tf.float16)

## 模型转换

1. 将生成的模型转pb(在转pb以及tflite的过程中要确保tensorflow版本为1.15.0)
pip install tensorflow==1.15.0
freeze_graph --input_checkpoint albert_model.ckpt \
--output_graph albert_tiny_zh.pb \
--output_node_names finetune_mrc/truediv \
--checkpoint_version 1 --input_meta_graph albert_model.ckpt.meta --input_binary true
2. pb文件转tflite文件
pip install tf-nightly
tflite_convert --graph_def_file albert_tiny_zh.pb \
--input_arrays 'input_ids,input_masks,segment_ids' \
--output_arrays 'finetune_mrc/add, finetune_mrc/add_1'\
--input_shapes 1,512:1,512:1,512 \
--output_file saved_model.tflite \
--enable_v1_converter --experimental_new_converter

Binary file added media/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e9d1869

Please sign in to comment.