#[derive(Debug, Clone)]
pub struct Example {
pub input_ids: Vec<u32>,
pub attention_mask: Vec<u8>,
pub labels: Option<Vec<u32>>,
pub text: Option<String>,
}
impl Example {
#[must_use]
pub fn from_tokens(input_ids: Vec<u32>) -> Self {
let len = input_ids.len();
Self { input_ids, attention_mask: vec![1; len], labels: None, text: None }
}
#[must_use]
pub fn with_labels(mut self, labels: Vec<u32>) -> Self {
self.labels = Some(labels);
self
}
#[must_use]
pub fn with_text(mut self, text: impl Into<String>) -> Self {
self.text = Some(text.into());
self
}
#[must_use]
pub fn len(&self) -> usize {
self.input_ids.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.input_ids.is_empty()
}
}