dspy.ts
Version:
DSPy.ts - Declarative Self-Learning TypeScript: A framework for compositional LM pipelines with self-improving prompt strategies.
78 lines (66 loc) • 1.85 kB
Markdown
# ONNX Example Implementation Log
## Overview
Added example demonstrating ONNX model integration with DSPy.ts for sentiment analysis.
## Changes Made
### 1. Core Implementation (examples/onnx/index.ts)
- Created SentimentModule class extending Module
- Implemented text to feature vector conversion
- Added ONNX model integration with proper error handling
- Set up pipeline-based processing
- Added resource cleanup
### 2. Test Coverage (tests/examples/onnx.spec.ts)
- Added comprehensive test suite
- Mocked ONNX model and file system
- Covered all key functionality:
- Model initialization
- Sentiment analysis
- Feature vector generation
- Error handling
- Pipeline execution
- Resource cleanup
### 3. Documentation (examples/onnx/README.md)
- Added setup instructions
- Included usage examples
- Documented configuration options
- Provided advanced usage patterns
## Technical Details
### Model Output Format
```typescript
{
label: {
cpuData: { 0: string },
dataLocation: "cpu",
type: "int64",
dims: [1],
size: 1
},
probabilities: {
cpuData: [number, number],
dataLocation: "cpu",
type: "float32",
dims: [1, 2],
size: 2
}
}
```
### Feature Vector Generation
- Text is split into words
- Words are matched against feature vocabulary
- Occurrences are counted into fixed-size vector
- Vector size matches model input requirements (11 features)
### Error Handling
- Input validation
- Model initialization errors
- Inference errors
- Resource cleanup errors
- Pipeline execution errors
## Testing Results
- All tests passing
- Coverage for key functionality
- Proper error cases tested
- Pipeline integration verified
## Next Steps
- Consider adding more advanced text preprocessing
- Add support for custom vocabularies
- Implement batched inference
- Add performance benchmarks