class_docstr: Stacked model that generates first the knowledge, and then the dialogue response.
class_docstr_tok: ["Stacked","model","that","generates","first","the","knowledge",",","and","then","the","dialogue","response","."]
code: def _filter_beams(
      self,
      reply,
      filter_for_knowledge: bool = True,
      filter_questions: bool = False,
      filter_self_references: bool = False,
  ):
      knowledge = normalize_answer(reply["knowledge_response"])
      self_references = [
          "I live",
          "I love",
          " me ",
          "my favorite",
          "My favorite",
          "do you know",
          "I have",
          "I like ",
          "My ",
      ]
      question_words = [
          "who",
          "when",
          "where",
          "what",
          "do you",
          "are you",
      ]
  
      def filter_fn(text: str) -> bool:
          normalized_text = normalize_answer(text)
          if filter_for_knowledge and knowledge not in normalized_text:
              return False
          if filter_questions and (
              "?" in text
              or any([qw in normalized_text for qw in question_words])
          ):
              return False
          if filter_self_references and any(
              [ref in text for ref in self_references]
          ):
              return False
          return True
  
      if not (
          "text" in reply
          and "beam_texts" in reply
          and "knowledge_response" in reply
          and len(reply["beam_texts"]) > 1
      ):
          return
  
      beam_texts = [
          text
          for text, _ in sorted(
              reply["beam_texts"], key=lambda x: x[1], reverse=True
          )
      ]
      # print('\t' + '\n\t'.join(beam_texts[:10]))
      for text in [reply["text"]] + beam_texts:
          if filter_fn(text):
              reply.force_set("text", text)
              return
  
imports: from copy import deepcopy
  from typing import Optional, List
  from types import MethodType
  from collections import defaultdict
  from nltk.tokenize import sent_tokenize
  from nltk.corpus import stopwords
  import random
  import spacy
  import torch
  from parlai.core.agents import create_agent, create_agent_from_shared
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.core.message import Message
  from parlai.core.agents import Agent
  from parlai.core.metrics import F1Metric
  from parlai.agents.rag.args import setup_rag_args
  from parlai.agents.bart.bart import BartAgent
  from parlai.core.metrics import normalize_answer
  from parlai.tasks.wizard_of_wikipedia.agents import TOKEN_NOCHOSEN
  from parlai.tasks.wizard_of_wikipedia.agents import TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE
label_desc: Use image node_id 14 for calling the StackedKnowledgeDialogueAgent obj's underlying member method code with example usage: obj._filter_beams(reply, filter_for_knowledge, filter_questions, filter__references) and returns: True, False, False, False