sentiment-analyzer-coreml
This is a CoreML version of the DistilBERT sentiment analysis model, converted from the Hugging Face model distilbert-base-uncased-finetuned-sst-2-english
.
Model Details
- Original Model:
distilbert-base-uncased-finetuned-sst-2-english
- Task: Sentiment Analysis
- Framework: CoreML
- Input: Text (tokenized as input_ids and attention_mask)
- Output: Logits for sentiment classification (2 classes: negative, positive)
Usage
Python (CoreML)
import coremltools as ct
# Load the model
model = ct.models.MLModel("sentiment_analyzer.mlpackage")
# Get model spec
spec = model.get_spec()
print("Model type:", spec.WhichOneof('Type'))
# Make predictions (you'll need to tokenize your input first)
# The model expects input_ids and attention_mask as inputs
Swift (iOS/macOS)
import CoreML
// Load the model
guard let model = try? MLModel(contentsOf: URL(fileURLWithPath: "sentiment_analyzer.mlpackage")) else { return }
// Make predictions
// You'll need to convert your text to the required input format
Input Format
The model expects two inputs:
input_ids
: Tokenized input text (shape: [1, sequence_length])attention_mask
: Attention mask (shape: [1, sequence_length])
Output Format
The model outputs logits for sentiment classification:
- Shape: [1, 2] (batch_size, num_classes)
- Classes: [negative, positive]
Conversion Notes
This model was converted using coremltools from the original PyTorch model. The conversion process involved:
- Loading the Hugging Face model
- Wrapping it to return only logits (tensor output)
- Tracing with PyTorch JIT
- Converting to CoreML format
Requirements
- iOS 15+ / macOS 12+ (for ML Program format)
- CoreML framework
- Downloads last month
- 6