feat: model metadata attributes & source generator infrastructure (#956) - #965
Conversation
Add ModelDomain, ModelCategory, ModelTask, ModelComplexity enums and ModelDomainAttribute, ModelCategoryAttribute, ModelTaskAttribute, ModelComplexityAttribute, ModelInputAttribute, ModelPaperAttribute classes for annotating all ~700 model classes with rich metadata. Part of #957 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Roslyn incremental source generator that auto-discovers all concrete IFullModel implementations via AllInterfaces chain traversal (no hardcoded base types). Emits AIDN001/010-012/020 diagnostics for missing attributes and documentation. Discovers 1484 model classes. AIDN diagnostics added to NoWarn until models are annotated (#958). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Auto-generates a static ModelMetadataRegistry class at compile time that collects all model metadata from attributes on IFullModel implementations. Zero runtime reflection. Includes query methods for domain, category, task, complexity, and type name lookups. Registry is currently empty (0 annotated models) and will auto- populate when models are annotated in issue #958. Also removes null-forgiving operator from validation generator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughExtensive updates across causal discovery algorithms (Bayesian, constraint-based, score-based, deep/continuous/time-series) introduce NOTEARS-based acyclicity, multivariate OLS weight estimation, stricter validations, and configuration handling. A new ModelRegistryGenerator is added. Broad metadata attributes decorate many models (vision, diffusion, anomaly detection, etc.). Several algorithms gain seeded RNG, thresholds, and constructor/option handling. Changes
Estimated code review effort🎯 5 (Critical) | ⏱️ ~180 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
|
There was a problem hiding this comment.
Pull request overview
This PR introduces the foundational “model metadata” surface area (enums + attributes) and adds Roslyn incremental source generators to (a) validate metadata presence/documentation and (b) generate a compile-time model metadata registry intended to avoid runtime reflection.
Changes:
- Added
ModelDomain/Category/Task/Complexityenums with XML docs and corresponding attribute types (Model*Attribute, plusModelInputAttributeandModelPaperAttribute). - Added two incremental generators:
ModelMetadataValidationGenerator(AIDN diagnostics) andModelRegistryGenerator(emitsModelMetadataRegistry.g.cs). - Updated
AiDotNet.csprojto suppress AIDN diagnostics viaNoWarnuntil model annotations land; added analyzer release tracking files to the generator project.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Enums/ModelDomain.cs | New domain enum with beginner-friendly XML docs. |
| src/Enums/ModelCategory.cs | New category enum with XML docs. |
| src/Enums/ModelTask.cs | New task enum with XML docs. |
| src/Enums/ModelComplexity.cs | New complexity enum with XML docs. |
| src/Attributes/ModelDomainAttribute.cs | New attribute for domain tagging. |
| src/Attributes/ModelCategoryAttribute.cs | New attribute for single category tagging. |
| src/Attributes/ModelTaskAttribute.cs | New multi-use attribute for task tagging. |
| src/Attributes/ModelComplexityAttribute.cs | New attribute for complexity tagging. |
| src/Attributes/ModelInputAttribute.cs | New attribute for input/output type declaration. |
| src/Attributes/ModelPaperAttribute.cs | New attribute for paper references. |
| src/AiDotNet.Generators/ModelMetadataValidationGenerator.cs | Generator emitting AIDN diagnostics for missing metadata/docs/URLs. |
| src/AiDotNet.Generators/ModelRegistryGenerator.cs | Generator emitting ModelMetadataRegistry from discovered model symbols/attributes. |
| src/AiDotNet.Generators/AnalyzerReleases.Shipped.md | Analyzer release tracking scaffold. |
| src/AiDotNet.Generators/AnalyzerReleases.Unshipped.md | Records newly introduced AIDN rules. |
| src/AiDotNet.Generators/AiDotNet.Generators.csproj | Adds analyzer release tracking files as AdditionalFiles. |
| src/AiDotNet.csproj | Suppresses AIDN diagnostics via NoWarn in Debug/Release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Emits ModelDiscoveryManifest.g.cs listing all 1515 concrete IFullModel implementations with file paths and annotation status. Used to plan and track the annotation effort for issue #958. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/AiDotNet.csproj`:
- Around line 26-27: The project currently suppresses analyzer IDs via the
NoWarn MSBuild property (NoWarn contains
AIDN001;AIDN010;AIDN011;AIDN012;AIDN020), which hides them entirely; change
those IDs from NoWarn into WarningsNotAsErrors so they remain visible as
warnings while not being elevated to errors when TreatWarningsAsErrors is true;
update both PropertyGroup entries (the Debug and Release groups that contain
NoWarn) to remove the AIDN IDs from NoWarn and add them to WarningsNotAsErrors,
ensuring the analyzer IDs are preserved exactly
(AIDN001;AIDN010;AIDN011;AIDN012;AIDN020).
In `@src/AiDotNet.Generators/ModelMetadataValidationGenerator.cs`:
- Around line 175-183: The loop in ModelMetadataValidationGenerator is
validating the same INamedTypeSymbol multiple times because Collect() returns
one entry per partial declaration; deduplicate candidates before calling
ValidateRequiredAttributes/ValidatePaperUrls/ValidateXmlDocumentation by
creating a HashSet using SymbolEqualityComparer.Default (or the same seen logic
used in ModelRegistryGenerator) and only iterate over unique modelClass symbols
so each model emits diagnostics once.
- Around line 276-288: The generator currently only treats presence of
"<example>" in xmlDoc as a usage example, causing false positives when authors
use a "<code>" block inside "<remarks>"; update the check in
ModelMetadataValidationGenerator so it reports MissingExample only when neither
an "<example>" tag nor a "<remarks>" tag containing a "<code>" tag is present
(i.e., change the condition that references xmlDoc and the MissingExample
diagnostic to allow xmlDoc.Contains("<example>") OR
(xmlDoc.Contains("<remarks>") && xmlDoc.Contains("<code>"))); keep the same
context.ReportDiagnostic call and location/className parameters.
In `@src/AiDotNet.Generators/ModelRegistryGenerator.cs`:
- Around line 277-290: ExtractXmlElement is currently cleaning XML before
isolating the BeginnerGuide portion, causing nested tags like </b> or </para> to
be removed and preventing correct detection of the beginner-only boundaries;
update the logic in ExtractXmlElement (and the code handling BeginnerGuide
extraction) to first slice the raw xml to isolate the "For Beginners" section
(searching for the raw markers like "For Beginners" and the closing tags inside
the uncleaned substring) and only call CleanXmlText once on that final sliced
text (remove intermediate CleanXmlText calls that strip tags before you locate
end markers). Ensure you reference the ExtractXmlElement method and the
BeginnerGuide extraction code path so the slicing happens on the original xml
and cleaning happens once after isolation.
- Around line 494-556: BuildLookups has a race because it only checks _byDomain
and assigns the dictionaries without synchronization; fix by making BuildLookups
atomic using a private static readonly object _lookupsLock and wrapping the
method body in lock(_lookupsLock) so the null check and assignment of _byDomain,
_byCategory, _byTask, _byComplexity, and _byTypeName happen under the same lock
(or alternatively check all fields and only return if all are non-null); update
BuildLookups to use this lock and ensure the fields are either all set together
inside the lock or _byDomain is assigned last if you choose the assign-order
approach.
- Around line 394-406: Change the generated accessibility of the generator
plumbing types from public to internal so they are not part of the public API:
replace public with internal for the ModelPaperEntry type (and its constructor
and any generated member accessors like Title, Url, Year, Authors), and do the
same for ModelMetadataEntry and ModelMetadataRegistry (including constructors,
properties and any IReadOnlyList/ backing-array exposures) so the entire
AiDotNet.Generated surface is internal-only rather than public.
In `@src/Attributes/ModelInputAttribute.cs`:
- Around line 38-42: The ModelInputAttribute constructor currently assigns
InputType and OutputType without null checks; add defensive validation in the
ModelInputAttribute(Type inputType, Type outputType) constructor to throw
ArgumentNullException for null inputType or outputType (use
ArgumentNullException.ThrowIfNull(inputType/ outputType) when targeting modern
.NET, or the classic inputType ?? throw new
ArgumentNullException(nameof(inputType)) pattern if ThrowIfNull isn't available)
so InputType and OutputType are never set to null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 67d7a93f-4484-4914-99bb-f16ab9436411
📒 Files selected for processing (16)
src/AiDotNet.Generators/AiDotNet.Generators.csprojsrc/AiDotNet.Generators/AnalyzerReleases.Shipped.mdsrc/AiDotNet.Generators/AnalyzerReleases.Unshipped.mdsrc/AiDotNet.Generators/ModelMetadataValidationGenerator.cssrc/AiDotNet.Generators/ModelRegistryGenerator.cssrc/AiDotNet.csprojsrc/Attributes/ModelCategoryAttribute.cssrc/Attributes/ModelComplexityAttribute.cssrc/Attributes/ModelDomainAttribute.cssrc/Attributes/ModelInputAttribute.cssrc/Attributes/ModelPaperAttribute.cssrc/Attributes/ModelTaskAttribute.cssrc/Enums/ModelCategory.cssrc/Enums/ModelComplexity.cssrc/Enums/ModelDomain.cssrc/Enums/ModelTask.cs
…nd fingerprinting models with metadata attributes (#958) Add all 6 metadata attributes (ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, ModelPaper) to 45 concrete audio model classes across 5 subdirectories. Add Enhancement and SignalProcessing to ModelTask enum, add SignalProcessing to ModelCategory enum. Update ModelCategoryAttribute to AllowMultiple=true and registry generator to handle multiple categories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…speech, and voice activity models Annotate 62 concrete model classes with 6 metadata attributes (ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, ModelPaper). Add MachineLearning to ModelDomain enum, DimensionalityReduction to ModelTask enum, and SVM/Kernel/InstanceBased/Linear/DecisionTree/Statistical/ Regularization/Interpretable to ModelCategory enum. Fix ModelInput to use two-parameter form across all audio models. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Annotate 51 audio model classes across AudioGen, AudioLDM, Foundations, Generation, LanguageIdentification, Multimodal, MusicAnalysis, MusicGen, Speaker, SpeechRecognition, StableAudio, and Whisper directories with ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Annotate 27 clustering model classes with ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes across AutoK, Density, Hierarchical, Partitioning, Probabilistic, Neural, SemiSupervised, Spectral, Streaming, Subspace, and Ensemble directories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes to all remaining regression model classes. Add Optimization value to ModelCategory enum for genetic algorithm and symbolic regression models. Includes papers for AdaBoost.R2, Beta, DART, EBM, Extra Trees, GAMLSS, GAM, HistGBT, M5, NGBoost, Quantile, QRF, Super Learner, DeepHit, DeepSurv, and Zero-Inflated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 251 out of 251 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…g regression models Annotate all 59 anomaly detection models across 8 subdirectories (Statistical, AngleBased, ClusterBased, DistanceBased, Linear, NeuralNetwork, Ensemble, Probabilistic, TimeSeries, TreeBased) and 12 remaining regression models with ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lysis, and mixed effects models Annotate 15 concrete model classes with all 6 metadata attributes: - 7 CausalInference models (CausalForest, DoublyRobustEstimator, IPW, PSM, S/T/X-Learner) - 6 SurvivalAnalysis models (Cox, KaplanMeier, LogNormalAFT, NelsonAalen, RSF, WeibullAFT) - 2 Regression MixedEffects models (GLMM, LMM) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… attributes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ransfer models Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ibutes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… add video task enums Add ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes to all remaining Video model files including base Video, AudioVisual, LongVideo, VideoEditing, and WorldModels subdirectories. Add VideoGeneration, ImageToVideo, and VideoToVideo values to ModelTask enum to support video-specific task classification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ModelDomain, ModelCategory, ModelTask, ModelComplexity, ModelInput, and ModelPaper attributes to EQVAEModel, LiteVAEModel, and SDXLVAEModel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ributes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ion loss, and net471 compatibility - LeidenCommunityDetector: replace ContainsKey+indexer with TryGetValue - KGEmbeddingBase: cast to double before int multiplication to prevent overflow - RCDAlgorithm: replace Math.Log2 with Math.Log(n, 2) for net471 compat Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CausalInference (4 files): Vector<>,Vector<> → Matrix<>,Vector<> (Fit takes Matrix<T>) SurvivalAnalysis (6 files): Vector<>,Vector<> → Matrix<>,Vector<> (Predict takes Matrix<T>) OnlineLearning (4 files): Vector<>,Vector<> → Matrix<>,Vector<> (Train/Predict take Matrix<T>) Finance/Volatility (2 files): Vector<>,Vector<> → Tensor<>,Tensor<> (Train/Predict take Tensor<T>) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All TimeSeries models inherit TimeSeriesModelBase which exposes Train(Matrix<T>, Vector<T>) and Predict(Matrix<T>) → Vector<T>. Changed Vector<>,Vector<> → Matrix<>,Vector<> to match actual API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BinaryRelevance and RAkELClassifier output Matrix<T> (multi-label), not Vector<T>. Updated to match MultiLabelClassifierBase.Predict signature. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Tracking models (ByteTrack, DeepSORT, SORT): add Tracking task - DeepSORT: add Embedding task (Re-ID embeddings) - Voice Activity Detectors (EnergyBasedVad, SileroVad, WebRTCVad): add Detection task - AudioEventDetector: add Detection task - SpeakerVerifier: add Embedding task - All 34 TextToImage diffusion models: add Language domain and TextToImage task Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…data attributes Add ThreeD domain and ThreeDGeneration task to all 14 3D diffusion models. Add Language domain to FastConformer speech recognition model. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All models in Diffusion/SuperResolution now have both Enhancement and SuperResolution tasks. UpscaleAVideoModel also gets Video domain. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…with metadata Add MotionGeneration task and Language domain to 3 motion generation models. Add TextToImage task to 6 panorama generation models. Add ImageEditing task to 5 virtual try-on models. Add Video domain to FashionVDMModel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…cific tasks Add Language domain to all text-conditioned audio models. Add TextToSpeech task to Bark, DiffWave, VoiceCraft, SoundStorm. Add Editing task to VoiceCraft (speech editing capability). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove [ModelDomain], [ModelCategory], [ModelTask], [ModelComplexity], and [ModelPaper] attributes from 300 files in FederatedLearning/, RetrievalAugmentedGeneration/, and Finance/Trading/Environments/ that do not implement IFullModel. These are strategy, utility, and infrastructure classes that should not have model metadata annotations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
IFullModelimplementations (~2100+ classes) with metadata attributes (ModelDomain,ModelCategory,ModelTask,ModelComplexity,ModelInput,ModelPaper).ModelMetadataValidationGenerator— a Roslyn incremental source generator that auto-discovers all concreteIFullModelimplementations viaAllInterfaceschain traversal and emits AIDN001/010-012/020 diagnostics for missing attributes and documentation.ModelRegistryGenerator— a Roslyn incremental source generator that auto-generates a staticModelMetadataRegistryclass at compile time with zero runtime reflection. Includes query methods (GetByDomain,GetByCategory,GetByTask,GetByComplexity,GetByTypeName,GetByClassName).Non-model directories clarified
IFullModel. Model metadata attributes were removed from these 299 non-model classes. These issues should be closed as "not applicable" since there are no model classes to annotate.Also included (partial coverage of other issues)
Key Design Decisions
AllInterfacesto recursively walk the entire inheritance chain from any class back toIFullModel<,,>. No hardcoded list of base types.initaccessors) for .NET Framework compatibility.IFullModel. Strategy, utility, and infrastructure classes do not get annotations.[ModelDomain],[ModelCategory], and[ModelTask]attributes (e.g., VisionLanguage models have both Vision and Language domains).Remaining Work (follow-up issues)
ModelTypeenum (deferred until annotations provide replacement)Test plan
dotnet build src/AiDotNet.csproj --framework net10.0 -c Release— 0 errorsdotnet build src/AiDotNet.csproj --framework net471 -c Release— 0 errorsIFullModelimplementations have required attributes🤖 Generated with Claude Code