in sockeye/arguments.py [0:0]
def add_inference_args(params):
decode_params = params.add_argument_group("Inference parameters")
decode_params.add_argument(C.INFERENCE_ARG_INPUT_LONG, C.INFERENCE_ARG_INPUT_SHORT,
default=None,
help='Input file to translate. One sentence per line. '
'If not given, will read from stdin.')
decode_params.add_argument(C.INFERENCE_ARG_INPUT_FACTORS_LONG, C.INFERENCE_ARG_INPUT_FACTORS_SHORT,
required=False,
nargs='+',
type=regular_file(),
default=None,
help='List of input files containing additional source factors,'
'each token-parallel to the source. Default: %(default)s.')
decode_params.add_argument('--json-input',
action='store_true',
default=False,
help="If given, the CLI expects string-serialized json objects as input."
"Requires at least the input text field, for example: "
"{'text': 'some input string'} "
"Optionally, a list of factors can be provided: "
"{'text': 'some input string', 'factors': ['C C C', 'X X X']}.")
decode_params.add_argument(C.INFERENCE_ARG_OUTPUT_LONG, C.INFERENCE_ARG_OUTPUT_SHORT,
default=None,
help='Output file to write translations to. '
'If not given, will write to stdout.')
decode_params.add_argument('--models', '-m',
required=True,
nargs='+',
help='Model folder(s). Use multiple for ensemble decoding. '
'Model determines config, best parameters and vocab files.')
decode_params.add_argument('--checkpoints', '-c',
default=None,
type=int,
nargs='+',
help='If not given, chooses best checkpoints for model(s). '
'If specified, must have the same length as --models and be integer')
decode_params.add_argument('--nbest-size',
type=int_greater_or_equal(1),
default=1,
help='Size of the nbest list of translations. Default: %(default)s.')
decode_params.add_argument('--beam-size', '-b',
type=int_greater_or_equal(1),
default=5,
help='Size of the beam. Default: %(default)s.')
decode_params.add_argument('--greedy', '-g',
action="store_true",
default=False,
help='Enables an alternative, faster greedy decoding implementation. It does not '
'support batch decoding, ensembles, and hypothesis scores '
'are not normalized. Default: %(default)s.')
decode_params.add_argument('--beam-search-stop',
choices=[C.BEAM_SEARCH_STOP_ALL, C.BEAM_SEARCH_STOP_FIRST],
default=C.BEAM_SEARCH_STOP_ALL,
help='Stopping criteria. Quit when (all) hypotheses are finished '
'or when a finished hypothesis is in (first) position. Default: %(default)s.')
decode_params.add_argument('--batch-size',
type=int_greater_or_equal(1),
default=1,
help='Batch size during decoding. Determines how many sentences are translated '
'simultaneously. Default: %(default)s.')
decode_params.add_argument('--chunk-size',
type=int_greater_or_equal(1),
default=None,
help='Size of the chunks to be read from input at once. The chunks are sorted and then '
'split into batches. Therefore the larger the chunk size the better the grouping '
'of segments of similar length and therefore the higher the increase in throughput.'
' Default: %d without batching '
'and %d * batch_size with batching.' % (C.CHUNK_SIZE_NO_BATCHING,
C.CHUNK_SIZE_PER_BATCH_SEGMENT))
decode_params.add_argument('--mc-dropout',
default=False,
action='store_true',
help='Turn on dropout during inference (Monte Carlo dropout). '
'This will make translations non-deterministic and might slow '
'down translation speed.')
decode_params.add_argument('--softmax-temperature',
type=float,
default=None,
help='Controls peakiness of model predictions. Values < 1.0 produce '
'peaked predictions, values > 1.0 produce smoothed distributions.')
decode_params.add_argument('--sample',
type=int_greater_or_equal(0),
default=None,
nargs='?',
const=0,
help='Sample from softmax instead of taking best. Optional argument will restrict '
'sampling to top N vocabulary items at each step. Default: %(default)s.')
decode_params.add_argument('--seed',
type=int,
default=None,
help='Random seed used if sampling. Default: %(default)s.')
decode_params.add_argument('--ensemble-mode',
type=str,
default='linear',
choices=['linear', 'log_linear'],
help='Ensemble mode. Default: %(default)s.')
decode_params.add_argument('--bucket-width',
type=int_greater_or_equal(0),
default=10,
help='Bucket width for encoder steps. 0 means no bucketing. Default: %(default)s.')
decode_params.add_argument('--max-input-length',
type=int_greater_or_equal(1),
default=None,
help='Maximum input sequence length. Default: value from model(s).')
decode_params.add_argument('--max-output-length-num-stds',
type=int,
default=C.DEFAULT_NUM_STD_MAX_OUTPUT_LENGTH,
help='Number of target-to-source length ratio standard deviations from training to add '
'to calculate maximum output length for beam search for each sentence. '
'Default: %(default)s.')
decode_params.add_argument('--max-output-length',
type=int_greater_or_equal(1),
default=None,
help='Maximum number of words to generate during translation. '
'If None, it will be computed automatically. Default: %(default)s.')
decode_params.add_argument('--restrict-lexicon',
nargs='+',
type=multiple_values(num_values=2, data_type=str),
default=None,
help="Specify top-k lexicon to restrict output vocabulary to the k most likely context-"
"free translations of the source words in each sentence (Devlin, 2017). See the "
"lexicon module for creating top-k lexicons. To use multiple lexicons, provide "
"'--restrict-lexicon key1:path1 key2:path2 ...' and use JSON input to specify the "
"lexicon for each sentence: "
"{\"text\": \"some input string\", \"restrict_lexicon\": \"key\"}. "
"Default: %(default)s.")
decode_params.add_argument('--restrict-lexicon-topk',
type=int,
default=None,
help="Specify the number of translations to load for each source word from the lexicon "
"given with --restrict-lexicon. Default: Load all entries from the lexicon.")
# TODO(migration): remove once MXNet is removed
decode_params.add_argument('--avoid-list',
type=str,
default=None,
help="Specify a file containing phrases (pre-processed, one per line) to block "
"from the output. Default: %(default)s.")
decode_params.add_argument('--strip-unknown-words',
action='store_true',
default=False,
help='Remove any <unk> symbols from outputs. Default: %(default)s.')
decode_params.add_argument('--prevent-unk',
action='store_true',
default=False,
help='Avoid generating <unk> during decoding. Default: %(default)s.')
decode_params.add_argument('--output-type',
default='translation',
choices=C.OUTPUT_HANDLERS,
help='Output type. Default: %(default)s.')
# common params with score CLI
add_length_penalty_args(decode_params)
add_brevity_penalty_args(decode_params)
decode_params.add_argument('--dtype', default=None, choices=[None, C.DTYPE_FP32, C.DTYPE_FP16, C.DTYPE_INT8],
help="Data type. Default: %(default)s infers from saved model.")