KhmerCoreMLSMSClassifier
A Swift package for on-device classification of Khmer SMS messages using CoreML. Features lightweight, offline processing with specialized Khmer language text preprocessing.
Install / Use
/learn @VatanaChhorn/KhmerCoreMLSMSClassifierREADME
KhmerCoreMLSMSClassifier
A Swift package for classifying Khmer SMS messages as spam or legitimate using CoreML. Built with modern Swift practices and optimized for on-device machine learning.
Features
- 🚀 Lightweight, efficient SMS classification
- 🇰🇭 Specifically designed for Khmer language messages
- 📱 Works completely offline with on-device processing
- 🔄 Handles text preprocessing for improved accuracy
- 🧠 Leverages CoreML for efficient inference
- ⚙️ Easily customizable with your own trained models
Requirements
- iOS 16.0+ / macOS 13.0+
- Swift 6.0+
- Xcode 15.0+
Installation
Swift Package Manager
Add the following line to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/vatanachhorn/KhmerCoreMLSMSClassifier.git", from: "1.0.0")
]
Or add it directly in Xcode:
- Go to File > Add Package Dependencies
- Enter the repository URL:
https://github.com/vatanachhorn/KhmerCoreMLSMSClassifier.git - Select the version or branch you want to use
Usage
Basic Classification
import KhmerCoreMLSMSClassifier
// Initialize the classifier
let classifier = KhmerCoreMLSMSClassifier()
// Classify a Khmer message
let message = "ពេលនេះ លោកអ្នកទទួលបានប្រាក់ ១០០$ សូមចុចតំណរភ្ជាប់ដើម្បីទទួលយកប្រាក់ https://example.com/claim"
let category = classifier.classify(message: message)
switch category {
case .spam:
print("This message is spam")
case .ham:
print("This message is legitimate")
case .unknown:
print("Could not determine message category")
}
Classification with Confidence Score
// Get classification with confidence score
let result = classifier.getDetailedClassification(message: message)
print("Category: \(result.category.rawValue), Confidence: \(result.confidence * 100)%")
// Get all confidence scores for each category
let confidences = classifier.classifyWithConfidence(message: message)
for (category, confidence) in confidences {
print("\(category.rawValue): \(confidence * 100)%")
}
Text Preprocessing
The package includes a text preprocessor specifically designed for Khmer language:
import KhmerCoreMLSMSClassifier
let originalText = " ពេលនេះ លោកអ្នកទទួលបានប្រាក់ ១០០$ សូមចុចតំណរភ្ជាប់ដើម្បីទទួលយកប្រាក់ https://example.com/claim "
let normalizedText = TextPreprocessor.normalizeKhmerText(originalText)
print(normalizedText)
// Output: "ពេលនេះ លោកអ្នកទទួលបានប្រាក់ ១០០ សូមចុចតំណរភ្ជាប់ដើម្បីទទួលយកប្រាក់ https://example.com/claim"
iOS Example App
An iOS example application is included in the Examples directory that demonstrates all the features of the package:
Example App Features
- Basic Classification: Simple classification of Khmer SMS messages
- Detailed Classification: Visualization of classification with confidence scores
- Text Preprocessing: Demonstration of Khmer text normalization with highlighted changes
Running the Example
- Open
Examples/KhmerCoreMLSMSClassifierExample/KhmerCoreMLSMSClassifierExample.xcodeprojin Xcode - Select your iOS device or simulator
- Build and run the project
For more details, see the Example App README.
Architecture
The package is organized into a modular structure:
Sources/
└── KhmerCoreMLSMSClassifier/
├── Core/ # Core functionality and primary classifier
├── Models/ # CoreML model loader and generated model classes
├── Utils/ # Helper utilities such as text preprocessing
└── Resources/ # CoreML model files
Running the Console Demo
The package also includes a command-line demo application:
swift run KhmerCoreMLSMSClassifierDemo
Performance Considerations
- The classifier works entirely on-device, maintaining user privacy
- Model inference is fast and suitable for real-time classification
- Memory usage is minimal, making it suitable for mobile applications
License
This project is available under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Author
Created by Vatana Chhorn
Related Skills
next
A beautifully designed, floating Pomodoro timer that respects your workspace.
product-manager-skills
50PM skill for Claude Code, Codex, Cursor, and Windsurf: diagnose SaaS metrics, critique PRDs, plan roadmaps, run discovery, and coach PM career transitions.
pm
PM Agent Rule This rule is triggered when the user types `@pm` and activates the Product Manager agent persona.
