class_docstr: Translator: basic wrapper around MarianMT model for language translation
class_docstr_tok: ["Translator",":","basic","wrapper","around","MarianMT","model","for","language","translation"]
docstr: ```
  Translate sentences using model_name as model.
  To speed up translations, you can set num_beams and early_stopping (e.g., num_beams=4, early_stopping=True).
  Args:
    sentences(list): list of strings representing sentences that need to be translated
                   IMPORTANT NOTE: Sentences are joined together and fed to model as single batch.
                                   If the input text is very large (e.g., an entire book), you should
                                   break it up into reasonbly-sized chunks (e.g., pages, paragraphs, or sentences) and
                                   feed each chunk separately into translate to avoid out-of-memory issues.
    num_beams(int): Number of beams for beam search. Defaults to None.  If None, the transformers library defaults this to 1,
                    whicn means no beam search.
    early_stopping(bool):  Whether to stop the beam search when at least ``num_beams`` sentences
                           are finished per batch or not. Defaults to None.  If None, the transformers library
                           sets this to False.
  Returns:
    str: translated sentences
  ```
docstr_tok: ["``","`","Translate","sentences","using","model_name","as","model",".","To","speed","up","translations",",","you","can","set","num_beams","and","early_stopping","(","e.g.",",","num_beams=4",",","early_stopping=True",")",".","Args",":","sentences","(","list",")",":","list","of","strings","representing","sentences","that","need","to","be","translated","IMPORTANT","NOTE",":","Sentences","are","joined","together","and","fed","to","model","as","single","batch",".","If","the","input","text","is","very","large","(","e.g.",",","an","entire","book",")",",","you","should","break","it","up","into","reasonbly-sized","chunks","(","e.g.",",","pages",",","paragraphs",",","or","sentences",")","and","feed","each","chunk","separately","into","translate","to","avoid","out-of-memory","issues",".","num_beams","(","int",")",":","Number","of","beams","for","beam","search",".","Defaults","to","None",".","If","None",",","the","transformers","library","defaults","this","to","1",",","whicn","means","no","beam","search",".","early_stopping","(","bool",")",":","Whether","to","stop","the","beam","search","when","at","least","``","num_beams","``","sentences","are","finished","per","batch","or","not",".","Defaults","to","None",".","If","None",",","the","transformers","library","sets","this","to","False",".","Returns",":","str",":","translated","sentences","``","`"]
code: def translate_sentences(
      self, sentences, num_beams=1, early_stopping=False
  ):
      """
      ```
      Translate sentences using model_name as model.
      To speed up translations, you can set num_beams and early_stopping (e.g., num_beams=4, early_stopping=True).
      Args:
        sentences(list): list of strings representing sentences that need to be translated
                       IMPORTANT NOTE: Sentences are joined together and fed to model as single batch.
                                       If the input text is very large (e.g., an entire book), you should
                                       break it up into reasonbly-sized chunks (e.g., pages, paragraphs, or sentences) and
                                       feed each chunk separately into translate to avoid out-of-memory issues.
        num_beams(int): Number of beams for beam search. Defaults to None.  If None, the transformers library defaults this to 1,
                        whicn means no beam search.
        early_stopping(bool):  Whether to stop the beam search when at least ``num_beams`` sentences
                               are finished per batch or not. Defaults to None.  If None, the transformers library
                               sets this to False.
      Returns:
        str: translated sentences
      ```
      """
      import torch
  
      with torch.no_grad():
          translated = self.model.generate(
              **self.tokenizer.prepare_seq2seq_batch(
                  sentences, return_tensors="pt"
              ).to(self.torch_device),
              num_beams=num_beams,
              early_stopping=early_stopping,
          )
          tgt_sentences = [
              self.tokenizer.decode(t, skip_special_tokens=True)
              for t in translated
          ]
      return tgt_sentences
  
file_path: ktrain/ktrain/text/translation/core.py
imports: from ...None import utils
  from ...imports import *
  from ...torch_base import TorchBase
  from ..None import textutils
label_desc: Use image node_id 3 for calling the Translator obj's underlying member method code with example usage: obj.translate_sentences(sentences, num_beams, early_stopping) and returns: tgt_sentences