With the continuous progress of information technology and communication technology,we have entered the era of intelligent industry.In this era,the application of various intelligent technologies is driving the upgrading and transformation of industry,and new generation information technologies such as artificial intelligence technology,5G technology,and industrial internet technology are continuously promoting the progress and development of the era.
Artificial intelligence technology is one of the core technologies in the era of intelligent industry.Artificial intelligence technology includes machine learning,deep learning,natural language processing,computer vision,and so on.The application of these technologies enables machines to learn,understand,and judge independently,and can help industrial enterprises achieve automated,intelligent,and efficient production and management.
通过torch.onnx.export接口进行转换,其中input_names,out_names是模型的输入输出在模型构建时取的名字。
input_names=['input_ids','input_masks','token_type_ids']
outputs_names=['output1','output2']
onnx_name='convert.onnx'
torch.onnx.export(model,(),onnx_name,input_names=input_names,
output_names=outputs_names,verbose=True,opset_version=11,
dynamic_axes={'input_ids':{0:'batch_size'},
{'input_masks':{0:'batch_size'},
{'token_type_ids':{0:'batch_size'},
{'output1':{0:'batch_size'},
{'output2':{0:'batch_size'}})
sent_tokens=fine_grade_tokenize(sen,tokenizer)
encode_dict=tokenizer.encode_plus(text=sent_tokens,
max_length=MAX_SEQ_LEN,
is_pretokenized=True,
pad_to_max_length=True,
return_tensors='pt',
return_token_type_ids=True,
return_attention_mask=True)
batch_size=32
input1=encode_dict['input_ids']
input2=encode_dict['attention_masks']
input3=encode_dict['token_type_ids']
batch_input1=torch.repeat_interleave(input1,repeats=batch_size,dim=0)
batch_input2=torch.repeat_interleave(input2,repeats=batch_size,dim=0)
batch_input3=torch.repeat_interleave(input3,repeats=batch_size,dim=0)
tensor_input0=torch.LongTensor(batch_input1)
tensor_input1=torch.LongTensor(batch_input2)
tensor_input2=torch.LongTensor(batch_input3)