Skip to content

Merge alpha: classification docs + top_k fix#496

Merged
satra merged 1 commit into
mainfrom
alpha
Apr 30, 2026
Merged

Merge alpha: classification docs + top_k fix#496
satra merged 1 commit into
mainfrom
alpha

Conversation

@satra

@satra satra commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Fix doc.md/quickstart naming, consistent top_k slicing.

* Fix review: update doc.md/quickstart naming, simplify top_k slicing

Addresses PR #494 review comments:
- doc.md: classify_audios_in_windows → classify_audios(..., win_length=)
- doc.md: window_size/hop_size → win_length/hop_length
- quickstart.md: same naming fix
- Simplified top_k: direct list slicing (handles empty/short lists)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix: apply top_k slicing consistently to final batch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@satra
satra merged commit c5c86f1 into main Apr 30, 2026
10 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request renames the windowed classification function to classify_audios and updates its parameter names to win_length and hop_length for consistency. Documentation and examples have been updated to reflect these changes. Review feedback indicates that the top_k parameter is not being passed to the underlying classification call, which may limit the number of labels returned regardless of the user's input. Additionally, there is a suggestion to refactor duplicated logic used for processing and storing classification results to improve maintainability.

Comment on lines +137 to +138
"labels": result.labels[:top_k],
"scores": result.scores[:top_k],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The top_k parameter is used here for slicing the results, but it is not passed to the _classify_whole call on line 131 (and line 148). This means the underlying classifier will use its default top_k value (typically 5). If a user requests a top_k value larger than the model's default, they will still only receive the default number of labels. Consider passing top_k=top_k to _classify_whole to ensure the requested number of labels is retrieved from the model. Additionally, the default value of 5 for windowed mode (set in classify_audios) contradicts the docstring which states that None should keep all labels.

Comment on lines 150 to 158
audio_results.append(
{
"start": bp / sr,
"end": min(bp + win_samples, n_samples) / sr,
"labels": result.labels[:k],
"scores": result.scores[:k],
"labels": result.labels[:top_k],
"scores": result.scores[:top_k],
"win_length": win_length,
"hop_length": hop_length,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for processing classification results and appending them to audio_results is duplicated here and on lines 133-141. Consider refactoring this into a small helper function or restructuring the loop to avoid code duplication and improve maintainability.

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.

1 participant