UNPARTYTextClassifier.mlmodel

UNPARTYTextClassifier Documentation

Overview

UNPARTYTextClassifier.mlmodel is a Core ML model trained to classify text into sentiment categories. The model uses a Maximum Entropy algorithm and is designed to be incrementally trained as users interact with the app.

Model Specifications

Input Features

struct ModelInput {
    let text: String
}

Output Features

struct ModelOutput {
    let label: String
    let labelProbabilities: [String: Double]
}

Model Parameters

  • Algorithm: Maximum Entropy

  • Iterations: 10

  • Platform Compatibility: iOS 12.0+, macOS 10.14+

  • Input Type: Text (String)

  • Output Type: Classification with probabilities

Using the Model

Basic Usage

import CoreML

func classifyText(_ text: String) throws -> String {
    let config = MLModelConfiguration()
    guard let model = try? UnpartyTextClassifier(configuration: config) else {
        throw ClassificationError.modelLoadFailed
    }
    
    let input = UnpartyTextClassifierInput(text: text)
    let prediction = try model.prediction(input: input)
    
    return prediction.label
}

With Probability Scores

func classifyWithProbabilities(_ text: String) throws -> (label: String, confidence: Double) {
    let config = MLModelConfiguration()
    let model = try UnpartyTextClassifier(configuration: config)
    
    let input = UnpartyTextClassifierInput(text: text)
    let prediction = try model.prediction(input: input)
    
    return (prediction.label, prediction.labelProbabilities[prediction.label] ?? 0)
}

Error Handling

enum ClassificationError: Error {
    case modelLoadFailed
    case predictionFailed
    case invalidInput
}

Integration Points

With TextEmbeddingsService

class TextEmbeddingsService {
    private let classifier: UnpartyTextClassifier?
    
    init() {
        classifier = try? UnpartyTextClassifier(configuration: MLModelConfiguration())
    }
    
    func processText(_ text: String) async throws -> (embeddings: [Float], classification: String) {
        // Combine embeddings and classification
    }
}

With TrainingDataManager

extension TrainingDataManager {
    func updateModelWithNewData(_ data: TrainingData) async throws {
        // Handle model updates with new training data
    }
}

Best Practices

  1. Model Loading

    • Load model once at initialization

    • Handle loading errors gracefully

    • Configure model based on device capabilities

  2. Performance

    • Process text on background threads

    • Cache results when appropriate

    • Monitor memory usage

  3. Error Handling

    • Validate input text

    • Handle prediction errors

    • Provide fallback classifications

  4. Model Updates

    • Version control model updates

    • Validate new training data

    • Test model performance after updates

Limitations

  1. Input Constraints

    • Text length limitations

    • Language support (English primary)

    • Character encoding requirements

  2. Performance Considerations

    • Memory usage for large texts

    • Processing time variations

    • Device compatibility requirements

  3. Training Constraints

    • Minimum data requirements

    • Training frequency limits

    • Storage space needs

  • TextEmbeddingsService: Uses classifications for embedding context

  • TrainingDataManager: Provides data for model updates

  • MLTrainingService: Handles model retraining

  • ModelPersistenceManager: Manages model versions

Last updated