Skip to content

Commit 8e12448

Browse files
authored
Merge pull request #110 from ChEB-AI/fix/prediction-smoothing-empty-labels
fix handling of 0-label predictions
2 parents be279f7 + ef3ba09 commit 8e12448

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

chebai/result/analyse_sem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ def set_label_names(self, label_names):
217217
self.label_successors = self.label_successors.unsqueeze(0)
218218

219219
def __call__(self, preds):
220+
if preds.shape[1] == 0:
221+
# no labels predicted
222+
return preds
223+
# preds shape: (n_samples, n_labels)
220224
preds_sum_orig = torch.sum(preds)
221225
# step 1: apply implications: for each class, set prediction to max of itself and all successors
222226
preds = preds.unsqueeze(1)
223227
preds_masked_succ = torch.where(self.label_successors, preds, 0)
228+
# preds_masked_succ shape: (n_samples, n_labels, n_labels)
229+
224230
preds = preds_masked_succ.max(dim=2).values
225231
if torch.sum(preds) != preds_sum_orig:
226232
print(f"Preds change (step 1): {torch.sum(preds) - preds_sum_orig}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "chebai"
7-
version = "1.0.2"
7+
version = "1.0.3"
88
description = "ChEBai is a deep learning library designed for the integration of deep learning methods with chemical ontologies, particularly ChEBI."
99
authors = [
1010
{ name = "MGlauer", email = "[email protected]" }

0 commit comments

Comments
 (0)