@hazeljs/ml 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +37 -36
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -98,10 +98,7 @@ export class MLController {
98
98
 
99
99
  @Post('predict')
100
100
  async predict(@Body() body: { text: string; model?: string }) {
101
- const result = await this.predictor.predict(
102
- body.model ?? 'sentiment-classifier',
103
- body
104
- );
101
+ const result = await this.predictor.predict(body.model ?? 'sentiment-classifier', body);
105
102
  return { result };
106
103
  }
107
104
  }
@@ -115,13 +112,13 @@ The package uses three decorators to declare ML models and their behaviour. The
115
112
 
116
113
  Marks a class as an ML model and attaches **registry metadata**. Required so the model can be registered and looked up by name/version.
117
114
 
118
- | Property | Type | Required | Description |
119
- |---------------|----------|----------|-------------|
115
+ | Property | Type | Required | Description |
116
+ | ------------- | -------- | -------- | ------------------------------------------------ |
120
117
  | `name` | string | Yes | Unique model id (e.g. `'sentiment-classifier'`). |
121
- | `version` | string | Yes | Semver (e.g. `'1.0.0'`). |
122
- | `framework` | string | Yes | `'tensorflow'` \| `'onnx'` \| `'custom'`. |
123
- | `description` | string | No | Human-readable description. |
124
- | `tags` | string[] | No | Tags for filtering (default: `[]`). |
118
+ | `version` | string | Yes | Semver (e.g. `'1.0.0'`). |
119
+ | `framework` | string | Yes | `'tensorflow'` \| `'onnx'` \| `'custom'`. |
120
+ | `description` | string | No | Human-readable description. |
121
+ | `tags` | string[] | No | Tags for filtering (default: `[]`). |
125
122
 
126
123
  **Example:** One model per class; use `@Injectable()` so the app can construct it.
127
124
 
