concepts.language.neural_ccg.grammar.NeuralCCGSemantics#

class NeuralCCGSemantics[source]#

Bases: CCGSemantics

We implement the execution result of the current subtree in the following way: For primitive types (syntax.is_value == True), the execution_buffer field is a list containing a single element recording the execution result. For function types (syntax.is_function == True), the execution_buffer stores a partially bound function application. It is stored as a list, where the first element is the function and the rest are bound arguments (the order of these elements is decided by syntax.linearization).

There are two auxiliary properties of this class:

  • partial_type: It summarizes the intermediate execution result of the composition. Specifically, if there is only one string in the list,

    the string is the type of the semantics LF. Otherwise, the first element is of type NeuralCCGSemanticsPartialTypeLex, which records the candidate lexicon index and the word index (which can be None).

  • nr_execution_steps: the number of forwarding steps that have been executed during the construction of this subtree.

Methods

bapp(lhs)

Backward application composition.

canonize_execution_buffer()

Canonize the execution buffer.

compose(rhs, composition_type)

Compose this element with another element.

coord(other)

Coordination composition.

coord3(lhs, rhs)

Coordination composition with three elements.

fapp(rhs)

Forward application composition.

has_execution_result()

Check whether the semantics has a fully-executed result.

none(rhs)

None composition (composition with a None element).

set_execution_result(value)

Set the fully-executed result.

Attributes

arity

execution_result

Get the fully-executed result.

flags

A set of flags that indicates the type of the semantics.

hash

is_conj

Whether the semantics is a conjunction.

is_constant

Whether the semantics is a constant.

is_function

Whether the semantics is a function.

is_function_application

Whether the semantics is a function application expression.

is_lazy

Whether the semantics is a lazy value.

is_none

Whether the semantics is None.

is_py_function

Whether the semantics is a Python function.

is_value

Whether the semantics is a value (either a constant or a function application expression).

return_type

The return type of the semantics.

value

The semantic form.

execution_buffer

The execution buffer for partially executed values.

partial_type

The partial type of the semantics.

nr_execution_steps

The number of execution steps that have been executed.

__init__(value, execution_buffer=None, partial_type=None, nr_execution_steps=0, is_conj=False)[source]#

Initialize a neural CCG semantics object.

Parameters:
__new__(**kwargs)#
bapp(lhs)#

Backward application composition.

Parameters:

lhs (CCGComposable)

Return type:

CCGComposable

canonize_execution_buffer()[source]#

Canonize the execution buffer. Specifically, if the execution buffer has all argument values to the function, we execute the function and replace the execution buffer with the result.

Return type:

NeuralCCGSemantics

compose(rhs, composition_type)#

Compose this element with another element. This function will call the corresponding composition function according to the composition type. Note that since the coordination composition has three arguments, this function will return a CCGCoordinationImmNode for the first two arguments in coordination composition.

Parameters:
Returns:

The composed element.

Return type:

CCGComposable | CCGCoordinationImmNode

coord(other)#

Coordination composition.

Parameters:

other (CCGComposable | CCGCoordinationImmNode)

Return type:

CCGComposable | CCGCoordinationImmNode

coord3(lhs, rhs)#

Coordination composition with three elements.

Parameters:
Return type:

CCGComposable

fapp(rhs)#

Forward application composition.

Parameters:

rhs (CCGComposable)

Return type:

CCGComposable

has_execution_result()[source]#

Check whether the semantics has a fully-executed result.

none(rhs)#

None composition (composition with a None element).

Parameters:

rhs (CCGComposable)

Return type:

CCGComposable

set_execution_result(value)[source]#

Set the fully-executed result.

Parameters:

value – the value to be set.

property arity#
execution_buffer: List[None | Callable | Value] | None#

The execution buffer for partially executed values.

property execution_result#

Get the fully-executed result. If the result is not fully executed, raise an exception.

property flags: Dict[str, bool]#

A set of flags that indicates the type of the semantics.

property hash#
property is_conj#

Whether the semantics is a conjunction.

property is_constant#

Whether the semantics is a constant.

property is_function#

Whether the semantics is a function.

property is_function_application#

Whether the semantics is a function application expression.

property is_lazy#

Whether the semantics is a lazy value.

property is_none#

Whether the semantics is None.

property is_py_function#

Whether the semantics is a Python function.

property is_value#

Whether the semantics is a value (either a constant or a function application expression).

nr_execution_steps: int#

The number of execution steps that have been executed.

partial_type: List[str] | None#

The partial type of the semantics.

property return_type#

The return type of the semantics. If the semantics is a function or a value, the return type is the type of the function or the value. Otherwise, this function will raise an error.

property value: Callable | Function | ConstantExpression | FunctionApplicationExpression | CCGSemanticsLazyValue#

The semantic form.