Class HuggingFaceTokenCountEstimator
java.lang.Object
dev.langchain4j.model.embedding.onnx.HuggingFaceTokenCountEstimator
- All Implemented Interfaces:
TokenCountEstimator
A token count estimator for models that can be found on HuggingFace.
Uses DJL's
Requires
Uses DJL's
HuggingFaceTokenizer under the hood.
Requires
tokenizer.json to instantiate.
An example.-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of aHuggingFaceTokenCountEstimatorusing a built-intokenizer.jsonfile.HuggingFaceTokenCountEstimator(String pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.HuggingFaceTokenCountEstimator(String pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.HuggingFaceTokenCountEstimator(Path pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.HuggingFaceTokenCountEstimator(Path pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options. -
Method Summary
Modifier and TypeMethodDescriptionintestimateTokenCountInMessage(ChatMessage message) Estimates the count of tokens in the given message.intestimateTokenCountInMessages(Iterable<ChatMessage> messages) Estimates the count of tokens in the given messages.intEstimates the count of tokens in the given text.
-
Constructor Details
-
HuggingFaceTokenCountEstimator
public HuggingFaceTokenCountEstimator()Creates an instance of aHuggingFaceTokenCountEstimatorusing a built-intokenizer.jsonfile. -
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")options- The DJL's tokenizer options
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")options- The DJL's tokenizer options
-
-
Method Details
-
estimateTokenCountInText
Description copied from interface:TokenCountEstimatorEstimates the count of tokens in the given text.- Specified by:
estimateTokenCountInTextin interfaceTokenCountEstimator- Parameters:
text- the text.- Returns:
- the estimated count of tokens.
-
estimateTokenCountInMessage
Description copied from interface:TokenCountEstimatorEstimates the count of tokens in the given message.- Specified by:
estimateTokenCountInMessagein interfaceTokenCountEstimator- Parameters:
message- the message.- Returns:
- the estimated count of tokens.
-
estimateTokenCountInMessages
Description copied from interface:TokenCountEstimatorEstimates the count of tokens in the given messages.- Specified by:
estimateTokenCountInMessagesin interfaceTokenCountEstimator- Parameters:
messages- the messages.- Returns:
- the estimated count of tokens.
-