diff --git a/_modules/mammoth/modules/embeddings.html b/_modules/mammoth/modules/embeddings.html index 5d19914f..3043f666 100644 --- a/_modules/mammoth/modules/embeddings.html +++ b/_modules/mammoth/modules/embeddings.html @@ -515,12 +515,12 @@

Source code for mammoth.modules.embeddings

     return tensor
 
 # FIXME: seems it got nuked during the great refactoring of data
-# def prepare_pretrained_embeddings(opt, fields):
-#     if all([opt.both_embeddings is None, opt.src_embeddings is None, opt.tgt_embeddings is None]):
+# def prepare_pretrained_embeddings(opts, fields):
+#     if all([opts.both_embeddings is None, opts.src_embeddings is None, opts.tgt_embeddings is None]):
 #         return
 #
 #     assert (
-#         opt.save_data
+#         opts.save_data
 #     ), "-save_data is required when using \
 #         pretrained embeddings."
 #
@@ -533,45 +533,45 @@ 

Source code for mammoth.modules.embeddings

 #         vocs.append(vocab)
 #     enc_vocab, dec_vocab = vocs
 #
-#     skip_lines = 1 if opt.embeddings_type == "word2vec" else 0
-#     if opt.both_embeddings is not None:
+#     skip_lines = 1 if opts.embeddings_type == "word2vec" else 0
+#     if opts.both_embeddings is not None:
 #         set_of_src_and_tgt_vocab = set(enc_vocab.stoi.keys()) | set(dec_vocab.stoi.keys())
-#         logger.info("Reading encoder and decoder embeddings from {}".format(opt.both_embeddings))
-#         src_vectors, total_vec_count = read_embeddings(opt.both_embeddings, skip_lines, set_of_src_and_tgt_vocab)
+#         logger.info("Reading encoder and decoder embeddings from {}".format(opts.both_embeddings))
+#         src_vectors, total_vec_count = read_embeddings(opts.both_embeddings, skip_lines, set_of_src_and_tgt_vocab)
 #         tgt_vectors = src_vectors
 #         logger.info("\tFound {} total vectors in file".format(total_vec_count))
 #     else:
-#         if opt.src_embeddings is not None:
-#             logger.info("Reading encoder embeddings from {}".format(opt.src_embeddings))
-#             src_vectors, total_vec_count = read_embeddings(opt.src_embeddings, skip_lines, filter_set=enc_vocab.stoi)
+#         if opts.src_embeddings is not None:
+#             logger.info("Reading encoder embeddings from {}".format(opts.src_embeddings))
+#             src_vectors, total_vec_count = read_embeddings(opts.src_embeddings, skip_lines, filter_set=enc_vocab.stoi)
 #             logger.info("\tFound {} total vectors in file.".format(total_vec_count))
 #         else:
 #             src_vectors = None
-#         if opt.tgt_embeddings is not None:
-#             logger.info("Reading decoder embeddings from {}".format(opt.tgt_embeddings))
-#             tgt_vectors, total_vec_count = read_embeddings(opt.tgt_embeddings, skip_lines, filter_set=dec_vocab.stoi)
+#         if opts.tgt_embeddings is not None:
+#             logger.info("Reading decoder embeddings from {}".format(opts.tgt_embeddings))
+#             tgt_vectors, total_vec_count = read_embeddings(opts.tgt_embeddings, skip_lines, filter_set=dec_vocab.stoi)
 #             logger.info("\tFound {} total vectors in file".format(total_vec_count))
 #         else:
 #             tgt_vectors = None
 #     logger.info("After filtering to vectors in vocab:")
-#     if opt.src_embeddings is not None or opt.both_embeddings is not None:
+#     if opts.src_embeddings is not None or opts.both_embeddings is not None:
 #         logger.info("\t* enc: %d match, %d missing, (%.2f%%)" % calc_vocab_load_stats(enc_vocab, src_vectors))
-#     if opt.tgt_embeddings is not None or opt.both_embeddings is not None:
+#     if opts.tgt_embeddings is not None or opts.both_embeddings is not None:
 #         logger.info("\t* dec: %d match, %d missing, (%.2f%%)" % calc_vocab_load_stats(dec_vocab, tgt_vectors))
 #
 #     # Write to file
-#     enc_output_file = opt.save_data + ".enc_embeddings.pt"
-#     dec_output_file = opt.save_data + ".dec_embeddings.pt"
-#     if opt.src_embeddings is not None or opt.both_embeddings is not None:
+#     enc_output_file = opts.save_data + ".enc_embeddings.pt"
+#     dec_output_file = opts.save_data + ".dec_embeddings.pt"
+#     if opts.src_embeddings is not None or opts.both_embeddings is not None:
 #         logger.info("\nSaving encoder embeddings as:\n\t* enc: %s" % enc_output_file)
 #         torch.save(convert_to_torch_tensor(src_vectors, enc_vocab), enc_output_file)
-#         # set the opt in place
-#         opt.pre_word_vecs_enc = enc_output_file
-#     if opt.tgt_embeddings is not None or opt.both_embeddings is not None:
+#         # set the opts in place
+#         opts.pre_word_vecs_enc = enc_output_file
+#     if opts.tgt_embeddings is not None or opts.both_embeddings is not None:
 #         logger.info("\nSaving decoder embeddings as:\n\t* dec: %s" % dec_output_file)
 #         torch.save(convert_to_torch_tensor(tgt_vectors, dec_vocab), dec_output_file)
