xmodaler.modeling.decode_strategy

xmodaler.modeling.decode_strategy.build_beam_searcher(cfg)[source]
xmodaler.modeling.decode_strategy.build_greedy_decoder(cfg)[source]
class xmodaler.modeling.decode_strategy.GreedyDecoder(*, vocab_path, beam_size, max_seq_len, bert_tokenizer, bos_token_id, eos_token_id)[source]

Bases: DecodeStrategy

_abc_impl = <_abc_data object>
_backward_hooks: Dict[int, Callable]
_buffers: Dict[str, Optional[Tensor]]
_forward(batched_inputs, model)[source]
_forward_hooks: Dict[int, Callable]
_forward_pre_hooks: Dict[int, Callable]
_is_full_backward_hook: Optional[bool]
_load_state_dict_post_hooks: Dict[int, Callable]
_load_state_dict_pre_hooks: Dict[int, Callable]
_modules: Dict[str, Optional[Module]]
_non_persistent_buffers_set: Set[str]
_parameters: Dict[str, Optional[Parameter]]
_state_dict_hooks: Dict[int, Callable]
training: bool
class xmodaler.modeling.decode_strategy.BeamSearcher(*, vocab_path, beam_size, max_seq_len, bert_tokenizer, bos_token_id, eos_token_id)[source]

Bases: DecodeStrategy

_abc_impl = <_abc_data object>
_backward_hooks: Dict[int, Callable]
_buffers: Dict[str, Optional[Tensor]]
_expand_state(states, selected_beam, batch_size, beam_size, cur_beam_size)[source]
_forward(batched_inputs, model)[source]
_forward_hooks: Dict[int, Callable]
_forward_pre_hooks: Dict[int, Callable]
_is_full_backward_hook: Optional[bool]
_load_state_dict_post_hooks: Dict[int, Callable]
_load_state_dict_pre_hooks: Dict[int, Callable]
_modules: Dict[str, Optional[Module]]
_non_persistent_buffers_set: Set[str]
_parameters: Dict[str, Optional[Parameter]]
_select(batch_size, beam_size, t, candidate_logprob)[source]
_state_dict_hooks: Dict[int, Callable]
training: bool
class xmodaler.modeling.decode_strategy.decode_strategy.DecodeStrategy(*, vocab_path, beam_size, max_seq_len, bert_tokenizer, bos_token_id, eos_token_id)[source]

Bases: Module

__init__(*, vocab_path, beam_size, max_seq_len, bert_tokenizer, bos_token_id, eos_token_id)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

_abc_impl = <_abc_data object>
_backward_hooks: Dict[int, Callable]
_buffers: Dict[str, Optional[Tensor]]
abstract _forward(batched_inputs, model)[source]
_forward_hooks: Dict[int, Callable]
_forward_pre_hooks: Dict[int, Callable]
_is_full_backward_hook: Optional[bool]
_load_state_dict_post_hooks: Dict[int, Callable]
_load_state_dict_pre_hooks: Dict[int, Callable]
_modules: Dict[str, Optional[Module]]
_non_persistent_buffers_set: Set[str]
_parameters: Dict[str, Optional[Parameter]]
_state_dict_hooks: Dict[int, Callable]
forward(batched_inputs, output_sents, model)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

classmethod from_config(cfg)[source]
training: bool