Class DefaultVocabulary

java.lang.Object
ai.djl.modality.nlp.DefaultVocabulary
All Implemented Interfaces:
Vocabulary

public class DefaultVocabulary extends Object implements Vocabulary
The default implementation of Vocabulary.
  • Constructor Details

  • Method Details

    • contains

      public boolean contains(String token)
      Check if the vocabulary contains a token.
      Specified by:
      contains in interface Vocabulary
      Parameters:
      token - String token to be checked
      Returns:
      whether this vocabulary contains the token
    • getToken

      public String getToken(long index)
      Returns the token corresponding to the given index.
      Specified by:
      getToken in interface Vocabulary
      Parameters:
      index - the index
      Returns:
      the token corresponding to the given index
    • getIndex

      public long getIndex(String token)
      Returns the index of the given token.
      Specified by:
      getIndex in interface Vocabulary
      Parameters:
      token - the token
      Returns:
      the index of the given token.
    • size

      public long size()
      Returns the size of the Vocabulary.
      Specified by:
      size in interface Vocabulary
      Returns:
      the size of the Vocabulary
    • builder

      public static DefaultVocabulary.Builder builder()
      Creates a new builder to build a DefaultVocabulary.
      Returns:
      a new builder