-#         # set the opt in place
-#         opt.pre_word_vecs_dec = dec_output_file
+#         # set the opts in place
+#         opts.pre_word_vecs_dec = dec_output_file
 
diff --git a/_modules/mammoth/trainer.html b/_modules/mammoth/trainer.html index 053e1aa2..a5878c3b 100644 --- a/_modules/mammoth/trainer.html +++ b/_modules/mammoth/trainer.html @@ -207,7 +207,7 @@

Source code for mammoth.trainer

 
 
 def build_trainer(
-    opt,
+    opts,
     device_context,
     model,
     vocabs_dict,
@@ -217,10 +217,10 @@ 

Source code for mammoth.trainer

     generators_md=None,
 ):
     """
-    Simplify `Trainer` creation based on user `opt`s*
+    Simplify `Trainer` creation based on user `opts`s*
 
     Args:
-        opt (:obj:`Namespace`): user options (usually from argument parsing)
+        opts (:obj:`Namespace`): user options (usually from argument parsing)
         model (:obj:`mammoth.models.NMTModel`): the model to train
         vocabs_dict (dict): dict of vocabs
         optim (:obj:`mammoth.utils.Optimizer`): optimizer used during training
@@ -238,31 +238,31 @@ 

Source code for mammoth.trainer

         generator = generators_md[f'generator_{lang}']
         train_loss_md.add_module(
             f'trainloss{lang}',
-            mammoth.utils.loss.build_loss_compute(model, tgt_vocab, opt, train=True, generator=generator),
+            mammoth.utils.loss.build_loss_compute(model, tgt_vocab, opts, train=True, generator=generator),
         )
         valid_loss_md.add_module(
             f'valloss{lang}',
-            mammoth.utils.loss.build_loss_compute(model, tgt_vocab, opt, train=False, generator=generator),
+            mammoth.utils.loss.build_loss_compute(model, tgt_vocab, opts, train=False, generator=generator),
         )
 
-    trunc_size = opt.truncated_decoder  # Badly named...
-    shard_size = opt.max_generator_batches if opt.model_dtype == 'fp32' else 0
-    norm_method = opt.normalization
-    accum_count = opt.accum_count
-    accum_steps = opt.accum_steps
-    average_decay = opt.average_decay
-    average_every = opt.average_every
-    dropout = opt.dropout
-    dropout_steps = opt.dropout_steps
-    gpu_verbose_level = opt.gpu_verbose_level
+    trunc_size = opts.truncated_decoder  # Badly named...
+    shard_size = opts.max_generator_batches if opts.model_dtype == 'fp32' else 0
+    norm_method = opts.normalization
+    accum_count = opts.accum_count
+    accum_steps = opts.accum_steps
+    average_decay = opts.average_decay
+    average_every = opts.average_every
+    dropout = opts.dropout
+    dropout_steps = opts.dropout_steps
+    gpu_verbose_level = opts.gpu_verbose_level
 
     earlystopper = (
-        mammoth.utils.EarlyStopping(opt.early_stopping, scorers=mammoth.utils.scorers_from_opts(opt))
-        if opt.early_stopping > 0
+        mammoth.utils.EarlyStopping(opts.early_stopping, scorers=mammoth.utils.scorers_from_opts(opts))
+        if opts.early_stopping > 0
         else None
     )
 
-    report_manager = mammoth.utils.build_report_manager(opt, device_context.node_rank, device_context.local_rank)
+    report_manager = mammoth.utils.build_report_manager(opts, device_context.node_rank, device_context.local_rank)
     trainer = mammoth.Trainer(
         model,
         train_loss_md,
@@ -276,16 +276,16 @@ 

Source code for mammoth.trainer

         device_context=device_context,
         gpu_verbose_level=gpu_verbose_level,
         report_manager=report_manager,
-        with_align=True if opt.lambda_align > 0 else False,
+        with_align=True if opts.lambda_align > 0 else False,
         model_saver=model_saver,
         average_decay=average_decay,
         average_every=average_every,
-        model_dtype=opt.model_dtype,
+        model_dtype=opts.model_dtype,
         earlystopper=earlystopper,
         dropout=dropout,
         dropout_steps=dropout_steps,
         task_queue_manager=task_queue_manager,
-        report_stats_from_parameters=opt.report_stats_from_parameters,
+        report_stats_from_parameters=opts.report_stats_from_parameters,
     )
     return trainer
 
diff --git a/_modules/mammoth/translate/beam_search.html b/_modules/mammoth/translate/beam_search.html
index 06d48d9e..3106fc07 100644
--- a/_modules/mammoth/translate/beam_search.html
+++ b/_modules/mammoth/translate/beam_search.html
@@ -587,8 +587,8 @@ 

Source code for mammoth.translate.beam_search

""" @classmethod - def from_opt(cls, opt): - return cls(opt.alpha, opt.beta, opt.length_penalty, opt.coverage_penalty) + def from_opts(cls, opts): + return cls(opts.alpha, opts.beta, opts.length_penalty, opts.coverage_penalty) def __init__(self, alpha, beta, length_penalty, coverage_penalty): self._validate(alpha, beta, length_penalty, coverage_penalty) diff --git a/_modules/mammoth/translate/translation_server.html b/_modules/mammoth/translate/translation_server.html index 2673a19f..b1075639 100644 --- a/_modules/mammoth/translate/translation_server.html +++ b/_modules/mammoth/translate/translation_server.html @@ -272,7 +272,7 @@

Source code for mammoth.translate.translation_server

