compositional_graph_models/data.py
def build_vocabs(serialized_equations) -> Tuple[Dict[str, int], Dict[str, int]]:
    """
    Build a function vocabulary and a variable vocabulary from a serialized dataset.

    Parameters
    ----------
    serialized_equations
        A list of equations in the serialization format of the equation verification
        task.

    Returns
    -------
    function_vocab : Dict[str, int]
        A vocabulary of function symbols.
    token_vocab : Dict[str, int]
        A vocabulary of variable and number symbols.
    """
    functions: Set[str] = {PAD_FUNCTION, LEAF_FUNCTION}
    tokens: Set[str] = {PAD_TOKEN, NONLEAF_TOKEN}

    for ex in serialized_equations:
        eq = ex["equation"]
        eq_funcs = eq["func"].split(",")
        eq_tokens = eq["vars"].split(",")
        for func, token in zip(eq_funcs, eq_tokens):
            if token:
                tokens.add(token)
            elif func != "#":
                functions.add(func)

    function_vocab = {sym: i for i, sym in enumerate(functions)}
    token_vocab = {sym: i for i, sym in enumerate(tokens)}
    return function_vocab, token_vocab

    Build a function vocabulary and a variable vocabulary from a serialized dataset.

    Parameters
    ----------
    serialized_equations
        A list of equations in the serialization format of the equation verification
        task.

    Returns
    -------
    function_vocab : Dict[str, int]
        A vocabulary of function symbols.
    token_vocab : Dict[str, int]
        A vocabulary of variable and number symbols.
    
Build a function vocabulary and a variable vocabulary from a serialized dataset.
Parameters

serialized_equations
A list of equations in the serialization format of the equation verification
task.

Returns

function_vocab : Dict[str, int]
A vocabulary of function symbols.
token_vocab : Dict[str, int]
A vocabulary of variable and number symbols.
Build a function vocabulary and a variable vocabulary from a serialized dataset . Parameters serialized_equations A list of equations in the serialization format of the equation verification task . Returns function_vocab : Dict [ str int ] A vocabulary of function symbols . token_vocab : Dict [ str int ] A vocabulary of variable and number symbols .
def build_vocabs(serialized_equations) -> Tuple[Dict[str, int], Dict[str, int]]:
    functions: Set[str] = {PAD_FUNCTION, LEAF_FUNCTION}
    tokens: Set[str] = {PAD_TOKEN, NONLEAF_TOKEN}
    for ex in serialized_equations:
        eq = ex["equation"]
        eq_funcs = eq["func"].split(",")
        eq_tokens = eq["vars"].split(",")
        for func, token in zip(eq_funcs, eq_tokens):
            if token:
                tokens.add(token)
            elif func != "#":
                functions.add(func)
    function_vocab = {sym: i for i, sym in enumerate(functions)}
    token_vocab = {sym: i for i, sym in enumerate(tokens)}
    return function_vocab, token_vocab
def build_vocabs ( serialized_equations ) -> Tuple [ Dict [ str , int ] , Dict [ str , int ] ] : functions : Set [ str ] = { PAD_FUNCTION , LEAF_FUNCTION } tokens : Set [ str ] = { PAD_TOKEN , NONLEAF_TOKEN } for ex in serialized_equations : eq = ex [ "equation" ] eq_funcs = eq [ "func" ] . split ( "," ) eq_tokens = eq [ "vars" ] . split ( "," ) for func , token in zip ( eq_funcs , eq_tokens ) : if token : tokens . add ( token ) elif func != "#" : functions . add ( func ) function_vocab = { sym : i for i , sym in enumerate ( functions ) } token_vocab = { sym : i for i , sym in enumerate ( tokens ) } return function_vocab , token_vocab
Build a function vocabulary and a variable vocabulary from a serialized dataset.
Build a function vocabulary and a variable vocabulary from a serialized dataset .
"""
    Build a function vocabulary and a variable vocabulary from a serialized dataset.

    Parameters
    ----------
    serialized_equations
        A list of equations in the serialization format of the equation verification
        task.

    Returns
    -------
    function_vocab : Dict[str, int]
        A vocabulary of function symbols.
    token_vocab : Dict[str, int]
        A vocabulary of variable and number symbols.
    """
serialized_equations