kiwi.systems.encoders.bert
TransformersTextEncoder
Encode a field, handling vocabulary, tokenization and embeddings.
BertEncoder
BERT model as presented in Google’s paper and using Hugging Face’s code
kiwi.systems.encoders.bert.
logger
Bases: kiwi.data.encoders.field_encoders.TextEncoder
kiwi.data.encoders.field_encoders.TextEncoder
Heavily inspired in torchtext and torchnlp.
fit_vocab
Bases: kiwi.systems._meta_module.MetaModule
kiwi.systems._meta_module.MetaModule
References
https://arxiv.org/abs/1810.04805
Config
Bases: kiwi.utils.io.BaseConfig
kiwi.utils.io.BaseConfig
Base class for all pydantic configs. Used to configure base behaviour of configs.
model_name
Pre-trained BERT model to use.
use_mismatch_features
Use Alibaba’s mismatch features.
use_predictor_features
Use features originally proposed in the Predictor model.
interleave_input
Concatenate SOURCE and TARGET without internal padding (111222000 instead of 111002220)
freeze
Freeze BERT during training.
use_mlp
Apply a linear layer on top of BERT.
hidden_size
Size of the linear layer on top of BERT.
scalar_mix_dropout
scalar_mix_layer_norm
fix_relative_path
no_implementation
load_state_dict
Copies parameters and buffers from state_dict into this module and its descendants. If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.
state_dict
strict
True
state_dict()
state_dict (dict) – a dict containing parameters and persistent buffers.
strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True
missing_keys is a list of str containing the missing keys
unexpected_keys is a list of str containing the unexpected keys
NamedTuple with missing_keys and unexpected_keys fields
NamedTuple
missing_keys
unexpected_keys
input_data_encoders
size
forward
concat_input
Concatenate the target + source embeddings into one tensor.
(as zeroes) and concatenation of attention_mask
split_outputs
Split features back into sentences A and B.
features – BERT’s output: [CLS] target [SEP] source [SEP]. Shape of (bs, 1 + target_len + 1 + source_len + 1, 2)
[CLS] target [SEP] source [SEP]
batch_inputs – the regular batch object, containing source and target batches
source
target
interleaved – whether the concat strategy was interleaved
dict of tensors for source and target.
Interleave the source + target embeddings into one tensor.
This means making the input as [batch, target [SEP] source].
and concatenation of attention_mask.
get_mismatch_features
kiwi.systems.encoders
kiwi.systems.encoders.predictor