Skip to content

Commit

Permalink
Add clear_previous_text_on_temperature parameter (#397)
Browse files Browse the repository at this point in the history
* Add clear_previous_text_on_temperature parameter

* Add a description
  • Loading branch information
hoonlight authored Aug 3, 2023
1 parent 5c17de1 commit 1a1eb1a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TranscriptionOptions(NamedTuple):
no_speech_threshold: Optional[float]
compression_ratio_threshold: Optional[float]
condition_on_previous_text: bool
clear_previous_text_on_temperature: float
temperatures: List[float]
initial_prompt: Optional[Union[str, Iterable[int]]]
prefix: Optional[str]
Expand Down Expand Up @@ -171,6 +172,7 @@ def transcribe(
log_prob_threshold: Optional[float] = -1.0,
no_speech_threshold: Optional[float] = 0.6,
condition_on_previous_text: bool = True,
clear_previous_text_on_temperature: float = 0.5,
initial_prompt: Optional[Union[str, Iterable[int]]] = None,
prefix: Optional[str] = None,
suppress_blank: bool = True,
Expand Down Expand Up @@ -209,6 +211,8 @@ def transcribe(
as a prompt for the next window; disabling may make the text inconsistent across
windows, but the model becomes less prone to getting stuck in a failure loop,
such as repetition looping or timestamps going out of sync.
clear_previous_text_on_temperature: If the temperature is above this value,
clear the previous text.
initial_prompt: Optional text string or iterable of token ids to provide as a
prompt for the first window.
prefix: Optional text to provide as a prefix for the first window.
Expand Down Expand Up @@ -319,6 +323,7 @@ def transcribe(
no_speech_threshold=no_speech_threshold,
compression_ratio_threshold=compression_ratio_threshold,
condition_on_previous_text=condition_on_previous_text,
clear_previous_text_on_temperature=clear_previous_text_on_temperature,
temperatures=(
temperature if isinstance(temperature, (list, tuple)) else [temperature]
),
Expand Down Expand Up @@ -559,7 +564,10 @@ def generate_segments(
),
)

if not options.condition_on_previous_text or temperature > 0.5:
if (
not options.condition_on_previous_text
or temperature > options.clear_previous_text_on_temperature
):
prompt_reset_since = len(all_tokens)

def encode(self, features: np.ndarray) -> ctranslate2.StorageView:
Expand Down

0 comments on commit 1a1eb1a

Please sign in to comment.