Skip to content

New function to aggregate attention maps

We need a new function in the dan.predict.attention module to aggregate attention maps. This is useful when investigating attention at different levels (char, word, line).

The code needed is already done in https://gitlab.com/teklia/atr/dan/-/blob/main/dan/predict/attention.py#L68-79. We need to port it in a separate function with signature

def compute_coverage(text: str, max_value: float, offset: int, attentions):
    ...
    return coverage_vector

You should be able to infer height, width from the shape of attentions (as it will be the weights parameter in the function call.

Then the plot_attention function should be updated to use this new function.

Edited by Yoann Schneider