docstr: Override abstract method from TransformerRankerAgent to use knowledge field as
  memories.
docstr_tok: ["Override","abstract","method","from","TransformerRankerAgent","to","use","knowledge","field","as","memories","."]
code: def _vectorize_memories(self, observation):
      """
      Override abstract method from TransformerRankerAgent to use knowledge field as
      memories.
      """
  
      if not self.use_knowledge:
          return observation
  
      observation["memory_vecs"] = []
  
      checked = observation.get("checked_sentence", "")
      if observation.get("knowledge"):
          knowledge = observation["knowledge"].split("\n")[:-1]
      else:
          knowledge = []
  
      to_vectorize = []
      if checked and self.chosen_sentence:
          # if `self.chosen_sentence` is True, only keep golden knowledge
          to_vectorize = [checked]
      elif (
          self.knowledge_dropout == 0 or not self.is_training
      ) and knowledge:
          # during evaluation we use all of the knowledge
          to_vectorize = knowledge
      elif knowledge:
          for line in knowledge:
              if checked and checked in line:
                  # make sure we keep the chosen sentence
                  keep = 1
              else:
                  # dropout knowledge
                  keep = np.random.binomial(
                      1, 1 - self.knowledge_dropout
                  )
              if keep:
                  to_vectorize.append(line)
  
      # vectorize knowledge
      observation.force_set(
          "memory_vecs",
          [
              self._vectorize_text(
                  line, truncate=self.knowledge_truncate
              )
              for line in to_vectorize
          ],
      )
      return observation
  
file_path: ParlAI/projects/wizard_of_wikipedia/wizard_transformer_ranker/wizard_transformer_ranker.py
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.agents.transformer.transformer import TransformerRankerAgent
  from .wizard_dict import WizardDictAgent
  from parlai.utils.io import PathManager
  import numpy
  import torch
label_desc: Use image node_id 5 for calling the WizardTransformerRankerAgent obj's underlying member method code with example usage: obj._vectorize_memories(observation) and returns: observation, observation