transformer_lens.components.bert_embed#

Hooked Transformer Bert Embed Component.

This module contains all the component BertEmbed.

class transformer_lens.components.bert_embed.BertEmbed(cfg: Union[Dict, HookedTransformerConfig])#

Bases: Module

Custom embedding layer for a BERT-like model. This module computes the sum of the token, positional and token-type embeddings and takes the layer norm of the result.

forward(input_ids: Int[Tensor, 'batch pos'], token_type_ids: Optional[Int[Tensor, 'batch pos']] = None)#

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.