]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
embedding : add EOS token if not present (#899)
authorGeorgi Gerganov <redacted>
Thu, 14 Mar 2024 13:14:14 +0000 (15:14 +0200)
committerGeorgi Gerganov <redacted>
Thu, 14 Mar 2024 13:14:14 +0000 (15:14 +0200)
examples/embedding/embedding.cpp

index 895469a3152715fd1fed9c7597bbd82273e7d8f0..cbf9aa2b560dde1036373a213e6c06d185a9254f 100644 (file)
@@ -112,13 +112,20 @@ int main(int argc, char ** argv) {
     // tokenize the prompts and trim
     std::vector<std::vector<int32_t>> inputs;
     for (const auto & prompt : prompts) {
-        auto inp = ::llama_tokenize(ctx, prompt, true);
+        auto inp = ::llama_tokenize(ctx, prompt, true, false);
         if (inp.size() > n_batch) {
             inp.resize(n_batch);
         }
         inputs.push_back(inp);
     }
 
+    // add eos if not present
+    for (auto & inp : inputs) {
+        if (inp.empty() || inp.back() != llama_token_eos(model)) {
+            inp.push_back(llama_token_eos(model));
+        }
+    }
+
     // tokenization stats
     if (params.verbose_prompt) {
         for (int i = 0; i < (int) inputs.size(); i++) {
@@ -172,7 +179,7 @@ int main(int argc, char ** argv) {
     for (int j = 0; j < n_prompts; j++) {
         fprintf(stdout, "embedding %d: ", j);
         for (int i = 0; i < std::min(16, n_embd); i++) {
-            fprintf(stdout, "%f ", emb[j * n_embd + i]);
+            fprintf(stdout, "%9.6f ", emb[j * n_embd + i]);
         }
         fprintf(stdout, "\n");
     }