@@ -145,11 +142,11 @@ export class SpamClassifier {
145
142
 
146
143
  Marks the **single method** that trains this model. `TrainerService.train(modelName, data)` will call it. Optional config is for documentation or pipeline wiring.
147
144
 
148
- | Option | Type | Default | Description |
149
- |-------------|--------|-----------|-------------|
145
+ | Option | Type | Default | Description |
146
+ | ----------- | ------ | ----------- | ----------------------------------------------------------------------- |
150
147
  | `pipeline` | string | `'default'` | Name of a registered `PipelineService` pipeline to run before training. |
151
- | `batchSize` | number | `32` | Hint for batching (your logic can ignore it). |
152
- | `epochs` | number | `10` | Hint for epochs (your logic can ignore it). |
148
+ | `batchSize` | number | `32` | Hint for batching (your logic can ignore it). |
149
+ | `epochs` | number | `10` | Hint for epochs (your logic can ignore it). |
153
150
 
154
151
  **Example:** Exactly one `@Train()` method per model; it receives training data and can return metrics.
155
152
 
@@ -167,10 +164,10 @@ async train(data: { samples: Array<{ text: string; label: string }> }): Promise<
167
164
 
168
165
  Marks the **single method** that runs inference. `PredictorService.predict(modelName, input)` will call it.
169
166
 
170
- | Option | Type | Default | Description |
171
- |-----------|---------|------------|-------------|
172
- | `batch` | boolean | `false` | Hint that the method supports batch input (semantic only). |
173
- | `endpoint`| string | `'/predict'` | Hint for route naming (semantic only). |
167
+ | Option | Type | Default | Description |
168
+ | ---------- | ------- | ------------ | ---------------------------------------------------------- |
169
+ | `batch` | boolean | `false` | Hint that the method supports batch input (semantic only). |
170
+ | `endpoint` | string | `'/predict'` | Hint for route naming (semantic only). |
174
171
 
175
172
  **Example:** Exactly one `@Predict()` method per model; it receives one input and returns a prediction object.
176
173
 
@@ -200,12 +197,7 @@ Models are registered when passed to `MLModule.forRoot({ models: [...] })`. The
200
197
  import { registerMLModel, ModelRegistry, TrainerService, PredictorService } from '@hazeljs/ml';
201
198
 
202
199
  // When injecting ModelRegistry in a custom service:
203
- registerMLModel(
204
- sentimentInstance,
205
- modelRegistry,
206
- trainerService,
207
- predictorService
208
- );
200
+ registerMLModel(sentimentInstance, modelRegistry, trainerService, predictorService);
209
201
  ```
210
202
 
211
203
  ## Training pipeline
@@ -217,8 +209,17 @@ import { PipelineService } from '@hazeljs/ml';
217
209
 
218
210
  const pipeline = new PipelineService();
219
211
  const steps = [
220
- { name: 'normalize', transform: (d: unknown) => ({ ...(d as object), text: (d as { text: string }).text?.toLowerCase() }) },
221
- { name: 'filter', transform: (d: unknown) => (d as { text: string }).text?.length > 0 ? d : null },
212
+ {
213
+ name: 'normalize',
214
+ transform: (d: unknown) => ({
215
+ ...(d as object),
216
+ text: (d as { text: string }).text?.toLowerCase(),
217
+ }),
218
+ },
219
+ {
220
+ name: 'filter',
221
+ transform: (d: unknown) => ((d as { text: string }).text?.length > 0 ? d : null),
222
+ },
222
223
  ];
223
224
  // Inline steps (no registration required)
224
225
  const processed = await pipeline.run(data, steps);
@@ -259,8 +260,8 @@ class EvaluationService {
259
260
  ];
260
261
  const evaluation = await this.metricsService.evaluate('sentiment-classifier', testData, {
261
262
  metrics: ['accuracy', 'f1', 'precision', 'recall'],
262
- labelKey: 'label', // key in test sample for ground truth
263
- predictionKey: 'sentiment', // key in prediction result (auto-detect: label, sentiment, class)
263
+ labelKey: 'label', // key in test sample for ground truth
264
+ predictionKey: 'sentiment', // key in prediction result (auto-detect: label, sentiment, class)
264
265
  });
265
266
  // evaluation.metrics: { accuracy, precision, recall, f1Score }
266
267
  // Result is automatically recorded via recordEvaluation()
@@ -278,14 +279,14 @@ metricsService.recordEvaluation({
278
279
 
279
280
  ## API summary
280
281
 
281
- | Service | Purpose |
282
- |---------|---------|
283
- | `ModelRegistry` | Register and lookup models by name/version |
284
- | `TrainerService` | Discover and invoke `@Train` methods |
285
- | `PredictorService` | Discover and invoke `@Predict` methods |
286
- | `PipelineService` | Data preprocessing pipeline |
287
- | `BatchService` | Batch prediction with configurable batch size |
288
- | `MetricsService` | Model evaluation and metrics tracking |
282
+ | Service | Purpose |
283
+ | ------------------ | --------------------------------------------- |
284
+ | `ModelRegistry` | Register and lookup models by name/version |
285
+ | `TrainerService` | Discover and invoke `@Train` methods |
286
+ | `PredictorService` | Discover and invoke `@Predict` methods |
287
+ | `PipelineService` | Data preprocessing pipeline |
288
+ | `BatchService` | Batch prediction with configurable batch size |
289
+ | `MetricsService` | Model evaluation and metrics tracking |
289
290
 
290
291
  ## Examples
291
292
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazeljs/ml",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
4
4
  "description": "Machine Learning & Model Management for HazelJS framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,5 +48,5 @@
48
48
  "url": "https://github.com/hazeljs/hazel-js/issues"
49
49
  },
50
50
  "homepage": "https://hazeljs.ai",
51
- "gitHead": "906cacdc08d52c4616831b888748f1d1887edb80"
51
+ "gitHead": "e0ed98ca074dd4f7472816d3c32ef576900dcca6"
52
52
  }