# Attention mask for the TimeSeriesTransformer summary network

**URL:** <https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32>\
**Category:** General\
**Created:** [December 12, 2023, 2:59pm UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32 "2023-12-12T14:59:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@leo](https://discuss.bayesflow.org/u/leo)\
**Post date:** [December 12, 2023, 2:59pm UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/1 "2023-12-12T14:59:50Z")

</div>

Hi!  
I am trying to use time series data of different lengths with the TimeSeriesTransformer as summary network. To avoid having to make batches of time series of the same length I was thinking of padding them to a fixed length and then use an attention mask. Is there an easy way to use an attention mask in the TimeSeriesTransformer summary network or would I have to rewrite the class?

Cheers,  
Leonardo

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [December 13, 2023, 6:30pm UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/2 "2023-12-13T18:30:05Z")

</div>

Hi Leonardo,

This may be tricky to do currently and requires some modifications where we allow masks in the configured inputs. Let’s discuss the possibility of adding this functionality.

@marvinschmitt @elseml @paul.buerkner @valentin What do you think about:

`inference_mask`: `...`,  
`summary_mask`: `...`,

In the configurator keys, which, when present, are propagated to the appropriate networks?

@leo To get you started quickly, you can do a custom modification to the existing time series transformer.

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@paul.buerkner](https://discuss.bayesflow.org/u/paul.buerkner)\
**Post date:** [December 14, 2023, 8:50am UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/3 "2023-12-14T08:50:14Z")

</div>

Can you write out some example code to showcase the syntax you have in mind?

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [December 14, 2023, 3:07pm UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/4 "2023-12-14T15:07:09Z")

</div>

@paul.buerkner The syntax will be the one above. Currently, our configuration dictionaries have some combination of the keys:

```auto
conf = {
    "parameters": ...,
    "summary_conditions",...
    "direct_conditions",...

```

I am proposing to allow for additional optional keys:

```auto
conf = {
    "parameters": ...,
    "summary_conditions",...
    "direct_conditions",...
    "inference_mask",...
    "summary_mask"...

```

which can hold masks for each of the networks’ outputs and are propagated to the associated networks by the Amortizer, if they are present.

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@paul.buerkner](https://discuss.bayesflow.org/u/paul.buerkner)\
**Post date:** [December 14, 2023, 4:02pm UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/5 "2023-12-14T16:02:14Z")

</div>

Thanks for the details. That looks reasonable to me!

---

<div class="post-metadata">

**Author:** ![elseml](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/elseml/32/19_2.png) [@elseml](https://discuss.bayesflow.org/u/elseml)\
**Post date:** [December 15, 2023, 9:04am UTC](https://discuss.bayesflow.org/t/attention-mask-for-the-timeseriestransformer-summary-network/32/6 "2023-12-15T09:04:05Z")

</div>

Agree, optional keys for specific use cases are an elegant solution.
