class_docstr: Average policy for bag-level relation extraction.
docstr: Args:
      bag: bag of sentences with the same entity pair
          [{
            'text' or 'token': ..., 
            'h': {'pos': [start, end], ...}, 
            't': {'pos': [start, end], ...}
          }]
  Return:
      (relation, score)
docstr_tok: ["Args",":","bag",":","bag","of","sentences","with","the","same","entity","pair","[","{","'text","'","or","'token","'",":","...",",","'","h","'",":","{","'pos","'",":","[","start",",","end","]",",","...","}",",","'t","'",":","{","'pos","'",":","[","start",",","end","]",",","...","}","}","]","Return",":","(","relation",",","score",")"]
code: def infer(self, bag):
      """
      Args:
          bag: bag of sentences with the same entity pair
              [{
                'text' or 'token': ...,
                'h': {'pos': [start, end], ...},
                't': {'pos': [start, end], ...}
              }]
      Return:
          (relation, score)
      """
      pass
  
      """
          tokens = []
          pos1s = []
          pos2s = []
          masks = []
          for item in bag:
              if 'text' in item:
                  token, pos1, pos2, mask = self.tokenizer(item['text'], 
                      item['h']['pos'], item['t']['pos'], is_token=False, padding=True)
              else:
                  token, pos1, pos2, mask = self.tokenizer(item['token'], 
                      item['h']['pos'], item['t']['pos'], is_token=True, padding=True)
              tokens.append(token)
              pos1s.append(pos1)
              pos2s.append(pos2)
              masks.append(mask)
          tokens = torch.cat(tokens, 0) # (n, L)
          pos1s = torch.cat(pos1s, 0)
          pos2s = torch.cat(pos2s, 0)
          masks = torch.cat(masks, 0) 
          scope = torch.tensor([[0, len(bag)]]).long() # (1, 2)
          bag_logits = self.forward(None, scope, tokens, pos1s, pos2s, masks, train=False).squeeze(0) # (N) after softmax
          score, pred = bag_logits.max()
          score = score.item()
          pred = pred.item()
          rel = self.id2rel[pred]
          return (rel, score)
          """
  
file_path: OpenNRE/opennre/model/bag_average.py
imports: import torch
  from torch import nn, optim
  from .base_model import BagRE
label_desc: Use image node_id 2 for calling the BagAverage obj's underlying member method code with example usage: obj.infer(bag) without return types