File size: 2,051 Bytes
676533d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#!/usr/bin/env python3
"""
Integration test for softmax selection with backend word service.
"""
import os
def test_backend_integration():
"""Test how the backend would use the softmax selection"""
print("🧪 Testing backend integration with softmax selection...")
# Simulate backend environment variables
os.environ['SIMILARITY_TEMPERATURE'] = '0.7'
os.environ['USE_SOFTMAX_SELECTION'] = 'true'
# Test the interface that backend services would use
from thematic_word_generator import UnifiedThematicWordGenerator
generator = UnifiedThematicWordGenerator()
print("✅ Generator created with softmax enabled")
# Test the key parameters
print(f"📊 Configuration:")
print(f" Temperature: {generator.similarity_temperature}")
print(f" Softmax enabled: {generator.use_softmax_selection}")
# Test different temperature values
test_temperatures = [0.3, 0.7, 1.0, 1.5]
print(f"\n🌡️ Testing different temperatures:")
for temp in test_temperatures:
generator.similarity_temperature = temp
if temp == 0.3:
print(f" {temp}: More deterministic (favors high similarity)")
elif temp == 0.7:
print(f" {temp}: Balanced (recommended default)")
elif temp == 1.0:
print(f" {temp}: Standard softmax")
elif temp == 1.5:
print(f" {temp}: More random (flatter distribution)")
print(f"\n📝 Backend usage example:")
print(f" # Set environment variables:")
print(f" export SIMILARITY_TEMPERATURE=0.7")
print(f" export USE_SOFTMAX_SELECTION=true")
print(f" ")
print(f" # Use in backend:")
print(f" generator = UnifiedThematicWordGenerator()")
print(f" words = generator.generate_thematic_words(['animals'], num_words=15)")
print(f" # Words will be selected using softmax-weighted sampling")
print("✅ Backend integration test completed!")
if __name__ == "__main__":
test_backend_integration() |