sevensense-learning
Graph Neural Network (GNN) learning for bioacoustic pattern discovery.
sevensense-learning implements online learning algorithms that discover patterns in bird vocalizations over time. Using Graph Neural Networks with Elastic Weight Consolidation (EWC), it learns species-specific call patterns, dialect variations, and behavioral signatures without forgetting previously learned knowledge.
Features
- GNN Architecture: Graph-based learning on similarity networks
- EWC Regularization: Prevents catastrophic forgetting in online learning
- Online Updates: Continuous learning from streaming data
- Transition Graphs: Model sequential call patterns
- Fisher Information: Importance-weighted parameter updates
- Gradient Checkpointing: Memory-efficient training
Use Cases
| Use Case | Description | Key Functions |
|---|---|---|
| Pattern Learning | Learn call patterns | train(), learn_patterns() |
| Online Updates | Incremental learning | online_update() |
| Transition Modeling | Sequential patterns | TransitionGraph::learn() |
| EWC Training | Continual learning | ewc_train() |
| Inference | Pattern prediction | predict(), infer() |
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
Creating from Embeddings
use ;
// Config for graph construction
let config = GraphConfig ;
// Build graph from embeddings with timestamps
let graph = new;
for in recordings.iter
// Automatically computes edges based on similarity
graph.build_edges?;
println!;
Analyzing Graph Structure
use TransitionGraph;
// Get neighbors for a node
let neighbors = graph.neighbors?;
for in neighbors
// Compute graph statistics
let stats = graph.statistics;
println!;
println!;
println!;
Sequential Patterns
// Analyze sequential call patterns
let sequences = graph.find_sequences?;
for seq in sequences
Basic Training
use ;
let model_config = GnnConfig ;
let mut model = new;
let train_config = TrainingConfig ;
// Train on graph
let history = model.train?;
println!;
println!;
Training with Validation
let = split_graph?;
let history = model.train_with_validation?;
// Plot training curves
for in history.iter
Custom Loss Functions
use ;
// Contrastive loss for similarity learning
let loss_fn = Contrastive ;
model.set_loss_function;
model.train?;
Why EWC?
Standard neural networks suffer from "catastrophic forgetting"—learning new patterns erases old ones. EWC prevents this by protecting important parameters.
EWC Training
use ;
let ewc_config = EwcConfig ;
let mut model = new;
// Train on first dataset
model.train?;
// Compute Fisher information (importance weights)
model.compute_fisher?;
// Train on second dataset with EWC
model.ewc_train?;
// Model remembers patterns from both datasets!
Continual Learning Pipeline
use ;
let mut learner = new;
// Learn from streaming data batches
for batch in data_stream
// Test on all historical patterns
let recall = learner.evaluate_recall?;
println!;
Incremental Updates
use ;
let online_config = OnlineConfig ;
let mut model = new;
model.enable_online_learning;
// Process streaming data
for sample in stream
Experience Replay
use ;
let mut buffer = new; // Store 1000 samples
let mut model = new;
for sample in stream
Predicting Similar Patterns
use GnnModel;
let model = load?;
// Get learned representation
let embedding = model.encode?;
// Find similar learned patterns
let similar = model.find_similar?;
for in similar
Predicting Next Call
// Given a sequence of calls, predict the next one
let sequence = vec!;
let prediction = model.predict_next?;
println!;
println!;
Anomaly Detection
use ;
let detector = new;
for embedding in embeddings
Configuration
GnnConfig Parameters
| Parameter | Default | Description |
|---|---|---|
input_dim |
1536 | Input embedding dimension |
hidden_dim |
256 | Hidden layer dimension |
output_dim |
64 | Output dimension |
num_layers |
3 | Number of GNN layers |
dropout |
0.1 | Dropout rate |
EwcConfig Parameters
| Parameter | Default | Description |
|---|---|---|
lambda |
1000.0 | Regularization strength |
fisher_samples |
200 | Samples for Fisher estimation |
online |
true | Use online EWC variant |
Architecture
Input Embeddings (1536-dim)
│
▼
┌─────────┐
│ GNN │ ◄── Graph structure (adjacency)
│ Layer 1 │
└────┬────┘
│
┌────▼────┐
│ GNN │
│ Layer 2 │
└────┬────┘
│
┌────▼────┐
│ GNN │
│ Layer 3 │
└────┬────┘
│
▼
Output Embeddings (64-dim)
Links
- Homepage: ruv.io
- Repository: github.com/ruvnet/ruvector
- Crates.io: crates.io/crates/sevensense-learning
- Documentation: docs.rs/sevensense-learning
License
MIT License - see LICENSE for details.
Part of the 7sense Bioacoustic Intelligence Platform by rUv