Skip to content

Instantly share code, notes, and snippets.

@matheusruschel
Created March 10, 2023 17:15
Show Gist options
  • Save matheusruschel/5070ac57d696093b9f5013bd868c3e91 to your computer and use it in GitHub Desktop.
Save matheusruschel/5070ac57d696093b9f5013bd868c3e91 to your computer and use it in GitHub Desktop.
ReviewClassifier.swift
import CoreML
import NaturalLanguage
class ReviewClassifier {
let model: NLModel
init() {
let modelURL = Bundle.main.url(forResource: "ReviewModel", withExtension: "mlmodelc")!
model = try! NLModel(contentsOf: modelURL)
}
func classifyReview(text: String) -> String {
let classification = model.predictedLabel(for: text)
print("Classification: \(classification)")
return classification
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment