rbnet.pcfg.ExpandedPCFG
- class rbnet.pcfg.ExpandedPCFG(non_terminals, terminals, non_term_variables, rules, start)[source]
Bases:
PCFG
An ExpandedPCFG…
- Parameters:
non_terminals – list or array of non-terminal symbols
terminals – list or array of terminal symbols
non_term_variables – list of non-terminal variables corresponding to the non-terminal symbols
rules – iterable of rules-weight-transition tuples with rules provided either as strings of the form (“X –> Y Z”, w, t) or (“X –> Y”, w, t) for non-terminal and terminal rules, respectively (symbols have to be strings without whitespace for this), or of the form ((X, (Y, Z)), w, t) or ((X, (Y,)), w, t) for arbitrary symbols, where w is the rule weight, and t is the transition for the corresponding variables.
start – the start symbol
Public Data Attributes:
Inherited from
PCFG
dump_patches
call_super_init
forward
(*input)Define the computation performed at every call.
Inherited from
SequentialRBN
Return the location of the root variables.
Return the chart with inside probabilities for all variables.
Return the chart with terminal variables.
Return the prior transition (typically an instance of
Prior
), which has to implementPrior.marginal_likelihood()
.dump_patches
training
call_super_init
forward
(*input)Define the computation performed at every call.
Inherited from
RBN
Return the location of the root variables.
Return the chart with inside probabilities for all variables.
Return the chart with terminal variables.
Return the prior transition (typically an instance of
Prior
), which has to implementPrior.marginal_likelihood()
.Inherited from
Module
dump_patches
call_super_init
T_destination
training
Public Methods:
__init__
(non_terminals, terminals, ...)An ExpandedPCFG...
Inherited from
PCFG
__init__
(cells, prior, terminal_indices, ...)tokenise
(sequence)init_inside
(sequence)Initialise for parsing a new input.
map_inside_chart
([precision])Inherited from
SequentialRBN
__init__
(cells, prior, *args, **kwargs)init_inside
(sequence)Initialise for parsing a new input.
inside_schedule
(*args, **kwargs)Iterate through (batches of) non-terminal locations for computing inside probabilities.
cells
()Return iterable over cells (corresponding to the non-terminal variables).
update_inside_chart
(var_idx, locations, values)For the specified variable, update the chart for inside probabilities with given values at given locations.
Inherited from
RBN
__init__
(*args, **kwargs)inside_schedule
(*args, **kwargs)Iterate through (batches of) non-terminal locations for computing inside probabilities.
cells
()Return iterable over cells (corresponding to the non-terminal variables).
init_inside
(*args, **kwargs)Initialise for parsing a new input.
update_inside_chart
(var_idx, locations, values)For the specified variable, update the chart for inside probabilities with given values at given locations.
inside
(*args, **kwargs)Compute the inside probabilities and return the marginal data likelihood.
Inherited from
Module
__init__
(*args, **kwargs)Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward
(*input)Define the computation performed at every call.
register_buffer
(name, tensor[, persistent])Add a buffer to the module.
register_parameter
(name, param)Add a parameter to the module.
add_module
(name, module)Add a child module to the current module.
register_module
(name, module)Alias for
add_module()
.get_submodule
(target)Return the submodule given by
target
if it exists, otherwise throw an error.set_submodule
(target, module)Set the submodule given by
target
if it exists, otherwise throw an error.get_parameter
(target)Return the parameter given by
target
if it exists, otherwise throw an error.get_buffer
(target)Return the buffer given by
target
if it exists, otherwise throw an error.get_extra_state
()Return any extra state to include in the module's state_dict.
set_extra_state
(state)Set extra state contained in the loaded state_dict.
apply
(fn)Apply
fn
recursively to every submodule (as returned by.children()
) as well as self.cuda
([device])Move all model parameters and buffers to the GPU.
ipu
([device])Move all model parameters and buffers to the IPU.
xpu
([device])Move all model parameters and buffers to the XPU.
mtia
([device])Move all model parameters and buffers to the MTIA.
cpu
()Move all model parameters and buffers to the CPU.
type
(dst_type)Casts all parameters and buffers to
dst_type
.float
()Casts all floating point parameters and buffers to
float
datatype.double
()Casts all floating point parameters and buffers to
double
datatype.half
()Casts all floating point parameters and buffers to
half
datatype.bfloat16
()Casts all floating point parameters and buffers to
bfloat16
datatype.to_empty
(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
to
(*args, **kwargs)Move and/or cast the parameters and buffers.
register_full_backward_pre_hook
(hook[, prepend])Register a backward pre-hook on the module.
register_backward_hook
(hook)Register a backward hook on the module.
register_full_backward_hook
(hook[, prepend])Register a backward hook on the module.
register_forward_pre_hook
(hook, *[, ...])Register a forward pre-hook on the module.
register_forward_hook
(hook, *[, prepend, ...])Register a forward hook on the module.
__call__
(*args, **kwargs)Call self as a function.
__getstate__
()__setstate__
(state)__getattr__
(name)__setattr__
(name, value)Implement setattr(self, name, value).
__delattr__
(name)Implement delattr(self, name).
register_state_dict_post_hook
(hook)Register a post-hook for the
state_dict()
method.register_state_dict_pre_hook
(hook)Register a pre-hook for the
state_dict()
method.state_dict
(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
register_load_state_dict_pre_hook
(hook)Register a pre-hook to be run before module's
load_state_dict()
is called.register_load_state_dict_post_hook
(hook)Register a post-hook to be run after module's
load_state_dict()
is called.load_state_dict
(state_dict[, strict, assign])Copy parameters and buffers from
state_dict
into this module and its descendants.parameters
([recurse])Return an iterator over module parameters.
named_parameters
([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
buffers
([recurse])Return an iterator over module buffers.
named_buffers
([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
children
()Return an iterator over immediate children modules.
named_children
()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
modules
()Return an iterator over all modules in the network.
named_modules
([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
train
([mode])Set the module in training mode.
eval
()Set the module in evaluation mode.
requires_grad_
([requires_grad])Change if autograd should record operations on parameters in this module.
zero_grad
([set_to_none])Reset gradients of all model parameters.
share_memory
()See
torch.Tensor.share_memory_()
.extra_repr
()Set the extra representation of the module.
__repr__
()Return repr(self).
__dir__
()Default dir() implementation.
compile
(*args, **kwargs)Compile this Module's forward using
torch.compile()
.Private Data Attributes:
_abc_impl
Inherited from
PCFG
_abc_impl
_version
This allows better BC support for
load_state_dict()
._parameters
_buffers
_non_persistent_buffers_set
_backward_pre_hooks
_backward_hooks
_is_full_backward_hook
_forward_hooks
_forward_hooks_with_kwargs
_forward_hooks_always_called
_forward_pre_hooks
_forward_pre_hooks_with_kwargs
_state_dict_hooks
_load_state_dict_pre_hooks
_state_dict_pre_hooks
_load_state_dict_post_hooks
_modules
_compiled_call_impl
Inherited from
SequentialRBN
_abc_impl
_version
This allows better BC support for
load_state_dict()
._parameters
_buffers
_non_persistent_buffers_set
_backward_pre_hooks
_backward_hooks
_is_full_backward_hook
_forward_hooks
_forward_hooks_with_kwargs
_forward_hooks_always_called
_forward_pre_hooks
_forward_pre_hooks_with_kwargs
_state_dict_hooks
_load_state_dict_pre_hooks
_state_dict_pre_hooks
_load_state_dict_post_hooks
_modules
_compiled_call_impl
Inherited from
RBN
_abc_impl
Inherited from
ABC
_abc_impl
Inherited from
Module
_version
This allows better BC support for
load_state_dict()
._compiled_call_impl
_parameters
_buffers
_non_persistent_buffers_set
_backward_pre_hooks
_backward_hooks
_is_full_backward_hook
_forward_hooks
_forward_hooks_with_kwargs
_forward_hooks_always_called
_forward_pre_hooks
_forward_pre_hooks_with_kwargs
_state_dict_hooks
_load_state_dict_pre_hooks
_state_dict_pre_hooks
_load_state_dict_post_hooks
_modules
Private Methods:
Inherited from
Module
_apply
(fn[, recurse])_get_backward_hooks
()Return the backward hooks for use in the call function.
_get_backward_pre_hooks
()_maybe_warn_non_full_backward_hook
(inputs, ...)_slow_forward
(*input, **kwargs)_wrapped_call_impl
(*args, **kwargs)_call_impl
(*args, **kwargs)_register_state_dict_hook
(hook)Register a post-hook for the
state_dict()
method._save_to_state_dict
(destination, prefix, ...)Save module state to the destination dictionary.
_register_load_state_dict_pre_hook
(hook[, ...])See
register_load_state_dict_pre_hook()
for details._load_from_state_dict
(state_dict, prefix, ...)Copy parameters and buffers from
state_dict
into only this module, but not its descendants._named_members
(get_members_fn[, prefix, ...])Help yield various names + members of modules.
_get_name
()_replicate_for_data_parallel
()