pub struct DataExample {
pub input_ids: Vec<u32>,
pub attention_mask: Option<Vec<u32>>,
pub token_type_ids: Option<Vec<u32>>,
pub labels: Option<Vec<i64>>,
pub metadata: HashMap<String, Value>,
}Expand description
Input example for data collation
Represents a single training/inference example that can be batched together with other examples during data collation.
Fields§
§input_ids: Vec<u32>Token IDs for the input sequence
attention_mask: Option<Vec<u32>>Attention mask indicating which tokens should be attended to
token_type_ids: Option<Vec<u32>>Token type IDs for distinguishing different segments
labels: Option<Vec<i64>>Labels for supervised learning tasks
metadata: HashMap<String, Value>Additional metadata for the example
Implementations§
Source§impl DataExample
impl DataExample
Sourcepub fn sequence_length(&self) -> usize
pub fn sequence_length(&self) -> usize
Get the sequence length
Sourcepub fn with_attention_mask(self, mask: Vec<u32>) -> Self
pub fn with_attention_mask(self, mask: Vec<u32>) -> Self
Add an attention mask
Sourcepub fn with_token_type_ids(self, type_ids: Vec<u32>) -> Self
pub fn with_token_type_ids(self, type_ids: Vec<u32>) -> Self
Add token type IDs
Sourcepub fn with_labels(self, labels: Vec<i64>) -> Self
pub fn with_labels(self, labels: Vec<i64>) -> Self
Add labels
Sourcepub fn with_metadata(self, key: String, value: Value) -> Self
pub fn with_metadata(self, key: String, value: Value) -> Self
Add metadata
Sourcepub fn has_labels(&self) -> bool
pub fn has_labels(&self) -> bool
Check if the example has labels
Trait Implementations§
Source§impl Clone for DataExample
impl Clone for DataExample
Source§fn clone(&self) -> DataExample
fn clone(&self) -> DataExample
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DataExample
impl Debug for DataExample
Source§impl<'de> Deserialize<'de> for DataExample
impl<'de> Deserialize<'de> for DataExample
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for DataExample
impl RefUnwindSafe for DataExample
impl Send for DataExample
impl Sync for DataExample
impl Unpin for DataExample
impl UnsafeUnpin for DataExample
impl UnwindSafe for DataExample
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
Source§fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
Save to file
Source§fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
Load from file
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more