Collect representative examples
Gather typical inputs and edge cases from the model’s domain so visual checks focus on realistic behaviour rather than synthetic patterns.
Visualise transformer attention. Assess explanation stability.
Attention visualisation inspects the attention weights inside transformer layers to help developers understand which input tokens the model attends to for a prediction. Visualisations are helpful but fragile: attention patterns vary by input, layer and head, and they can be misread as causal explanations rather than model artefacts.
Learning concept · Not a validated service
Attention visualisation inspects the attention weights inside transformer layers to help developers understand which input tokens the model attends to for a prediction. Visualisations are helpful but fragile: attention patterns vary by input, layer and head, and they can be misread as causal explanations rather than model artefacts.
A proposed application: an interactive tool for ML engineers to inspect attention patterns on tagged examples and to compare heads and layers. The tool is intended for investigation and debugging; a human must review any interpretation before acting on model decisions.
Gather typical inputs and edge cases from the model’s domain so visual checks focus on realistic behaviour rather than synthetic patterns.
Run a trained transformer on examples and save attention matrices per layer and head for later visualisation.
Create token-level heatmaps and attention-flow plots, allow head and layer selection and token highlighting for inspection.
Measure explanation stability across perturbations and compare attention-based insights with alternative methods such as Integrated Gradients.
The supplied starter generates a synthetic tabular classification dataset, trains a RandomForestClassifier, computes permutation-based feature importances, and prints a simple report and test accuracy. It does not load a transformer model nor extract or plot attention weights.
X, y = make_classification(n_samples=700, n_features=8, n_informative=5, random_state=42)
columns = [f"feature_{i}" for i in range(X.shape[1])]
X = pd.DataFrame(X, columns=columns)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42, stratify=y)
model = RandomForestClassifier(n_estimators=250, random_state=42)
model.fit(X_train, y_train)
importance = permutation_importance(model, X_test, y_test, n_repeats=10, random_state=42)
report = pd.DataFrame({"feature": columns, "importance": importance.importances_mean})
report = report.sort_values("importance", ascending=False)The starter uses scikit-learn’s make_classification and a RandomForest on tabular data; it computes permutation feature importances rather than any transformer attention matrices. Therefore it does not implement attention extraction, attention visualisation, or Transformer models referenced in the project title.
Proposed extension: replace the starter with a small transformer (e.g. a pretrained BERT) and code to extract per-layer, per-head attention matrices; add interactive token-level heatmaps and controls to compare heads and perturbations.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.