Class TokenClassificationServingTranslator

java.lang.Object
ai.djl.modality.nlp.translator.TokenClassificationServingTranslator
All Implemented Interfaces:
NoBatchifyTranslator<Input,Output>, PostProcessor<Output>, PreProcessor<Input>, Translator<Input,Output>

public class TokenClassificationServingTranslator extends Object implements NoBatchifyTranslator<Input,Output>
A Translator that can handle generic token classification Input and Output.
  • Constructor Details

    • TokenClassificationServingTranslator

      public TokenClassificationServingTranslator(Translator<String,NamedEntity[]> translator)
      Constructs a TokenClassificationServingTranslator instance.
      Parameters:
      translator - a Translator processes token classification input
  • Method Details

    • prepare

      public void prepare(TranslatorContext ctx) throws Exception
      Prepares the translator with the manager and model to use.
      Specified by:
      prepare in interface Translator<Input,Output>
      Parameters:
      ctx - the context for the Predictor.
      Throws:
      Exception - if there is an error for preparing the translator
    • processInput

      public NDList processInput(TranslatorContext ctx, Input input) throws Exception
      Processes the input and converts it to NDList.
      Specified by:
      processInput in interface PreProcessor<Input>
      Parameters:
      ctx - the toolkit for creating the input NDArray
      input - the input object
      Returns:
      the NDList after pre-processing
      Throws:
      Exception - if an error occurs during processing input
    • processOutput

      public Output processOutput(TranslatorContext ctx, NDList list) throws Exception
      Processes the output NDList to the corresponding output object.
      Specified by:
      processOutput in interface PostProcessor<Output>
      Parameters:
      ctx - the toolkit used for post-processing
      list - the output NDList after inference, usually immutable in engines like PyTorch. @see Issue 1774
      Returns:
      the output object of expected type
      Throws:
      Exception - if an error occurs during processing output