Skip to content

Commit

Permalink
docs: add doc comment to storage_view and whisper modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jkawamoto committed Jul 13, 2024
1 parent 6978b79 commit bf45f84
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/storage_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//
// http://opensource.org/licenses/mit-license.php

//! This module provides a Rust binding to the
//! [`ctranslate2::StorageView`](https://opennmt.net/CTranslate2/python/ctranslate2.StorageView.html).
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;
use std::ops::Deref;
Expand Down Expand Up @@ -79,7 +82,11 @@ impl<'a> StorageView<'a> {

impl Debug for StorageView<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "StorageView {{{} }}", ffi::to_string(self).replace("\n", ", "))
write!(
f,
"StorageView {{{} }}",
ffi::to_string(self).replace("\n", ", ")
)
}
}

Expand Down
51 changes: 39 additions & 12 deletions src/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
//
// http://opensource.org/licenses/mit-license.php

//! This module provides a Rust binding to the
//! [`ctranslate2::models::Whisper`](https://opennmt.net/CTranslate2/python/ctranslate2.models.Whisper.html).
//!
//! The main structure provided by this module is the [`Whisper`] structure.
//!
//! In addition to the `Whisper`, this module also offers various supportive structures such
//! as [`WhisperOptions`], [`DetectionResult`], and [`WhisperGenerationResult`].
//!
//! For more detailed information on each structure and its usage, please refer to their respective
//! documentation within this module.
use std::ffi::OsString;
use std::fmt::{Debug, Formatter};
use std::path::Path;
Expand All @@ -21,38 +32,51 @@ use crate::whisper::ffi::VecDetectionResult;

#[cxx::bridge]
mod ffi {
/// Options for whisper generation.
/// # Examples
///
/// Example of creating a default `TranslationOptions`:
///
/// ```
/// use ct2rs::whisper::WhisperOptions;
///
/// let options = WhisperOptions::default();
/// ```
#[derive(Clone, Debug)]
pub struct WhisperOptions {
/// Beam size to use for beam search (set 1 to run greedy search).
/// Beam size to use for beam search (set 1 to run greedy search). (default: 5)
pub beam_size: usize,
/// Beam search patience factor, as described in https://arxiv.org/abs/2204.05424.
/// Beam search patience factor, as described in <https://arxiv.org/abs/2204.05424>.
/// The decoding will continue until beam_size*patience hypotheses are finished.
/// (default: 1.0)
pub patience: f32,
/// Exponential penalty applied to the length during beam search.
/// Exponential penalty applied to the length during beam search. (default: 1.0)
pub length_penalty: f32,
/// Penalty applied to the score of previously generated tokens, as described in
/// https://arxiv.org/abs/1909.05858 (set > 1 to penalize).
/// <https://arxiv.org/abs/1909.05858> (set > 1 to penalize). (default: 1.0)
pub repetition_penalty: f32,
/// Prevent repetitions of ngrams with this size (set 0 to disable).
/// Prevent repetitions of ngrams with this size (set 0 to disable). (default: 0)
pub no_repeat_ngram_size: usize,
/// Maximum generation length.
/// Maximum generation length. (default: 448)
pub max_length: usize,
/// Randomly sample from the top K candidates (set 0 to sample from the full distribution).
/// (default: 1)
pub sampling_topk: usize,
/// High temperatures increase randomness.
/// High temperatures increase randomness. (default: 1.0)
pub sampling_temperature: f32,
/// Number of hypotheses to include in the result.
/// Number of hypotheses to include in the result. (default: 1)
pub num_hypotheses: usize,
/// Include scores in the result.
/// Include scores in the result. (default: false)
pub return_scores: bool,
/// Include the probability of the no speech token in the result.
/// Include the probability of the no speech token in the result. (default: false)
pub return_no_speech_prob: bool,
/// Maximum index of the first predicted timestamp.
/// Maximum index of the first predicted timestamp. (default: 50)
pub max_initial_timestamp_index: usize,
/// Suppress blank outputs at the beginning of the sampling.
/// Suppress blank outputs at the beginning of the sampling. (default: true)
pub suppress_blank: bool,
/// List of token IDs to suppress.
/// -1 will suppress a default set of symbols as defined in the model config.json file.
/// (default: `[-1]`)
pub suppress_tokens: Vec<i32>,
}

Expand All @@ -63,9 +87,12 @@ mod ffi {
no_speech_prob: f32,
}

/// Pair of the detected language and its probability.
#[derive(PartialEq, Clone, Debug)]
pub struct DetectionResult {
/// Token of the language.
language: String,
/// Probability of the language.
probability: f32,
}

Expand Down

0 comments on commit bf45f84

Please sign in to comment.