class_docstr: This is a abstract sequential recommender. All the sequential model should implement This class.
class_docstr_tok: ["This","is","a","abstract","sequential","recommender",".","All","the","sequential","model","should","implement","This","class","."]
docstr: Generate left-to-right uni-directional or bidirectional attention mask for multi-head attention.
docstr_tok: ["Generate","left-to-right","uni-directional","or","bidirectional","attention","mask","for","multi-head","attention","."]
code: def get_attention_mask(self, item_seq, bidirectional=False):
      """Generate left-to-right uni-directional or bidirectional attention mask for multi-head attention."""
      attention_mask = item_seq != 0
      extended_attention_mask = attention_mask.unsqueeze(1).unsqueeze(
          2
      )  # torch.bool
      if not bidirectional:
          extended_attention_mask = torch.tril(
              extended_attention_mask.expand(
                  (-1, -1, item_seq.size(-1), -1)
              )
          )
      extended_attention_mask = torch.where(
          extended_attention_mask, 0.0, -10000.0
      )
      return extended_attention_mask
  
imports: from logging import getLogger
  import numpy
  import torch
  import torch.nn
  from recbole.model.layers import FMEmbedding, FMFirstOrderLinear, FLEmbedding
  from recbole.utils import ModelType, InputType, FeatureSource, FeatureType, set_color
label_desc: Use image node_id 3 for calling the SequentialRecommender obj's underlying member method code with example usage: obj.get_attention_mask(item_seq, bidirectional) and returns: extended_attention_mask