Skip to content

Commit

Permalink
kwargs in decode() for convenience (openai#1061)
Browse files Browse the repository at this point in the history
* kwargs in decode() for convenience

* formatting fix
  • Loading branch information
jongwook authored and ilanit1997 committed May 16, 2023
1 parent 88d2811 commit 5c8405c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions whisper/decoding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import dataclass, field
from dataclasses import dataclass, field, replace
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Sequence, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -801,7 +801,10 @@ def run(self, mel: Tensor) -> List[DecodingResult]:

@torch.no_grad()
def decode(
model: "Whisper", mel: Tensor, options: DecodingOptions = DecodingOptions()
model: "Whisper",
mel: Tensor,
options: DecodingOptions = DecodingOptions(),
**kwargs,
) -> Union[DecodingResult, List[DecodingResult]]:
"""
Performs decoding of 30-second audio segment(s), provided as Mel spectrogram(s).
Expand All @@ -825,6 +828,9 @@ def decode(
if single := mel.ndim == 2:
mel = mel.unsqueeze(0)

if kwargs:
options = replace(options, **kwargs)

result = DecodingTask(model, options).run(mel)

return result[0] if single else result

0 comments on commit 5c8405c

Please sign in to comment.