Skip to content

Commit da1e025

Browse files
jgallowa07claude
andauthored
Enhance model factory with comprehensive improvements (Issue #151) (#156)
* Enhance model factory with comprehensive improvements (Issue #151) ## Summary - Add comprehensive model factory infrastructure with validation, presets, and multi-format support - Fix datetime deprecation warning affecting all model creation - Add extensive testing and documentation improvements ## Features Added - JSON configuration file support alongside YAML - Auto-format detection for configuration files (.yaml/.yml/.json) - 5 predefined model presets for common configurations - Parameter validation with helpful error messages - Model introspection and utility functions ## API Enhancements - `create_selection_model_from_json()` - JSON file support - `create_selection_model_from_file()` - Auto-detect file format - `create_model_from_preset()` - Create from predefined configurations - `list_available_models()` - List all available model classes - `get_model_info()` - Model parameter introspection - `describe_model()` - Model architecture summary ## Bug Fixes - Fix datetime.utcnow() deprecation warning in netam/models.py - Enhanced error messages with suggestions and usage hints - Comprehensive parameter validation for transformer models ## Testing - 25 comprehensive tests covering all new functionality - Tests for error conditions, validation, and edge cases - All existing tests still pass (113 total) ## Documentation - Enhanced docstrings with examples and parameter details - 6 example configuration files (5 YAML + 1 JSON) - Clear usage examples for all new functions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Remove JSON support and move presets to config files Based on PR feedback: - Remove JSON configuration support to maintain YAML-only approach - Move preset configurations from hardcoded dictionary to model_configs/ directory - Add list_available_presets() function for preset discovery - Update package configuration to include model_configs/*.yaml files This change improves consistency by using YAML throughout and separates configuration from code, making presets easier to maintain and extend. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * more robust configuration of MODEL_CONFIGS_DIR --------- Co-authored-by: Claude <[email protected]>
1 parent fa28bdf commit da1e025

15 files changed

+964
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
model_class: BidirectionalTransformerBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
6+
nhead: 4
7+
d_model_per_head: 6
8+
dim_feedforward: 512
9+
layer_count: 2
10+
dropout_prob: 0.1

examples/parent_independent.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
model_class: ParentIndependentBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20

examples/single.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
model_class: SingleValueBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20

examples/transformer_large.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
model_class: TransformerBinarySelectionModelWiggleAct
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
6+
nhead: 8
7+
d_model_per_head: 8
8+
dim_feedforward: 2048
9+
layer_count: 6
10+
dropout_prob: 0.1

examples/transformer_sml.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
model_class: TransformerBinarySelectionModelWiggleAct
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
6+
nhead: 4
7+
d_model_per_head: 4
8+
dim_feedforward: 1024
9+
layer_count: 3
10+
dropout_prob: 0.1

netam/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""netam: Neural networks for antibody affinity maturation."""
2+
3+
from .model_factory import (
4+
create_selection_model_from_dict,
5+
create_selection_model_from_yaml,
6+
create_selection_model_from_file,
7+
create_model_from_preset,
8+
list_available_models,
9+
list_available_presets,
10+
get_model_info,
11+
describe_model,
12+
)
13+
14+
__all__ = [
15+
"create_selection_model_from_dict",
16+
"create_selection_model_from_yaml",
17+
"create_selection_model_from_file",
18+
"create_model_from_preset",
19+
"list_available_models",
20+
"list_available_presets",
21+
"get_model_info",
22+
"describe_model",
23+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
model_class: BidirectionalTransformerBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
6+
nhead: 4
7+
d_model_per_head: 6
8+
dim_feedforward: 256
9+
layer_count: 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
model_class: ParentIndependentBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
model_class: SingleValueBinarySelectionModel
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
model_class: TransformerBinarySelectionModelWiggleAct
2+
hparams:
3+
model_type: dasm
4+
known_token_count: 21
5+
output_dim: 20
6+
nhead: 8
7+
d_model_per_head: 8
8+
dim_feedforward: 2048
9+
layer_count: 6
10+
dropout_prob: 0.1

0 commit comments

Comments
 (0)