James Trageser (jtrag) commited on
fix: institutional URL update and peak resonance search optimization
Browse files- app.py +1 -0
- nrc_engine.py +18 -8
app.py
CHANGED
|
@@ -212,6 +212,7 @@ with gr.Blocks(title="NRC φ^∞ Engine") as demo:
|
|
| 212 |
with gr.Column(scale=4):
|
| 213 |
gr.Markdown("<div class='nrc-title'>φ^∞ Infinite Context Engine</div>")
|
| 214 |
gr.Markdown("<div class='nrc-subtitle'>Institutional High-Dimensional Lattice Resonance</div>")
|
|
|
|
| 215 |
with gr.Column(scale=1):
|
| 216 |
preload_btn = gr.Button("Preload Bible (High-Vol)", variant="secondary")
|
| 217 |
|
|
|
|
| 212 |
with gr.Column(scale=4):
|
| 213 |
gr.Markdown("<div class='nrc-title'>φ^∞ Infinite Context Engine</div>")
|
| 214 |
gr.Markdown("<div class='nrc-subtitle'>Institutional High-Dimensional Lattice Resonance</div>")
|
| 215 |
+
gr.Markdown("[Repository](https://github.com/Nexus-Resonance-Codex/Phi-Infinity-Lattice-Compression) | [Space](https://huggingface.co/spaces/Nexus-Resonance-Codex/LLM-Infinite-Context-Engine)")
|
| 216 |
with gr.Column(scale=1):
|
| 217 |
preload_btn = gr.Button("Preload Bible (High-Vol)", variant="secondary")
|
| 218 |
|
nrc_engine.py
CHANGED
|
@@ -92,21 +92,31 @@ class PhiInfinityEngine:
|
|
| 92 |
padded_query = torch.nn.functional.pad(query_embed, (0, self.lattice_dim - query_embed.shape[-1]))
|
| 93 |
padded_reconstructed = torch.nn.functional.pad(reconstructed, (0, self.lattice_dim - reconstructed.shape[-1]))
|
| 94 |
|
| 95 |
-
resonance
|
|
|
|
| 96 |
|
| 97 |
-
# Calculate per-residual resonance for visualization
|
| 98 |
# We look at how much each residual aligns with the query
|
| 99 |
res_resonances = []
|
|
|
|
|
|
|
| 100 |
for res in residuals:
|
| 101 |
-
#
|
| 102 |
-
score = torch.
|
| 103 |
res_resonances.append(score)
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
return {
|
| 106 |
-
"resonance":
|
|
|
|
|
|
|
| 107 |
"res_resonances": res_resonances,
|
| 108 |
-
"reconstructed_norm": torch.norm(reconstructed).item()
|
| 109 |
-
"query_norm": torch.norm(padded_query).item()
|
| 110 |
}
|
| 111 |
|
| 112 |
def get_spiral_coordinates(self, residuals: List[torch.Tensor], highlights: List[float] = None) -> List[Dict[str, Any]]:
|
|
|
|
| 92 |
padded_query = torch.nn.functional.pad(query_embed, (0, self.lattice_dim - query_embed.shape[-1]))
|
| 93 |
padded_reconstructed = torch.nn.functional.pad(reconstructed, (0, self.lattice_dim - reconstructed.shape[-1]))
|
| 94 |
|
| 95 |
+
# Baseline resonance with the aggregate context
|
| 96 |
+
aggregate_resonance = torch.nn.functional.cosine_similarity(padded_query, padded_reconstructed, dim=0).item()
|
| 97 |
|
| 98 |
+
# Calculate per-residual resonance for visualization and PEAK detection
|
| 99 |
# We look at how much each residual aligns with the query
|
| 100 |
res_resonances = []
|
| 101 |
+
peak_signal = -1.0
|
| 102 |
+
|
| 103 |
for res in residuals:
|
| 104 |
+
# We use cosine similarity for each residual component to find specific signal alignment
|
| 105 |
+
score = torch.nn.functional.cosine_similarity(padded_query, res, dim=0).item()
|
| 106 |
res_resonances.append(score)
|
| 107 |
+
if score > peak_signal:
|
| 108 |
+
peak_signal = score
|
| 109 |
+
|
| 110 |
+
# Final resonance score is a weighted max of peak and aggregate
|
| 111 |
+
# This allows finding specific keywords even in dense manifolds
|
| 112 |
+
final_resonance = max(aggregate_resonance, peak_signal * 1.5)
|
| 113 |
+
|
| 114 |
return {
|
| 115 |
+
"resonance": min(1.0, final_resonance),
|
| 116 |
+
"aggregate_resonance": aggregate_resonance,
|
| 117 |
+
"peak_signal": peak_signal,
|
| 118 |
"res_resonances": res_resonances,
|
| 119 |
+
"reconstructed_norm": torch.norm(reconstructed).item()
|
|
|
|
| 120 |
}
|
| 121 |
|
| 122 |
def get_spiral_coordinates(self, residuals: List[torch.Tensor], highlights: List[float] = None) -> List[Dict[str, Any]]:
|