Package ai.djl.modality.nlp
Class DefaultVocabulary
- java.lang.Object
-
- ai.djl.modality.nlp.DefaultVocabulary
-
- All Implemented Interfaces:
Vocabulary
public class DefaultVocabulary extends java.lang.Object implements Vocabulary
The default implementation of Vocabulary.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultVocabulary.BuilderBuilder class that is used to build theDefaultVocabulary.
-
Constructor Summary
Constructors Constructor Description DefaultVocabulary(DefaultVocabulary.Builder builder)Creates aDefaultVocabularyobject with aDefaultVocabulary.Builder.DefaultVocabulary(java.util.List<java.lang.String> tokens)Creates aDefaultVocabularyobject with the given list of tokens.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DefaultVocabulary.Builderbuilder()Creates a new builder to build aDefaultVocabulary.booleancontains(java.lang.String token)Check if the vocabulary contains a token.longgetIndex(java.lang.String token)Returns the index of the given token.java.lang.StringgetToken(long index)Returns the token corresponding to the given index.longsize()Returns the size of theVocabulary.
-
-
-
Constructor Detail
-
DefaultVocabulary
public DefaultVocabulary(java.util.List<java.lang.String> tokens)
Creates aDefaultVocabularyobject with the given list of tokens.- Parameters:
tokens- theListof tokens to build the vocabulary with
-
DefaultVocabulary
public DefaultVocabulary(DefaultVocabulary.Builder builder)
Creates aDefaultVocabularyobject with aDefaultVocabulary.Builder.- Parameters:
builder- theDefaultVocabulary.Builderto build the vocabulary with
-
-
Method Detail
-
contains
public boolean contains(java.lang.String token)
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
public java.lang.String getToken(long index)
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
public long getIndex(java.lang.String token)
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
public static DefaultVocabulary.Builder builder()
Creates a new builder to build aDefaultVocabulary.- Returns:
- a new builder
-
-