self.translator.unload_model(to_cpu=True) @staticmethod - def convert_onmt_to_ct2_opts(ct2_translator_args, ct2_translate_batch_args, opt): + def convert_onmt_to_ct2_opts(ct2_translator_args, ct2_translate_batch_args, opts): def setdefault_if_exists_must_match(obj, name, value): if name in obj: assert value == obj[name], ( @@ -292,18 +292,18 @@

Source code for mammoth.translate.translation_server

ct2_translator_args.setdefault(name, value) onmt_for_translator = { - "device": "cuda" if opt.cuda else "cpu", - "device_index": opt.gpu if opt.cuda else 0, + "device": "cuda" if opts.cuda else "cpu", + "device_index": opts.gpu if opts.cuda else 0, } for name, value in onmt_for_translator.items(): setdefault_if_exists_must_match(ct2_translator_args, name, value) onmt_for_translate_batch_enforce = { - "beam_size": opt.beam_size, - "max_batch_size": opt.batch_size, - "num_hypotheses": opt.n_best, - "max_decoding_length": opt.max_length, - "min_decoding_length": opt.min_length, + "beam_size": opts.beam_size, + "max_batch_size": opts.batch_size, + "num_hypotheses": opts.n_best, + "max_decoding_length": opts.max_length, + "min_decoding_length": opts.min_length, } for name, value in onmt_for_translate_batch_enforce.items(): setdefault_if_exists_must_match(ct2_translate_batch_args, name, value) @@ -368,32 +368,32 @@

Source code for mammoth.translate.translation_server

} kwargs = {k: v for (k, v) in kwargs.items() if v is not None} model_id = conf.get("id", None) - opt = conf["opt"] - opt["models"] = conf["models"] - self.preload_model(opt, model_id=model_id, **kwargs)
+ opts = conf["opts"] + opts["models"] = conf["models"] + self.preload_model(opts, model_id=model_id, **kwargs)
-
[docs] def clone_model(self, model_id, opt, timeout=-1): +
[docs] def clone_model(self, model_id, opts, timeout=-1): """Clone a model `model_id`. - Different options may be passed. If `opt` is None, it will use the + Different options may be passed. If `opts` is None, it will use the same set of options """ if model_id in self.models: - if opt is None: - opt = self.models[model_id].user_opt - opt["models"] = self.models[model_id].opt.models - return self.load_model(opt, timeout) + if opts is None: + opts = self.models[model_id].user_opt + opts["models"] = self.models[model_id].opts.models + return self.load_model(opts, timeout) else: raise ServerModelError("No such model '%s'" % str(model_id))
-
[docs] def load_model(self, opt, model_id=None, **model_kwargs): +
[docs] def load_model(self, opts, model_id=None, **model_kwargs): """Load a model given a set of options""" - model_id = self.preload_model(opt, model_id=model_id, **model_kwargs) + model_id = self.preload_model(opts, model_id=model_id, **model_kwargs) load_time = self.models[model_id].load_time return model_id, load_time
-
[docs] def preload_model(self, opt, model_id=None, **model_kwargs): +
[docs] def preload_model(self, opts, model_id=None, **model_kwargs): """Preloading the model: updating internal datastructure It will effectively load the model if `load` is set @@ -407,7 +407,7 @@

Source code for mammoth.translate.translation_server

model_id += 1 self.next_id = model_id + 1 print("Pre-loading model %d" % model_id) - model = ServerModel(opt, model_id, **model_kwargs) + model = ServerModel(opts, model_id, **model_kwargs) self.models[model_id] = model return model_id
@@ -451,7 +451,7 @@

Source code for mammoth.translate.translation_server

"""Wrap a model with server functionality. Args: - opt (dict): Options for the Translator + opts (dict): Options for the Translator model_id (int): Model ID preprocess_opt (list): Options for preprocess processus or None tokenizer_opt (dict): Options for the tokenizer or None @@ -469,7 +469,7 @@

Source code for mammoth.translate.translation_server

def __init__( self, - opt, + opts, model_id, preprocess_opt=None, tokenizer_opt=None, @@ -484,7 +484,7 @@

Source code for mammoth.translate.translation_server

ct2_translate_batch_args=None, ): self.model_root = model_root - self.opt = self.parse_opt(opt) + self.opts = self.parse_opt(opts) self.custom_opt = custom_opt self.model_id = model_id @@ -499,20 +499,20 @@

Source code for mammoth.translate.translation_server

self.ct2_translate_batch_args = ct2_translate_batch_args self.unload_timer = None - self.user_opt = opt + self.user_opt = opts self.tokenizers = None - if len(self.opt.log_file) > 0: - log_file = os.path.join(model_root, self.opt.log_file) + if len(self.opts.log_file) > 0: + log_file = os.path.join(model_root, self.opts.log_file) else: log_file = None - self.logger = init_logger(log_file=log_file, log_file_level=self.opt.log_file_level, rotate=True) + self.logger = init_logger(log_file=log_file, log_file_level=self.opts.log_file_level, rotate=True) self.loading_lock = threading.Event() self.loading_lock.set() self.running_lock = threading.Semaphore(value=1) - set_random_seed(self.opt.seed, self.opt.cuda) + set_random_seed(self.opts.seed, self.opts.cuda) if self.preprocess_opt is not None: self.logger.info("Loading preprocessor") @@ -547,14 +547,14 @@

Source code for mammoth.translate.translation_server

