class_docstr: Per-field annotator.
  
  Annotates individual fields from a dataset given an annotator model that takes
  a single input field in its input_spec() to create annotations.
  Each annotated field will be named as
  '{annotator name}:{annotator model output key}:{dataset field key}'.
code: def annotate(
      self,
      inputs: list[dict[str, Any]],
      dataset: lit_dataset.Dataset,
      dataset_spec_to_annotate: Optional[types.Spec] = None,
  ):
      if len(self._annotator_model.input_spec().items()) != 1:
          raise ValueError(
              "Annotator model provided to PerFieldAnnotator does not "
              "operate on a single field"
          )
  
      datasets = {}
      for (
          input_name,
          input_type,
      ) in self._annotator_model.input_spec().items():
          # Do remap of inputs based on input name needed by annotator.
          ds_keys = utils.find_spec_keys(
              dataset.spec(), type(input_type)
          )
          for ds_key in ds_keys:
              temp_ds = lit_dataset.Dataset(
                  examples=inputs, base=dataset
              )
              datasets[ds_key] = temp_ds.remap({ds_key: input_name})
  
      for ds_key, ds in datasets.items():
          outputs = self._annotator_model.predict(ds.examples)
          for (
              output_name,
              output_type,
          ) in self._annotator_model.output_spec().items():
              # Update dataset spec with new annotated field.
              field_name = f"{self._name}:{output_name}:{ds_key}"
              if dataset_spec_to_annotate:
                  dataset_spec_to_annotate[field_name] = attr.evolve(
                      output_type, annotated=True
                  )
  
              # Update all examples with annotator output.
              for example, output in zip(inputs, outputs):
                  example[field_name] = output[output_name]
  
file_path: lit/lit_nlp/components/annotators.py
imports: from typing import Any, Optional
  import attr
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import types
  from lit_nlp.lib import utils
label_desc: Use image node_id 1 for calling the PerFieldAnnotator obj's underlying member method code with example usage: obj.annotate(inputs, dataset, dataset_spec_to_annotate) without return types