entrenar/hf_pipeline/dataset/
example.rs1#[derive(Debug, Clone)]
5pub struct Example {
6 pub input_ids: Vec<u32>,
8 pub attention_mask: Vec<u8>,
10 pub labels: Option<Vec<u32>>,
12 pub text: Option<String>,
14}
15
16impl Example {
17 #[must_use]
19 pub fn from_tokens(input_ids: Vec<u32>) -> Self {
20 let len = input_ids.len();
21 Self { input_ids, attention_mask: vec![1; len], labels: None, text: None }
22 }
23
24 #[must_use]
26 pub fn with_labels(mut self, labels: Vec<u32>) -> Self {
27 self.labels = Some(labels);
28 self
29 }
30
31 #[must_use]
33 pub fn with_text(mut self, text: impl Into<String>) -> Self {
34 self.text = Some(text.into());
35 self
36 }
37
38 #[must_use]
40 pub fn len(&self) -> usize {
41 self.input_ids.len()
42 }
43
44 #[must_use]
46 pub fn is_empty(&self) -> bool {
47 self.input_ids.is_empty()
48 }
49}