Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to disable selectors and rename dropdown lists #85

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/circuitsvis/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def text_neuron_activations(
second_dimension_name: Optional[str] = "Neuron",
first_dimension_labels: Optional[List[str]] = None,
second_dimension_labels: Optional[List[str]] = None,
first_dimension_default: Optional[int] = 0,
second_dimension_default: Optional[int] = 0,
show_selectors: Optional[bool] = True,
) -> RenderedHTML:
"""Show activations (colored by intensity) for each token in a text or set
of texts.
Expand Down Expand Up @@ -54,4 +57,7 @@ def text_neuron_activations(
secondDimensionName=second_dimension_name,
firstDimensionLabels=first_dimension_labels,
secondDimensionLabels=second_dimension_labels,
firstDimensionDefault=first_dimension_default,
secondDimensionDefault=second_dimension_default,
showSelectors=show_selectors,
)
126 changes: 65 additions & 61 deletions react/src/activations/TextNeuronActivations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export function TextNeuronActivations({
firstDimensionName = "Layer",
secondDimensionName = "Neuron",
firstDimensionLabels,
secondDimensionLabels
secondDimensionLabels,
firstDimensionDefault = 0,
secondDimensionDefault = 0,
showSelectors = true
}: TextNeuronActivationsProps) {
// If there is only one sample (i.e. if tokens is an array of strings), cast tokens and activations to an array with
// a single element
Expand Down Expand Up @@ -68,8 +71,8 @@ export function TextNeuronActivations({
const [sampleNumbers, setSampleNumbers] = useState<number[]>([
...Array(samplesPerPage).keys()
]);
const [layerNumber, setLayerNumber] = useState<number>(0);
const [neuronNumber, setNeuronNumber] = useState<number>(0);
const [layerNumber, setLayerNumber] = useState<number>(firstDimensionDefault);
const [neuronNumber, setNeuronNumber] = useState<number>(secondDimensionDefault);

useEffect(() => {
// When the user changes the samplesPerPage, update the sampleNumbers
Expand All @@ -96,77 +99,62 @@ export function TextNeuronActivations({

return (
<Container fluid>
<Row>
<Col>
<Row style={selectRowStyle}>
<Col>
<label htmlFor="layer-selector" style={{ marginRight: 15 }}>
{firstDimensionName}:
</label>
<NumberSelector
id="layer-selector"
largestNumber={numberOfLayers! - 1}
currentValue={layerNumber}
setCurrentValue={setLayerNumber}
labels={firstDimensionLabels}
/>
</Col>
</Row>
<Row style={selectRowStyle}>
<Col>
<label htmlFor="neuron-selector" style={{ marginRight: 15 }}>
{secondDimensionName}:
</label>
<NumberSelector
id="neuron-selector"
largestNumber={numberOfNeurons! - 1}
currentValue={neuronNumber}
setCurrentValue={setNeuronNumber}
labels={secondDimensionLabels}
/>
</Col>
</Row>
{/* Only show the sample selector if there is more than one sample */}
{numberOfSamples > 1 && (
{showSelectors && (
<Row>
<Col>
<Row style={selectRowStyle}>
<Col>
<label htmlFor="sample-selector" style={{ marginRight: 15 }}>
Samples:
<label htmlFor="layer-selector" style={{ marginRight: 15 }}>
{firstDimensionName}:
</label>
<RangeSelector
id="sample-selector"
largestNumber={numberOfSamples - 1}
currentRangeArr={sampleNumbers}
setCurrentValue={setSampleNumbers}
numValsInRange={samplesPerPage}
<NumberSelector
id="layer-selector"
largestNumber={numberOfLayers! - 1}
currentValue={layerNumber}
setCurrentValue={setLayerNumber}
labels={firstDimensionLabels}
/>
</Col>
</Row>
)}
</Col>
<Col>
{/* Only show the sample per page selector if there is more than one sample */}
{numberOfSamples > 1 && (
<Row style={selectRowStyle}>
<Col>
<label
htmlFor="samples-per-page-selector"
style={{ marginRight: 15 }}
>
Samples per page:
<label htmlFor="neuron-selector" style={{ marginRight: 15 }}>
{secondDimensionName}:
</label>
<NumberSelector
id="samples-per-page-selector"
smallestNumber={1}
largestNumber={numberOfSamples}
currentValue={samplesPerPage}
setCurrentValue={setSamplesPerPage}
id="neuron-selector"
largestNumber={numberOfNeurons! - 1}
currentValue={neuronNumber}
setCurrentValue={setNeuronNumber}
labels={secondDimensionLabels}
/>
</Col>
</Row>
)}
</Col>
</Row>
</Col>
<Col>
{/* Only show the sample per page selector if there is more than one sample */}
{numberOfSamples > 1 && (
<Row style={selectRowStyle}>
<Col>
<label
htmlFor="samples-per-page-selector"
style={{ marginRight: 15 }}
>
Samples per page:
</label>
<NumberSelector
id="samples-per-page-selector"
smallestNumber={1}
largestNumber={numberOfSamples}
currentValue={samplesPerPage}
setCurrentValue={setSamplesPerPage}
/>
</Col>
</Row>
)}
</Col>
</Row>
)}
<Row>
<Col>
<SampleItems
Expand Down Expand Up @@ -218,4 +206,20 @@ export interface TextNeuronActivationsProps {
* Labels for the second dimension
*/
secondDimensionLabels?: string[];

/**
* Default index for the first dimension
*/
firstDimensionDefault?: number;

/**
* Default index for the second dimension
*/
secondDimensionDefault?: number;


/**
* Whether to show the selector dropdowns
*/
showSelectors?: boolean;
}
Loading