@holoscript/framework 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ALL-test-results.json +1 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/ROADMAP.md +175 -0
- package/dist/AgentManifest-CB4xM-Ma.d.cts +704 -0
- package/dist/AgentManifest-CB4xM-Ma.d.ts +704 -0
- package/dist/BehaviorTree-BrBFECv5.d.cts +103 -0
- package/dist/BehaviorTree-BrBFECv5.d.ts +103 -0
- package/dist/InvisibleWallet-BB6tFvRA.d.cts +1732 -0
- package/dist/InvisibleWallet-rtRrBOA8.d.ts +1732 -0
- package/dist/OrchestratorAgent-BvWgf9uw.d.cts +798 -0
- package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +798 -0
- package/dist/agents/index.cjs +4790 -0
- package/dist/agents/index.d.cts +1788 -0
- package/dist/agents/index.d.ts +1788 -0
- package/dist/agents/index.js +4695 -0
- package/dist/ai/index.cjs +5347 -0
- package/dist/ai/index.d.cts +1753 -0
- package/dist/ai/index.d.ts +1753 -0
- package/dist/ai/index.js +5244 -0
- package/dist/behavior.cjs +449 -0
- package/dist/behavior.d.cts +130 -0
- package/dist/behavior.d.ts +130 -0
- package/dist/behavior.js +407 -0
- package/dist/economy/index.cjs +3659 -0
- package/dist/economy/index.d.cts +747 -0
- package/dist/economy/index.d.ts +747 -0
- package/dist/economy/index.js +3617 -0
- package/dist/implementations-D9T3un9D.d.cts +236 -0
- package/dist/implementations-D9T3un9D.d.ts +236 -0
- package/dist/index.cjs +24550 -0
- package/dist/index.d.cts +1729 -0
- package/dist/index.d.ts +1729 -0
- package/dist/index.js +24277 -0
- package/dist/learning/index.cjs +219 -0
- package/dist/learning/index.d.cts +104 -0
- package/dist/learning/index.d.ts +104 -0
- package/dist/learning/index.js +189 -0
- package/dist/negotiation/index.cjs +970 -0
- package/dist/negotiation/index.d.cts +610 -0
- package/dist/negotiation/index.d.ts +610 -0
- package/dist/negotiation/index.js +931 -0
- package/dist/skills/index.cjs +1118 -0
- package/dist/skills/index.d.cts +289 -0
- package/dist/skills/index.d.ts +289 -0
- package/dist/skills/index.js +1079 -0
- package/dist/swarm/index.cjs +5268 -0
- package/dist/swarm/index.d.cts +2433 -0
- package/dist/swarm/index.d.ts +2433 -0
- package/dist/swarm/index.js +5221 -0
- package/dist/training/index.cjs +2745 -0
- package/dist/training/index.d.cts +1734 -0
- package/dist/training/index.d.ts +1734 -0
- package/dist/training/index.js +2687 -0
- package/extract-failures.js +10 -0
- package/package.json +82 -0
- package/src/__tests__/bounty-marketplace.test.ts +374 -0
- package/src/__tests__/delegation.test.ts +144 -0
- package/src/__tests__/distributed-claimer.test.ts +147 -0
- package/src/__tests__/done-log-audit.test.ts +342 -0
- package/src/__tests__/framework.test.ts +865 -0
- package/src/__tests__/goal-synthesizer.test.ts +236 -0
- package/src/__tests__/presence.test.ts +223 -0
- package/src/__tests__/protocol-agent.test.ts +254 -0
- package/src/__tests__/revenue-splitter.test.ts +114 -0
- package/src/__tests__/scenario-driven-todo.test.ts +197 -0
- package/src/__tests__/self-improve.test.ts +349 -0
- package/src/__tests__/service-lifecycle.test.ts +237 -0
- package/src/__tests__/skill-router.test.ts +121 -0
- package/src/agents/AgentManifest.ts +493 -0
- package/src/agents/AgentRegistry.ts +475 -0
- package/src/agents/AgentTypes.ts +585 -0
- package/src/agents/AgentWalletRegistry.ts +83 -0
- package/src/agents/AuthenticatedCRDT.ts +388 -0
- package/src/agents/CapabilityMatcher.ts +453 -0
- package/src/agents/CrossRealityHandoff.ts +305 -0
- package/src/agents/CulturalMemory.ts +454 -0
- package/src/agents/FederatedRegistryAdapter.ts +429 -0
- package/src/agents/NormEngine.ts +450 -0
- package/src/agents/OrchestratorAgent.ts +414 -0
- package/src/agents/SkillWorkflowEngine.ts +472 -0
- package/src/agents/TaskDelegationService.ts +551 -0
- package/src/agents/__tests__/AgentManifest.prod.test.ts +134 -0
- package/src/agents/__tests__/AgentManifest.test.ts +182 -0
- package/src/agents/__tests__/AgentModule.test.ts +864 -0
- package/src/agents/__tests__/AgentRegistry.prod.test.ts +125 -0
- package/src/agents/__tests__/AgentRegistry.test.ts +148 -0
- package/src/agents/__tests__/AgentTypes.test.ts +534 -0
- package/src/agents/__tests__/AgentWalletRegistry.test.ts +152 -0
- package/src/agents/__tests__/AuthenticatedCRDT.test.ts +558 -0
- package/src/agents/__tests__/CapabilityMatcher.prod.test.ts +117 -0
- package/src/agents/__tests__/CapabilityMatcher.test.ts +178 -0
- package/src/agents/__tests__/CrossRealityHandoff.test.ts +402 -0
- package/src/agents/__tests__/CulturalMemory.test.ts +200 -0
- package/src/agents/__tests__/FederatedRegistryAdapter.test.ts +409 -0
- package/src/agents/__tests__/NormEngine.test.ts +276 -0
- package/src/agents/__tests__/OrchestratorAgent.test.ts +182 -0
- package/src/agents/__tests__/SkillWorkflowEngine.test.ts +357 -0
- package/src/agents/__tests__/TaskDelegationService.test.ts +446 -0
- package/src/agents/index.ts +107 -0
- package/src/agents/spatial-comms/Layer1RealTime.ts +621 -0
- package/src/agents/spatial-comms/Layer2A2A.ts +661 -0
- package/src/agents/spatial-comms/Layer3MCP.ts +651 -0
- package/src/agents/spatial-comms/ProtocolTypes.ts +543 -0
- package/src/agents/spatial-comms/SpatialCommClient.ts +483 -0
- package/src/agents/spatial-comms/__tests__/performance-benchmark.test.ts +465 -0
- package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +409 -0
- package/src/agents/spatial-comms/index.ts +66 -0
- package/src/ai/AIAdapter.ts +313 -0
- package/src/ai/AICopilot.ts +331 -0
- package/src/ai/AIOutputValidator.ts +203 -0
- package/src/ai/BTNodes.ts +239 -0
- package/src/ai/BehaviorSelector.ts +135 -0
- package/src/ai/BehaviorTree.ts +153 -0
- package/src/ai/Blackboard.ts +165 -0
- package/src/ai/GenerationAnalytics.ts +461 -0
- package/src/ai/GenerationCache.ts +265 -0
- package/src/ai/GoalPlanner.ts +165 -0
- package/src/ai/HoloScriptGenerator.ts +580 -0
- package/src/ai/InfluenceMap.ts +180 -0
- package/src/ai/NavMesh.ts +168 -0
- package/src/ai/PerceptionSystem.ts +178 -0
- package/src/ai/PromptTemplates.ts +453 -0
- package/src/ai/SemanticSearchService.ts +80 -0
- package/src/ai/StateMachine.ts +196 -0
- package/src/ai/SteeringBehavior.ts +150 -0
- package/src/ai/SteeringBehaviors.ts +244 -0
- package/src/ai/TrainingDataGenerator.ts +1082 -0
- package/src/ai/UtilityAI.ts +145 -0
- package/src/ai/__tests__/AIAdapter.prod.test.ts +259 -0
- package/src/ai/__tests__/AIAdapter.test.ts +109 -0
- package/src/ai/__tests__/AICopilot.prod.test.ts +341 -0
- package/src/ai/__tests__/AICopilot.test.ts +178 -0
- package/src/ai/__tests__/AIOutputValidator.prod.test.ts +226 -0
- package/src/ai/__tests__/AIOutputValidator.test.ts +138 -0
- package/src/ai/__tests__/BTNodes.prod.test.ts +391 -0
- package/src/ai/__tests__/BTNodes.test.ts +263 -0
- package/src/ai/__tests__/BehaviorSelector.prod.test.ts +129 -0
- package/src/ai/__tests__/BehaviorSelector.test.ts +132 -0
- package/src/ai/__tests__/BehaviorTree.prod.test.ts +266 -0
- package/src/ai/__tests__/BehaviorTree.test.ts +216 -0
- package/src/ai/__tests__/Blackboard.prod.test.ts +339 -0
- package/src/ai/__tests__/Blackboard.test.ts +183 -0
- package/src/ai/__tests__/GenerationAnalytics.prod.test.ts +141 -0
- package/src/ai/__tests__/GenerationAnalytics.test.ts +165 -0
- package/src/ai/__tests__/GenerationCache.prod.test.ts +144 -0
- package/src/ai/__tests__/GenerationCache.test.ts +171 -0
- package/src/ai/__tests__/GoalPlanner.prod.test.ts +189 -0
- package/src/ai/__tests__/GoalPlanner.test.ts +137 -0
- package/src/ai/__tests__/GoalPlannerDepth.prod.test.ts +217 -0
- package/src/ai/__tests__/HoloScriptGenerator.test.ts +125 -0
- package/src/ai/__tests__/InfluenceMap.prod.test.ts +146 -0
- package/src/ai/__tests__/InfluenceMap.test.ts +149 -0
- package/src/ai/__tests__/NavMesh.prod.test.ts +141 -0
- package/src/ai/__tests__/NavMesh.test.ts +159 -0
- package/src/ai/__tests__/PerceptionSystem.prod.test.ts +135 -0
- package/src/ai/__tests__/PerceptionSystem.test.ts +250 -0
- package/src/ai/__tests__/PromptTemplates.prod.test.ts +313 -0
- package/src/ai/__tests__/PromptTemplates.test.ts +146 -0
- package/src/ai/__tests__/SemanticSearch.test.ts +37 -0
- package/src/ai/__tests__/StateMachine.prod.test.ts +162 -0
- package/src/ai/__tests__/StateMachine.test.ts +163 -0
- package/src/ai/__tests__/SteeringBehavior.prod.test.ts +251 -0
- package/src/ai/__tests__/SteeringBehavior.test.ts +135 -0
- package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +133 -0
- package/src/ai/__tests__/SteeringBehaviors.test.ts +151 -0
- package/src/ai/__tests__/TrainingDataGenerator.prod.test.ts +286 -0
- package/src/ai/__tests__/TrainingDataGenerator.test.ts +286 -0
- package/src/ai/__tests__/UtilityAI.prod.test.ts +207 -0
- package/src/ai/__tests__/UtilityAI.test.ts +155 -0
- package/src/ai/__tests__/adapters.prod.test.ts +263 -0
- package/src/ai/__tests__/adapters.test.ts +320 -0
- package/src/ai/adapters.ts +1585 -0
- package/src/ai/index.ts +130 -0
- package/src/behavior/BehaviorPresets.ts +140 -0
- package/src/behavior/BehaviorTree.ts +236 -0
- package/src/behavior/StateMachine.ts +176 -0
- package/src/behavior/StateTrait.ts +67 -0
- package/src/behavior/index.ts +8 -0
- package/src/behavior.ts +8 -0
- package/src/board/audit.ts +284 -0
- package/src/board/board-ops.ts +336 -0
- package/src/board/board-types.ts +302 -0
- package/src/board/index.ts +69 -0
- package/src/define-agent.ts +46 -0
- package/src/define-team.ts +33 -0
- package/src/delegation.ts +265 -0
- package/src/distributed-claimer.ts +228 -0
- package/src/economy/AgentBudgetEnforcer.ts +464 -0
- package/src/economy/BountyManager.ts +185 -0
- package/src/economy/CreatorRevenueAggregator.ts +460 -0
- package/src/economy/InvisibleWallet.ts +82 -0
- package/src/economy/KnowledgeMarketplace.ts +193 -0
- package/src/economy/PaymentWebhookService.ts +512 -0
- package/src/economy/RevenueSplitter.ts +156 -0
- package/src/economy/SubscriptionManager.ts +546 -0
- package/src/economy/UnifiedBudgetOptimizer.ts +635 -0
- package/src/economy/UsageMeter.ts +440 -0
- package/src/economy/_core-stubs.ts +219 -0
- package/src/economy/index.ts +100 -0
- package/src/economy/x402-facilitator.ts +1978 -0
- package/src/index.ts +348 -0
- package/src/knowledge/__tests__/knowledge-consolidator.test.ts +444 -0
- package/src/knowledge/__tests__/knowledge-store-vector.test.ts +291 -0
- package/src/knowledge/brain.ts +167 -0
- package/src/knowledge/consolidation.ts +581 -0
- package/src/knowledge/knowledge-consolidator.ts +510 -0
- package/src/knowledge/knowledge-store.ts +616 -0
- package/src/learning/MemoryConsolidator.ts +102 -0
- package/src/learning/MemoryScorer.ts +69 -0
- package/src/learning/ProceduralCompiler.ts +45 -0
- package/src/learning/SemanticClusterer.ts +66 -0
- package/src/learning/index.ts +8 -0
- package/src/llm/llm-adapter.ts +159 -0
- package/src/mesh/index.ts +309 -0
- package/src/negotiation/NegotiationProtocol.ts +694 -0
- package/src/negotiation/NegotiationTypes.ts +473 -0
- package/src/negotiation/VotingMechanisms.ts +691 -0
- package/src/negotiation/index.ts +49 -0
- package/src/protocol/goal-synthesizer.ts +317 -0
- package/src/protocol/implementations.ts +474 -0
- package/src/protocol/micro-phase-decomposer.ts +299 -0
- package/src/protocol/micro-step-decomposer.test.ts +306 -0
- package/src/protocol-agent.test.ts +353 -0
- package/src/protocol-agent.ts +670 -0
- package/src/self-improve/absorb-scanner.ts +252 -0
- package/src/self-improve/evolution-engine.ts +149 -0
- package/src/self-improve/framework-absorber.ts +214 -0
- package/src/self-improve/index.ts +50 -0
- package/src/self-improve/prompt-optimizer.ts +212 -0
- package/src/self-improve/test-generator.ts +175 -0
- package/src/skill-router.ts +186 -0
- package/src/skills/index.ts +5 -0
- package/src/skills/skill-md-bridge.ts +1699 -0
- package/src/swarm/ACOEngine.ts +261 -0
- package/src/swarm/CollectiveIntelligence.ts +383 -0
- package/src/swarm/ContributionSynthesizer.ts +481 -0
- package/src/swarm/LeaderElection.ts +393 -0
- package/src/swarm/PSOEngine.ts +206 -0
- package/src/swarm/QuorumPolicy.ts +173 -0
- package/src/swarm/SwarmCoordinator.ts +335 -0
- package/src/swarm/SwarmManager.ts +442 -0
- package/src/swarm/SwarmMembership.ts +456 -0
- package/src/swarm/VotingRound.ts +255 -0
- package/src/swarm/__tests__/ACOEngine.prod.test.ts +164 -0
- package/src/swarm/__tests__/ACOEngine.test.ts +117 -0
- package/src/swarm/__tests__/CollectiveIntelligence.prod.test.ts +296 -0
- package/src/swarm/__tests__/CollectiveIntelligence.test.ts +457 -0
- package/src/swarm/__tests__/ContributionSynthesizer.prod.test.ts +269 -0
- package/src/swarm/__tests__/ContributionSynthesizer.test.ts +254 -0
- package/src/swarm/__tests__/LeaderElection.prod.test.ts +196 -0
- package/src/swarm/__tests__/LeaderElection.test.ts +151 -0
- package/src/swarm/__tests__/PSOEngine.prod.test.ts +162 -0
- package/src/swarm/__tests__/PSOEngine.test.ts +106 -0
- package/src/swarm/__tests__/QuorumPolicy.prod.test.ts +216 -0
- package/src/swarm/__tests__/QuorumPolicy.test.ts +177 -0
- package/src/swarm/__tests__/SwarmCoordinator.prod.test.ts +186 -0
- package/src/swarm/__tests__/SwarmCoordinator.test.ts +167 -0
- package/src/swarm/__tests__/SwarmManager.prod.test.ts +308 -0
- package/src/swarm/__tests__/SwarmManager.test.ts +373 -0
- package/src/swarm/__tests__/SwarmMembership.prod.test.ts +273 -0
- package/src/swarm/__tests__/SwarmMembership.test.ts +264 -0
- package/src/swarm/__tests__/VotingRound.prod.test.ts +233 -0
- package/src/swarm/__tests__/VotingRound.test.ts +174 -0
- package/src/swarm/analytics/SwarmInspector.ts +476 -0
- package/src/swarm/analytics/SwarmMetrics.ts +449 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.prod.test.ts +366 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.test.ts +454 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.prod.test.ts +254 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.test.ts +370 -0
- package/src/swarm/analytics/index.ts +7 -0
- package/src/swarm/index.ts +69 -0
- package/src/swarm/messaging/BroadcastChannel.ts +509 -0
- package/src/swarm/messaging/GossipProtocol.ts +565 -0
- package/src/swarm/messaging/SwarmEventBus.ts +443 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +331 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.test.ts +333 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +356 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.test.ts +437 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +191 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +247 -0
- package/src/swarm/messaging/index.ts +8 -0
- package/src/swarm/spatial/FlockingBehavior.ts +462 -0
- package/src/swarm/spatial/FormationController.ts +500 -0
- package/src/swarm/spatial/Vector3.ts +170 -0
- package/src/swarm/spatial/ZoneClaiming.ts +509 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.prod.test.ts +239 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.test.ts +298 -0
- package/src/swarm/spatial/__tests__/FormationController.prod.test.ts +240 -0
- package/src/swarm/spatial/__tests__/FormationController.test.ts +297 -0
- package/src/swarm/spatial/__tests__/Vector3.prod.test.ts +283 -0
- package/src/swarm/spatial/__tests__/Vector3.test.ts +224 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.prod.test.ts +246 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.test.ts +374 -0
- package/src/swarm/spatial/index.ts +28 -0
- package/src/team.ts +1245 -0
- package/src/training/LRScheduler.ts +377 -0
- package/src/training/QualityScoringPipeline.ts +139 -0
- package/src/training/SoftDedup.ts +461 -0
- package/src/training/SparsityMonitor.ts +685 -0
- package/src/training/SparsityMonitorTypes.ts +209 -0
- package/src/training/SpatialTrainingDataGenerator.ts +1526 -0
- package/src/training/SpatialTrainingDataTypes.ts +216 -0
- package/src/training/TrainingPipelineConfig.ts +215 -0
- package/src/training/constants.ts +94 -0
- package/src/training/index.ts +138 -0
- package/src/training/schema.ts +147 -0
- package/src/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
- package/src/training/scripts/generate-spatial-dataset.ts +521 -0
- package/src/training/training/data/novel-use-cases.jsonl +153 -0
- package/src/training/training/data/spatial-reasoning-10k.jsonl +9354 -0
- package/src/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
- package/src/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
- package/src/training/trainingmonkey/index.ts +26 -0
- package/src/training/trait-mappings.ts +157 -0
- package/src/types/core-stubs.d.ts +113 -0
- package/src/types.ts +304 -0
- package/test-output.txt +0 -0
- package/test-result.json +1 -0
- package/tsc-errors.txt +4 -0
- package/tsc_output.txt +0 -0
- package/tsconfig.json +14 -0
- package/tsup-learning-esm.config.ts +12 -0
- package/tsup.config.ts +21 -0
- package/typescript-errors-2.txt +0 -0
- package/typescript-errors.txt +22 -0
- package/vitest-log-utf8.txt +268 -0
- package/vitest-log.txt +0 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Spatial Reasoning Training Dataset Generator
|
|
4
|
+
*
|
|
5
|
+
* Generates 10,000 spatial reasoning training examples for Brittney fine-tuning.
|
|
6
|
+
* Applies deduplication per W.004 and quality validation per W.010.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* npx tsx packages/core/src/training/scripts/generate-spatial-dataset.ts
|
|
10
|
+
*
|
|
11
|
+
* Output:
|
|
12
|
+
* packages/core/src/training/data/spatial-reasoning-10k.jsonl
|
|
13
|
+
*
|
|
14
|
+
* @module training/scripts/generate-spatial-dataset
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
18
|
+
import { join, dirname } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
|
|
21
|
+
import { SpatialTrainingDataGenerator } from '../SpatialTrainingDataGenerator';
|
|
22
|
+
import type {
|
|
23
|
+
SpatialTrainingExample,
|
|
24
|
+
SpatialTrainingJSONLEntry,
|
|
25
|
+
SpatialRelationshipType,
|
|
26
|
+
SpatialDifficulty,
|
|
27
|
+
} from '../SpatialTrainingDataTypes';
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// CONFIGURATION
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
const CONFIG = {
|
|
34
|
+
/** Target number of examples (before dedup) */
|
|
35
|
+
targetExamples: 10_008, // 1112 * 9 categories = 10,008
|
|
36
|
+
/** Examples per category (relationship_type x difficulty_level) */
|
|
37
|
+
examplesPerCategory: 1112, // 9 categories => 10,008 total
|
|
38
|
+
/** Positive/negative ratio: 60% positive, 40% negative */
|
|
39
|
+
positiveRatio: 0.6,
|
|
40
|
+
/** Seed for reproducibility */
|
|
41
|
+
seed: 2026_0306,
|
|
42
|
+
/** Include HoloScript context in instructions */
|
|
43
|
+
includeContext: true,
|
|
44
|
+
/** Output file path */
|
|
45
|
+
outputPath: join(
|
|
46
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
47
|
+
'..',
|
|
48
|
+
'data',
|
|
49
|
+
'spatial-reasoning-10k.jsonl'
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// N-GRAM DEDUPLICATION (W.004)
|
|
55
|
+
// =============================================================================
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generates n-grams from text for near-duplicate detection.
|
|
59
|
+
*/
|
|
60
|
+
function getNgrams(text: string, n: number = 3): Set<string> {
|
|
61
|
+
const words = text
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.replace(/[^a-z0-9\s]/g, '')
|
|
64
|
+
.split(/\s+/)
|
|
65
|
+
.filter(Boolean);
|
|
66
|
+
const ngrams = new Set<string>();
|
|
67
|
+
for (let i = 0; i <= words.length - n; i++) {
|
|
68
|
+
ngrams.add(words.slice(i, i + n).join(' '));
|
|
69
|
+
}
|
|
70
|
+
return ngrams;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Jaccard similarity between two n-gram sets.
|
|
75
|
+
*/
|
|
76
|
+
function jaccardSimilarity(a: Set<string>, b: Set<string>): number {
|
|
77
|
+
if (a.size === 0 && b.size === 0) return 1.0;
|
|
78
|
+
let intersection = 0;
|
|
79
|
+
for (const gram of a) {
|
|
80
|
+
if (b.has(gram)) intersection++;
|
|
81
|
+
}
|
|
82
|
+
const union = a.size + b.size - intersection;
|
|
83
|
+
return union === 0 ? 0 : intersection / union;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Deduplicates examples using n-gram Jaccard similarity.
|
|
88
|
+
* W.004: ALWAYS run deduplication before training.
|
|
89
|
+
*
|
|
90
|
+
* Uses a combination of exact hash dedup (instruction+response) and
|
|
91
|
+
* near-duplicate detection via 3-gram Jaccard similarity > 0.85 threshold.
|
|
92
|
+
*/
|
|
93
|
+
function deduplicateExamples(
|
|
94
|
+
examples: SpatialTrainingExample[],
|
|
95
|
+
threshold: number = 0.85
|
|
96
|
+
): { unique: SpatialTrainingExample[]; duplicateCount: number; duplicateRate: number } {
|
|
97
|
+
console.log('\n--- W.004: Running Deduplication ---');
|
|
98
|
+
|
|
99
|
+
// Phase 1: Exact deduplication (hash-based)
|
|
100
|
+
const seen = new Set<string>();
|
|
101
|
+
const afterExact: SpatialTrainingExample[] = [];
|
|
102
|
+
let exactDupes = 0;
|
|
103
|
+
|
|
104
|
+
for (const ex of examples) {
|
|
105
|
+
const key = `${ex.instruction}|||${ex.response}`;
|
|
106
|
+
if (seen.has(key)) {
|
|
107
|
+
exactDupes++;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
seen.add(key);
|
|
111
|
+
afterExact.push(ex);
|
|
112
|
+
}
|
|
113
|
+
console.log(` Phase 1 (Exact): ${exactDupes} exact duplicates removed`);
|
|
114
|
+
|
|
115
|
+
// Phase 2: Near-duplicate detection (n-gram Jaccard)
|
|
116
|
+
// For performance with 10K examples, we compare within same category
|
|
117
|
+
const categories = new Map<string, SpatialTrainingExample[]>();
|
|
118
|
+
for (const ex of afterExact) {
|
|
119
|
+
const cat = `${ex.relationshipType}:${ex.difficulty}`;
|
|
120
|
+
if (!categories.has(cat)) categories.set(cat, []);
|
|
121
|
+
categories.get(cat)!.push(ex);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const unique: SpatialTrainingExample[] = [];
|
|
125
|
+
let nearDupes = 0;
|
|
126
|
+
|
|
127
|
+
for (const [cat, catExamples] of categories) {
|
|
128
|
+
const catUnique: SpatialTrainingExample[] = [];
|
|
129
|
+
const ngramCache: Array<Set<string>> = [];
|
|
130
|
+
|
|
131
|
+
for (const ex of catExamples) {
|
|
132
|
+
const combined = `${ex.instruction} ${ex.response}`;
|
|
133
|
+
const ngrams = getNgrams(combined);
|
|
134
|
+
|
|
135
|
+
let isDup = false;
|
|
136
|
+
// Compare against existing unique examples in this category
|
|
137
|
+
// Only check last 100 to keep O(n) reasonable
|
|
138
|
+
const startIdx = Math.max(0, ngramCache.length - 100);
|
|
139
|
+
for (let i = startIdx; i < ngramCache.length; i++) {
|
|
140
|
+
if (jaccardSimilarity(ngrams, ngramCache[i]) > threshold) {
|
|
141
|
+
isDup = true;
|
|
142
|
+
nearDupes++;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!isDup) {
|
|
148
|
+
catUnique.push(ex);
|
|
149
|
+
ngramCache.push(ngrams);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
unique.push(...catUnique);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log(
|
|
157
|
+
` Phase 2 (Near-dup): ${nearDupes} near-duplicates removed (threshold: ${threshold})`
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const totalDupes = exactDupes + nearDupes;
|
|
161
|
+
const rate = totalDupes / examples.length;
|
|
162
|
+
console.log(
|
|
163
|
+
` Total: ${totalDupes} duplicates removed (${(rate * 100).toFixed(1)}% duplication rate)`
|
|
164
|
+
);
|
|
165
|
+
console.log(` Remaining: ${unique.length} unique examples`);
|
|
166
|
+
|
|
167
|
+
return { unique, duplicateCount: totalDupes, duplicateRate: rate };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// =============================================================================
|
|
171
|
+
// QUALITY VALIDATION (W.010)
|
|
172
|
+
// =============================================================================
|
|
173
|
+
|
|
174
|
+
interface QualityScores {
|
|
175
|
+
helpfulness: number;
|
|
176
|
+
correctness: number;
|
|
177
|
+
coherence: number;
|
|
178
|
+
complexity: number;
|
|
179
|
+
verbosity: number;
|
|
180
|
+
overall: number;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Multi-dimensional quality scoring per W.010.
|
|
185
|
+
* Evaluates each example on 5 metrics: helpfulness, correctness, coherence, complexity, verbosity.
|
|
186
|
+
*/
|
|
187
|
+
function scoreQuality(ex: SpatialTrainingExample): QualityScores {
|
|
188
|
+
// Helpfulness: Does the instruction ask a clear, answerable question?
|
|
189
|
+
let helpfulness = 0;
|
|
190
|
+
if (ex.instruction.length > 20) helpfulness += 0.3;
|
|
191
|
+
if (
|
|
192
|
+
ex.instruction.includes('?') ||
|
|
193
|
+
ex.instruction.toLowerCase().includes('evaluate') ||
|
|
194
|
+
ex.instruction.toLowerCase().includes('check') ||
|
|
195
|
+
ex.instruction.toLowerCase().includes('analyze') ||
|
|
196
|
+
ex.instruction.toLowerCase().includes('verify')
|
|
197
|
+
)
|
|
198
|
+
helpfulness += 0.3;
|
|
199
|
+
if (ex.instruction.includes('"')) helpfulness += 0.2; // References specific objects
|
|
200
|
+
if (ex.response.length > 20) helpfulness += 0.2;
|
|
201
|
+
|
|
202
|
+
// Correctness: Does the response contain concrete spatial data (distances, positions)?
|
|
203
|
+
let correctness = 0;
|
|
204
|
+
if (ex.response.match(/\d+\.\d+m/)) correctness += 0.4; // Contains distance measurement
|
|
205
|
+
if (
|
|
206
|
+
ex.response.includes('Yes') ||
|
|
207
|
+
ex.response.includes('No') ||
|
|
208
|
+
ex.response.includes('constraint') ||
|
|
209
|
+
ex.response.includes('satisf') ||
|
|
210
|
+
ex.response.includes('violat') ||
|
|
211
|
+
ex.response.includes('pass') ||
|
|
212
|
+
ex.response.includes('fail')
|
|
213
|
+
)
|
|
214
|
+
correctness += 0.3; // Contains a definitive answer
|
|
215
|
+
if (
|
|
216
|
+
ex.tags.includes('positive') &&
|
|
217
|
+
(ex.response.includes('Yes') || ex.response.includes('pass') || ex.response.includes('satisf'))
|
|
218
|
+
) {
|
|
219
|
+
correctness += 0.3; // Positive label matches positive response
|
|
220
|
+
} else if (
|
|
221
|
+
ex.tags.includes('negative') &&
|
|
222
|
+
(ex.response.includes('No') ||
|
|
223
|
+
ex.response.includes('fail') ||
|
|
224
|
+
ex.response.includes('violat') ||
|
|
225
|
+
ex.response.includes('block'))
|
|
226
|
+
) {
|
|
227
|
+
correctness += 0.3; // Negative label matches negative response
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Coherence: Is the instruction-response pair logically consistent?
|
|
231
|
+
let coherence = 0;
|
|
232
|
+
// Check that the response references objects from the instruction
|
|
233
|
+
const instructionObjects = ex.instruction.match(/"([^"]+)"/g) || [];
|
|
234
|
+
const responseObjects = ex.response.match(/"([^"]+)"/g) || [];
|
|
235
|
+
if (instructionObjects.length > 0 && responseObjects.length > 0) {
|
|
236
|
+
const instrSet = new Set(instructionObjects);
|
|
237
|
+
const overlap = responseObjects.filter((o) => instrSet.has(o));
|
|
238
|
+
coherence += Math.min(1.0, overlap.length / instructionObjects.length);
|
|
239
|
+
} else {
|
|
240
|
+
coherence += 0.5; // Partial credit if no quoted objects
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Complexity: Is the example sufficiently complex for training value?
|
|
244
|
+
let complexity = 0;
|
|
245
|
+
const difficultyScore: Record<SpatialDifficulty, number> = {
|
|
246
|
+
basic: 0.3,
|
|
247
|
+
intermediate: 0.6,
|
|
248
|
+
advanced: 1.0,
|
|
249
|
+
};
|
|
250
|
+
complexity = difficultyScore[ex.difficulty];
|
|
251
|
+
|
|
252
|
+
// Verbosity: Is the response appropriately verbose (not too short, not excessive)?
|
|
253
|
+
let verbosity = 0;
|
|
254
|
+
const responseLen = ex.response.length;
|
|
255
|
+
if (responseLen >= 20 && responseLen <= 300) {
|
|
256
|
+
verbosity = 1.0; // Ideal range
|
|
257
|
+
} else if (responseLen < 20) {
|
|
258
|
+
verbosity = responseLen / 20; // Too short
|
|
259
|
+
} else {
|
|
260
|
+
verbosity = Math.max(0.5, 1.0 - (responseLen - 300) / 500); // Slightly penalize verbose
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const overall = (helpfulness + correctness + coherence + complexity + verbosity) / 5;
|
|
264
|
+
|
|
265
|
+
return { helpfulness, correctness, coherence, complexity, verbosity, overall };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Validate quality across all examples per W.010.
|
|
270
|
+
* Returns distribution stats and flags low-quality examples.
|
|
271
|
+
*/
|
|
272
|
+
function validateQuality(
|
|
273
|
+
examples: SpatialTrainingExample[],
|
|
274
|
+
minQualityThreshold: number = 0.4
|
|
275
|
+
): {
|
|
276
|
+
passed: SpatialTrainingExample[];
|
|
277
|
+
rejected: SpatialTrainingExample[];
|
|
278
|
+
avgScores: QualityScores;
|
|
279
|
+
distribution: Record<string, number>;
|
|
280
|
+
} {
|
|
281
|
+
console.log('\n--- W.010: Multi-Dimensional Quality Validation ---');
|
|
282
|
+
|
|
283
|
+
const allScores: QualityScores[] = [];
|
|
284
|
+
const passed: SpatialTrainingExample[] = [];
|
|
285
|
+
const rejected: SpatialTrainingExample[] = [];
|
|
286
|
+
const distribution: Record<string, number> = {
|
|
287
|
+
'excellent (0.8-1.0)': 0,
|
|
288
|
+
'good (0.6-0.8)': 0,
|
|
289
|
+
'fair (0.4-0.6)': 0,
|
|
290
|
+
'poor (0.2-0.4)': 0,
|
|
291
|
+
'bad (0.0-0.2)': 0,
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
for (const ex of examples) {
|
|
295
|
+
const scores = scoreQuality(ex);
|
|
296
|
+
allScores.push(scores);
|
|
297
|
+
|
|
298
|
+
if (scores.overall >= minQualityThreshold) {
|
|
299
|
+
passed.push(ex);
|
|
300
|
+
} else {
|
|
301
|
+
rejected.push(ex);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (scores.overall >= 0.8) distribution['excellent (0.8-1.0)']++;
|
|
305
|
+
else if (scores.overall >= 0.6) distribution['good (0.6-0.8)']++;
|
|
306
|
+
else if (scores.overall >= 0.4) distribution['fair (0.4-0.6)']++;
|
|
307
|
+
else if (scores.overall >= 0.2) distribution['poor (0.2-0.4)']++;
|
|
308
|
+
else distribution['bad (0.0-0.2)']++;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Compute averages
|
|
312
|
+
const avgScores: QualityScores = {
|
|
313
|
+
helpfulness: allScores.reduce((s, q) => s + q.helpfulness, 0) / allScores.length,
|
|
314
|
+
correctness: allScores.reduce((s, q) => s + q.correctness, 0) / allScores.length,
|
|
315
|
+
coherence: allScores.reduce((s, q) => s + q.coherence, 0) / allScores.length,
|
|
316
|
+
complexity: allScores.reduce((s, q) => s + q.complexity, 0) / allScores.length,
|
|
317
|
+
verbosity: allScores.reduce((s, q) => s + q.verbosity, 0) / allScores.length,
|
|
318
|
+
overall: allScores.reduce((s, q) => s + q.overall, 0) / allScores.length,
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
console.log(` Average Quality Score: ${(avgScores.overall * 100).toFixed(1)}%`);
|
|
322
|
+
console.log(` - Helpfulness: ${(avgScores.helpfulness * 100).toFixed(1)}%`);
|
|
323
|
+
console.log(` - Correctness: ${(avgScores.correctness * 100).toFixed(1)}%`);
|
|
324
|
+
console.log(` - Coherence: ${(avgScores.coherence * 100).toFixed(1)}%`);
|
|
325
|
+
console.log(` - Complexity: ${(avgScores.complexity * 100).toFixed(1)}%`);
|
|
326
|
+
console.log(` - Verbosity: ${(avgScores.verbosity * 100).toFixed(1)}%`);
|
|
327
|
+
console.log(`\n Quality Distribution:`);
|
|
328
|
+
for (const [band, count] of Object.entries(distribution)) {
|
|
329
|
+
const pct = ((count / examples.length) * 100).toFixed(1);
|
|
330
|
+
const bar = '#'.repeat(Math.round((count / examples.length) * 50));
|
|
331
|
+
console.log(` ${band.padEnd(22)} ${String(count).padStart(6)} (${pct.padStart(5)}%) ${bar}`);
|
|
332
|
+
}
|
|
333
|
+
console.log(
|
|
334
|
+
`\n Passed: ${passed.length} (${((passed.length / examples.length) * 100).toFixed(1)}%)`
|
|
335
|
+
);
|
|
336
|
+
console.log(
|
|
337
|
+
` Rejected: ${rejected.length} (${((rejected.length / examples.length) * 100).toFixed(1)}%)`
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
return { passed, rejected, avgScores, distribution };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// =============================================================================
|
|
344
|
+
// STATISTICS REPORTING
|
|
345
|
+
// =============================================================================
|
|
346
|
+
|
|
347
|
+
function reportStatistics(
|
|
348
|
+
examples: SpatialTrainingExample[],
|
|
349
|
+
generator: SpatialTrainingDataGenerator,
|
|
350
|
+
dedupStats: { duplicateCount: number; duplicateRate: number },
|
|
351
|
+
qualityStats: { avgScores: QualityScores; distribution: Record<string, number> },
|
|
352
|
+
originalCount: number
|
|
353
|
+
): void {
|
|
354
|
+
const stats = generator.getStats(examples);
|
|
355
|
+
|
|
356
|
+
console.log('\n' + '='.repeat(70));
|
|
357
|
+
console.log(' SPATIAL REASONING TRAINING DATASET - FINAL REPORT');
|
|
358
|
+
console.log('='.repeat(70));
|
|
359
|
+
|
|
360
|
+
console.log('\n--- Generation Summary ---');
|
|
361
|
+
console.log(` Seed: ${CONFIG.seed}`);
|
|
362
|
+
console.log(` Target Examples: ${CONFIG.targetExamples}`);
|
|
363
|
+
console.log(` Generated: ${originalCount}`);
|
|
364
|
+
console.log(` After Dedup: ${examples.length}`);
|
|
365
|
+
console.log(
|
|
366
|
+
` Dedup Removed: ${dedupStats.duplicateCount} (${(dedupStats.duplicateRate * 100).toFixed(1)}%)`
|
|
367
|
+
);
|
|
368
|
+
console.log(` Positive Ratio: ${CONFIG.positiveRatio} (target: 60/40)`);
|
|
369
|
+
|
|
370
|
+
console.log('\n--- Examples by Relationship Type ---');
|
|
371
|
+
console.log(` spatial_adjacent: ${stats.byRelationship.spatial_adjacent}`);
|
|
372
|
+
console.log(` spatial_contains: ${stats.byRelationship.spatial_contains}`);
|
|
373
|
+
console.log(` spatial_reachable: ${stats.byRelationship.spatial_reachable}`);
|
|
374
|
+
|
|
375
|
+
console.log('\n--- Examples by Difficulty Level ---');
|
|
376
|
+
console.log(` basic: ${stats.byDifficulty.basic}`);
|
|
377
|
+
console.log(` intermediate: ${stats.byDifficulty.intermediate}`);
|
|
378
|
+
console.log(` advanced: ${stats.byDifficulty.advanced}`);
|
|
379
|
+
|
|
380
|
+
console.log('\n--- Positive/Negative Balance ---');
|
|
381
|
+
const actualPositiveRatio = stats.positiveCount / stats.totalExamples;
|
|
382
|
+
console.log(
|
|
383
|
+
` Positive: ${stats.positiveCount} (${(actualPositiveRatio * 100).toFixed(1)}%)`
|
|
384
|
+
);
|
|
385
|
+
console.log(
|
|
386
|
+
` Negative: ${stats.negativeCount} (${((1 - actualPositiveRatio) * 100).toFixed(1)}%)`
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
console.log('\n--- Template Diversity (G.002 Compliance) ---');
|
|
390
|
+
console.log(` Unique Templates: ${stats.uniqueTemplatesUsed}`);
|
|
391
|
+
console.log(
|
|
392
|
+
` G.002 Mandate: ${stats.uniqueTemplatesUsed >= 10 ? 'PASS (>=10)' : 'FAIL (<10)'}`
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
// Detailed template usage per relationship type
|
|
396
|
+
const templatesByType: Record<string, Set<string>> = {
|
|
397
|
+
spatial_adjacent: new Set(),
|
|
398
|
+
spatial_contains: new Set(),
|
|
399
|
+
spatial_reachable: new Set(),
|
|
400
|
+
};
|
|
401
|
+
for (const ex of examples) {
|
|
402
|
+
const tplTag = ex.tags.find((t) => t.startsWith('template:'));
|
|
403
|
+
if (tplTag) {
|
|
404
|
+
templatesByType[ex.relationshipType].add(tplTag);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
console.log(` Templates per type:`);
|
|
408
|
+
for (const [type, templates] of Object.entries(templatesByType)) {
|
|
409
|
+
console.log(` ${type}: ${templates.size} unique templates`);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
console.log('\n--- Quality Metrics (W.010) ---');
|
|
413
|
+
console.log(` Overall Score: ${(qualityStats.avgScores.overall * 100).toFixed(1)}%`);
|
|
414
|
+
console.log(` Distribution:`);
|
|
415
|
+
for (const [band, count] of Object.entries(qualityStats.distribution)) {
|
|
416
|
+
console.log(` ${band}: ${count}`);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Cross-tabulation: relationship x difficulty
|
|
420
|
+
console.log('\n--- Cross-Tabulation (Relationship x Difficulty) ---');
|
|
421
|
+
const crossTab: Record<string, Record<string, number>> = {};
|
|
422
|
+
for (const ex of examples) {
|
|
423
|
+
const key = ex.relationshipType;
|
|
424
|
+
if (!crossTab[key]) crossTab[key] = { basic: 0, intermediate: 0, advanced: 0 };
|
|
425
|
+
crossTab[key][ex.difficulty]++;
|
|
426
|
+
}
|
|
427
|
+
console.log(
|
|
428
|
+
' ' +
|
|
429
|
+
'Type'.padEnd(25) +
|
|
430
|
+
'Basic'.padStart(8) +
|
|
431
|
+
'Intermediate'.padStart(15) +
|
|
432
|
+
'Advanced'.padStart(12)
|
|
433
|
+
);
|
|
434
|
+
for (const [type, diffs] of Object.entries(crossTab)) {
|
|
435
|
+
console.log(
|
|
436
|
+
` ${type.padEnd(25)}${String(diffs.basic).padStart(8)}${String(diffs.intermediate).padStart(15)}${String(diffs.advanced).padStart(12)}`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
console.log('\n--- Output ---');
|
|
441
|
+
console.log(` File: ${CONFIG.outputPath}`);
|
|
442
|
+
console.log(` Format: JSONL (one JSON object per line)`);
|
|
443
|
+
console.log(` Lines: ${examples.length}`);
|
|
444
|
+
|
|
445
|
+
console.log('\n' + '='.repeat(70));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// =============================================================================
|
|
449
|
+
// MAIN
|
|
450
|
+
// =============================================================================
|
|
451
|
+
|
|
452
|
+
async function main(): Promise<void> {
|
|
453
|
+
console.log('='.repeat(70));
|
|
454
|
+
console.log(' HoloScript Spatial Reasoning Training Data Generator');
|
|
455
|
+
console.log(' Target: 10,000 examples | 3 types | 3 difficulties | 60/40 ratio');
|
|
456
|
+
console.log('='.repeat(70));
|
|
457
|
+
|
|
458
|
+
const startTime = Date.now();
|
|
459
|
+
|
|
460
|
+
// Step 1: Generate raw examples
|
|
461
|
+
console.log('\n--- Step 1: Generating Raw Examples ---');
|
|
462
|
+
const generator = new SpatialTrainingDataGenerator({
|
|
463
|
+
seed: CONFIG.seed,
|
|
464
|
+
examplesPerCategory: CONFIG.examplesPerCategory,
|
|
465
|
+
positiveRatio: CONFIG.positiveRatio,
|
|
466
|
+
includeContext: CONFIG.includeContext,
|
|
467
|
+
relationshipTypes: ['spatial_adjacent', 'spatial_contains', 'spatial_reachable'],
|
|
468
|
+
difficultyLevels: ['basic', 'intermediate', 'advanced'],
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const rawExamples = generator.generate();
|
|
472
|
+
const originalCount = rawExamples.length;
|
|
473
|
+
console.log(` Generated ${rawExamples.length} raw examples`);
|
|
474
|
+
console.log(` Time: ${((Date.now() - startTime) / 1000).toFixed(1)}s`);
|
|
475
|
+
|
|
476
|
+
// Step 2: Deduplication (W.004)
|
|
477
|
+
const dedupStart = Date.now();
|
|
478
|
+
const { unique: dedupExamples, duplicateCount, duplicateRate } = deduplicateExamples(rawExamples);
|
|
479
|
+
console.log(` Dedup time: ${((Date.now() - dedupStart) / 1000).toFixed(1)}s`);
|
|
480
|
+
|
|
481
|
+
// Step 3: Quality Validation (W.010)
|
|
482
|
+
const qualStart = Date.now();
|
|
483
|
+
const { passed: qualityExamples, avgScores, distribution } = validateQuality(dedupExamples);
|
|
484
|
+
console.log(` Quality validation time: ${((Date.now() - qualStart) / 1000).toFixed(1)}s`);
|
|
485
|
+
|
|
486
|
+
// Step 4: Export to JSONL
|
|
487
|
+
console.log('\n--- Step 4: Exporting to JSONL ---');
|
|
488
|
+
const outputDir = dirname(CONFIG.outputPath);
|
|
489
|
+
if (!existsSync(outputDir)) {
|
|
490
|
+
mkdirSync(outputDir, { recursive: true });
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Use the generator's exportJSONL for consistency
|
|
494
|
+
const jsonl = generator.exportJSONL(qualityExamples);
|
|
495
|
+
writeFileSync(CONFIG.outputPath, jsonl, 'utf-8');
|
|
496
|
+
console.log(` Written ${qualityExamples.length} examples to:`);
|
|
497
|
+
console.log(` ${CONFIG.outputPath}`);
|
|
498
|
+
|
|
499
|
+
// File size
|
|
500
|
+
const fileSizeBytes = Buffer.byteLength(jsonl, 'utf-8');
|
|
501
|
+
const fileSizeMB = (fileSizeBytes / (1024 * 1024)).toFixed(2);
|
|
502
|
+
console.log(` File size: ${fileSizeMB} MB`);
|
|
503
|
+
|
|
504
|
+
// Step 5: Final Report
|
|
505
|
+
reportStatistics(
|
|
506
|
+
qualityExamples,
|
|
507
|
+
generator,
|
|
508
|
+
{ duplicateCount, duplicateRate },
|
|
509
|
+
{ avgScores, distribution },
|
|
510
|
+
originalCount
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
514
|
+
console.log(`\nTotal generation time: ${totalTime}s`);
|
|
515
|
+
console.log('Done.');
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
main().catch((err) => {
|
|
519
|
+
console.error('Fatal error:', err);
|
|
520
|
+
process.exit(1);
|
|
521
|
+
});
|