code: def extract_entities(
      sentence,
      pos=("PROPN", "NOUN"),
      use_named_entities=True,
      use_noun_chunks=True,
  ):
      global nlp
      if nlp is None:
          nlp = spacy.load("en_core_web_sm")
      doc = nlp(sentence)
      results = []
      if pos:
          for token in doc:
              if token.pos_ in pos:
                  results.append(token)
      if use_named_entities:
          for ent in doc.ents:
              results.append(ent)
      if use_noun_chunks:
          for chunk in doc.noun_chunks:
              if chunk.text.lower() not in STOP_WORDS:
                  results.append(chunk)
      results = list(set([r.text for r in results]))
      return results
  
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 4 for calling a global function with example usage: extract_entities(sentence, pos, use_named_entities, use_noun_chunks) and returns: results