Skip to content

Fix stale and misnamed parameters in docstrings (head_detector, ActivationCache) - #2030

Open
hojaeklee wants to merge 4 commits into
TransformerLensOrg:devfrom
hojaeklee:typos
Open

hojaeklee wants to merge 4 commits into
TransformerLensOrg:devfrom
hojaeklee:typos

Conversation

@hojaeklee

Copy link
Copy Markdown

Description

Docstring-only fixes in head_detector.py and ActivationCache.py where the documented parameters had drifted from the actual signatures, plus two typos. No code changes.

transformer_lens/head_detector.py

  • detect_head: remove the head_name entry; the parameter no longer exists (a head name is now passed via detection_pattern).
  • get_duplicate_token_head_detection_pattern, get_induction_head_detection_pattern: the Args documented sequence: String …, but the parameter is tokens: torch.Tensor. Now tokens: Tokens being fed to the model., matching get_previous_token_head_detection_pattern.
  • compute_head_attention_similarity_score: exclude_bcurrent_token → exclude_current_token.

transformer_lens/ActivationCache.py

  • stack_activation: remove the incl_remainder entry (copied from stack_head_results; not in this signature).
  • get_neuron_results: "results of for neurons" → "results for neurons".
  • Class docstring example: "proceeding space" → "preceding space".

Type of change

  • Bug fix (non-breaking change which fixes an issue): documentation only

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (N/A: docstring-only)
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @hojaeklee! Always appreciate little maintenance items like this. I have a couple of related areas you could also take a look at, if you're willing. See comments below.


Args:
sequence: String being fed to the model.
tokens: Tokens being fed to the model.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demos/Head_Detector_Demo.ipynb carries a copy of these functions, so the same stale entries are still there. Would you be willing to fix that version as well?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I edited the JSON entry directly so avoid messy output, hope that is okay! Done in f3896ae.

Comment thread transformer_lens/head_detector.py Outdated
@@ -213,7 +211,7 @@ def get_duplicate_token_head_detection_pattern(
"""Outputs a detection score for [duplicate token heads](https://dynalist.io/d/n2ZWtnoYHrU1s4vnFSAQ519J#z=2UkvedzOnghL5UHUgVhROxeo).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary states that the function outputs a detection score, but what comes back is the pattern. Would you be willing to update this line as well?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 8e5f049.

Args:
activation_name:
The name of the activation to be stacked
layer:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This layer entry is also out of date, would you be willing to update it as well?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in b490698.

@hojaeklee
hojaeklee requested a review from jlarson4 November 18, 2026 02:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants