Skip to content

Commit

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

* formatting fix
  • Loading branch information
jongwook committed Mar 8, 2023
1 parent 38f2f4d commit c4b50c0
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 @@ -778,7 +778,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 @@ -802,6 +805,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 c4b50c0

Please sign in to comment.