transformer_lens.components.token_typed_embed#
Hooked Transformer Token Typed Embed Component.
This module contains all the component TokenTypeEmbed.
- class transformer_lens.components.token_typed_embed.TokenTypeEmbed(cfg: Dict | HookedTransformerConfig)#
Bases:
ModuleThe token-type embed is a binary ids indicating whether a token belongs to sequence A or B. For example, for two sentences: “[CLS] Sentence A [SEP] Sentence B [SEP]”, token_type_ids would be [0, 0, …, 0, 1, …, 1, 1]. 0 represents tokens from Sentence A, 1 from Sentence B. If not provided, BERT assumes a single sequence input. Typically, shape is (batch_size, sequence_length).
See the BERT paper for more information: https://arxiv.org/pdf/1810.04805.pdf
- forward(token_type_ids: Int[Tensor, 'batch pos'])#
Define 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.