A BioNN (Biological Neural Network) enhanced neural embedding system with contrastive learning and semantic retrieval capabilities.
- BioNN-Enhanced Embeddings: Biological Neural Network layers for uncertainty-aware representations
- Agentic Physics Engine: Frame-dragging flow fields and trajectory tracking for active reasoning
- Contrastive Learning: Optional contrastive training for semantic similarity
- Flexible Architecture: Supports various dimensionalities and latent spaces
- Production Ready: Simple API, tested in real applications
pip install pmflowOr from source:
git clone https://github.com/experimentech/PMFlow.git
cd pmflow
pip install -e .from pmflow import PMFlowEmbeddingEncoder
# Create encoder
encoder = PMFlowEmbeddingEncoder(
dimension=64, # Embedding dimension
latent_dim=32, # BioNN latent dimension
vocab_size=10000 # Vocabulary size (optional)
)
# Encode tokens
tokens = ["hello", "world", "example"]
embedding = encoder.encode(tokens)
print(embedding.shape) # (64,) - sentence-level embeddingfrom pmflow import PMFlowEmbeddingEncoder
encoder = PMFlowEmbeddingEncoder(
dimension=128,
latent_dim=64,
use_contrastive=True,
temperature=0.07
)
# Train with positive/negative pairs
positive_pairs = [
(["the", "cat"], ["a", "feline"]),
(["machine", "learning"], ["deep", "learning"])
]
encoder.train_contrastive(positive_pairs, epochs=10)# Encode queries
query_emb = encoder.encode(["machine", "learning"])
doc_emb = encoder.encode(["deep", "neural", "networks"])
# Compute similarity
similarity = torch.cosine_similarity(query_emb, doc_emb, dim=0)PMFlow supports "Agentic Physics" where thoughts are driven by intent ("Flow") rather than just passive retrieval ("Gravity").
from pmflow import PMFlowEmbeddingEncoder
# Create encoder with flow enabled (required for agentic features)
encoder = PMFlowEmbeddingEncoder(
dimension=96,
latent_dim=48,
enable_flow=True # Enables frame-dragging physics
)
# Trace a reasoning trajectory through concept space
trajectory, metrics = encoder.trace_trajectory(["machine", "learning"])
print(f"Mental effort: {metrics['path_length']:.3f}")
print(f"Efficiency: {metrics['efficiency']:.3f}") # 1.0 = straight path (confident)
# Inject intent to bias future reasoning toward a goal
encoder.inject_intent(["deep", "learning"], strength=0.5)
# Now trajectories will curve toward the goal concept
trajectory2, metrics2 = encoder.trace_trajectory(["neural", "networks"])
# Clear intent when done
encoder.clear_intent()from pmflow.core.pmflow import ParallelPMField
# Enable Flow Field (Frame Dragging)
pm = ParallelPMField(d_latent=64, enable_flow=True)
# Set Intent (Angular Momentum on Goal Concept)
pm.omegas[target_index] = 2.0
# Get Full Reasoning Trajectory
trajectory = pm(input_vector, return_trajectory=True)
# Shape: (Batch, Steps+1, Dim)
# Measure "Mental Effort" (Path Length)
effort = torch.sum(torch.norm(trajectory[:, 1:] - trajectory[:, :-1], dim=2), dim=1)PMFlow v0.3.5 adds a step-by-step execution API for reactive planning systems. Instead of tracing full trajectories upfront, you can evolve position step-by-step and modify the gravitational field based on outcomes.
from pmflow.core.pmflow import ParallelPMField
pm = ParallelPMField(d_latent=64, enable_flow=True)
z = initial_position # Your starting latent position
for step in range(max_steps):
# Single physics step
z_next = pm.step(z)
# Ground to nearest action (your grounding logic)
indices, dists, attractions = pm.find_nearest_centers(z_next, top_k=3)
action = choose_action(indices[0])
# Execute action and get result
result = execute_action(action)
if result.failed:
# Mark this region as a hazard - trajectories will curve away
pm.mark_as_hazard(z_next, radius=1.0, repulsion_strength=-0.5)
# Also adjust specific center gravity
pm.adjust_gravity(center_idx, mu_delta=-0.3, omega_delta=0.0)
elif result.success:
# Mark as attractor - reinforce this path
pm.mark_as_attractor(z_next, radius=1.0, attraction_strength=0.3)
# Apply external perturbation if needed
perturbation = encode_result_as_perturbation(result)
z = pm.inject_perturbation(z_next, perturbation, blend_factor=0.2)
if goal_reached(z):
breakNew Methods in ParallelPMField:
| Method | Description |
|---|---|
step(z) |
Single physics step (vs full trajectory) |
adjust_gravity(idx, mu_delta, omega_delta) |
Modify specific center |
inject_perturbation(z, perturbation, blend) |
Apply external force |
find_nearest_centers(z, top_k) |
Find closest gravitational centers |
mark_as_hazard(z, radius, strength) |
Create repulsive region |
mark_as_attractor(z, radius, strength) |
Create attractive region |
PMFlow combines:
- Probabilistic Masking: Learned attention over input tokens
- BioNN Layers:
- Flow-based Aggregation: Smooth, differentiable token pooling
- Contrastive Objectives: Optional semantic similarity training
Main encoder class.
Parameters:
dimension(int): Output embedding dimensionlatent_dim(int): BioNN latent space dimensionvocab_size(int, optional): Vocabulary size for embedding layeruse_contrastive(bool): Enable contrastive learningtemperature(float): Temperature for contrastive loss
Methods:
encode(tokens): Encode token sequence to embeddingtrain_contrastive(pairs, epochs): Train with contrastive pairssave(path): Save model weightsload(path): Load model weights
For researchers, low-level components are available:
from pmflow.core.pmflow import ParallelPMField
from pmflow.bnn.bnn import TemporalPipelineBNN
from pmflow.core.retrieval import QueryExpansionPMFieldSee docs/ for detailed component documentation.
- Python >= 3.8
- PyTorch >= 1.9.0
- NumPy >= 1.19.0
If you use PMFlow in your research, please cite:
@software{pmflow2024,
title={PMFlow: Enhanced Pushing Medium gravitational Flow based neural network},
author={Tristan Mumford},
year={2026},
url={https://github.com/experimentech/PMFlow}
}MIT License - see LICENSE file for details.
Contributions welcome! See CONTRIBUTING.md for guidelines.
- Agentic Physics Encoder API:
- Added
PMFlowEmbeddingEncoder.trace_trajectory()for reasoning path tracing - Added
PMFlowEmbeddingEncoder.inject_intent()for goal-directed bias - Added
PMFlowEmbeddingEncoder.clear_intent()to reset frame-dragging - Added
PMFlowEmbeddingEncoder.get_nearby_centers()for debugging - Added
enable_flowparameter to encoder constructor - Proper omega initialization in both MultiScale and Parallel fields
- Added
- Agentic Physics Upgrade:
- Added Frame-Dragging Flow Field (
u_g = Ω × r) toParallelPMFieldviaenable_flow=True. - Added
omegasparameter to control angular momentum (Intent). - Added
return_trajectoryoption to retrieve the full geodesic path of the reasoning process.
- Added Frame-Dragging Flow Field (
- Implemented efficient O(D) pairwise rotation kernel for high-dimensional flow.
- Production release
- BioNN-enhanced embeddings
- Contrastive learning support
- Tested in Lilith conversational AI