mwptoolkit.module.Environment.stack_machine¶
- class mwptoolkit.module.Environment.stack_machine.StackMachine(operations, constants, embeddings, bottom_embedding, dry_run=False)[source]¶
Bases:
object
- Parameters
constants (list) – Value of numbers.
embeddings (tensor) – Tensor of shape [len(constants), dim_embedding]. Embedding of the constants.
bottom_embedding (teonsor) – Tensor of shape (dim_embedding,). The embeding to return when stack is empty.
- add_variable(embedding)[source]¶
- Tell the stack machine to increase the number of nuknown variables
by 1.
- Parameters
embedding (torch.Tensor) – Tensor of shape (dim_embedding). Embedding of the unknown varialbe.
- apply_embed_only(operation, embed_res)[source]¶
Apply operator on stack with embedding operation only.
- Parameters
operator (mwptoolkit.module.Environment.stack_machine.OPERATION) – One of - OPERATIONS.ADD - OPERATIONS.SUB - OPERATIONS.MUL - OPERATIONS.DIV - OPERATIONS.EQL
embed_res (torch.FloatTensor) – Resulted embedding after transformation, with size (dim_embedding,).
- Returns
embedding on the top of the stack.
- Return type
torch.Tensor
- get_solution()[source]¶
Get solution. If the problem has not been solved, return None.
- Returns
If the problem has been solved, return result from sympy.solve. If not, return None.
- Return type
list