MCPcopy Create free account
hub / github.com/hankcs/HanLP / __init__

Method __init__

hanlp/common/dataset.py:776–786  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

774class 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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected