-
Notifications
You must be signed in to change notification settings - Fork 9.9k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I get input embeddings? #224
Comments
I believe you can get the embedding using |
Those wouldn't be embeddings, those would just be tokenized values. The embeddings are obtained in the call to |
Those are the token embeddings for the window (line 582 if it didn't change from my last pull). I wanted the sentence representation, which would be the embedding of the last word after doing one feedforward through the transformer. |
Is this what you're thinking?
|
That is exactly what I wanted to do! I was going crazy trying to do the
indexing right.
I will test this tonight. Thank you!
If interested, I can do a PR adding this functionality under a console flag
(I'm thinking --embedding or --sentence-representation, but please feel
free to suggest another). I saw other open issues requesting the same and
the repo gets enough attention that more people are bound to want it.
Thank you!
…On Fri, Mar 17, 2023, 12:12 MillionthOdin16 ***@***.***> wrote:
Is this what you're thinking?
/// (loop handling each layer) ///
// input for next layer
inpL = cur;
}
// norm
{
inpL = ggml_rms_norm(ctx0, inpL);
// inpL = norm*inpL
inpL = ggml_mul(ctx0,
ggml_repeat(ctx0, model.norm, inpL),
inpL);
std::vector<float> embedding_representation;
embedding_representation.resize(n_embd);
memcpy(embedding_representation.data(), (float *) ggml_get_data(inpL) + (n_embd * (N - 1)), sizeof(float) * n_embd);
}
/// (forward expand) ///
—
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD6JCX3GZD6HRUCL7QKRMZDW4SZR3ANCNFSM6AAAAAAV6CDIWM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I know I want it. It should probably be folded into the in-progress API implementation too at #77 |
Would be awesome to have the option to get the embeddings as well as an option. Did you end up doing a PR for it? @StrikingLoo |
Hi both of you. I did! It's here. |
@StrikingLoo by any chance did you explore evaluation of these embeddings? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I am trying to output just the sentence embedding for a given input, instead of any new generated text. I think this should be rather straightforward but figured someone more familiar with the codebase could help me.
I just want to return the sentence embedding vector and stop execution for a given input.
I am almost sure the place where I want to make the embedding is right after
norm
but beforelm_head
, and I think they will be ininpL
if I runHowever I am confused by the struct and not sure how to get the sentence embedding itself. I understand it should be some index of ggml_get_data(inpL), but don't get which index, and that is why I come to you. Would anyone lend me a hand?
The text was updated successfully, but these errors were encountered: