How to get embedding for a code snippet using Codex API?

Can we use Codex API to get embedding for a given code snippet?

Lets say the code input is as follows:

import Random
a = random.randint(1,12)
b = random.randint(1,12)
for i in range(10):
    question = "What is "+a+" x "+b+"? "
    answer = input(question)
    if answer = a*b
        print (Well done!)
    else:
        print("No.")

I want to get embedding of the input code from the Codex API.

Codex is a fine tuned version of GPT3, is there an issue with using the normal embeddings method?

@jhsmith12345 generating embedding using word2vec/glove is not applicable for my use case as I want to get embedding for source code.

Of course, there are embeddings for source code as well. For example, I can get embedding with code2vec which is designed for source code.

However, I want to employ codex to get embedding as it is likely to outperform existing source code embedding techniques.

Is there a way I can get embedding of the input code using the Codex API? Would really appreciate your help.

@nashid.noor Have you figured out how to use Codex API to embedding the code to vector ?

1 Like