Text Analysis System Documentation
Overview
The Text Analysis System is a core component of Gradiant that provides advanced natural language processing capabilities for therapy sessions. It combines multiple ML models and rule-based systems to analyze text content while maintaining HIPAA compliance.Components
1. Emotion Model
- Uses RoBERTa-based model fine-tuned on emotion detection
- Provides primary and secondary emotions with intensity scores
- Normalizes emotions to a standard set for consistency
2. Therapy Technique Model
- Zero-shot classification for therapy technique identification
- Supports common techniques like CBT, DBT, mindfulness
- Provides confidence scores for detected techniques
3. Crisis Detection Model
- Specialized model for identifying crisis situations
- Five-level severity classification
- Real-time trigger detection and immediate action flags
4. Semantic Analysis
- Rule-based system for extracting:
- Key phrases and themes
- Relationship context
- Temporal information
- Setting detection
5. HIPAA Compliance Checker
- Pattern-based PHI detection
- Identifies sensitive information categories
- Flags content requiring redaction
Enhancements
Emotion Model
- New Emotion Categories: Added
shame,guilt,envy,pride, andreliefto the emotion detection capabilities.
Therapy Technique Model
- Expanded Techniques: Recognizes additional therapy techniques including:
- Narrative Therapy
- Acceptance Commitment Therapy
- Emotionally Focused Therapy
- Interpersonal Therapy
- Play Therapy
Crisis Detection Model
- Nuanced Categories: Enhanced crisis detection with:
- Severe Anxiety
- Depression
- Psychosis
Usage
Security and Compliance
The system is designed with security and HIPAA compliance in mind:- All operations are logged through SecurityAuditService
- PHI detection prevents accidental data exposure
- Crisis detection triggers immediate safety protocols
- Data is processed with appropriate encryption
Testing
Comprehensive test suite includes:- Unit tests for each model
- Integration tests for the TextAnalysisService
- HIPAA compliance validation tests
- Crisis detection accuracy tests
- EmotionModel tests now cover unknown labels, empty inputs, and multiple emotions.
- TextAnalysisService tests include scenarios for handling no emotions, multiple techniques, and crisis detection.
Future Enhancements
-
Multi-modal Analysis
- Audio emotion detection
- Video sentiment analysis
- Non-verbal cue recognition
-
Advanced Features
- Therapy progress tracking
- Outcome prediction
- Treatment recommendation
-
Performance Optimization
- Model quantization
- Batch processing
- Caching strategies
Dependencies
- @xenova/transformers: ^2.15.0
- TypeScript
- (for testing)
Contributing
When contributing to the text analysis system:- Follow TypeScript best practices
- Maintain HIPAA compliance
- Add appropriate tests
- Update documentation
- Consider performance implications
Monitoring and Maintenance
The system includes:- Performance monitoring
- Error tracking
- Usage analytics
- Model version control
- Update ML models
- Review security logs
- Validate HIPAA compliance
- Optimize performance