CoreML Text Classifier in Message Filter

Hi all,

I'm trying to build a scam detection in Message Filter powered by CoreML. I find the predictions of ML reliable and the solution for text frauds and scams are sorely needed.

I was able to create a trained MLModel and deploy it in the app. It works on my container app, but when I try to use and initialise the model in the Message Filter extension, I get an error;

initialization of text classifier model with model data failed

I have tried putting the model in the container app, extension, even made a shared framework for container and extension but to no avail. Every time I invoke the codes to init my model from the extension, I am met with the same error.

Here's my code for initializing the model

do {
    let model = try Ace_v24_6(configuration: .init())
    let output = try model.prediction(text: text)
    
    guard !output.label.isEmpty else {
        return nil
    }
    
    return MessagePrediction(rawValue: output.label)
} catch {
    return nil
}

My question is: Is it impossible to use CoreML in MessageFilters?

Cheers

I would not say it is impossible, but due to the restrictive sandbox message filters need to execute in, you are likely running into the allowed memory limits and would also be careful about behavioral restrictions like trying to access private information.

This unfortunately creates a dilemma, as you won't be allowed to access any network resources you need to have all your resources in the extension, which contributes to the memory limit issue.

Like I said, not impossible, but could be limited, and may need some creative thinking.

CoreML Text Classifier in Message Filter
 
 
Q