code: def to_patterns(
      dataset,
      spacy_model,
      label,
      output_file="-",
      case_sensitive=False,
      dry=False,
  ):
      """
      Convert a dataset of phrases collected with sense2vec.teach to token-based
      match patterns that can be used with spaCy's EntityRuler or recipes like
      ner.match. If no output file is specified, the patterns are written to
      stdout. The examples are tokenized so that multi-token terms are represented
      correctly, e.g.:
      {"label": "SHOE_BRAND", "pattern": [{"LOWER": "new"}, {"LOWER": "balance"}]}
  
      For tokenization, you can either pass in the name of a spaCy model (e.g. if
      you're using a model with custom tokenization), or "blank:" plus the
      language code you want to use, e.g. blank:en or blank:de. Make sure to use
      the same language / tokenizer you're planning to use at runtime – otherwise
      your patterns may not match.
      """
      log("RECIPE: Starting recipe sense2vec.to-patterns", locals())
      if spacy_model.startswith("blank:"):
          nlp = spacy.blank(spacy_model.replace("blank:", ""))
      else:
          nlp = spacy.load(spacy_model)
      log(f"RECIPE: Loaded spaCy model '{spacy_model}'")
      DB = connect()
      if dataset not in DB:
          msg.fail(f"Can't find dataset '{dataset}'", exits=1)
      examples = DB.get_dataset(dataset)
      terms = set(
          [eg["word"] for eg in examples if eg["answer"] == "accept"]
      )
      if case_sensitive:
          patterns = [
              [{"text": t.text} for t in nlp.make_doc(term)]
              for term in terms
          ]
      else:
          terms = set([word.lower() for word in terms])
          patterns = [
              [{"lower": t.lower_} for t in nlp.make_doc(term)]
              for term in terms
          ]
      patterns = [
          {"label": label, "pattern": pattern} for pattern in patterns
      ]
      log(f"RECIPE: Generated {len(patterns)} patterns")
      if not dry:
          srsly.write_jsonl(output_file, patterns)
      return patterns
  
file_path: sense2vec/sense2vec/prodigy_recipes.py
imports: import prodigy
  from prodigy.components.db import connect
  from prodigy.util import log, split_string, set_hashes, TASK_HASH_ATTR, INPUT_HASH_ATTR
  import murmurhash
  from sense2vec import Sense2Vec
  import srsly
  import spacy
  import random
  from wasabi import msg
  from collections import defaultdict, Counter
  import copy
  import catalogue
label_desc: Use image node_id 2 for calling a global function with example usage: to_patterns(dataset, spacy_model, label, output_file, case_sensitive, dry) and returns: patterns