SymbolCodeEmbeddingBuilder
SymbolCodeEmbeddingBuilder is a class in the
automata.symbol_embedding.symbol_embedding_builders module. It’s
primarily used for generating source code embeddings for a given symbol.
Overview
SymbolCodeEmbeddingBuilder contains two methods: build and
batch_build. The build method generates the embedding for a
symbol’s source code, and the batch_build method generates the
embeddings for a list of symbols’ source code.
The class inherits from the EmbeddingBuilder and is instrumental in
building the SymbolCodeEmbedding, which consists of the symbol, its
source code, and the corresponding embedding vector.
Example
The following example demonstrates building a SymbolCodeEmbedding:
from automata.symbol_embedding.symbol_embedding_builders import SymbolCodeEmbeddingBuilder
from symbol_representation.symbol import Symbol
from symbol_representation.symbol_code_embedding import SymbolCodeEmbedding
symbol_code = "def hello_world(): print('Hello, world!')"
symbol = Symbol('hello_world', symbol_code)
embedding_builder = SymbolCodeEmbeddingBuilder()
# Building SymbolCodeEmbedding for a single symbol
symbol_code_embedding = embedding_builder.build(symbol_code, symbol)
print(symbol_code_embedding)
# Building SymbolCodeEmbedding for a batch of symbols
symbol_codes = [symbol_code, symbol_code]
symbols = [symbol, symbol]
symbol_code_embeddings = embedding_builder.batch_build(symbol_codes, symbols)
print(symbol_code_embeddings)
Limitations
SymbolCodeEmbeddingBuilder does not handle symbols that are not
identifiable in the source code, like variables or symbols from imported
modules. Ensuring that the source code passed to the build or
batch_build methods contains the defined symbol is crucial for
proper functionality.
In addition, the actual implementation of the EmbeddingBuilder and
EmbeddingProvider is not shown in the context, so assumptions have
been made in the example provided. Depending on the specific
implementations of those classes, additional set-up may be required.
Follow-up Questions:
Are there specific requirements or best practice guidelines for source code passed to this builder class?
How are symbols that are not defined in the provided source code handled?