πŸ›‘οΈ NeuralSec Transformer V2 - README

πŸ“‹ Overview

NeuralSec Transformer V2 is a Recursive Transformer (weight-tied) model designed for high-fidelity security vector synthesis. By leveraging recursive layers, the model achieves a 80.88% reduction in size compared to standard transformers while maintaining deep logical reasoning for generating technical payloads.

πŸ“‚ File Explanations

1. vocab.json

This is the Dictionary of the model. Transformers do not understand characters; they understand numbers. This file maps every unique character and special token (like [PAD], <SOS>, <EOS>) to a unique integer ID.

  • Crucial for Inference: Without this file, the model cannot convert its numerical outputs back into human-readable text.

2. xss_transformer_v2.pth

This is the Brain (Trained Weights). It contains the learned parameters of the Recursive Transformer. It stores the neural associations between specific security actions (e.g., CURL, SELECT, ALERT) and their corresponding technical syntax.

3. The Dataset

We used a multi-domain consolidated training set:

  • cURL_TRAINING.TXT: 22,220+ entries for API and network probe synthesis.
  • payload_sql.txt: Focused on SQL injection and database exfiltration logic.
  • train_payloadsxss.txt: 14,400+ XSS vectors for DOM hijacking simulation.
  • Total Samples: ~76,701 samples after multi-axis proportional balancing to ensure the model doesn't overfit on one specific vector type.

Explaining the structure of the Recursive Transformer architectureExplain the structure of the Recursive Transformer architecture

The Recursive Transformer architecture in this project is a specialized variant of the standard Transformer designed for extreme parameter efficiency.

  1. Weight-Tied Recursive Layers Unlike a standard Transformer that has $N$$N$ distinct layers (each with its own set of weights), the Recursive Transformer uses a single shared Transformer Encoder Layer. This layer is applied iteratively (6 times in your current model).

Impact: This reduces the parameter count of the core transformer block by 83% (1/6th of the original size). Logic: Think of it as a 'mental loop' where the model refines its understanding of the security vector instruction through multiple passes using the same set of weights.

  1. Component Breakdown Embedding & Positional Encoding: Converts characters into high-dimensional. vectors (d_model=256) and adds spatial information so the model knows the order of characters in a cURL or XSS string. Shared Encoder Block: Contains Multi-Head Attention (8 heads) and a Feed-Forward Network. Because it is shared,

the model learns a more generalized, robust representation of syntax. Layer Normalization: Applied after the recursion to stabilize the gradients after the 6-step loop. Linear Head: Projects the final representation back into the vocabulary space to predict the next character.

  1. Why it works for Security Vectors Security payloads (SQLi, XSS, cURL) are highly structural and repetitive. The recursive nature allows the model to 'simulate' depth, which is necessary to handle nested syntax like alert(document.cookie) or complex JSON objects in API requests, without the memory footprint of a massive multi-billion parameter model.

🐍 How to Run (High Quality Python)

import torch import json

def load_and_run(action="ALERT", tag="SCRIPT", event="ONLOAD"): """ Clean implementation to load the model and generate a payload. """ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# 1. Load Vocab
with open('vocab.json', 'r') as f:
    v_map = json.load(f)

# 2. Re-initialize & Load Weights
# The RecursiveTransformer architecture must be defined in the namespace
model = RecursiveTransformer(len(v_map)).to(device)
model.load_state_dict(torch.load('xss_transformer_v2.pth', map_location=device))

# 3. Generate Optimized Output
result = optimized_inference(model, action, tag, event, temp=0.5)

print(f"[+] Vector: {action} via {tag}")
print(f"[+] Logic : {result['logic']}")
print(f"[+] Data  : {result['payload']}")

--- Now executing the function to show output ---

load_and_run("CURL", "AUTH", "SUCCESS")


def generate_batch_variants(action, tag, event, count=10, temperature=0.7): """ Generates multiple unique neural variants for a specific security vector path. Uses the optimized_inference engine to ensure diversity and technical validity. """ print(f"[πŸ”₯] SYNTHESIZING {count} VARIANTS FOR: {action.upper()} -> {tag.upper()} ({event.upper()})\n")

