Skip to content

hmohebbi/context_mixing_toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A handy library for measuring context-mixing in Transformers

The goal of this toolkit is to quantify how much each token/frame representation (in text/speech models) in a Transformer layer relies on information from other tokens/frames in the context when forming its contextualized representation.


Measures of context-mixing:

How to use?

INPUT_EXAMPLE = "Either you win the game or you"
cm_config = CMConfig(output_attention=True, output_attention_norm=True, output_globenc=True, output_value_zeroing=True)
inputs = tokenizer(INPUT_EXAMPLE, return_tensors="pt")
with torch.no_grad():
  outputs = model(**inputs, output_context_mixings=cm_config)

Notebooks

Colab notebooks are available for both text and speech Transformer models.

About

A library for measuring context-mixing in Transformers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages