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

return stride information in callback from speech recognition #605

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ export class PreTrainedModel extends Callable {

// Run callback
if (generation_config.callback_function) {
beams.stride = generation_config.stride;
generation_config.callback_function(beams);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ export class ZeroShotAudioClassificationPipeline extends (/** @type {new (option
* @property {number[][]} [kwargs.forced_decoder_ids] A list of pairs of integers which indicates a mapping from generation indices to token indices
* that will be forced before sampling. For example, [[1, 123]] means the second generated token will always be a token of index 123.
* @property {number} [num_frames] The number of frames in the input audio.
* @property {number[]} [stride] Audio chunk information needed to generate proper timestamps.
* @typedef {import('./utils/generation.js').GenerationConfigType & AutomaticSpeechRecognitionSpecificParams} AutomaticSpeechRecognitionConfig
*
* @callback AutomaticSpeechRecognitionPipelineCallback Transcribe the audio sequence(s) given as inputs to text.
Expand Down Expand Up @@ -1661,6 +1662,7 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options
// Generate for each set of input features
for (const chunk of chunks) {
kwargs.num_frames = Math.floor(chunk.stride[0] / hop_length);
kwargs.stride = chunk.stride.map(x => x / sampling_rate);

// NOTE: doing sequentially for now
const data = await this.model.generate(chunk.input_features, kwargs);
Expand Down