class_docstr: Base class for support set <--> query attention.
class_docstr_tok: ["Base","class","for","support","set","<","--",">","query","attention","."]
docstr: Each query attends to each time point in each series of its support set.
  
  Note that we cannot use a canonical attention mechanism here because of the composition of the batches.
  The support time series are stacked along the batch dimension. Suppose a fixed support set size `x`
  batch size `bs` the batch dimension is `x * bs` i.e. a batch looks like
  
      [ts_11, ts_12, ...,ts_1x, ts_21, ts_22, ...ts_2x, ...,ts_bs1, ts_bs2, ..., ts_bsx].
  
  This is done to avoid padding and support differing support set sizes.
  However, this als means that each query should attend over multiple elements ts_*1, ...ts_*x
  along the batch dimension.
  
  Parameters
  ----------
  query:
      A SeriesBatch containing sequences of size [q_batch, q_size].
  supps:
       A SeriesBatch containing sequences of size [supps_batch, sequence length, supps_size].
  
  Returns
  -------
  torch.Tensor:
      The transformed batch containing sequences with the encoded support set series
      of size [q_batch, embedding size].
docstr_tok: ["Each","query","attends","to","each","time","point","in","each","series","of","its","support","set",".","Note","that","we","can","not","use","a","canonical","attention","mechanism","here","because","of","the","composition","of","the","batches",".","The","support","time","series","are","stacked","along","the","batch","dimension",".","Suppose","a","fixed","support","set","size","`","x","`","batch","size","`","bs","`","the","batch","dimension","is","`","x","*","bs","`","i.e",".","a","batch","looks","like","[","ts_11",",","ts_12",",","...",",","ts_1x",",","ts_21",",","ts_22",",","...","ts_2x",",","...",",","ts_bs1",",","ts_bs2",",","...",",","ts_bsx","]",".","This","is","done","to","avoid","padding","and","support","differing","support","set","sizes",".","However",",","this","als","means","that","each","query","should","attend","over","multiple","elements","ts_","*","1",",","...","ts_","*","x","along","the","batch","dimension",".","Parameters","--","--","--","--","--","query",":","A","SeriesBatch","containing","sequences","of","size","[","q_batch",",","q_size","]",".","supps",":","A","SeriesBatch","containing","sequences","of","size","[","supps_batch",",","sequence","length",",","supps_size","]",".","Returns","--","--","--","-","torch.Tensor",":","The","transformed","batch","containing","sequences","with","the","encoded","support","set","series","of","size","[","q_batch",",","embedding","size","]","."]
code: def forward(
      self, query: SeriesBatch, supps: SeriesBatch
  ) -> Union[Tuple[torch.Tensor, torch.Tensor], torch.Tensor]:
      """
      Each query attends to each time point in each series of its support set.
  
      Note that we cannot use a canonical attention mechanism here because of the composition of the batches.
      The support time series are stacked along the batch dimension. Suppose a fixed support set size `x`
      batch size `bs` the batch dimension is `x * bs` i.e. a batch looks like
  
          [ts_11, ts_12, ...,ts_1x, ts_21, ts_22, ...ts_2x, ...,ts_bs1, ts_bs2, ..., ts_bsx].
  
      This is done to avoid padding and support differing support set sizes.
      However, this als means that each query should attend over multiple elements ts_*1, ...ts_*x
      along the batch dimension.
  
      Parameters
      ----------
      query:
          A SeriesBatch containing sequences of size [q_batch, q_size].
      supps:
           A SeriesBatch containing sequences of size [supps_batch, sequence length, supps_size].
  
      Returns
      -------
      torch.Tensor:
          The transformed batch containing sequences with the encoded support set series
          of size [q_batch, embedding size].
      """
  
file_path: gluonts/src/gluonts/nursery/few_shot_prediction/src/meta/models/EcDc/components/attention.py
imports: from typing import Union, Tuple
  from abc import ABC, abstractmethod
  import torch
  from torch import nn
  from meta.data.batch import SeriesBatch
label_desc: Use image node_id 1 for calling the SupportSetQueryAttention obj's underlying member method code with example usage: obj.forward(query, supps) without return types