Richard Burkhardt
Richard Burkhardt

Reputation: 883

Can not load the safetensors huggingface model in DJL in Java

I tried a lot, but I want to read embeddings from the jina embeddings

this is my java code:

public static float[] getTextEmbedding(String text) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
        Criteria<String, float[]> criteria = Criteria.builder()
                .setTypes(String.class, float[].class)
                .optEngine("PyTorch")
                .optModelPath(Paths.get("/jina-embeddings-v2-base-de"))
                .optTranslator(
                    TextEmbeddingTranslator
                        .builder(HuggingFaceTokenizer.newInstance(Paths.get("/jina-embeddings-v2-base-de")))
                        .build()
                )
                .optProgress(new ProgressBar())
                .optOption("trust_remote_code", "true")
                .build();

        try (Predictor<String, float[]> predictor = ModelZoo.loadModel(criteria).newPredictor()) {
            return predictor.predict(text);
        }
    }

but I keept getting this error:

java.io.FileNotFoundException: jina-embeddings-v2-base-de.pt file not found in: /jina-embeddings-v2-base-de

Upvotes: 0

Views: 118

Answers (1)

Frank Liu
Frank Liu

Reputation: 336

djl-convert can convert local model into DJL format as well:

djl-convert -m /jina-embeddings-v2-base-de

Then you can point to model/jina-embeddings-v2-base-de folder in Java code. You will find the following files in the folder:

  • jina-embeddings-v2-base-de.pt
  • config.json
  • serving.properties
  • tokenizer_config.json
  • tokenizer.json

Upvotes: 0

Related Questions