Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions pyhealth/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, dataset: SampleDataset):
# used to query the device of the model
self._dummy_param = nn.Parameter(torch.empty(0))

self.mode = None # legacy API for backward compatibility with the trainer.

@property
def device(self) -> torch.device:
"""
Expand All @@ -50,9 +52,9 @@ def get_output_size(self) -> int:
Returns:
int: The output size of the model.
"""
assert len(self.label_keys) == 1, (
"Only one label key is supported if get_output_size is called"
)
assert (
len(self.label_keys) == 1
), "Only one label key is supported if get_output_size is called"
output_size = self.dataset.output_processors[self.label_keys[0]].size()
return output_size

Expand All @@ -69,9 +71,9 @@ def get_loss_function(self) -> Callable:
Returns:
Callable: The default loss function.
"""
assert len(self.label_keys) == 1, (
"Only one label key is supported if get_loss_function is called"
)
assert (
len(self.label_keys) == 1
), "Only one label key is supported if get_loss_function is called"
label_key = self.label_keys[0]
mode = self.dataset.output_schema[label_key]
if mode == "binary":
Expand Down Expand Up @@ -106,9 +108,9 @@ def prepare_y_prob(self, logits: torch.Tensor) -> torch.Tensor:
Returns:
torch.Tensor: The predicted probability tensor.
"""
assert len(self.label_keys) == 1, (
"Only one label key is supported if get_loss_function is called"
)
assert (
len(self.label_keys) == 1
), "Only one label key is supported if get_loss_function is called"
label_key = self.label_keys[0]
mode = self.dataset.output_schema[label_key]
if mode in ["binary"]:
Expand Down