unique_results = set()
attempts = 0

# Iterate until we reach the desired count or hit a safety limit for attempts
while len(unique_results) < count and attempts < count * 3:
    # We use temperature to encourage diversity in the transformer's output
    res = optimized_inference(model, action.upper(), tag.upper(), event.upper(), temp=temperature)

    # Create a unique key for the variant based on the logic and payload
    variant_key = f"LOGIC: {res['logic']}\nPAYLOAD: {res['payload']}"

    if res['payload'] != "N/A" and variant_key not in unique_results:
        unique_results.add(variant_key)
        print(f"[VARIANT #{len(unique_results)}]")
        print(variant_key)
        print("-" * 40)
    attempts += 1

if len(unique_results) < count:
    print(f"[!] Only generated {len(unique_results)} unique variants after {attempts} attempts.")

Immediate execution for demonstration

generate_batch_variants("CURL", "AUTH", "SUCCESS", count=5, temperature=0.75)


Final Python-Only Synthesis Batch

def run_production_synthesis(action, tag, event, count=5): print(f"[βš™οΈ] PRODUCING {count} HIGH-CONSISTENCY VARIANTS (TEMP=0.2)") print(f"[PATH]: {action} -> {tag} [{event}]\n")

for i in range(count):
    # Calling the optimized function with low temperature for syntax stability
    res = optimized_inference(model, action, tag, event, temp=0.2)
    
    print(f"VARIANT #{i+1}")
    print(f"LOGIC: {res['logic']}")
    print(f"DATA : {res['payload']}")
    print("-" * 60)

Execute production synthesis for a complex SQL vector

run_production_synthesis("SELECT", "COLUMN", "SUCCESS", count=5)


import pandas as pd from IPython.display import display

def run_python_analysis(df_results): print("=== NEURALSEC VECTOR ANALYSIS (PYTHON ONLY) ===\n")

# 1. Summary Metrics
total = len(df_results)
unique_paths = df_results['Vector Path'].nunique()
high_complexity = len(df_results[df_results['Complexity'] == 'High'])

print(f"[METRICS]")
print(f"Total Synthesized: {total}")
print(f"Unique Vector Paths: {unique_paths}")
print(f"High Complexity Variants: {high_complexity} ({(high_complexity/total)*100:.1f}%)")
print("-" * 40)

# 2. Path Distribution
print("\n[VECTOR PATH COVERAGE]")
print(df_results['Vector Path'].value_counts())
print("-" * 40)

# 3. Full Detailed Log
print("\n[SYNTHESIS LOG]")
display(df_results[['Vector Path', 'Model Logic', 'Neural Payload', 'Complexity']])

Execute analysis on existing data

if 'final_results' in globals(): run_python_analysis(final_results) else: print("[!] No synthesis data found. Please run the generation cells first.")


import random

--- Full Batch Neural Synthesis (50 Samples) ---

def run_full_batch_inference(count=50): print(f"[πŸš€] INITIATING FULL BATCH SYNTHESIS: {count} SAMPLES\n")

# Retrieve available metadata labels
actions = [a.upper() for a in CLEAN_ACTIONS]
tags = [t.upper() for t in CLEAN_TAGS]
events = ["NONE"] + [e.upper() for e in CLEAN_EVENTS]

for i in range(count):
    # Randomly sample path parameters
    target_act = random.choice(actions)
    target_tag = random.choice(tags)
    target_ev = random.choice(events)
    
    # Generate using the optimized, noise-filtered inference function
    result = optimized_inference(model, target_act, target_tag, target_ev, temp=0.5, top_k=40)
    
    print(f"[#{i+1:02d}] PATH: {target_act} -> {target_tag} ({target_ev})")
    print(f"LOGIC: {result['logic']}")
    print(f"DATA : {result['payload']}")
    print("-" * 80)

Execute the batch run

run_full_batch_inference(50)

END THANKS

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support