ONNX Runtime Mobile Question Answering iOS sample application with Ort-Extensions support for pre/post processing
This is a basic Question Answering example application for ONNX Runtime on iOS with Ort-Extensions support for pre/post processing. The demo app accomplishes the task of basic QA, i.e. gives answers based on user provided context.
The model used here is from source: HuggingFace and accomodated into ONNX version with pre/post processing support.
- Install Xcode 13.0 and above (preferably latest version)
- A valid Apple Developer ID
- An iOS device or iOS simulator
- Xcode command line tools
xcode-select --install
- Clone the
onnxruntime-inference-examples
source code repo
-
Install CocoaPods.
sudo gem install cocoapods
-
In terminal, run
pod install
under<onnxruntime-inference-example-root>/mobile/examples/question_answering/ios/
to generate the workspace file and install required pod files.Note: At the end of this step, you should get a file called
ORTQuestionAnswering.xcworkspace
. -
Prepare the required model used in this sample.
Use provided
prepare_model.py
script undermobile/examples/question_answering/android/
to do the model-preparing work. The whole procedure includes four steps.- download model from huggingface.
- convert model to onnx.
- quantize onnx model.
- add pre/post processing to onnx model.
Note: See more information in
mobile/examples/question_answering/android/README.md
.cd mobile/examples/question_answering/android bash prepare_models.sh
Note: Currently the model is already provided under
mobile/examples/question_answering/ios/ORTQuestionAnswering/ORTQuestionAnswering/csarron_mobilebert_uncased_squad_v2_quant_with_pre_post_processing.onnx
-
Open
<ONNXRuntime-inference-example-root>/mobile/examples/question_answering/ios/ORTQuestionAnswering.xcworkspace
in Xcode and make sure to select your corresponding development team underTarget-General-Signing
for a proper codesign procedure to run the app (only on device required, if running on iOS simulator can skip this step.) -
Connect your iOS device/simulator, build and run the app. Click
Get Answers!
button to see performed answer based on the given context. A default hint message will be displayed on initial screen.
Here's an example screenshot of the app: