Skip to content

Commit

Permalink
Enable confidence by default.
Browse files Browse the repository at this point in the history
Change option use_confidence by ignore_confidence
  • Loading branch information
ZJaume committed Oct 3, 2024
1 parent 00ed743 commit d5bf217
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ struct IdentifyCmd {
help="Number of text segments to pre-load for parallel processing")]
batch_size: usize,

#[arg(short = 'c', long, help="Use confidence thresholds. Predictions under the thresholds will become 'und'")]
use_confidence: bool,
#[arg(short = 's', long, help="Print raw scores (higher is better) or confidence (higher is better) in case '-c' is enabled")]
#[arg(short = 'c', long, help="Ignore confidence thresholds. Predictions under the thresholds will not be labeled as 'und'")]
ignore_confidence: bool,
#[arg(short = 's', long, help="Print confidence score (higher is better) or raw score (higher is better) in case '-c' is provided")]
print_scores: bool,

#[arg(help="Input file, default: stdin", )]
Expand Down Expand Up @@ -193,8 +193,8 @@ impl IdentifyCmd {
// Load identifier
let mut identifier = Identifier::load(&model_dir, relevant_langs)
.or_abort(1);
if self.use_confidence {
identifier.enable_confidence();
if self.ignore_confidence {
identifier.disable_confidence();
}

// do not run on separated threads if multithreading is not requested
Expand Down
14 changes: 7 additions & 7 deletions src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Identifier {
lang_points: LangScores,
word_scores: LangScores,
heli_score: BTreeMap<OrderedFloat<f32>, Vec<Lang>>,
pub use_confidence: bool,
pub ignore_confidence: bool,
}

/// A clone of Identifier creates new instances for all the members
Expand All @@ -40,7 +40,7 @@ impl Clone for Identifier {
fn clone(&self) -> Self {
Self::new(
self.model.clone(),
self.use_confidence,
self.ignore_confidence,
)
}
}
Expand All @@ -56,20 +56,20 @@ impl Identifier {
))
}

pub fn new(model: Arc<Model>, use_confidence: bool) -> Self {
pub fn new(model: Arc<Model>, ignore_confidence: bool) -> Self {
Self {
model: model,
lang_scored: LangBitmap::new(),
lang_points: LangScores::new(),
word_scores: LangScores::new(),
heli_score: BTreeMap::new(),
use_confidence: use_confidence,
ignore_confidence: ignore_confidence,
}
}

/// Enable use of confidence thresholds
pub fn enable_confidence(&mut self) -> &mut Self {
self.use_confidence = true;
pub fn disable_confidence(&mut self) -> &mut Self {
self.ignore_confidence = true;
self
}

Expand All @@ -90,7 +90,7 @@ impl Identifier {

// Compute confidence value
// confidence is absolute difference with the second scoring language
if self.use_confidence {
if !self.ignore_confidence {
let mut second = Self::PENALTY_VALUE + 1.0;
for lang in Lang::iter() {
let points = self.lang_points.get(lang);
Expand Down
8 changes: 4 additions & 4 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub fn module_path() -> PyResult<PathBuf> {
#[pymethods]
impl Identifier {
#[new]
#[pyo3(signature = (use_confidence = false))]
fn py_new(use_confidence: bool) -> PyResult<Self> {
#[pyo3(signature = (ignore_confidence = false))]
fn py_new(ignore_confidence: bool) -> PyResult<Self> {
let modulepath = module_path().expect("Error loading python module path");
let mut identifier = Identifier::load(&modulepath, None)?;
if use_confidence {
identifier.enable_confidence();
if ignore_confidence {
identifier.disable_confidence();
}
Ok(identifier)
}
Expand Down

0 comments on commit d5bf217

Please sign in to comment.