Prior to developing the chatbot, when using tokenizer in CoreML, there is a problem that it cannot be converted from the existing Python code.

 

CoreML has a problem because it receives a "number array" as input, and the "string" input cannot be converted. When converting a PyTorch or TensorFlow model to Core ML, only the weight and operation of the model are converted, and the tokenizer operates in Python code, so it is deleted without being converted.

 

Therefore, a temporary model was implemented to confirm whether the function of the kobert model was executed when converting the KoBERT model to the CoreML model.

 

Methods for converting the Kobert model into the CoreML model is as follow.

  • Initial Implementation Method : PyTorch → ONNX → CoreML

Why convert the pytorch model through ONNX instead of directly converting it to CoreML? 

-> Because Open Neural Network Exchange (ONNX) translates models into intermediate formats, increasing compatibility across different frameworks!
Core ML does not fully support the direct transformation of PyTorch models, so it can be transformed more reliably through ONNX.

 

PyTorch → ONNX → CoreML

[PyTorch Model] → (ONNX Converting) → [ONNX Model] → (CoreML Converting) → [CoreML Model],
Run the Core ML model on iOS

 

Since mlmodel cannot be opened in Xcode, it is recommended to change it to mlpackage format and open it in an ios environment. In addition, when opening a file converted from Xcode, you should check whether the input and output sizes and types are the same. When the file was opened in Xcode, it was confirmed that int32, the data type of the input and output of the file, was not converted correctly. Since CoreML does not support int64 or int32, it unifies the input and output types as float32.

 

When the model of the project is completed in the future, it will be converted into CoreML in the same way as above.

 

 

Additionally, when I tried to open mlpackage through Xcode in an ios environment(iMAC 24), an outputSchema problem occurred. 

The cause of the problem was that Bert_model's path was inaccurate.

I learned that it is necessary to double-check the code after changing the name of the folder or moving the data.

+ Recent posts