Enum Class PaddingStrategy

java.lang.Object
java.lang.Enum<PaddingStrategy>
opennlp.dl.vectors.PaddingStrategy
All Implemented Interfaces:
Serializable, Comparable<PaddingStrategy>, Constable

public enum PaddingStrategy extends Enum<PaddingStrategy>
How SentenceVectorsDL.embedAll(List) shapes the tensors of one inference when the texts of a call differ in tokenized length.

A padded position is 0 in the attention mask and Pooling reads only the positions a row's own mask covers, so the vectors of the strategies match up to floating-point rounding, provided the model honors the attention mask. A sentence_embedding output that ignores the mask changes with padding. The strategies differ in tensor shape and in how many times the session runs.

Since:
3.0.0
  • Enum Constant Details

    • AUTO

      public static final PaddingStrategy AUTO
      Selects LONGEST on a GPU for a model with token output and a padding token in its vocabulary, EXACT_LENGTH otherwise. Resolved when the embedder is constructed.
    • EXACT_LENGTH

      public static final PaddingStrategy EXACT_LENGTH
      No padding. Texts are grouped by their exact tokenized length and each group runs on its own. This is the default on the CPU. On natural text most groups hold one or two texts.
    • LONGEST

      public static final PaddingStrategy LONGEST
      Every row of a batch is padded to the longest row of that batch. Texts are ordered by length before batching, so one long text does not pad out a batch of short ones. Requires a padding token in the vocabulary. This is the default on a GPU if the vocabulary has one, except for a model with a sentence_embedding output, which may ignore the attention mask.
    • MAX_LENGTH

      public static final PaddingStrategy MAX_LENGTH
      Every row is padded to the maximum length, so every inference has the same sequence length. Single calls such as SentenceVectorsDL.embed(CharSequence) and SentenceVectorsDL.getVectors(String) pad to the maximum length as well. Useful for a model or accelerator that needs a fixed sequence length. Requires a padding token in the vocabulary. If the output dimension must be probed during construction, that inference also uses the maximum length and can fail if it exceeds the model's position limit.
  • Method Details

    • values

      public static PaddingStrategy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static PaddingStrategy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null