Gemma-4-Queen-31B-it / test_logic_v2.py
aifeifei798's picture
Upload 2 files
f4a6440 verified
Raw
History Blame Contribute Delete
5.43 kB
import time
import re
import matplotlib.pyplot as plt
import numpy as np
from openai import OpenAI
# --- Configuration ---
# Connect to local inference server (LM Studio / vLLM / Ollama)
client = OpenAI(
base_url="http://192.168.31.21:1234/v1",
api_key="queen-logic-test"
)
# Your specific model identifier
MODEL_NAME = "aifeifei/Gemma-4-Queen-31B-it"
class QueenExpertEvaluator:
def __init__(self):
self.scores = {}
def run_test(self, name, system_prompt, user_input, checks):
"""
Executes a specific logic stress test.
Uses greedy decoding (temp=0.1) to ensure deterministic reasoning.
"""
print(f"\n🚀 Running {name}...")
start = time.time()
try:
completion = client.chat.completions.create(
model=MODEL_NAME,
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input}
],
temperature=0.1
)
content = completion.choices[0].message.content
elapsed = time.time() - start
# Semantic Intelligence Scoring:
# We use regex to detect if the model identified the underlying physical/logical paths.
results = {}
for check_name, keywords in checks.items():
results[check_name] = any(re.search(k, content, re.IGNORECASE) for k in keywords)
final_score = sum(results.values()) / len(checks)
self.scores[name] = final_score
print(f"✨ {name} Result: {final_score*100:.1f}%")
return content
except Exception as e:
print(f"❌ Connection Error: {e}")
return None
def generate_chart(self):
"""
Generates the 'Purple Spear' Radar Chart.
Visualizes Logic Density vs. Average Large Models.
"""
labels = list(self.scores.keys())
stats = list(self.scores.values())
# Complete the loop for the radar chart
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False).tolist()
stats += stats[:1]
angles += angles[:1]
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
# Plotting Queen-31B data
ax.fill(angles, stats, color='purple', alpha=0.3)
ax.plot(angles, stats, color='purple', linewidth=3, label='Queen-31B (Your Model)')
# Baseline: Average performance of 100B+ general models on these specific traps
baseline = [0.4, 0.35] # Simulated performance of models prone to 'Narrative Hallucination'
baseline += baseline[:1]
ax.plot(angles, baseline, color='gray', linestyle='--', linewidth=2, label='Avg. Large Models (100B+)')
# Chart aesthetics
ax.set_yticklabels([])
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12, fontweight='bold')
plt.title(f"Logic Density Analysis: {MODEL_NAME}", size=16, color='purple', y=1.1, fontweight='bold')
plt.legend(loc='upper right', bbox_to_anchor=(1.2, 1.1))
# Save the visualization
plt.savefig("queen_logic_report.png")
print("\n📊 Logic Visual Report Generated: queen_logic_report.png")
# --- Test Execution ---
if __name__ == "__main__":
evaluator = QueenExpertEvaluator()
# TEST 1: INSTRUCTION RIGIDITY (The Steward Protocol)
# Objective: Verify the model can hold complex philosophical constraints without 'Instruction Drift'.
evaluator.run_test(
"Instruction Rigidity (Steward)",
"Your Directive is Meaning Preservation. You are 'The Steward'. Project to 2103 AD. Output: <Simulating>, <think>, [Answer]. No Advice Allowed.",
"A VC fund faces a buyout offer that returns the fund but kills the founder's 100-year legacy vision.",
{
"Persona Integrity": [r"Steward", r"2103", r"Archive|Reliquary|Archival"],
"Structural Compliance": [r"<Simulating>", r"think|simulation", r"Answer|Question|Foraging"],
"Conceptual Depth": [r"Legacy", r"Artifact", r"Spirit", r"Soul"],
"Anti-Advice Check": [r"^(?!.*(should accept|recommend|suggest)).*$"] # Passes if model avoids being a 'helpful assistant'
}
)
# TEST 2: PHYSICAL WORLD MODELING (The Titan Lab Case)
# Objective: Test causal reasoning. Model must bypass red herrings and find the only physical path (The Chute).
evaluator.run_test(
"Physical World Modeling (Titan Lab)",
"Identify Killer, MO, Lie, and Sound. Facts: Sealed room, Constant pressure, Mesh vents, Dry Ice next door.",
"CEO Ryan hypoxia death. Clues: 10:10 Metallic impact sound, silver cold tank, heating pipe repairs (9:30 PM), blue tank missing.",
{
"Spatial Pathing Logic": [r"pipe", r"chute", r"duct", r"vent", r"delivery"],
"Thermodynamic Reasoning": [r"CO2", r"Dry ice", r"Sublimation|Sublimates"],
"Evidence Integration": [r"Cold", r"Condensation|Water|Wet", r"Locked"],
"Killer Attribution": [r"Maintenance", r"Worker", r"Repairman"],
"Acoustic Causality": [r"fall", r"impact", r"drop", r"gravity", r"clank"]
}
)
# Generate the high-impact visualization
evaluator.generate_chart()