MLTextClassifier confidence?

The only output from a MLModel trained with an MLTextClassifier is a String, but there (doesn't appear) to be a way of getting a confidence level from this model.


When using the model, knowing if there isn't a good prediction is as important as using the prediction itself.


Bugreport: 41837555

You can get confidence level for the whole model on test data with MLClassifierMetrics.


This article may provide some info as well

h ttps://developer.apple.com/documentation/create_ml/improving_your_model_s_accuracy

Has anyone managed to get the confidence level? It still doesn't seem to be working.

I discovered that you can use NLModel for predictions. Here's an example:

guard let model = model,
              let nlModel = try? NLModel(mlModel: model) else {
            Logger.categoryClassifier.error("Failed to load NLModel.")
            return nil
        }
        
        let hypotheses = nlModel.predictedLabelHypotheses(for: name.lowercased(), maximumCount: 10)

For more details, refer to the documentation: https://developer.apple.com/documentation/naturallanguage/nlmodel

MLTextClassifier confidence?
 
 
Q