Is it possible to save or convert the result of an NLP text classification job as an ONNX model?

James 5 Reputation points
2023-03-31T13:49:11.2066667+00:00

Is it possible to save or convert the result of an NLP text classification job as an ONNX model? For normal classification tasks, I know it's possible using the enable_onnx_compatible_models parameter.

But for NLP Text Classification jobs using the Python SDK v2, I can't seem to find any parameter like this. I've checked the reference in https://learn.microsoft.com/en-us/python/api/azure-ai-ml/azure.ai.ml.automl.textclassificationjob?view=azure-python, as well as the example notebooks in https://github.com/Azure/azureml-examples/tree/main/sdk/python/jobs/automl-standalone-jobs, but I couldn't find any examples of converting it to ONNX format.

Is this something that can be done using the Python SDK v2 or some other library?

For reference the code I'm using to create the job looks something like this:

from azure.ai.ml import automl

text_classification_job = automl.text_classification(
    compute=compute_cluster_name,
    experiment_name=experiment_name,
    training_data=training_data,
    validation_data=validation_data,
    target_column_name="labels",
    primary_metric="accuracy"
)


returned_job = ml_client.jobs.create_or_update(
    text_classification_job
)
Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,587 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
977 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 46,996 Reputation points
    2023-04-01T20:00:31.3766667+00:00

    Hello @James

    Thanks for reaching out to us, there are two ways you may have a try -

    1.AutoML & ONNX

    With Azure Machine Learning, you can use automated ML to build a Python model and have it converted to the ONNX format. Once the models are in the ONNX format, they can be run on a variety of platforms and devices. Learn more about accelerating ML models with ONNX.

    See how to convert to ONNX format in this Jupyter notebook example. Learn which algorithms are supported in ONNX.

    I would suggest you to see the notebook example but please make sure it is supported in the ONNX.

    2.Try the onnxconverter-common package if above not working

    The onnxconverter-common package provides common functions and utilities for use in converters from various AI frameworks to ONNX. It also enables the different converters to work together to convert a model from mixed frameworks, like a scikit-learn pipeline embedding a xgboost model.

    https://github.com/microsoft/onnxconverter-common

    At the meantime, I have contact Azure machine learning sdk team to check since in the document there is not a clear way to do so. I will let you know once I get any response from them.

    I hope this helps.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.