Package ai.djl.modality.nlp
Class DefaultVocabulary
java.lang.Object
ai.djl.modality.nlp.DefaultVocabulary
- All Implemented Interfaces:
Vocabulary
The default implementation of Vocabulary.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder class that is used to build theDefaultVocabulary. -
Constructor Summary
ConstructorsConstructorDescriptionCreates aDefaultVocabularyobject with aDefaultVocabulary.Builder.DefaultVocabulary(List<String> tokens) Creates aDefaultVocabularyobject with the given list of tokens. -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultVocabulary.Builderbuilder()Creates a new builder to build aDefaultVocabulary.booleanCheck if the vocabulary contains a token.longReturns the index of the given token.getToken(long index) Returns the token corresponding to the given index.longsize()Returns the size of theVocabulary.
-
Constructor Details
-
DefaultVocabulary
Creates aDefaultVocabularyobject with the given list of tokens.- Parameters:
tokens- theListof tokens to build the vocabulary with
-
DefaultVocabulary
Creates aDefaultVocabularyobject with aDefaultVocabulary.Builder.- Parameters:
builder- theDefaultVocabulary.Builderto build the vocabulary with
-
-
Method Details
-
contains
Check if the vocabulary contains a token.- Specified by:
containsin interfaceVocabulary- Parameters:
token- String token to be checked- Returns:
- whether this vocabulary contains the token
-
getToken
Returns the token corresponding to the given index.- Specified by:
getTokenin interfaceVocabulary- Parameters:
index- the index- Returns:
- the token corresponding to the given index
-
getIndex
Returns the index of the given token.- Specified by:
getIndexin interfaceVocabulary- Parameters:
token- the token- Returns:
- the index of the given token.
-
size
public long size()Returns the size of theVocabulary.- Specified by:
sizein interfaceVocabulary- Returns:
- the size of the
Vocabulary
-
builder
Creates a new builder to build aDefaultVocabulary.- Returns:
- a new builder
-