Extracting word alignment from translation models

Hi! I am trying to extract alignments from translation models. I have gone thru this paper for extracting word alignments.
Is this implemented in CTranslate2 or any plans to implement it?
Can you also suggest some alternates if any.
Your help is greatly appreciated, thanks.


Many training frameworks support learning word alignments using one or more attention heads. I know that OpenNMT-py, OpenNMT-tf, Fairseq, and Marian have such options. Search for “guided alignment” or “alignment layer”.

These options are correctly applied in CTranslate2. After converting the model you can enable the translation parameter return_attention=True which will return the attention vectors that were optimized during the training. The word alignments can be inferred from these attention vectors.

Hello, I use score_batch from ctranslate2 to get word alignments, but I use it to follow this research paper: https://aclanthology.org/W18-6314.pdf. Here is an example for you:

results = translator.translate_batch(

output_tokens = results[0].hypotheses[0]
scores = translator.score_batch([input_tokens], [output_tokens])  # here is your word alignments