gliner/model/
params.rs

1//! Processing parameters
2
3
4/// Represents the set of parameters for the whole pipeline
5/// 
6/// * pre-processing
7/// * post-processing
8/// 
9/// The easiest way to instanciate sound parameters is to use the
10/// `default()` constructor and then use individual setters as needed.
11pub struct Parameters {
12    /// Probability threshold (default: 0.5)
13    pub threshold: f32,    
14    /// Setting this parameter to `true` means that no entity can overlap with another one (default: true)
15    pub flat_ner: bool,
16    /// If `flat_ner=false`, setting this parameter to `true` means that overlapping spans can belong to the *same* class (default: false)
17    pub dup_label: bool,
18    /// If `flat_ner=false`, setting this parameter to `true` means that overlapping spans can belong to *different* classes (default: false)
19    pub multi_label: bool,    
20    /// For span mode, maximum span width (default: 12)
21    pub max_width: usize,
22    /// Maximum sequence length (default: 512)
23    pub max_length: Option<usize>,
24}
25
26impl Default for Parameters {
27    /// Default configuration, which can be safely used in most cases
28    fn default() -> Self {
29        Self::new(
30            0.5, 
31            12, 
32            Some(512),
33            true,             
34            false,
35            false,
36        )
37    }
38}
39
40impl Parameters {
41    /// New configuration specifying every parameter
42    pub fn new(threshold: f32, max_width: usize, max_length: Option<usize>, flat_ner: bool, dup_label: bool, multi_label: bool) -> Self {
43        Self { 
44            threshold, 
45            max_width, 
46            max_length,
47            flat_ner,
48            dup_label,
49            multi_label,
50        }
51    }
52
53    pub fn with_threshold(mut self, threshold: f32) -> Self {
54        self.threshold = threshold;
55        self
56    }
57
58    pub fn with_max_width(mut self, max_width: usize) -> Self {
59        self.max_width = max_width;
60        self
61    }
62
63    pub fn with_max_length(mut self, max_length: Option<usize>) -> Self {
64        self.max_length = max_length;
65        self
66    }
67
68    pub fn with_flat_ner(mut self, flat_ner: bool) -> Self {
69        self.flat_ner = flat_ner;
70        self
71    }
72
73    pub fn with_dup_label(mut self, dup_label: bool) -> Self {
74        self.dup_label = dup_label;
75        self
76    }
77
78    pub fn with_multi_label(mut self, multi_label: bool) -> Self {
79        self.multi_label = multi_label;
80        self
81    }
82
83}