[Outdated] -report_align not working

Hey, I’m trying to generate output of my model with alignements, so I use -report_align but I encounter this error:

[2023-07-06 15:03:47,001 INFO] Loading checkpoint from models/model.fren_step_52000.pt
[2023-07-06 15:03:47,619 INFO] Loading data into the model
['0-0.34585', '1-0.63270', '2-0.61036', '3-0.32734', '4-0.46401', '5-0.42423', '6-0.41460', '7-0.62102', '8-0.47739', '9-0.44198', '10-0.36853', '11-0.41361', '12-0.50141', '13-0.55924', '14-0.54243', '15-0.33698']
Traceback (most recent call last):
  File "/home/jourdelune/Bureau/dev/translation-engine/venv/bin/onmt_translate", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jourdelune/Bureau/dev/translation-engine/venv/lib/python3.11/site-packages/onmt/bin/translate.py", line 56, in main
    translate(opt)
  File "/home/jourdelune/Bureau/dev/translation-engine/venv/lib/python3.11/site-packages/onmt/bin/translate.py", line 37, in translate
    _, _ = translator._translate(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jourdelune/Bureau/dev/translation-engine/venv/lib/python3.11/site-packages/onmt/translate/translator.py", line 421, in _translate
    n_best_preds_align = [" ".join(align) for align in align_pharaohs]
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jourdelune/Bureau/dev/translation-engine/venv/lib/python3.11/site-packages/onmt/translate/translator.py", line 421, in <listcomp>
    n_best_preds_align = [" ".join(align) for align in align_pharaohs]
                          ^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, list found

I use this command: nmt_translate -model models/model.fren_step_52000.pt -src temps/.test.txt -output temps/.output.txt -report_align

Here is my model conf:

save_data: opennmt

# Training files
data:
    corpus_1:
        path_src: temps/src-train.subword
        path_tgt: temps/tgt-train.subword
    valid:
        path_src: temps/src-val.subword
        path_tgt: temps/tgt-val.subword

# Vocabulary files, generated by onmt_build_vocab
src_vocab: opennmt/source.vocab
tgt_vocab: opennmt/target.vocab

# Vocabulary size - should be the same as in sentence piece
src_vocab_size: 50000
tgt_vocab_size: 50000

# Tokenization options
src_subword_model: models/source.model
tgt_subword_model: models/target.model

# Where to save the log file and the output models/checkpoints
log_file: temps/train.log
save_model: models/model.fren

save_checkpoint_steps: 500
train_steps: 3000
valid_steps: 1000

early_stopping: 4

# Train on a single GPU
world_size: 1
gpu_ranks: [0]

keep_checkpoint: 3

seed: 3435

# Default: 4000 - for large datasets, try up to 8000
warmup_steps: 8000
report_every: 100

# Batching
bucket_size: 262144
batch_type: "tokens"
batch_size: 4096  
valid_batch_size: 2048
max_generator_batches: 2
accum_count: [4]
accum_steps: [0]

# Optimization
model_dtype: "fp16"
optim: "adam"
learning_rate: 2
# warmup_steps: 8000
decay_method: "noam"
adam_beta2: 0.998
max_grad_norm: 0
label_smoothing: 0.1
param_init: 0
param_init_glorot: true
normalization: "tokens"

# Model
encoder_type: transformer
decoder_type: transformer
position_encoding: true
enc_layers: 6
dec_layers: 6
heads: 8
hidden_size: 512
word_vec_size: 512
transformer_ff: 2048
dropout_steps: [0]
dropout: [0.1]
attention_dropout: [0.1]

(without this argument, onmt_translate work fine)

If I edit the line to replace by n_best_preds_align = [" ".join(str(align)) for align in align_pharaohs], that work fine :+1:.

Also, I’m wondering why there is this print here? OpenNMT-py/onmt/utils/alignment.py at master · OpenNMT/OpenNMT-py · GitHub, I find it floods the logs. (but it’s just a notice)

Closed and post on github (-report_align not work · Issue #2435 · OpenNMT/OpenNMT-py · GitHub) because it’s a bug report.