datasets #
VTL Datasets
VTL provides dataset loaders and batching utilities for ML examples and tests.
Available datasets
| Dataset | Loader | Purpose |
|---|---|---|
| MNIST | datasets.load_mnist() |
Handwritten digit images (28x28) |
| IMDB | datasets.load_imdb() |
Sentiment analysis reviews |
| CIFAR-10 | datasets.load_cifar10(...) |
Image classification examples |
| DataLoader | datasets.DataLoader[T] |
Batch, shuffle, and iterate tensors/labels |
| IterableDataLoader | datasets.IterableDataLoader[T] |
Stream and batch samples on demand |
| PrefetchLoader | datasets.PrefetchLoader[T] |
Bounded worker queue over a DataLoader |
DataLoader returns a view when a batch's sample indices form a contiguous range. Shuffled, non-contiguous batches allocate tensors to preserve the requested sample order. A non-positive batch_size produces an empty loader.
new_prefetch_loader(loader, capacity) starts one producer that walks batch indices in order through a bounded queue. next() returns a PrefetchStep with either a batch or done: true; worker errors are reported at the position where they occurred. close() drains the queue so the worker cannot remain blocked on a full channel. Pinning and device transfer remain explicit caller responsibilities; see #738.
DataLoaderConfig defaults to batch_size: 32, shuffle: true, and drop_last: true. These differ from PyTorch's defaults (1, false, and false), so set all three explicitly when porting a training pipeline. Call reset() between epochs to advance the deterministic shuffle order from the configured seed.
For sources that should not be materialized as one tensor, implement IterableDataset[T] with next_sample() and reset(), then pass it to new_iterable_data_loader. The loader holds at most one batch of samples, stacks matching feature and optional label shapes, and returns source errors. It snapshots each sample as it is read, so a source may reuse mutable buffers. StreamSample.finished ends iteration; reset() delegates replay to the source, which may return an error when it cannot rewind. Use next_batch_with_transform_pipeline for deterministic feature transforms or next_batch_with_random_transforms to apply random transforms with an explicit generator.
TransformPipeline[T] composes tensor transforms in order and propagates the first transform error. Apply it to a sample or batch tensor; transforms receive the preceding transform's output, and an empty pipeline returns its input. Transforms that should preserve their input must return a new tensor rather than mutating the input. For batch transforms, pass a pipeline to DataLoader.set_batch_transform_pipeline; collated_batch applies it to features after default batching or custom collation, preserves labels, and returns transform errors to the caller. split preserves the configured pipeline.
import vtl
import vtl.datasets
fn center(input &vtl.Tensor[f64]) !&vtl.Tensor[f64] {
mut output := vtl.zeros[f64](input.shape)
for i in 0 .. input.size {
output.set_nth(i, input.get_nth(i) - 1.0)
}
return output
}
fn scale(input &vtl.Tensor[f64]) !&vtl.Tensor[f64] {
mut output := vtl.zeros[f64](input.shape)
for i in 0 .. input.size {
output.set_nth(i, input.get_nth(i) * 0.5)
}
return output
}
pipeline := datasets.TransformPipeline.new[f64]([center, scale])
sample := vtl.from_1d([1.0, 3.0])!
transformed := pipeline.apply(sample)!
assert transformed.to_array() == [0.0, 1.0]
Use RandomTransformPipeline[T] when transforms need randomness. Each batch call receives an explicit vtl.RandomGenerator, so separate generators remain independent and snapshot()/restore() can replay the same augmentation stream: DataLoader.collated_batch_with_random_transforms and IterableDataLoader.next_batch_with_random_transforms accept the pipeline and generator explicitly.
import vtl
import vtl.datasets
fn add_noise(input &vtl.Tensor[f64], mut generator vtl.RandomGenerator) !&vtl.Tensor[f64] {
noise := generator.uniform(-0.1, 0.1, input.shape)!
mut output := vtl.zeros[f64](input.shape)
for i in 0 .. input.size {
output.set_nth(i, input.get_nth(i) + noise.get_nth(i))
}
return output
}
dataset := vtl.from_1d([1.0, 2.0])!
pipeline := datasets.RandomTransformPipeline.new[f64]([add_noise])
mut generator := vtl.new_random_generator(42)
loader := datasets.new_data_loader[f64](dataset, datasets.DataLoaderConfig{
batch_size: 2
shuffle: false
drop_last: false
})
batch := loader.collated_batch_with_random_transforms(0, pipeline, mut generator)!
assert batch.features.size == 2
For custom sample order, new_data_loader_with_sampler_checked and new_data_loader_with_labels_and_sampler_checked accept samplers from vtl.nn.data. Built-in options include sequential, random, subset-random, weighted, and fixed batch sampling. Wrap a sampler with FixedBatchSampler to choose batch boundaries and drop_last explicitly. Call reset_checked() between epochs when using a sampler; it reports errors from custom sampler implementations.
For custom batch construction, install a CollateFn[T] with DataLoader.set_collate_fn and call collated_batch(i) or for_each_collated(...). The callback receives the source feature tensor, an optional labels tensor, and a copy of the sample indices selected for that batch. It returns a CollatedBatch[T] containing the output features and optional labels. This supports dense tensor collation such as transforms, padding, filtering, and reordering; it does not model arbitrary Python objects or nested sample structures. See the custom collation example.
load_imdb() returns the full 25,000 review training and test splits. Use load_imdb_with_config for a smaller, class-balanced subset. Review features remain raw strings; labels are binary (1 positive, 0 negative).
For simple NLP pipelines, tokenize_text lowercases and splits on Unicode whitespace and ASCII punctuation while preserving UTF-8 text. build_text_vocabulary creates deterministic frequency-ranked IDs; <pad> is ID 0 and <unk> is ID 1. max_size includes those reserved IDs, and 0 means no size limit. This is a small preprocessing utility; it does not replace language-specific tokenizers or normalization.
import vtl.datasets
tokens := datasets.tokenize_text('A joyful, moving review!')
assert tokens == ['a', 'joyful', 'moving', 'review']
vocabulary := datasets.build_text_vocabulary([
'joyful moving review',
'moving review',
], 10000, 1)!
ids := vocabulary.encode('Joyful review')
assert vocabulary.decode(ids) == ['joyful', 'review']
import vtl.datasets
imdb := datasets.load_imdb_with_config(datasets.ImdbConfig{
train_count: 1000
test_count: 200
})!
assert imdb.train_features.shape == [1000]
assert imdb.test_features.shape == [200]
Examples
Run from ~/.vmodules:
v run vtl/examples/datasets_mnist/main.v
v run vtl/examples/datasets_imdb/main.v
v run ./vtl/examples/nn_cifar10_tiny_synth/main.v
Use synthetic examples (nn_cifar10_tiny_synth, nn_cifar10_f32_tiny_synth) for CI and quick local checks. Real dataset examples may download/cache data and should be treated as local integration tests.
Related docs
Constants #
const cifar10_base_url = 'https://www.cs.toronto.edu/~kriz/'
cifar10_base_url is a public constant used by this module.
const cifar10_file = 'cifar-10-binary.tar.gz'
cifar10_file is a public constant used by this module.
const imdb_file_name = 'aclImdb_v1.tar.gz'
imdb_file_name is a public constant used by this module.
const imdb_base_url = 'http://ai.stanford.edu/~amaas/data/sentiment/'
imdb_base_url is a public constant used by this module.
const mnist_base_url = 'https://github.com/golbin/TensorFlow-MNIST/raw/master/mnist/data/'
mnist_base_url is a public constant used by this module.
const mnist_train_images_file = 'train-images-idx3-ubyte.gz'
mnist_train_images_file is a public constant used by this module.
const mnist_train_labels_file = 'train-labels-idx1-ubyte.gz'
mnist_train_labels_file is a public constant used by this module.
const mnist_test_images_file = 't10k-images-idx3-ubyte.gz'
mnist_test_images_file is a public constant used by this module.
const mnist_test_labels_file = 't10k-labels-idx1-ubyte.gz'
mnist_test_labels_file is a public constant used by this module.
const text_pad_token = '<pad>'
text_pad_token is the reserved vocabulary token used for sequence padding.
const text_unknown_token = '<unk>'
text_unknown_token is the reserved vocabulary token used for out-of-vocabulary terms.
fn build_text_vocabulary #
fn build_text_vocabulary(texts []string, max_size int, min_frequency int) !TextVocabulary
build_text_vocabulary builds a frequency-ranked vocabulary from texts. max_size includes the reserved
fn class_names #
fn class_names() []string
class_names returns the CIFAR-10 class names.
fn load_cifar10 #
fn load_cifar10() !Cifar10Dataset
load_cifar10 loads the CIFAR-10 dataset. Returns train/test features (normalized [0,1]) and one-hot encoded labels.
fn load_cifar10_with_config #
fn load_cifar10_with_config(cfg Cifar10Config) !Cifar10Dataset
load_cifar10_with_config loads CIFAR-10 with custom configuration.
fn load_imdb #
fn load_imdb() !ImdbDataset
load_imdb loads the IMDB dataset.
fn load_imdb_with_config #
fn load_imdb_with_config(cfg ImdbConfig) !ImdbDataset
load_imdb_with_config loads a balanced subset of the IMDB dataset.
fn load_mnist #
fn load_mnist() !MnistDataset
load_mnist loads the MNIST dataset.
fn new_data_loader #
fn new_data_loader[T](dataset &vtl.Tensor[T], config DataLoaderConfig) &DataLoader[T]
new_data_loader creates a DataLoader from a dataset tensor (features only).
fn new_data_loader_with_batch_sampler_checked #
fn new_data_loader_with_batch_sampler_checked[T](dataset &vtl.Tensor[T], config DataLoaderConfig, batch_sampler nn_data.BatchSampler) !&DataLoader[T]
new_data_loader_with_batch_sampler_checked creates a loader using explicit sample batches from batch_sampler.
fn new_data_loader_with_labels #
fn new_data_loader_with_labels[T](dataset &vtl.Tensor[T], labels &vtl.Tensor[T], config DataLoaderConfig) &DataLoader[T]
new_data_loader_with_labels creates a DataLoader with both features and labels tensors. Both tensors must have the same first dimension (number of samples). This compatibility constructor panics for invalid shapes; prefer the checked variant when input dimensions are not already trusted.
fn new_data_loader_with_labels_and_batch_sampler_checked #
fn new_data_loader_with_labels_and_batch_sampler_checked[T](dataset &vtl.Tensor[T], labels &vtl.Tensor[T], config DataLoaderConfig, batch_sampler nn_data.BatchSampler) !&DataLoader[T]
new_data_loader_with_labels_and_batch_sampler_checked creates a labeled loader using explicit sample batches and preserves feature-label alignment.
fn new_data_loader_with_labels_and_sampler_checked #
fn new_data_loader_with_labels_and_sampler_checked[T](dataset &vtl.Tensor[T], labels &vtl.Tensor[T], config DataLoaderConfig, sampler nn_data.Sampler) !&DataLoader[T]
new_data_loader_with_labels_and_sampler_checked creates a labeled loader with a custom sample order and validates the data and sampler indices.
fn new_data_loader_with_labels_checked #
fn new_data_loader_with_labels_checked[T](dataset &vtl.Tensor[T], labels &vtl.Tensor[T], config DataLoaderConfig) !&DataLoader[T]
new_data_loader_with_labels_checked creates a labeled DataLoader and reports invalid dataset or label shapes as an error instead of deferring failure until a batch is read.
fn new_data_loader_with_sampler_checked #
fn new_data_loader_with_sampler_checked[T](dataset &vtl.Tensor[T], config DataLoaderConfig, sampler nn_data.Sampler) !&DataLoader[T]
new_data_loader_with_sampler_checked creates a loader whose sample order is supplied by sampler. The sampler is invoked again by reset_checked each epoch.
fn new_iterable_data_loader #
fn new_iterable_data_loader[T](dataset IterableDataset[T], batch_size int, drop_last bool) !&IterableDataLoader[T]
new_iterable_data_loader creates a loader over a source that yields equally shaped feature samples and, optionally, equally shaped labels.
fn new_prefetch_loader #
fn new_prefetch_loader[T](loader &DataLoader[T], capacity int) !&PrefetchLoader[T]
new_prefetch_loader starts a worker with a bounded queue of capacity batches. The default CPU path is always available; pinning and device transfer remain explicit caller responsibilities.
fn tokenize_text #
fn tokenize_text(text string) []string
tokenize_text lowercases text and splits on whitespace and ASCII punctuation. Non-ASCII characters are preserved so UTF-8 words remain intact.
fn RandomTransformPipeline.new #
fn RandomTransformPipeline.new[T](transforms []RandomTensorTransform[T]) RandomTransformPipeline[T]
RandomTransformPipeline.new snapshots the configured random transforms.
fn TransformPipeline.new #
fn TransformPipeline.new[T](transforms []TensorTransform[T]) TransformPipeline[T]
TransformPipeline.new creates a pipeline and snapshots the transform list.
interface IterableDataset #
interface IterableDataset[T] {
// next_sample returns one sample, a finished marker, or a source error.
mut:
next_sample() !StreamSample[T]
// reset rewinds the source or reports that replay is unsupported.
reset() !
}
IterableDataset produces samples on demand and owns its source state. Implement reset when the source can be replayed; otherwise return an error.
type CollateFn #
type CollateFn[T] = fn (dataset &vtl.Tensor[T], labels &vtl.Tensor[T], indices []int) !CollatedBatch[T]
CollateFn builds tensors for the selected sample indices. labels is nil for feature-only loaders. The callback owns the collation policy, including output shapes and ordering.
fn (DataLoaderIterator[T]) next #
fn (mut it DataLoaderIterator[T]) next[T]() ?&vtl.Tensor[T]
next returns the next batch. Returns none when exhausted.
fn (DataLoader[T]) batch #
fn (dl &DataLoader[T]) batch(i int) ?&vtl.Tensor[T]
batch returns a batch at index i. Contiguous indices return a view into the dataset; other index orders return a copy. Mutating a returned view also mutates the corresponding dataset elements. Returns none for invalid indices or a non-positive batch size.
fn (DataLoader[T]) batch_with_labels #
fn (dl &DataLoader[T]) batch_with_labels(i int) ?(&vtl.Tensor[T], &vtl.Tensor[T])
batch_with_labels returns both features and labels for batch i. Both tensors are extracted using the same index set. Returns none if the index is out of range or if no labels tensor was provided.
fn (DataLoader[T]) set_collate_fn #
fn (mut dl DataLoader[T]) set_collate_fn(collate_fn CollateFn[T])
set_collate_fn installs a callback used by collated_batch. Existing batch accessors keep their default tensor slicing and gathering behavior.
fn (DataLoader[T]) set_batch_transform_pipeline #
fn (mut dl DataLoader[T]) set_batch_transform_pipeline(pipeline TransformPipeline[T])
set_batch_transform_pipeline applies the pipeline to feature batches after collation. The TransformPipeline constructor snapshots the transform list.
fn (DataLoader[T]) collated_batch #
fn (dl &DataLoader[T]) collated_batch(i int) !CollatedBatch[T]
collated_batch builds the batch selected by i. A custom callback receives the source tensors and a copy of the selected indices, so it can implement custom padding, filtering, transforms, or ordering without changing loader state. Without a callback, this returns the same default tensors as batch and batch_with_labels. An optional transform pipeline runs on features after either default batching or custom collation; its errors are returned.
fn (DataLoader[T]) collated_batch_with_random_transforms #
fn (dl &DataLoader[T]) collated_batch_with_random_transforms(i int, pipeline RandomTransformPipeline[T], mut generator vtl.RandomGenerator) !CollatedBatch[T]
collated_batch_with_random_transforms applies random transforms after collation using the caller-owned generator, leaving its state available for replay.
fn (DataLoader[T]) len #
fn (dl &DataLoader[T]) len() int
len returns the number of batches (drop_last affects count).
fn (DataLoader[T]) total_samples #
fn (dl &DataLoader[T]) total_samples() int
total_samples returns the number of samples in the dataset.
fn (DataLoader[T]) reset #
fn (mut dl DataLoader[T]) reset()
reset re-shuffles the indices (call between epochs). Uses seed if set.
fn (DataLoader[T]) reset_checked #
fn (mut dl DataLoader[T]) reset_checked() !
reset_checked advances the loader to a new epoch and reports sampler errors.
fn (DataLoader[T]) iter #
fn (dl &DataLoader[T]) iter[T]() DataLoaderIterator[T]
iter returns an iterator over the DataLoader batches.
fn (DataLoader[T]) for_each #
fn (dl &DataLoader[T]) for_each(fn_each fn (batch &vtl.Tensor[T]) bool) int
for_each applies fn to each batch until exhaustion or fn returns false.
fn (DataLoader[T]) for_each_with_labels #
fn (dl &DataLoader[T]) for_each_with_labels(fn_each fn (features &vtl.Tensor[T], labels &vtl.Tensor[T]) bool) int
for_each_with_labels applies fn to each (features, labels) batch. Only works if the DataLoader was created with labels.
fn (DataLoader[T]) for_each_collated #
fn (dl &DataLoader[T]) for_each_collated(fn_each fn (batch CollatedBatch[T]) bool) !int
for_each_collated applies the custom collation callback to every batch and passes each result to fn_each. Callback errors stop iteration and return to the caller.
fn (DataLoader[T]) split #
fn (dl &DataLoader[T]) split(val_fraction f64) !(&DataLoader[T], &DataLoader[T])
split splits a DataLoader into train and validation DataLoaders. val_fraction must be finite and in the inclusive range [0, 1].
fn (DataLoader[T]) mini_batch_count #
fn (dl &DataLoader[T]) mini_batch_count() int
mini_batch_count returns the total number of batches in one epoch.
fn (IterableDataLoader[T]) next_batch #
fn (mut loader IterableDataLoader[T]) next_batch() !StreamBatch[T]
next_batch reads at most batch_size samples and stacks them into dense tensors. It returns available=false after exhaustion; source errors and inconsistent sample shapes are returned to the caller.
fn (IterableDataLoader[T]) next_batch_with_transform_pipeline #
fn (mut loader IterableDataLoader[T]) next_batch_with_transform_pipeline(pipeline TransformPipeline[T]) !StreamBatch[T]
next_batch_with_transform_pipeline applies deterministic transforms to features.
fn (IterableDataLoader[T]) next_batch_with_random_transforms #
fn (mut loader IterableDataLoader[T]) next_batch_with_random_transforms(pipeline RandomTransformPipeline[T], mut generator vtl.RandomGenerator) !StreamBatch[T]
next_batch_with_random_transforms applies random transforms to an available batch using the caller-owned generator; labels are returned unchanged.
fn (IterableDataLoader[T]) reset #
fn (mut loader IterableDataLoader[T]) reset() !
reset rewinds the underlying source. Sources that cannot replay should return an error from their reset implementation.
fn (PrefetchLoader[T]) next #
fn (mut p PrefetchLoader[T]) next() !PrefetchStep[T]
next returns the next batch, a done step after the final batch, or the worker's error at the position where it occurred.
fn (PrefetchLoader[T]) close #
fn (mut p PrefetchLoader[T]) close()
close marks the loader closed and signals the worker to stop collating. It drains the bounded queue until the worker's terminal item arrives, so a send already in progress is released before close returns.
fn (PrefetchLoader[T]) is_closed #
fn (p &PrefetchLoader[T]) is_closed() bool
is_closed reports whether close has been called.
type RandomTensorTransform #
type RandomTensorTransform[T] = fn (input &vtl.Tensor[T], mut generator vtl.RandomGenerator) !&vtl.Tensor[T]
RandomTensorTransform applies a tensor transform using an injected generator.
fn (RandomTransformPipeline[T]) apply #
fn (pipeline &RandomTransformPipeline[T]) apply(input &vtl.Tensor[T], mut generator vtl.RandomGenerator) !&vtl.Tensor[T]
apply passes an explicit generator through each transform for reproducible replay.
type TensorTransform #
type TensorTransform[T] = fn (input &vtl.Tensor[T]) !&vtl.Tensor[T]
TensorTransform maps one tensor to another and may report a transformation error. It can be applied to an individual sample or a complete batch.
fn (TransformPipeline[T]) apply #
fn (pipeline &TransformPipeline[T]) apply(input &vtl.Tensor[T]) !&vtl.Tensor[T]
apply passes the output of each transform to the next one. An empty pipeline returns the input unchanged; a transform error stops the pipeline.
struct Cifar10Config #
struct Cifar10Config {
pub:
channels int = 3
height int = 32
width int = 32
num_classes int = 10
train_count int = 50000
test_count int = 10000
}
Cifar10Config holds configuration for CIFAR-10 dataset loading.
struct Cifar10Dataset #
struct Cifar10Dataset {
pub:
train_features &vtl.Tensor[f64] = unsafe { nil }
train_labels &vtl.Tensor[f64] = unsafe { nil }
test_features &vtl.Tensor[f64] = unsafe { nil }
test_labels &vtl.Tensor[f64] = unsafe { nil }
}
Cifar10Dataset holds the CIFAR-10 dataset.
struct CollatedBatch #
struct CollatedBatch[T] {
pub:
features &vtl.Tensor[T]
labels &vtl.Tensor[T] = unsafe { nil }
}
CollatedBatch contains the tensors produced for one selected batch. Labels are nil when the source loader has no labels or the collator omits them.
struct DataLoader #
struct DataLoader[T] {
pub:
dataset &vtl.Tensor[T]
labels &vtl.Tensor[T] = unsafe { nil }
batch_size int
shuffle bool
drop_last bool
seed u64
pub mut:
indices []int
epoch int
mut:
sampler nn_data.Sampler
uses_sampler bool
batch_sampler nn_data.BatchSampler
uses_batch_sampler bool
batch_transform_pipeline TransformPipeline[T]
uses_batch_transform_pipeline bool
batches [][]int
// Erase the generic callback to avoid emitting an incomplete result type
// when consumers instantiate DataLoader without using collated batches.
collate_fn voidptr
}
DataLoader defines a public data structure for this module.
struct DataLoaderConfig #
struct DataLoaderConfig {
pub:
batch_size int = 32
shuffle bool = true
drop_last bool = true
seed u64
}
DataLoaderConfig holds configuration for creating a DataLoader.
struct DataLoaderIterator #
struct DataLoaderIterator[T] {
mut:
loader &DataLoader[T]
current int
}
DataLoaderIterator provides a for-in loop interface over a DataLoader.
struct ImdbConfig #
struct ImdbConfig {
pub:
train_count int = 25000
test_count int = 25000
}
ImdbConfig configures the number of balanced examples returned per split.
struct ImdbDataset #
struct ImdbDataset {
pub:
train_features &vtl.Tensor[string] = unsafe { nil }
train_labels &vtl.Tensor[int] = unsafe { nil }
test_features &vtl.Tensor[string] = unsafe { nil }
test_labels &vtl.Tensor[int] = unsafe { nil }
}
ImdbDataset is a dataset for sentiment analysis.
struct IterableDataLoader #
struct IterableDataLoader[T] {
pub:
batch_size int
drop_last bool
mut:
dataset IterableDataset[T]
exhausted bool
}
IterableDataLoader batches an IterableDataset without materializing it.
struct MnistDataset #
struct MnistDataset {
pub:
train_features &vtl.Tensor[u8] = unsafe { nil }
train_labels &vtl.Tensor[u8] = unsafe { nil }
test_features &vtl.Tensor[u8] = unsafe { nil }
test_labels &vtl.Tensor[u8] = unsafe { nil }
}
MnistDataset is a dataset of MNIST handwritten digits.
struct PrefetchLoader #
struct PrefetchLoader[T] {
mut:
items chan PrefetchItem[T]
closed bool
cancelled u64
}
PrefetchLoader reads a DataLoader's batches through a bounded queue using a single producer worker. Ordering is deterministic because the worker walks batch indices in ascending order.
struct PrefetchStep #
struct PrefetchStep[T] {
pub:
batch CollatedBatch[T]
done bool
}
PrefetchStep is the consumer-facing result of one queue read.
struct RandomTransformPipeline #
struct RandomTransformPipeline[T] {
transforms []RandomTensorTransform[T]
}
RandomTransformPipeline composes transforms that consume an explicit RNG.
struct StreamBatch #
struct StreamBatch[T] {
pub:
available bool
features &vtl.Tensor[T] = unsafe { nil }
labels &vtl.Tensor[T] = unsafe { nil }
}
StreamBatch contains one dense batch produced from an iterable source.
struct StreamSample #
struct StreamSample[T] {
pub:
features &vtl.Tensor[T] = unsafe { nil }
labels &vtl.Tensor[T] = unsafe { nil }
finished bool
}
StreamSample contains one feature sample and optional labels. Set finished to true to signal exhaustion; tensor fields are ignored in that result.
struct TextVocabulary #
struct TextVocabulary {
pub:
tokens []string
mut:
token_to_index map[string]int
}
TextVocabulary maps normalized text tokens to stable integer IDs. The first IDs are reserved for padding and out-of-vocabulary tokens.
fn (TextVocabulary) index #
fn (v &TextVocabulary) index(token string) int
index returns the ID for token, or the unknown-token ID when it is absent.
fn (TextVocabulary) encode #
fn (v &TextVocabulary) encode(text string) []int
encode tokenizes text and returns its vocabulary IDs.
fn (TextVocabulary) decode #
fn (v &TextVocabulary) decode(indices []int) []string
decode converts IDs back to tokens. Invalid IDs decode as
struct TransformPipeline #
struct TransformPipeline[T] {
transforms []TensorTransform[T]
}
TransformPipeline applies tensor transforms in their configured order.
- README
- Constants
- fn build_text_vocabulary
- fn class_names
- fn load_cifar10
- fn load_cifar10_with_config
- fn load_imdb
- fn load_imdb_with_config
- fn load_mnist
- fn new_data_loader
- fn new_data_loader_with_batch_sampler_checked
- fn new_data_loader_with_labels
- fn new_data_loader_with_labels_and_batch_sampler_checked
- fn new_data_loader_with_labels_and_sampler_checked
- fn new_data_loader_with_labels_checked
- fn new_data_loader_with_sampler_checked
- fn new_iterable_data_loader
- fn new_prefetch_loader
- fn tokenize_text
- fn RandomTransformPipeline.new
- fn TransformPipeline.new
- interface IterableDataset
- type CollateFn
- type DataLoaderIterator[T]
- type DataLoader[T]
- type IterableDataLoader[T]
- type PrefetchLoader[T]
- type RandomTensorTransform
- type RandomTransformPipeline[T]
- type TensorTransform
- type TransformPipeline[T]
- struct Cifar10Config
- struct Cifar10Dataset
- struct CollatedBatch
- struct DataLoader
- struct DataLoaderConfig
- struct DataLoaderIterator
- struct ImdbConfig
- struct ImdbDataset
- struct IterableDataLoader
- struct MnistDataset
- struct PrefetchLoader
- struct PrefetchStep
- struct RandomTransformPipeline
- struct StreamBatch
- struct StreamSample
- struct TextVocabulary
- struct TransformPipeline