class_docstr: Decodes a (random sample of a) dataset using parameters at given checkpoint and computes BLEU against references.
  
  :param model_folder: The model folder where checkpoint decoder outputs will be written to.
  :param inputs: Path(s) to file containing input sentences (and their factors).
  :param references: Path to file containing references (and their factors).
  :param source_vocabs: The source vocabularies.
  :param target_vocabs: The target vocabularies.
  :param device: The device to use for decoding.
  :param model: The translation model.
  :param max_input_len: Maximum input length.
  :param batch_size: Batch size.
  :param beam_size: Size of the beam.
  :param nbest_size: Size of nbest lists.
  :param length_penalty_alpha: Alpha factor for the length penalty.
  :param length_penalty_beta: Beta factor for the length penalty.
  :param max_output_length_num_stds: Number of standard deviations as safety margin for maximum output length.
  :param ensemble_mode: Ensemble mode: linear or log_linear combination.
  :param sample_size: Maximum number of sentences to sample and decode. If <=0, all sentences are used.
  :param random_seed: Random seed for sampling. Default: 42.
class_docstr_tok: ["Decodes","a","(","random","sample","of","a",")","dataset","using","parameters","at","given","checkpoint","and","computes","BLEU","against","references",".",":","param","model_folder",":","The","model","folder","where","checkpoint","decoder","outputs","will","be","written","to",".",":","param","inputs",":","Path","(","s",")","to","file","containing","input","sentences","(","and","their","factors",")",".",":","param","references",":","Path","to","file","containing","references","(","and","their","factors",")",".",":","param","source_vocabs",":","The","source","vocabularies",".",":","param","target_vocabs",":","The","target","vocabularies",".",":","param","device",":","The","device","to","use","for","decoding",".",":","param","model",":","The","translation","model",".",":","param","max_input_len",":","Maximum","input","length",".",":","param","batch_size",":","Batch","size",".",":","param","beam_size",":","Size","of","the","beam",".",":","param","nbest_size",":","Size","of","nbest","lists",".",":","param","length_penalty_alpha",":","Alpha","factor","for","the","length","penalty",".",":","param","length_penalty_beta",":","Beta","factor","for","the","length","penalty",".",":","param","max_output_length_num_stds",":","Number","of","standard","deviations","as","safety","margin","for","maximum","output","length",".",":","param","ensemble_mode",":","Ensemble","mode",":","linear","or","log_linear","combination",".",":","param","sample_size",":","Maximum","number","of","sentences","to","sample","and","decode",".","If","<","=0",",","all","sentences","are","used",".",":","param","random_seed",":","Random","seed","for","sampling",".","Default",":","42","."]
code: def __init__(
      self,
      model_folder: str,
      inputs: List[str],
      references: List[str],
      source_vocabs: List[vocab.Vocab],
      target_vocabs: List[vocab.Vocab],
      model: model.SockeyeModel,
      device: torch.device,
      max_input_len: Optional[int] = None,
      batch_size: int = 16,
      beam_size: int = C.DEFAULT_BEAM_SIZE,
      nbest_size: int = C.DEFAULT_NBEST_SIZE,
      bucket_width_source: int = 10,
      length_penalty_alpha: float = 1.0,
      length_penalty_beta: float = 0.0,
      max_output_length_num_stds: int = C.DEFAULT_NUM_STD_MAX_OUTPUT_LENGTH,
      ensemble_mode: str = "linear",
      sample_size: int = -1,
      random_seed: int = 42,
  ) -> None:
      self.max_input_len = max_input_len
      self.max_output_length_num_stds = max_output_length_num_stds
      self.ensemble_mode = ensemble_mode
      self.beam_size = beam_size
      self.nbest_size = nbest_size
      self.batch_size = batch_size
      self.bucket_width_source = bucket_width_source
      self.length_penalty_alpha = length_penalty_alpha
      self.length_penalty_beta = length_penalty_beta
      self.model = model
  
      with ExitStack() as exit_stack:
          inputs_fins = [
              exit_stack.enter_context(utils.smart_open(f))
              for f in inputs
          ]
          references_fins = [
              exit_stack.enter_context(utils.smart_open(f))
              for f in references
          ]
  
          inputs_sentences = [f.readlines() for f in inputs_fins]
          targets_sentences = [f.readlines() for f in references_fins]
  
          utils.check_condition(
              all(
                  len(l) == len(targets_sentences[0])
                  for l in chain(inputs_sentences, targets_sentences)
              ),
              "Sentences differ in length.",
          )
          utils.check_condition(
              all(
                  len(sentence.strip()) > 0
                  for sentence in targets_sentences[0]
              ),
              "Empty target validation sentence.",
          )
  
          if sample_size <= 0:
              sample_size = len(inputs_sentences[0])
          if sample_size < len(inputs_sentences[0]):
              sentences = parallel_subsample(
                  inputs_sentences + targets_sentences,
                  sample_size,
                  random_seed,
              )
              self.inputs_sentences = sentences[
                  0 : len(inputs_sentences)
              ]
              self.targets_sentences = sentences[
                  len(inputs_sentences) :
              ]
          else:
              self.inputs_sentences, self.targets_sentences = (
                  inputs_sentences,
                  targets_sentences,
              )
  
          if sample_size < self.batch_size:
              self.batch_size = sample_size
      for factor_idx, factor in enumerate(self.inputs_sentences):
          write_to_file(
              factor,
              os.path.join(
                  model_folder,
                  C.DECODE_IN_NAME.format(factor=factor_idx),
              ),
          )
      for factor_idx, factor in enumerate(self.targets_sentences):
          write_to_file(
              factor,
              os.path.join(
                  model_folder,
                  C.DECODE_REF_NAME.format(factor=factor_idx),
              ),
          )
  
      self.inputs_sentences = list(zip(*self.inputs_sentences))  # type: ignore
  
      scorer = inference.CandidateScorer(
          length_penalty_alpha=length_penalty_alpha,
          length_penalty_beta=length_penalty_beta,
          brevity_penalty_weight=0.0,
      )
  
      self.translator = inference.Translator(
          batch_size=self.batch_size,
          device=device,
          ensemble_mode=self.ensemble_mode,
          scorer=scorer,
          beam_search_stop="all",
          nbest_size=self.nbest_size,
          models=[self.model],
          source_vocabs=source_vocabs,
          target_vocabs=target_vocabs,
          restrict_lexicon=None,
      )
  
      logger.info(
          "Created CheckpointDecoder(max_input_len=%d, beam_size=%d, num_sentences=%d)",
          max_input_len if max_input_len is not None else -1,
          beam_size,
          len(self.targets_sentences[0]),
      )
  
file_path: sockeye/sockeye/checkpoint_decoder.py
imports: import logging
  import os
  import random
  import time
  from contextlib import ExitStack
  from itertools import chain
  from typing import Any, Dict, Optional, List
  import torch
  from .None import constants
  from .None import evaluate
  from .None import inference
  from .None import model
  from .None import utils
  from .None import vocab
label_desc: Use image node_id 1 to create a new CheckpointDecoder object  with example: obj = CheckpointDecoder(model_folder, inputs, references, source_vocabs, target_vocabs, model, device, max_input_len, batch_size, beam_size, nbest_size, bucket_width_source, length_penalty_alpha, length_penalty_beta, max_output_length_num_stds, ensemble_mode, sample_size, random_seed)