self.load(preload=True) self.stop_unload_timer() -
[docs] def parse_opt(self, opt): +
[docs] def parse_opt(self, opts): """Parse the option set passed by the user using `mammoth.opts` Args: - opt (dict): Options passed by the user + opts (dict): Options passed by the user Returns: - opt (argparse.Namespace): full set of options for the Translator + opts (argparse.Namespace): full set of options for the Translator """ prec_argv = sys.argv @@ -562,13 +562,13 @@

Source code for mammoth.translate.translation_server

parser = ArgumentParser() mammoth.opts.translate_opts(parser) - models = opt['models'] + models = opts['models'] if not isinstance(models, (list, tuple)): models = [models] - opt['models'] = [os.path.join(self.model_root, model) for model in models] - opt['src'] = "dummy_src" + opts['models'] = [os.path.join(self.model_root, model) for model in models] + opts['src'] = "dummy_src" - for (k, v) in opt.items(): + for (k, v) in opts.items(): if k == 'models': sys.argv += ['-model'] sys.argv += [str(model) for model in v] @@ -577,12 +577,12 @@

Source code for mammoth.translate.translation_server

else: sys.argv += ['-%s' % k, str(v)] - opt = parser.parse_args() - ArgumentParser.validate_translate_opts(opt) - opt.cuda = opt.gpu > -1 + opts = parser.parse_args() + ArgumentParser.validate_translate_opts(opts) + opts.cuda = opts.gpu > -1 sys.argv = prec_argv - return opt
+ return opts
@property def loaded(self): @@ -598,18 +598,18 @@

Source code for mammoth.translate.translation_server

try: if self.ct2_model is not None: CTranslate2Translator.convert_onmt_to_ct2_opts( - self.ct2_translator_args, self.ct2_translate_batch_args, self.opt + self.ct2_translator_args, self.ct2_translate_batch_args, self.opts ) self.translator = CTranslate2Translator( self.ct2_model, ct2_translator_args=self.ct2_translator_args, ct2_translate_batch_args=self.ct2_translate_batch_args, - target_prefix=self.opt.tgt_prefix, + target_prefix=self.opts.tgt_prefix, preload=preload, ) else: self.translator = build_translator( - self.opt, report_score=False, out_file=codecs.open(os.devnull, "w", "utf-8") + self.opts, report_score=False, out_file=codecs.open(os.devnull, "w", "utf-8") ) except RuntimeError as e: raise ServerModelError("Runtime Error: %s" % str(e)) @@ -647,7 +647,7 @@

Source code for mammoth.translate.translation_server

if not self.loaded: self.load() timer.tick(name="load") - elif self.opt.cuda: + elif self.opts.cuda: self.to_gpu() timer.tick(name="to_gpu") @@ -694,14 +694,14 @@

Source code for mammoth.translate.translation_server

scores, predictions = self.translator.translate( texts_to_translate, tgt=texts_ref, - batch_size=len(texts_to_translate) if self.opt.batch_size == 0 else self.opt.batch_size, + batch_size=len(texts_to_translate) if self.opts.batch_size == 0 else self.opts.batch_size, ) except (RuntimeError, Exception) as e: err = "Error: %s" % str(e) self.logger.error(err) self.logger.error("repr(text_to_translate): " + repr(texts_to_translate)) self.logger.error("model: #%s" % self.model_id) - self.logger.error("model opt: " + str(self.opt.__dict__)) + self.logger.error("model opts: " + str(self.opts.__dict__)) self.logger.error(traceback.format_exc()) raise ServerModelError(err) @@ -718,7 +718,7 @@

Source code for mammoth.translate.translation_server

def flatten_list(_list): return sum(_list, []) - tiled_texts = [t for t in texts_to_translate for _ in range(self.opt.n_best)] + tiled_texts = [t for t in texts_to_translate for _ in range(self.opts.n_best)] results = flatten_list(predictions) def maybe_item(x): @@ -733,24 +733,24 @@

Source code for mammoth.translate.translation_server

