Skip to content

Latest commit

 

History

History
184 lines (133 loc) · 5.07 KB

File metadata and controls

184 lines (133 loc) · 5.07 KB

RefNet Design Document

Overview

RefNet (Reflective Evaluation Network) is a transformer-based neural architecture designed to model and predict introspective metrics in Self-Reflective AI (SRAI) systems. The model processes sequences of thought tokens and outputs predictions for valence, semantic metric distance (SMD), quality, and next cognitive action.

Architecture

Core Components

1. Input Processing

  • Input Format: Sequences of 256-dimensional embeddings representing thought tokens
  • Sequence Length: Configurable maximum length (default: 64 tokens)
  • Padding: Zero-padding for variable-length sequences

2. Positional Encoding

  • Type: Sinusoidal positional encoding
  • Purpose: Provides sequence position information to the transformer
  • Implementation: Standard transformer sinusoidal positional encoding (fixed, non-learnable)

3. Transformer Encoder

  • Architecture: Multi-layer transformer encoder
  • Default Configuration:
    • Model dimension: 256
    • Attention heads: 8
    • Layers: 6
    • Feed-forward dimension: 1024 (4 × d_model)
    • Dropout: 0.1

4. Multi-Task Output Heads

  • Valence Head: Linear layer → 1 output (regression)
  • SMD Head: Linear layer → 1 output (regression)
  • Quality Head: Linear layer → 1 output (binary classification)
  • Action Head: Linear layer → 4 outputs (multi-class classification)

Data Flow

Input Embeddings (B, L, 256)
    ↓
Linear Projection (256 → 256)
    ↓
Positional Encoding Addition
    ↓
Transformer Encoder (6 layers)
    ↓
Global Average Pooling (L → 1)
    ↓
Multi-Task Heads
    ↓
Outputs: {valence, smd, quality, next_action}

Loss Function

The model uses a weighted combination of multiple loss functions:

L_total = λ_valence × MSE(valence_pred, valence_true) +
          λ_smd × MSE(smd_pred, smd_true) +
          λ_quality × BCE(quality_pred, quality_true) +
          λ_action × CE(action_pred, action_true)

Default Loss Weights

  • λ_valence = 1.0
  • λ_smd = 1.0
  • λ_quality = 0.5
  • λ_action = 0.5

Training Configuration

Optimizer

  • Type: AdamW
  • Learning Rate: 0.0003
  • Weight Decay: 0.01
  • Epochs: 20

Data Configuration

  • Batch Size: 32
  • Max Sequence Length: 64
  • Shuffle: Training data shuffled, validation data not shuffled

Input/Output Specifications

Input Format

{
  "tokens": [
    {
      "token_name": "reflect",
      "embed": [256-dimensional vector],
      "metrics": {"valence": float, "smd": float},
      "edges": []
    }
  ]
}

Output Format

{
  "valence": float,      // Emotional tone prediction
  "smd": float,          // Semantic metric distance prediction
  "quality": float,      // Thought quality prediction (0-1)
  "next_action": tensor  // Action logits [consolidate, recall, reframe, evaluate_alignment]
}

Model Capabilities

Predictions

  1. Valence: Predicts emotional tone of thought sequences
  2. SMD: Estimates semantic metric distance between thoughts
  3. Quality: Assesses thought quality (binary classification)
  4. Next Action: Predicts the most likely next cognitive action

Supported Actions

  • consolidate: Integrate information
  • recall: Retrieve stored information
  • reframe: Restructure understanding
  • evaluate_alignment: Check consistency

Design Rationale

Why Transformer Architecture?

  • Sequence Modeling: Naturally handles variable-length thought sequences
  • Attention Mechanism: Captures long-range dependencies in thought processes
  • Parallelization: Efficient training on modern hardware

Why Multi-Task Learning?

  • Shared Representations: Common features benefit all prediction tasks
  • Regularization: Multiple objectives prevent overfitting
  • Efficiency: Single model for multiple predictions

Why Global Average Pooling?

  • Sequence Length Independence: Works with variable-length inputs
  • Computational Efficiency: Reduces computational complexity
  • Interpretability: Provides single representation per sequence

Performance Considerations

Computational Requirements

  • Memory: ~2GB GPU memory for default configuration
  • Training Time: ~5-10 minutes on modern GPU for 20 epochs
  • Inference: Real-time prediction capability

Scalability

  • Model Size: ~1M parameters
  • Sequence Length: Limited by memory, tested up to 512 tokens
  • Batch Size: Scales linearly with available memory

Future Enhancements

Potential Improvements

  1. Attention Visualization: Add attention weight analysis
  2. Hierarchical Modeling: Multi-scale sequence processing
  3. Dynamic Weights: Adaptive loss weight adjustment
  4. Uncertainty Quantification: Prediction confidence estimation
  5. Few-Shot Learning: Adaptation to new domains

Research Directions

  • Interpretability: Understanding model decision-making
  • Causal Modeling: Capturing causal relationships in thoughts
  • Multi-Modal: Incorporating additional modalities
  • Real-Time: Optimizing for streaming applications