
Generation Demonstration¶
This notebook show case what can be done with interpreto for generation.
author: Antonin Poché
0. Imports and model loading¶
1. Attribution Demonstration¶
1.1 Obtain attribution¶
1.2 Evaluate attributions¶
2. Concepts Demonstration¶
2.1 Split model and get a dataset of activations¶
2.2 Learn concepts as patterns in the activations¶
2.3 Interpret the concepts¶
try:
from interpreto.commons.llm_interface import OpenAILLM
llm_interface = OpenAILLM(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4.1-nano")
# instantiate the interpretation method with the concept explainer
interpretation_method = LLMLabels(
concept_explainer=concept_explainer,
llm_interface=llm_interface,
k_examples=20,
)
except ImportError:
interpretation_method = TopKInputs(
concept_explainer=concept_explainer,
k=10,
)
# interpret the concepts via top-k words
interpretations = interpretation_method.interpret(
inputs=dataset,
latent_activations=activations,
concepts_indices="all",
)
print("\n".join(interpretations.values()))