# build back results with empty texts for i in empty_indices: - j = i * self.opt.n_best - results = results[:j] + [""] * self.opt.n_best + results[j:] - aligns = aligns[:j] + [None] * self.opt.n_best + aligns[j:] - scores = scores[:j] + [0] * self.opt.n_best + scores[j:] + j = i * self.opts.n_best + results = results[:j] + [""] * self.opts.n_best + results[j:] + aligns = aligns[:j] + [None] * self.opts.n_best + aligns[j:] + scores = scores[:j] + [0] * self.opts.n_best + scores[j:] rebuilt_segs, scores, aligns = self.rebuild_seg_packages( - all_preprocessed, results, scores, aligns, self.opt.n_best + all_preprocessed, results, scores, aligns, self.opts.n_best ) results = [self.maybe_postprocess(seg) for seg in rebuilt_segs] - head_spaces = [h for h in head_spaces for i in range(self.opt.n_best)] - tail_spaces = [h for h in tail_spaces for i in range(self.opt.n_best)] + head_spaces = [h for h in head_spaces for i in range(self.opts.n_best)] + tail_spaces = [h for h in tail_spaces for i in range(self.opts.n_best)] results = ["".join(items) for items in zip(head_spaces, results, tail_spaces)] self.logger.info("Translation Results: %d", len(results)) - return results, scores, self.opt.n_best, timer.times, aligns + return results, scores, self.opts.n_best, timer.times, aligns
[docs] def rebuild_seg_packages(self, all_preprocessed, results, scores, aligns, n_best): """ @@ -795,7 +795,7 @@

Source code for mammoth.translate.translation_server

def unload(self): self.logger.info("Unloading model %d" % self.model_id) del self.translator - if self.opt.cuda: + if self.opts.cuda: torch.cuda.empty_cache() self.stop_unload_timer() self.unload_timer = None @@ -816,7 +816,7 @@

Source code for mammoth.translate.translation_server

hide_opt = ["models", "src"] d = { "model_id": self.model_id, - "opt": {k: self.user_opt[k] for k in self.user_opt.keys() if k not in hide_opt}, + "opts": {k: self.user_opt[k] for k in self.user_opt.keys() if k not in hide_opt}, "models": self.user_opt["models"], "loaded": self.loaded, "timeout": self.timeout, @@ -832,7 +832,7 @@

Source code for mammoth.translate.translation_server

self.translator.to_cpu() else: self.translator.model.cpu() - if self.opt.cuda: + if self.opts.cuda: torch.cuda.empty_cache()
[docs] def to_gpu(self): @@ -840,7 +840,7 @@

Source code for mammoth.translate.translation_server

if type(self.translator) == CTranslate2Translator: self.translator.to_gpu() else: - torch.cuda.set_device(self.opt.gpu) + torch.cuda.set_device(self.opts.gpu) self.translator.model.cuda()
[docs] def maybe_preprocess(self, sequence): @@ -962,7 +962,7 @@

Source code for mammoth.translate.translation_server

sorted or None if no alignment in output. """ align = None - if self.opt.report_align: + if self.opts.report_align: # output contain alignment sequence, align = sequence.split(DefaultTokens.ALIGNMENT_SEPARATOR) if align != '': diff --git a/_modules/mammoth/translate/translator.html b/_modules/mammoth/translate/translator.html index a47098e2..7846c189 100644 --- a/_modules/mammoth/translate/translator.html +++ b/_modules/mammoth/translate/translator.html @@ -197,46 +197,46 @@

Source code for mammoth.translate.translator

from mammoth.inputters.dataloader import build_dataloader
 
 
-def build_translator(opt, task, report_score=True, logger=None, out_file=None):
+def build_translator(opts, task, report_score=True, logger=None, out_file=None):
     if out_file is None:
-        outdir = os.path.dirname(opt.output)
+        outdir = os.path.dirname(opts.output)
         if outdir and not os.path.isdir(outdir):
             # FIXME use warnings instead
             logger.info('WARNING: output file directory does not exist... creating it.')
-            os.makedirs(os.path.dirname(opt.output), exist_ok=True)
-        out_file = codecs.open(opt.output, "w+", "utf-8")
+            os.makedirs(os.path.dirname(opts.output), exist_ok=True)
+        out_file = codecs.open(opts.output, "w+", "utf-8")
 
     load_test_model = (
-        mammoth.modules.decoder_ensemble.load_test_model if len(opt.models) > 3
+        mammoth.modules.decoder_ensemble.load_test_model if len(opts.models) > 3
         else mammoth.model_builder.load_test_multitask_model
     )
     if logger:
         logger.info(str(task))
-    vocabs, model, model_opt = load_test_model(opt)
+    vocabs, model, model_opt = load_test_model(opts)
 
-    scorer = mammoth.translate.GNMTGlobalScorer.from_opt(opt)
+    scorer = mammoth.translate.GNMTGlobalScorer.from_opts(opts)
 
     if model_opt.model_task == ModelTask.LANGUAGE_MODEL:
-        translator = GeneratorLM.from_opt(
+        translator = GeneratorLM.from_opts(
             model,
             vocabs,
-            opt,
+            opts,
             model_opt,
             global_scorer=scorer,
             out_file=out_file,
-            report_align=opt.report_align,
+            report_align=opts.report_align,
             report_score=report_score,
             logger=logger,
         )
     else:
-        translator = Translator.from_opt(
+        translator = Translator.from_opts(
             model,
             vocabs,
-            opt,
+            opts,
             model_opt,
             global_scorer=scorer,
             out_file=out_file,
-            report_align=opt.report_align,
+            report_align=opts.report_align,
             report_score=report_score,
             logger=logger,
             task=task,
@@ -413,11 +413,11 @@ 

Source code for mammoth.translate.translator

set_random_seed(seed, self._use_cuda)
 
     @classmethod
-    def from_opt(
+    def from_opts(
         cls,
         model,
         vocabs,
-        opt,
+        opts,
         model_opt,
         global_scorer=None,
         out_file=None,
@@ -432,7 +432,7 @@ 

Source code for mammoth.translate.translator

            model (mammoth.modules.NMTModel): See :func:`__init__()`.
             vocabs (dict[str, mammoth.inputters.Vocab]): See
                 :func:`__init__()`.
-            opt (argparse.Namespace): Command line options
+            opts (argparse.Namespace): Command line options
             model_opt (argparse.Namespace): Command line options saved with
                 the model checkpoint.
             global_scorer (mammoth.translate.GNMTGlobalScorer): See
@@ -450,35 +450,35 @@ 

Source code for mammoth.translate.translator

return cls(
             model,
             vocabs,
-            opt.src,
-            tgt_file_path=opt.tgt,
-            gpu=opt.gpu,
-            n_best=opt.n_best,
-            min_length=opt.min_length,
-            max_length=opt.max_length,
-            ratio=opt.ratio,
-            beam_size=opt.beam_size,
-            random_sampling_topk=opt.random_sampling_topk,
-            random_sampling_topp=opt.random_sampling_topp,
-            random_sampling_temp=opt.random_sampling_temp,
-            stepwise_penalty=opt.stepwise_penalty,
-            dump_beam=opt.dump_beam,
-            block_ngram_repeat=opt.block_ngram_repeat,
-            ignore_when_blocking=set(opt.ignore_when_blocking),
-            replace_unk=opt.replace_unk,
-            ban_unk_token=opt.ban_unk_token,
-            tgt_prefix=opt.tgt_prefix,
-            phrase_table=opt.phrase_table,
-            data_type=opt.data_type,
-            verbose=opt.verbose,
-            report_time=opt.report_time,
+            opts.src,
+            tgt_file_path=opts.tgt,
+            gpu=opts.gpu,
+            n_best=opts.n_best,
+            min_length=opts.min_length,
+            max_length=opts.max_length,
+            ratio=opts.ratio,
+            beam_size=opts.beam_size,
+            random_sampling_topk=opts.random_sampling_topk,
+            random_sampling_topp=opts.random_sampling_topp,
+            random_sampling_temp=opts.random_sampling_temp,
+            stepwise_penalty=opts.stepwise_penalty,
+            dump_beam=opts.dump_beam,
+            block_ngram_repeat=opts.block_ngram_repeat,
+            ignore_when_blocking=set(opts.ignore_when_blocking),
+            replace_unk=opts.replace_unk,
+            ban_unk_token=opts.ban_unk_token,
+            tgt_prefix=opts.tgt_prefix,
+            phrase_table=opts.phrase_table,
+            data_type=opts.data_type,
+            verbose=opts.verbose,
+            report_time=opts.report_time,
             copy_attn=model_opt.copy_attn,
             global_scorer=global_scorer,
             out_file=out_file,
             report_align=report_align,
             report_score=report_score,
             logger=logger,
-            seed=opt.seed,
+            seed=opts.seed,
             task=task,
         )
 
diff --git a/_modules/mammoth/utils/loss.html b/_modules/mammoth/utils/loss.html
index 7cf7db3e..cf81ba48 100644
--- a/_modules/mammoth/utils/loss.html
+++ b/_modules/mammoth/utils/loss.html
@@ -187,7 +187,7 @@ 

Source code for mammoth.utils.loss

 from mammoth.constants import ModelTask, DefaultTokens
 
 
-def build_loss_compute(model, tgt_vocab, opt, train=True, generator=None):
+def build_loss_compute(model, tgt_vocab, opts, train=True, generator=None):
     """
     Returns a LossCompute subclass which wraps around an nn.Module subclass
     (such as nn.NLLLoss) which defines the loss criterion. The LossCompute
@@ -196,20 +196,20 @@ 

Source code for mammoth.utils.loss

     Currently, the NMTLossCompute class handles all loss computation except
     for when using a copy mechanism.
     """
-    device = torch.device("cuda" if mammoth.utils.misc.use_gpu(opt) else "cpu")
+    device = torch.device("cuda" if mammoth.utils.misc.use_gpu(opts) else "cpu")
 
     padding_idx = tgt_vocab.stoi[DefaultTokens.PAD]
     unk_idx = tgt_vocab.stoi[DefaultTokens.UNK]
 
-    if opt.lambda_coverage != 0:
-        assert opt.coverage_attn, "--coverage_attn needs to be set in order to use --lambda_coverage != 0"
+    if opts.lambda_coverage != 0:
+        assert opts.coverage_attn, "--coverage_attn needs to be set in order to use --lambda_coverage != 0"
 
-    if opt.copy_attn:
+    if opts.copy_attn:
         criterion = mammoth.modules.CopyGeneratorLoss(
-            len(tgt_vocab), opt.copy_attn_force, unk_index=unk_idx, ignore_index=padding_idx
+            len(tgt_vocab), opts.copy_attn_force, unk_index=unk_idx, ignore_index=padding_idx
         )
-    elif opt.label_smoothing > 0 and train:
-        criterion = LabelSmoothingLoss(opt.label_smoothing, len(tgt_vocab), ignore_index=padding_idx)
+    elif opts.label_smoothing > 0 and train:
+        criterion = LabelSmoothingLoss(opts.label_smoothing, len(tgt_vocab), ignore_index=padding_idx)
     else:
         criterion = nn.NLLLoss(ignore_index=padding_idx, reduction='sum')
 
@@ -221,35 +221,35 @@ 

Source code for mammoth.utils.loss

     loss_gen = (
         generator[0] if use_raw_logits else generator
     )  # loss_gen = model.generator[0] if use_raw_logits else model.generator
-    if opt.copy_attn:
-        if opt.model_task == ModelTask.SEQ2SEQ:
+    if opts.copy_attn:
+        if opts.model_task == ModelTask.SEQ2SEQ:
             compute = mammoth.modules.CopyGeneratorLossCompute(
-                criterion, loss_gen, tgt_vocab, opt.copy_loss_by_seqlength, lambda_coverage=opt.lambda_coverage
+                criterion, loss_gen, tgt_vocab, opts.copy_loss_by_seqlength, lambda_coverage=opts.lambda_coverage
             )
-        elif opt.model_task == ModelTask.LANGUAGE_MODEL:
+        elif opts.model_task == ModelTask.LANGUAGE_MODEL:
             compute = mammoth.modules.CopyGeneratorLMLossCompute(
-                criterion, loss_gen, tgt_vocab, opt.copy_loss_by_seqlength, lambda_coverage=opt.lambda_coverage
+                criterion, loss_gen, tgt_vocab, opts.copy_loss_by_seqlength, lambda_coverage=opts.lambda_coverage
             )
         else:
-            raise ValueError(f"No copy generator loss defined for task {opt.model_task}")
+            raise ValueError(f"No copy generator loss defined for task {opts.model_task}")
     else:
-        if opt.model_task == ModelTask.SEQ2SEQ:
+        if opts.model_task == ModelTask.SEQ2SEQ:
             compute = NMTLossCompute(
                 criterion,
                 loss_gen,
-                lambda_coverage=opt.lambda_coverage,
-                lambda_align=opt.lambda_align,
+                lambda_coverage=opts.lambda_coverage,
+                lambda_align=opts.lambda_align,
             )
-        elif opt.model_task == ModelTask.LANGUAGE_MODEL:
-            assert opt.lambda_align == 0.0, "lamdba_align not supported in LM loss"
+        elif opts.model_task == ModelTask.LANGUAGE_MODEL:
+            assert opts.lambda_align == 0.0, "lamdba_align not supported in LM loss"
             compute = LMLossCompute(
                 criterion,
                 loss_gen,
-                lambda_coverage=opt.lambda_coverage,
-                lambda_align=opt.lambda_align,
+                lambda_coverage=opts.lambda_coverage,
+                lambda_align=opts.lambda_align,
             )
         else:
-            raise ValueError(f"No compute loss defined for task {opt.model_task}")
+            raise ValueError(f"No compute loss defined for task {opts.model_task}")
     compute.to(device)
 
     return compute
diff --git a/_modules/mammoth/utils/optimizers.html b/_modules/mammoth/utils/optimizers.html
index eee78357..2c14ed5d 100644
--- a/_modules/mammoth/utils/optimizers.html
+++ b/_modules/mammoth/utils/optimizers.html
@@ -237,7 +237,7 @@ 

Source code for mammoth.utils.optimizers

     return optimizer
 
 
-def build_torch_optimizer(model, opt, task_queue_manager):
+def build_torch_optimizer(model, opts, task_queue_manager):
     """Builds the PyTorch optimizer.
 
     We use the default parameters for Adam that are suggested by
@@ -253,87 +253,91 @@ 

Source code for mammoth.utils.optimizers

 
     Args:
       model: The model to optimize.
-      opt. The dictionary of options.
+      opts. The dictionary of options.
 
     Returns:
       A ``torch.optim.Optimizer`` instance.
     """
     params = [p for p in model.parameters() if p.requires_grad]
-    betas = [opt.adam_beta1, opt.adam_beta2]
-    if opt.optim == 'sgd':
-        optimizer = optim.SGD(params, lr=opt.learning_rate)
-    elif opt.optim == 'adagrad':
-        optimizer = optim.Adagrad(params, lr=opt.learning_rate, initial_accumulator_value=opt.adagrad_accumulator_init)
-    elif opt.optim == 'adadelta':
-        optimizer = optim.Adadelta(params, lr=opt.learning_rate)
-    elif opt.optim == 'adafactor':
+    betas = [opts.adam_beta1, opts.adam_beta2]
+    if opts.optim == 'sgd':
+        optimizer = optim.SGD(params, lr=opts.learning_rate)
+    elif opts.optim == 'adagrad':
+        optimizer = optim.Adagrad(
+            params,
+            lr=opts.learning_rate,
+            initial_accumulator_value=opts.adagrad_accumulator_init,
+        )
+    elif opts.optim == 'adadelta':
+        optimizer = optim.Adadelta(params, lr=opts.learning_rate)
+    elif opts.optim == 'adafactor':
         optimizer = attention_bridge_optimizer(
             model,
             task_queue_manager,
-            lambda params: AdaFactorFairSeq(params, weight_decay=opt.weight_decay),
+            lambda params: AdaFactorFairSeq(params, weight_decay=opts.weight_decay),
         )
-    elif opt.optim == 'adam':
+    elif opts.optim == 'adam':
         optimizer = attention_bridge_optimizer(
             model,
             task_queue_manager,
             lambda params: optim.Adam(
-                params, lr=opt.learning_rate, betas=betas, eps=1e-9, weight_decay=opt.weight_decay
+                params, lr=opts.learning_rate, betas=betas, eps=1e-9, weight_decay=opts.weight_decay
             )
         )
-    elif opt.optim == 'adamw':
+    elif opts.optim == 'adamw':
         optimizer = attention_bridge_optimizer(
             model,
             task_queue_manager,
             lambda params: optim.AdamW(
-                params, lr=opt.learning_rate, betas=betas, eps=1e-9, weight_decay=opt.weight_decay
+                params, lr=opts.learning_rate, betas=betas, eps=1e-9, weight_decay=opts.weight_decay
             )
         )
-    elif opt.optim == 'fusedadam':
+    elif opts.optim == 'fusedadam':
         # we use here a FusedAdam() copy of an old Apex repo
-        optimizer = FusedAdam(params, lr=opt.learning_rate, betas=betas)
-        if opt.model_dtype == 'fp16':
+        optimizer = FusedAdam(params, lr=opts.learning_rate, betas=betas)
+        if opts.model_dtype == 'fp16':
             import apex
 
             # In this case use the old FusedAdam with FP16_optimizer wrapper
-            static_loss_scale = opt.loss_scale
-            dynamic_loss_scale = opt.loss_scale == 0
+            static_loss_scale = opts.loss_scale
+            dynamic_loss_scale = opts.loss_scale == 0
             optimizer = apex.contrib.optimizers.FP16_Optimizer(
                 optimizer, static_loss_scale=static_loss_scale, dynamic_loss_scale=dynamic_loss_scale
             )
     else:
-        raise ValueError('Invalid optimizer type: ' + opt.optim)
+        raise ValueError('Invalid optimizer type: ' + opts.optim)
 
     return optimizer
 
 
-def make_learning_rate_decay_fn(opt):
+def make_learning_rate_decay_fn(opts):
     """Returns the learning decay function from options."""
-    if opt.decay_method == 'noam':
-        return functools.partial(noam_decay, warmup_steps=opt.warmup_steps, model_size=opt.rnn_size)
-    elif opt.decay_method == 'noamwd':
+    if opts.decay_method == 'noam':
+        return functools.partial(noam_decay, warmup_steps=opts.warmup_steps, model_size=opts.rnn_size)
+    elif opts.decay_method == 'noamwd':
         return functools.partial(
             noamwd_decay,
-            warmup_steps=opt.warmup_steps,
-            model_size=opt.rnn_size,
-            rate=opt.learning_rate_decay,
-            decay_steps=opt.decay_steps,
-            start_step=opt.start_decay_steps,
+            warmup_steps=opts.warmup_steps,
+            model_size=opts.rnn_size,
+            rate=opts.learning_rate_decay,
+            decay_steps=opts.decay_steps,
+            start_step=opts.start_decay_steps,
         )
-    elif opt.decay_method == 'rsqrt':
-        return functools.partial(rsqrt_decay, warmup_steps=opt.warmup_steps)
-    elif opt.decay_method == 'linear_warmup':
+    elif opts.decay_method == 'rsqrt':
+        return functools.partial(rsqrt_decay, warmup_steps=opts.warmup_steps)
+    elif opts.decay_method == 'linear_warmup':
         return functools.partial(
             linear_warmup_decay,
-            warmup_steps=opt.warmup_steps,
-            rate=opt.learning_rate,
-            train_steps=opt.train_steps,
+            warmup_steps=opts.warmup_steps,
+            rate=opts.learning_rate,
+            train_steps=opts.train_steps,
         )
-    elif opt.start_decay_steps is not None:
+    elif opts.start_decay_steps is not None:
         return functools.partial(
             exponential_decay,
-            rate=opt.learning_rate_decay,
-            decay_steps=opt.decay_steps,
-            start_step=opt.start_decay_steps,
+            rate=opts.learning_rate_decay,
+            decay_steps=opts.decay_steps,
+            start_step=opts.start_decay_steps,
         )
 
 
@@ -451,25 +455,25 @@ 

Source code for mammoth.utils.optimizers

         self._fp16 = None
         self._scaler = None
 
-
[docs] @classmethod - def from_opt(cls, model, opt, task_queue_manager, checkpoint=None): +
[docs] @classmethod + def from_opts(cls, model, opts, task_queue_manager, checkpoint=None): """Builds the optimizer from options. Args: cls: The ``Optimizer`` class to instantiate. model: The model to optimize. - opt: The dict of user options. + opts: The dict of user options. checkpoint: An optional checkpoint to load states from. Returns: An ``Optimizer`` instance. """ - optim_opt = opt + optim_opt = opts optim_state_dict = None - if opt.train_from and checkpoint is not None: + if opts.train_from and checkpoint is not None: optim = checkpoint['optim'] - ckpt_opt = checkpoint['opt'] + ckpt_opt = checkpoint['opts'] ckpt_state_dict = {} if isinstance(optim, Optimizer): # Backward compatibility. ckpt_state_dict['training_step'] = optim._step + 1 @@ -478,19 +482,19 @@

Source code for mammoth.utils.optimizers

             else:
                 ckpt_state_dict = optim
 
-            if opt.reset_optim == 'none':
+            if opts.reset_optim == 'none':
                 # Load everything from the checkpoint.
                 optim_opt = ckpt_opt
                 optim_state_dict = ckpt_state_dict
-            elif opt.reset_optim == 'all':
+            elif opts.reset_optim == 'all':
                 # Build everything from scratch.
                 pass
-            elif opt.reset_optim == 'states':
+            elif opts.reset_optim == 'states':
                 # Reset optimizer, keep options.
                 optim_opt = ckpt_opt
                 optim_state_dict = ckpt_state_dict
                 del optim_state_dict['optimizer']
-            elif opt.reset_optim == 'keep_states':
+            elif opts.reset_optim == 'keep_states':
                 # Reset options, keep optimizer.
                 optim_state_dict = ckpt_state_dict
 
@@ -501,8 +505,8 @@ 

Source code for mammoth.utils.optimizers

             max_grad_norm=optim_opt.max_grad_norm,
         )
 
-        if opt.model_dtype == "fp16":
-            if opt.optim == "fusedadam":
+        if opts.model_dtype == "fp16":
+            if opts.optim == "fusedadam":
                 optimizer._fp16 = "legacy"
             else:
                 optimizer._fp16 = "amp"
diff --git a/genindex.html b/genindex.html
index f6479b04..341c0e3c 100644
--- a/genindex.html
+++ b/genindex.html
@@ -311,7 +311,7 @@ 

F

diff --git a/index.html b/index.html index 93fb97e0..2763f43b 100644 --- a/index.html +++ b/index.html @@ -232,7 +232,7 @@

ContentsBuild Vocab