Skip to content

Commit

Permalink
slightly adjusted calculation for edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
twerkmeister committed Sep 21, 2023
1 parent a54232c commit 7a74d8c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rasa/utils/tensorflow/data_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from typing import List, Union, Text, Optional, Any, Tuple, Dict, cast

import logging
Expand Down Expand Up @@ -380,8 +381,8 @@ def __len__(self) -> int:
# data was rebalanced, so need to recalculate number of examples
num_examples = self.model_data.number_of_examples(self._data)
batch_size = self._current_batch_size
# keep last batch only if it has more than half a batch size of examples
last_batch_half_full = num_examples % batch_size > batch_size // 2
# keep last batch only if it has at least half a batch size of examples
last_batch_half_full = num_examples % batch_size >= math.ceil(batch_size / 2)
num_batches = num_examples // batch_size + int(last_batch_half_full)
# Return at least 1 if there is an example
return max(num_batches, int(num_examples > 0))
Expand Down

0 comments on commit 7a74d8c

Please sign in to comment.