mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-23 00:35:35 +00:00
Also accept iterators of batches in train_from_iterator
This commit is contained in:
@ -1104,15 +1104,30 @@ impl PyTokenizer {
|
||||
.map(|_| {})
|
||||
});
|
||||
|
||||
ResultShunt::process(iterator.map(|seq| seq?.extract::<&str>()), |iter| {
|
||||
if let Some(send) = sender.take() {
|
||||
for seq in iter {
|
||||
send.send(seq)
|
||||
.map_err(|e| exceptions::PyException::new_err(e.to_string()))?;
|
||||
ResultShunt::process(
|
||||
// Each element of the iterator can either be:
|
||||
// - An iterator, to allow batching
|
||||
// - A string
|
||||
iterator.flat_map(|seq| match seq {
|
||||
Ok(s) => {
|
||||
if let Ok(iter) = s.iter() {
|
||||
itertools::Either::Left(iter.map(|i| i?.extract::<&str>()))
|
||||
} else {
|
||||
itertools::Either::Right(std::iter::once(s.extract::<&str>()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?
|
||||
Err(e) => itertools::Either::Right(std::iter::once(Err(e))),
|
||||
}),
|
||||
|iter| {
|
||||
if let Some(send) = sender.take() {
|
||||
for seq in iter {
|
||||
send.send(seq)
|
||||
.map_err(|e| exceptions::PyException::new_err(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user