code: def build_text_classifier_v2(
      tok2vec: Model[List[Doc], List[Floats2d]],
      linear_model: Model[List[Doc], Floats2d],
      nO: Optional[int] = None,
  ) -> Model[List[Doc], Floats2d]:
      # TODO: build the model with _build_parametric_attention_with_residual_nonlinear
      # in spaCy v4. We don't do this in spaCy v3 to preserve model
      # compatibility.
      exclusive_classes = not linear_model.attrs["multi_label"]
      with Model.define_operators({">>": chain, "|": concatenate}):
          width = tok2vec.maybe_get_dim("nO")
          attention_layer = ParametricAttention(width)
          maxout_layer = Maxout(nO=width, nI=width)
          norm_layer = LayerNorm(nI=width)
          cnn_model = (
              tok2vec
              >> list2ragged()
              >> attention_layer
              >> reduce_sum()
              >> residual(maxout_layer >> norm_layer >> Dropout(0.0))
          )
  
          nO_double = nO * 2 if nO else None
          if exclusive_classes:
              output_layer = Softmax(nO=nO, nI=nO_double)
          else:
              output_layer = Linear(nO=nO, nI=nO_double) >> Logistic()
          model = (linear_model | cnn_model) >> output_layer
          model.set_ref("tok2vec", tok2vec)
      if model.has_dim("nO") is not False and nO is not None:
          model.set_dim("nO", cast(int, nO))
      model.set_ref(
          "output_layer", linear_model.get_ref("output_layer")
      )
      model.set_ref("attention_layer", attention_layer)
      model.set_ref("maxout_layer", maxout_layer)
      model.set_ref("norm_layer", norm_layer)
      model.attrs["multi_label"] = not exclusive_classes
  
      model.init = init_ensemble_textcat  # type: ignore[assignment]
      return model
  
imports: from functools import partial
  from typing import List, Optional, Tuple, cast
  from thinc.api import Dropout, Gelu, LayerNorm, Linear, Logistic, Maxout, Model, ParametricAttention, ParametricAttention_v2, Relu, Softmax, SparseLinear, SparseLinear_v2, chain, clone, concatenate, list2ragged, reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum, residual, resizable, softmax_activation, with_cpu
  from thinc.layers.chain import init
  from thinc.layers.resizable import resize_linear_weighted, resize_model
  from thinc.types import ArrayXd, Floats2d
  from ...attrs import ORTH
  from ...errors import Errors
  from ...tokens import Doc
  from ...util import registry
  from ..extract_ngrams import extract_ngrams
  from ..staticvectors import StaticVectors
  from .tok2vec import get_tok2vec_width
label_desc: Use image node_id 6 for calling a global function with example usage: build_text_classifier_v2(tok2vec, linear_model, nO) and returns: model