| | |
| | """ |
| | 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...") |
| | |
| | |
| | os.environ['SIMILARITY_TEMPERATURE'] = '0.7' |
| | os.environ['USE_SOFTMAX_SELECTION'] = 'true' |
| | |
| | |
| | from thematic_word_generator import UnifiedThematicWordGenerator |
| | |
| | generator = UnifiedThematicWordGenerator() |
| | print("✅ Generator created with softmax enabled") |
| | |
| | |
| | print(f"📊 Configuration:") |
| | print(f" Temperature: {generator.similarity_temperature}") |
| | print(f" Softmax enabled: {generator.use_softmax_selection}") |
| | |
| | |
| | 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() |