class_docstr: spaCy backend for NER.
class_docstr_tok: ["spaCy","backend","for","NER","."]
docstr: Context manager used to run spaCy models on a specific
  GPU in a scoped manner.
docstr_tok: ["Context","manager","used","to","run","spaCy","models","on","a","specific","GPU","in","a","scoped","manner","."]
code: def _select_device(self):
      """
      Context manager used to run spaCy models on a specific
      GPU in a scoped manner.
      """
  
      # TODO: This won't restore the active device.
      # Since there are no opaque API functions to determine
      # the active device in spaCy/Thinc, we can't do much
      # about it as a consumer unless we start poking into their
      # internals.
      try:
          if self._device_id >= 0:
              spacy.require_gpu(self._device_id)
          yield
      finally:
          if self._device_id >= 0:
              spacy.require_cpu()
  
imports: from abc import ABC, abstractmethod
  from contextlib import contextmanager
  from dataclasses import dataclass
  from enum import Enum, EnumMeta
  from typing import Any, Dict, List, Optional, Union
  from ...None import ComponentError, DeserializationError, Document, component, default_from_dict, default_to_dict
  from ...lazy_imports import LazyImport
label_desc: Use image node_id 7 for calling the _SpacyBackend obj's underlying member method code with example usage: obj._select_device() without return types