Views
No views yet
| Model | Download | Download (with sample test data) | ONNX version | Opset version | Accuracy |
|---|---|---|---|---|---|
| BiDAF | 41.5 MB | 37.3 MB | 1.4 | 9 | EM of 68.1 in SQuAD v1.1 |
| BiDAF-int8 | 12 MB | 8.7 MB | 1.13.1 | 11 | EM of 65.93 in SQuAD v1.1 |
Compared with the fp32 BiDAF, int8 BiDAF accuracy drop ratio is 0.23% and performance improvement is 0.89x in SQuAD v1.1.The performance depends on the test hardware. Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
1import numpy as np
2import string
3from nltk import word_tokenize
4
5def preprocess(text):
6tokens = word_tokenize(text)
7# split into lower-case word tokens, in numpy array with shape of (seq, 1)
8words = np.asarray([w.lower() for w in tokens]).reshape(-1, 1)
9# split words into chars, in numpy array with shape of (seq, 1, 1, 16)
10chars = [[c for c in t][:16] for t in tokens]
11chars = [cs+['']*(16-len(cs)) for cs in chars]
12chars = np.asarray(chars).reshape(-1, 1, 1, 16)
13return words, chars
14
15# input
16context = 'A quick brown fox jumps over the lazy dog.'
17query = 'What color is the fox?'
18cw, cc = preprocess(context)
19qw, qc = preprocess(query)# assuming answer contains the np arrays for start_pos/end_pos
start = np.asscalar(answer[0])
end = np.asscalar(answer[1])
print([w.encode() for w in cw[start:end+1].reshape(-1)])[b'brown'].wget https://github.com/onnx/models/raw/main/text/machine_comprehension/bidirectional_attention_flow/model/bidaf-9.onnx1import onnx
2from onnx import version_converter
3
4model = onnx.load('bidaf-9.onnx')
5model = version_converter.convert_version(model, 11)
6onnx.save_model(model, 'bidaf-11.onnx')1bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
2--dataset_location=path/to/squad/dev-v1.1.json
3--output_model=path/to/model_tune