pub struct TextDataset { /* private fields */ }Expand description
Simple in-memory text dataset for LLM training
Implementations§
Source§impl TextDataset
impl TextDataset
Sourcepub fn add_sample(&mut self, input_ids: Vec<u32>, target_ids: Vec<u32>)
pub fn add_sample(&mut self, input_ids: Vec<u32>, target_ids: Vec<u32>)
Add a sample to the dataset
Sourcepub fn add_example(&mut self, example: TrainingExample)
pub fn add_example(&mut self, example: TrainingExample)
Add a prepared example (with its loss mask).
Sourcepub fn from_sequences(sequences: Vec<Vec<u32>>) -> Self
pub fn from_sequences(sequences: Vec<Vec<u32>>) -> Self
Create from list of token sequences (next-token prediction)
Sourcepub fn from_jsonl_sft<P: AsRef<Path>>(
path: P,
tokenizer: &Tokenizer,
use_chat_template: bool,
max_len: usize,
) -> Result<Self, Error>
pub fn from_jsonl_sft<P: AsRef<Path>>( path: P, tokenizer: &Tokenizer, use_chat_template: bool, max_len: usize, ) -> Result<Self, Error>
Create from a JSONL instruction dataset with {prompt,response} objects.
Uses chat-template encoding and response-only loss masks when use_chat_template.
Sourcepub fn from_jsonl<P: AsRef<Path>>(
path: P,
tokenizer: &Tokenizer,
) -> Result<Self, Error>
pub fn from_jsonl<P: AsRef<Path>>( path: P, tokenizer: &Tokenizer, ) -> Result<Self, Error>
Create from a JSONL instruction dataset with {prompt,response} objects.
Sourcepub fn from_text_file<P: AsRef<Path>>(
path: P,
tokenizer: &Tokenizer,
) -> Result<Self, Error>
pub fn from_text_file<P: AsRef<Path>>( path: P, tokenizer: &Tokenizer, ) -> Result<Self, Error>
Create from a plain text file, one training sample per non-empty line.
Sourcepub fn from_token_bin<P: AsRef<Path>>(
path: P,
sequence_length: usize,
) -> Result<Self, Error>
pub fn from_token_bin<P: AsRef<Path>>( path: P, sequence_length: usize, ) -> Result<Self, Error>
Create from a flat binary file of little-endian u32 token ids.
Sourcepub fn from_packed_tokens(tokens: Vec<u32>, sequence_length: usize) -> Self
pub fn from_packed_tokens(tokens: Vec<u32>, sequence_length: usize) -> Self
Create fixed-length training windows from a packed token stream.
Sourcepub fn pack_sequences(sequences: Vec<Vec<u32>>, max_len: usize) -> Self
pub fn pack_sequences(sequences: Vec<Vec<u32>>, max_len: usize) -> Self
Greedily pack short sequences into longer windows up to max_len.
Sourcepub fn examples(&self) -> &[TrainingExample]
pub fn examples(&self) -> &[TrainingExample]
All examples, in insertion order.
Trait Implementations§
Source§impl Clone for TextDataset
impl Clone for TextDataset
Source§impl Dataset for TextDataset
impl Dataset for TextDataset
Auto Trait Implementations§
impl Freeze for TextDataset
impl RefUnwindSafe for TextDataset
impl Send for TextDataset
impl Sync for TextDataset
impl Unpin for TextDataset
impl UnsafeUnpin for TextDataset
impl UnwindSafe for TextDataset
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> 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