Fix: During ONNX inference, the tensor of the return value of the tokenizer is now obtained in Numpy's NDArray format to eliminate the dependency on PyTorch
This commit is contained in:
@@ -98,7 +98,7 @@ def extract_bert_feature_onnx(
|
||||
"""
|
||||
|
||||
tokenizer = onnx_bert_models.load_tokenizer(Languages.ZH)
|
||||
inputs = tokenizer(text, return_tensors="pt")
|
||||
inputs = tokenizer(text, return_tensors="np")
|
||||
|
||||
session = onnx_bert_models.load_model(
|
||||
language=Languages.ZH,
|
||||
@@ -108,21 +108,21 @@ def extract_bert_feature_onnx(
|
||||
res = session.run(
|
||||
[output_name],
|
||||
{
|
||||
"input_ids": inputs["input_ids"].detach().numpy(), # type: ignore
|
||||
"token_type_ids": inputs["token_type_ids"].detach().numpy(), # type: ignore
|
||||
"attention_mask": inputs["attention_mask"].detach().numpy(), # type: ignore
|
||||
"input_ids": inputs["input_ids"],
|
||||
"token_type_ids": inputs["token_type_ids"],
|
||||
"attention_mask": inputs["attention_mask"],
|
||||
},
|
||||
)[0]
|
||||
|
||||
style_res_mean = None
|
||||
if assist_text:
|
||||
style_inputs = tokenizer(assist_text, return_tensors="pt")
|
||||
style_inputs = tokenizer(assist_text, return_tensors="np")
|
||||
style_res = session.run(
|
||||
[output_name],
|
||||
{
|
||||
"input_ids": style_inputs["input_ids"].detach().numpy(), # type: ignore
|
||||
"token_type_ids": style_inputs["token_type_ids"].detach().numpy(), # type: ignore
|
||||
"attention_mask": style_inputs["attention_mask"].detach().numpy(), # type: ignore
|
||||
"input_ids": style_inputs["input_ids"],
|
||||
"token_type_ids": style_inputs["token_type_ids"],
|
||||
"attention_mask": style_inputs["attention_mask"],
|
||||
},
|
||||
)[0]
|
||||
style_res_mean = np.mean(style_res, axis=0)
|
||||
|
||||
Reference in New Issue
Block a user