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) intestimateTokenCountInMessages(Iterable<ChatMessage> messages) int
-
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
- Specified by:
estimateTokenCountInTextin interfaceTokenCountEstimator
-
estimateTokenCountInMessage
- Specified by:
estimateTokenCountInMessagein interfaceTokenCountEstimator
-
estimateTokenCountInMessages
- Specified by:
estimateTokenCountInMessagesin interfaceTokenCountEstimator
-