MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / translator_score_iterable

Function translator_score_iterable

python/ctranslate2/extensions.py:91–127  ·  view source on GitHub ↗

Scores an iterable of tokenized examples. This method is built on top of :meth:`ctranslate2.Translator.score_batch` to efficiently score an arbitrarily large stream of data. It enables the following optimizations: * stream processing (the iterable is not fully materialized in memor

(
    translator: Translator,
    source: Iterable[List[str]],
    target: Iterable[List[str]],
    max_batch_size: int = 64,
    batch_type: str = "examples",
    **kwargs,
)

Source from the content-addressed store, hash-verified

89
90
91def translator_score_iterable(
92 translator: Translator,
93 source: Iterable[List[str]],
94 target: Iterable[List[str]],
95 max_batch_size: int = 64,
96 batch_type: str = "examples",
97 **kwargs,
98) -> Iterable[ScoringResult]:
99 """Scores an iterable of tokenized examples.
100
101 This method is built on top of :meth:`ctranslate2.Translator.score_batch`
102 to efficiently score an arbitrarily large stream of data. It enables the
103 following optimizations:
104
105 * stream processing (the iterable is not fully materialized in memory)
106 * parallel scoring (if the translator has multiple workers)
107 * asynchronous batch prefetching
108 * local sorting by length
109
110 Arguments:
111 source: An iterable of tokenized source examples.
112 target: An iterable of tokenized target examples.
113 max_batch_size: The maximum batch size.
114 batch_type: Whether :obj:`max_batch_size` is the number of "examples" or "tokens".
115 **kwargs: Any scoring options accepted by
116 :meth:`ctranslate2.Translator.score_batch`.
117
118 Returns:
119 A generator iterator over :class:`ctranslate2.ScoringResult` instances.
120 """
121 yield from _process_iterable(
122 translator.score_batch,
123 [source, target],
124 max_batch_size,
125 batch_type,
126 **kwargs,
127 )
128
129
130def generator_generate_iterable(

Callers

nothing calls this directly

Calls 1

_process_iterableFunction · 0.85

Tested by

no test coverage detected