Builds a :class:`~hanlp.common.dataset.SortingSampler`. Args: batch_max_tokens: Maximum tokens per batch. use_effective_tokens: Whether to calculate effective number of tokens when applying the `batch_max_tokens`. batch_size: Maximum samples per batch.
(self, batch_size=None, batch_max_tokens=None, use_effective_tokens=False)
| 774 | class SortingSamplerBuilder(SortingSampler, SamplerBuilder): |
| 775 | # noinspection PyMissingConstructor |
| 776 | def __init__(self, batch_size=None, batch_max_tokens=None, use_effective_tokens=False) -> None: |
| 777 | """Builds a :class:`~hanlp.common.dataset.SortingSampler`. |
| 778 | |
| 779 | Args: |
| 780 | batch_max_tokens: Maximum tokens per batch. |
| 781 | use_effective_tokens: Whether to calculate effective number of tokens when applying the `batch_max_tokens`. |
| 782 | batch_size: Maximum samples per batch. |
| 783 | """ |
| 784 | self.use_effective_tokens = use_effective_tokens |
| 785 | self.batch_max_tokens = batch_max_tokens |
| 786 | self.batch_size = batch_size |
| 787 | |
| 788 | def build(self, lengths: List[int], shuffle=False, gradient_accumulation=1, **kwargs) -> Sampler: |
| 789 | batch_size, batch_max_tokens = self.scale(gradient_accumulation) |
nothing calls this directly
no outgoing calls
no test coverage detected