Class CrossEncoderServingTranslator

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

public class CrossEncoderServingTranslator extends Object implements Translator<Input,Output>
A Translator that can handle generic cross encoder Input and Output.
  • Constructor Details

    • CrossEncoderServingTranslator

      public CrossEncoderServingTranslator(Translator<ai.djl.util.StringPair,float[]> translator)
      Constructs a CrossEncoderServingTranslator instance.
      Parameters:
      translator - a Translator processes question answering 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
    • batchProcessInput

      public NDList batchProcessInput(TranslatorContext ctx, List<Input> inputs) throws Exception
      Batch processes the inputs and converts it to NDList.
      Specified by:
      batchProcessInput in interface Translator<Input,Output>
      Parameters:
      ctx - the toolkit for creating the input NDArray
      inputs - a list of 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
    • batchProcessOutput

      public List<Output> batchProcessOutput(TranslatorContext ctx, NDList list) throws Exception
      Batch processes the output NDList to the corresponding output objects.
      Specified by:
      batchProcessOutput in interface Translator<Input,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:
      a list of the output object of expected type
      Throws:
      Exception - if an error occurs during processing output