).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
add_opt(common_arg(
{"--embd-output-format"}, "FORMAT",
- "empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix",
+ "empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix, \"raw\" = plain whitespace-delimited output (one embedding per line)",
[](common_params & params, const std::string & value) {
params.embd_out = value;
}
| | multiple embeddings | $[[x_1,...,x_n],[x_1,...,x_n],...,[x_1,...,x_n]]$
| 'json' | openai style |
| 'json+' | add cosine similarity matrix |
+| 'raw' | plain text output |
### --embd-separator $"string"$
| $"string"$ | |
}
}
+// plain, pipe-friendly output: one embedding per line
+static void print_raw_embeddings(const float * emb,
+ int n_embd_count,
+ int n_embd,
+ const llama_model * model,
+ enum llama_pooling_type pooling_type,
+ int embd_normalize) {
+ const uint32_t n_cls_out = llama_model_n_cls_out(model);
+ const bool is_rank = (pooling_type == LLAMA_POOLING_TYPE_RANK);
+ const int cols = is_rank ? std::min<int>(n_embd, (int) n_cls_out) : n_embd;
+
+ for (int j = 0; j < n_embd_count; ++j) {
+ for (int i = 0; i < cols; ++i) {
+ if (embd_normalize == 0) {
+ LOG("%1.0f%s", emb[j * n_embd + i], (i + 1 < cols ? " " : ""));
+ } else {
+ LOG("%1.7f%s", emb[j * n_embd + i], (i + 1 < cols ? " " : ""));
+ }
+ }
+ LOG("\n");
+ }
+}
+
int main(int argc, char ** argv) {
common_params params;
}
if (notArray) LOG("\n}\n");
+ } else if (params.embd_out == "raw") {
+ print_raw_embeddings(emb, n_embd_count, n_embd, model, pooling_type, params.embd_normalize);
}
LOG("\n");