Skip to content

Commit ab444eb

Browse files
committed
Cache sentence segmentation model
1 parent 57ca6b2 commit ab444eb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

argostranslate/translate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def __init__(self, from_lang: Language, to_lang: Language, pkg: Package):
160160
self.to_lang = to_lang
161161
self.pkg = pkg
162162
self.translator = None
163+
self.sentencizer = SpacySentencizerSmall()
163164

164165
def hypotheses(self, input_text: str, num_hypotheses: int = 4) -> list[Hypothesis]:
165166
if self.translator is None:
@@ -171,7 +172,7 @@ def hypotheses(self, input_text: str, num_hypotheses: int = 4) -> list[Hypothesi
171172
for paragraph in paragraphs:
172173
translated_paragraphs.append(
173174
apply_packaged_translation(
174-
self.pkg, paragraph, self.translator, num_hypotheses
175+
self.pkg, paragraph, self.translator, num_hypotheses, self.sentencizer
175176
)
176177
)
177178
info("translated_paragraphs:", translated_paragraphs)
@@ -394,7 +395,7 @@ def hypotheses(self, input_text: str, num_hypotheses: int = 1) -> list[Hypothesi
394395

395396

396397
def apply_packaged_translation(
397-
pkg: Package, input_text: str, translator: Translator, num_hypotheses: int = 4
398+
pkg: Package, input_text: str, translator: Translator, num_hypotheses: int = 4, sentencizer: sbd.ISentenceBoundaryDetectionModel = SpacySentencizerSmall()
398399
) -> list[Hypothesis]:
399400
"""Applies the translation in pkg to translate input_text.
400401
@@ -452,7 +453,6 @@ def apply_packaged_translation(
452453
info(input_text[start_index:sbd_index])
453454
start_index = sbd_index
454455
"""
455-
sentencizer = SpacySentencizerSmall()
456456
sentences = sentencizer.split_sentences(input_text)
457457

458458
info("sentences", sentences)

0 commit comments

Comments
 (0)