API Reference
This page documents the public types and functions. See the Guide for worked examples and background on the transform pipeline.
Types
HuggingFaceDatasets.Dataset — Type
DatasetA Julia wrapper around an object of the python datasets.Dataset class.
Provides:
- 1-based indexing.
- All python class' methods from
datasets.Dataset.
Usually constructed via load_dataset or from in-memory Julia data (see below), both of which default to the "julia" format so observations are converted to native Julia types on access. A raw datasets.Dataset object can also be wrapped directly, in which case its current Python format is preserved (use with_format to opt in to "julia").
See also load_dataset, DatasetDict, with_format, and reset_format!.
Examples
julia> ds = Dataset((; label=[5, 0, 4]))
Dataset({
features: ['label'],
num_rows: 3
})
julia> length(ds)
3
julia> ds[1] # observations are Julia values by default (the "julia" format)
Dict{String, Int64} with 1 entry:
"label" => 5
julia> ds[1:3] # a range or vector returns a batch (columns -> vectors)
Dict{String, Vector{Int64}} with 1 entry:
"label" => [5, 0, 4]
julia> set_format!(ds, nothing); # opt out: hand back the raw Python observations
julia> ds[1]
Python: {'label': 5}HuggingFaceDatasets.DatasetDict — Type
DatasetDict(splits::AbstractDict{<:AbstractString, Dataset})
DatasetDict(splits::Pair{<:AbstractString, Dataset}...)A DatasetDict is a dictionary of Datasets. It is a wrapper around a datasets.DatasetDict object.
A julia transform is stored per split: indexing a split (dd["train"]) hands back a Dataset carrying that split's transform. The py2jl transform provided by this package converts python types to julia types. Use set_jltransform! / with_jltransform with a single callable to set every split at once, or with an AbstractDict to set a different transform per split. set_format! / reset_format! act on all splits.
A DatasetDict is an AbstractDict{String, Dataset}, so keys, values, haskey, get, and iteration work as expected.
The constructors build a DatasetDict from in-memory Julia data — a mapping of split names to Datasets, given either as an AbstractDict or as name => dataset pairs. Each split inherits its source Dataset's own transform (so a dict built from Dataset((; ...))s is in the "julia" format, the Dataset default); change them afterwards with set_jltransform! or set_format!. The source Datasets are not mutated.
See also load_dataset and Dataset.
Examples
julia> train = Dataset((; label=[1, 0, 1, 0]));
julia> test = Dataset((; label=[1, 1]));
julia> dd = DatasetDict("train" => train, "test" => test)
DatasetDict({
train: Dataset({
features: ['label'],
num_rows: 4
})
test: Dataset({
features: ['label'],
num_rows: 2
})
})
julia> collect(keys(dd))
2-element Vector{String}:
"train"
"test"
julia> dd["train"]
Dataset({
features: ['label'],
num_rows: 4
})
julia> haskey(dd, "validation")
falseHuggingFaceDatasets.IterableDataset — Type
IterableDatasetA Julia wrapper around an object of the python datasets.IterableDataset class — the lazy, streaming counterpart of Dataset. This is what load_dataset(...; streaming=true) returns for a single split.
Unlike Dataset, an IterableDataset has no random access and no length: it is consumed by iteration (for obs in itds, collect(itds), Iterators.take(itds, n)), not by indexing. Its transforms (map/filter/shuffle(buffer_size=…)/take/skip) are lazy and return new IterableDatasets.
Provides:
Base.iterateover the underlying python iterator, applying the julia transform (py2jlunder the default"julia"format) to each yielded observation.- All python methods of
datasets.IterableDataset, forwarded viagetpropertyand re-wrapped (so.take(n),.skip(n),.shuffle(buffer_size=…),.map(f)come back asIterableDatasets carrying the same julia format/transform).
getindex, length, and firstindex/lastindex are intentionally not supported (they throw an explanatory ArgumentError): a stream has no random access. Materialize rows with collect, Iterators.take, or the lazy .take(n)/.skip(n) methods instead.
Usually constructed via load_dataset with streaming=true, or from a materialized Dataset via ds.to_iterable_dataset(). Defaults to the "julia" format so each yielded observation is converted to native Julia types on access. A raw datasets.IterableDataset can also be wrapped directly, in which case it is format-neutral (use with_format to opt in to "julia").
See also load_dataset, Dataset, IterableDatasetDict, and with_format.
Examples
julia> ds = Dataset((; x = [1, 2, 3]));
julia> itds = ds.to_iterable_dataset(); # wrapped IterableDataset, "julia" format
julia> for obs in itds
println(obs["x"])
end
1
2
3
julia> for obs in itds.take(2) # lazy `.take`, still an IterableDataset
println(obs["x"])
end
1
2HuggingFaceDatasets.IterableDatasetDict — Type
IterableDatasetDictA dictionary of IterableDatasets — the streaming counterpart of DatasetDict, wrapping a datasets.IterableDatasetDict. This is what load_dataset(...; streaming=true) returns when no split is selected.
Like DatasetDict it is an AbstractDict{String, IterableDataset} (so keys, values, haskey, get, and iteration work) and stores a julia transform per split: indexing a split (dd["train"]) hands back an IterableDataset carrying that split's transform. set_format! / reset_format! act on all splits.
See also load_dataset and IterableDataset.
HuggingFaceDatasets.Column — Type
Column{T} <: AbstractVector{T}A lazy, 1-based vector view over a single column of a [Dataset]. It wraps the python datasets.Column object that dataset[column_name] returns and converts each element from python to julia with py2jl only when it is accessed, so the whole column is never materialized at once.
Because Column <: AbstractVector, it indexes, slices, iterates, broadcasts, compares, and collects like an ordinary vector; collect(col) materializes it into a plain Vector. The element type T is inferred from the first element (Any if the column is empty).
Returned by py2jl on a datasets.Column, and hence by string indexing of a julia-formatted [Dataset], e.g. ds["label"].
Examples
julia> ds = Dataset((; label=[5, 0, 4])); # "julia" format by default
julia> col = ds["label"]
3-element HuggingFaceDatasets.Column{Int64}:
5
0
4
julia> col[2]
0
julia> col[1:2]
2-element Vector{Int64}:
5
0
julia> collect(col)
3-element Vector{Int64}:
5
0
4Schema (features)
HuggingFaceDatasets.features — Function
features(ds::Dataset)Return the schema of ds as a Features view (also reachable as ds.features). Indexing a column yields its feature type, with ClassLabel/Value leaves wrapped for Julian access.
See also class_names, int2str, and str2int.
Examples
julia> ds = Dataset((; label=[0, 1, 1], x=[1, 2, 3]));
julia> features(ds)["label"]
Value('int64')HuggingFaceDatasets.Features — Type
Features(schema::AbstractDict)A Julia view over a datasets.Features schema: an ordered mapping from column name to its feature type. Features <: AbstractDict{String, Any}, so it indexes, iterates, and supports keys/values/haskey/get like a dict; indexing a column returns the wrapped leaf (ClassLabel, Value) when recognized, or the raw Py otherwise (nested features, Image, Audio, Sequence, ...).
Obtained from a dataset via ds.features (or the features function), or built from Julia (Features(Dict("label" => ClassLabel(names=["neg", "pos"])))) and passed back to Python as a features= schema argument.
The column names are cached at construction, so keys/length/iteration never call Python (safe from the REPL's async feat[<TAB> completion, mirroring DatasetDict).
Examples
julia> ds = Dataset((; label=[0, 1, 1], x=[1.0, 2.0, 3.0]));
julia> f = ds.features;
julia> collect(keys(f))
2-element Vector{String}:
"label"
"x"
julia> f["x"]
Value('float64')HuggingFaceDatasets.ClassLabel — Type
ClassLabel(; names, num_classes)A Julia view over a datasets.ClassLabel feature: the integer-encoded label type whose names map class ids to human-readable strings.
Construct one from Julia (ClassLabel(names=["neg", "pos"])) — forwarding to datasets.ClassLabel — or obtain one from a dataset's schema via ds.features["label"] (see features). Attribute and method access forwards to Python, so cl.names, cl.num_classes, cl.int2str(i), and cl.str2int(s) all work, with results converted by py2jl.
Label integers are 0-based class ids (data, not 1-based Julia indices): int2str/str2int pass them through to Python unchanged. See also class_names, int2str, str2int, and Features.
Examples
julia> ds = Dataset((; label=["cat", "dog", "dog"], x=[1, 2, 3]));
julia> ds = ds.class_encode_column("label"); # string column -> ClassLabel
julia> cl = ds.features["label"]
ClassLabel(names=['cat', 'dog'])
julia> cl.names
2-element Vector{String}:
"cat"
"dog"
julia> cl.int2str(1) # 0-based class id -> name
"dog"
julia> cl.str2int("cat")
0HuggingFaceDatasets.Value — Type
Value(dtype::AbstractString)A Julia view over a datasets.Value feature: a scalar column type carrying an Arrow dtype (e.g. "int64", "float32", "string"). Construct one with Value("int64") (forwarding to datasets.Value) or obtain it from a schema via features. Attribute access forwards to Python, so v.dtype returns the dtype string (e.g. ds.features["x"]).
See also Features and ClassLabel.
HuggingFaceDatasets.class_names — Function
class_names(ds::Dataset, col)The ordered class names of column col's ClassLabel feature, as a Vector{String}; names[i] is the name of class id i - 1 (ids are 0-based). Errors if col is not a ClassLabel. Equivalent to the Pythonic ds.features[col].names.
See also int2str, str2int, and features.
Examples
julia> ds = Dataset((; label=["cat", "dog", "dog"]));
julia> ds = ds.class_encode_column("label");
julia> class_names(ds, "label")
2-element Vector{String}:
"cat"
"dog"HuggingFaceDatasets.int2str — Function
int2str(ds::Dataset, col, i)Decode 0-based class id(s) i (an integer or a vector of integers) to class name(s) via column col's ClassLabel, so no index offset is applied. Errors if col is not a ClassLabel. Equivalent to the Pythonic ds.features[col].int2str(i).
See also str2int, class_names, and features.
Examples
julia> ds = Dataset((; label=["cat", "dog", "dog"]));
julia> ds = ds.class_encode_column("label");
julia> int2str(ds, "label", 1)
"dog"
julia> int2str(ds, "label", [0, 1, 1])
3-element Vector{String}:
"cat"
"dog"
"dog"HuggingFaceDatasets.str2int — Function
str2int(ds::Dataset, col, s)Encode class name(s) s (a string or a vector of strings) to their 0-based class id(s) via column col's ClassLabel. Errors if col is not a ClassLabel. Equivalent to the Pythonic ds.features[col].str2int(s).
See also int2str, class_names, and features.
Examples
julia> ds = Dataset((; label=["cat", "dog", "dog"]));
julia> ds = ds.class_encode_column("label");
julia> str2int(ds, "label", "dog")
1Loading
HuggingFaceDatasets.load_dataset — Function
load_dataset(args...; kws...)Load a dataset from the HuggingFace Datasets library.
All arguments are passed to the python function datasets.load_dataset. See the documentation here.
Returns a DatasetDict or a Dataset depending on the split argument. With streaming=true it instead returns the lazy IterableDatasetDict or IterableDataset counterpart (consumed by iteration, not indexing).
The result is returned in the "julia" format, so observations are lazily converted to native Julia types on access (see with_format). Use set_format!(ds, nothing) (or the underlying .py object) if you want the raw Python observations instead.
Examples
Without a split argument, a DatasetDict is returned:
julia> d = load_dataset("nyu-mll/glue", "sst2")
DatasetDict({
train: Dataset({
features: ['sentence', 'label', 'idx'],
num_rows: 67349
})
validation: Dataset({
features: ['sentence', 'label', 'idx'],
num_rows: 872
})
test: Dataset({
features: ['sentence', 'label', 'idx'],
num_rows: 1821
})
})
julia> d["train"]
Dataset({
features: ['sentence', 'label', 'idx'],
num_rows: 67349
})Selecting a split returns a Dataset instead. Observations come back as native Julia values thanks to the default "julia" format:
julia> mnist = load_dataset("ylecun/mnist", split="train")
Dataset({
features: ['image', 'label'],
num_rows: 60000
})
julia> mnist[1]["label"]
5
julia> mnist[1]["image"] # a raw (W, H) numeric array under the numpy-backed format
28×28 Matrix{UInt8}:
[...]HuggingFaceDatasets.load_from_disk — Function
load_from_disk(path; kws...)Load a Dataset or DatasetDict previously written with save_to_disk, forwarding to datasets.load_from_disk. This is the read side of the ds.save_to_disk(path) method, closing the save/load asymmetry.
The result is returned in the default "julia" format. Extra keyword arguments (keep_in_memory, storage_options, ...) are forwarded to Python. The Python classmethods are also available under their names: Dataset.load_from_disk(path) and DatasetDict.load_from_disk(path) load specifically a Dataset / DatasetDict, whereas this top-level load_from_disk auto-detects which one was saved.
Examples
julia> ds = Dataset((; label=[5, 0, 4]));
julia> ds.save_to_disk("mydataset");
julia> load_from_disk("mydataset")
Dataset({
features: ['label'],
num_rows: 3
})HuggingFaceDatasets.from_csv — Function
from_csv(path_or_paths; kws...)
Dataset.from_csv(path_or_paths; kws...)Build a Dataset from a CSV file (or files), forwarding to datasets.Dataset.from_csv. Reachable both as the (public, not exported) HuggingFaceDatasets.from_csv and under the Python classmethod name Dataset.from_csv. See also from_json and from_parquet.
HuggingFaceDatasets.from_json — Function
from_json(path_or_paths; kws...)
Dataset.from_json(path_or_paths; kws...)Build a Dataset from a JSON / JSON Lines file (or files), forwarding to datasets.Dataset.from_json. Reachable both as the (public, not exported) HuggingFaceDatasets.from_json and under the Python classmethod name Dataset.from_json. See also from_csv and from_parquet.
HuggingFaceDatasets.from_parquet — Function
from_parquet(path_or_paths; kws...)
Dataset.from_parquet(path_or_paths; kws...)Build a Dataset from a Parquet file (or files), forwarding to datasets.Dataset.from_parquet. Reachable both as the (public, not exported) HuggingFaceDatasets.from_parquet and under the Python classmethod name Dataset.from_parquet. See also from_csv and from_json.
Combining
HuggingFaceDatasets.concatenate_datasets — Function
concatenate_datasets(dsets::AbstractVector; axis=0, kws...)
concatenate_datasets(dsets::Dataset...; axis=0, kws...)Concatenate several Datasets into a single one, forwarding to datasets.concatenate_datasets. Pass the datasets either as a vector or as individual arguments.
With axis=0 (the default) the datasets are stacked row-wise (they must share the same columns); with axis=1 they are concatenated column-wise (they must have the same number of rows). Extra keyword arguments (info, split, ...) are forwarded to Python. The result is returned in the default "julia" format.
Examples
julia> a = Dataset((; label=[1, 2]));
julia> b = Dataset((; label=[3, 4, 5]));
julia> ds = concatenate_datasets(a, b)
Dataset({
features: ['label'],
num_rows: 5
})
julia> ds[:]["label"]
5-element Vector{Int64}:
1
2
3
4
5HuggingFaceDatasets.interleave_datasets — Function
interleave_datasets(dsets::AbstractVector; probabilities=nothing, seed=nothing, kws...)
interleave_datasets(dsets::Dataset...; probabilities=nothing, seed=nothing, kws...)Interleave several Datasets into a single one by alternating between them, forwarding to datasets.interleave_datasets. Pass the datasets either as a vector or as individual arguments.
Without probabilities, examples are taken from each dataset in round-robin order; with probabilities (a vector summing to 1) each next example is sampled from a dataset according to those weights (pass seed for reproducibility). Extra keyword arguments (stopping_strategy, ...) are forwarded to Python. The result is returned in the default "julia" format.
Examples
julia> a = Dataset((; label=[1, 1, 1]));
julia> b = Dataset((; label=[2, 2, 2]));
julia> ds = interleave_datasets(a, b);
julia> ds[:]["label"]
6-element Vector{Int64}:
1
2
1
2
1
2Formats and transforms
HuggingFaceDatasets.with_format — Function
with_format(ds::Dataset, format)Return a copy of ds with the format set to format. If format is "julia", the returned dataset is backed by datasets' numpy format and transformed with py2jl, using copyless conversion from python types when possible. Any other string is forwarded to datasets' own set_format ("numpy", "torch", ...), with observations left as raw Python objects.
See also set_format! and reset_format!.
Examples
julia> ds = set_format!(Dataset((; label=[5, 0, 4])), nothing); # start from raw Python
julia> ds[1]
Python: {'label': 5}
julia> ds = with_format(ds, "julia");
julia> ds[1]
Dict{String, Int64} with 1 entry:
"label" => 5with_format(d::DatasetDict, format)Return a copy of d with the format set to format. If format is "julia", the returned dataset will be transformed with py2jl and copyless conversion from python types will be used when possible.
with_format(ds::IterableDataset, format)Return a copy of ds with the format set to format. As for Dataset, "julia" is numpy-backed + py2jl; nothing yields raw Python observations; any other string is forwarded to datasets' own with_format. See also set_format!.
with_format(d::IterableDatasetDict, format)Return a copy of d with the format set to format on every split (see with_format).
HuggingFaceDatasets.set_format! — Function
set_format!(ds::Dataset, format)Set the format of ds to format. Mutating version of with_format.
format == "julia" installs the julia format (numpy-backed + py2jl); nothing removes all formatting (raw Python observations); any other string is forwarded to datasets' set_format ("numpy", "torch", ...). The single-argument form set_format!(ds) restores the default julia format (see reset_format!).
set_format!(d::DatasetDict, format)Set the format of d to format. Mutating version of with_format.
set_format!(ds::IterableDataset, format)Set the format of ds to format. Mutating version of with_format. Unlike Dataset, datasets.IterableDataset has no in-place set_format, so this replaces the wrapped python object with py.with_format(...).
format == "julia" installs the julia format (numpy-backed + py2jl); nothing removes all formatting (raw Python observations); any other string is forwarded to datasets' with_format ("numpy", "torch", ...). The single-argument form restores the julia format.
set_format!(d::IterableDatasetDict, format)Set the format of every split of d to format. Mutating version of with_format.
HuggingFaceDatasets.reset_format! — Function
reset_format!(ds::Dataset)Reset ds to the default "julia" format, i.e. set_format!(ds, "julia"). To instead strip all formatting and get the raw Python observations, use set_format!(ds, nothing).
reset_format!(d::DatasetDict)Reset d to the default "julia" format, i.e. set_format!(d, "julia"). To instead strip all formatting and get raw Python observations, use set_format!(d, nothing).
reset_format!(ds::IterableDataset)Reset ds to the default "julia" format, i.e. set_format!(ds, "julia"). To instead strip all formatting and get raw Python observations, use set_format!(ds, nothing).
reset_format!(d::IterableDatasetDict)Reset d to the default "julia" format, i.e. set_format!(d, "julia").
HuggingFaceDatasets.with_jltransform — Function
with_jltransform(ds::Dataset, transform)
with_jltransform(transform, ds::Dataset)Return a copy of ds with the julia transform set to transform. The transform applies when indexing, e.g. ds[1] or ds[1:2].
The transform is always applied to a batch of data, even if the index is a single integer. That is, ds[1] is equivalent to ds[1:1] from the point of view of the transform.
The julia transform is applied after the python transform (if any). The python transform can be set with ds.set_transform(pytransform).
If transform is nothing or identity, the returned dataset will not be transformed.
See also set_jltransform! for the mutating version.
with_jltransform(d::DatasetDict, transform)
with_jltransform(transform, d::DatasetDict)Return a copy of d with the julia transform applied to each Dataset.
transform may be a single callable (or nothing), applied to every split, or an AbstractDict mapping split names to per-split transforms (splits it omits fall back to identity).
with_jltransform(ds::IterableDataset, transform)
with_jltransform(transform, ds::IterableDataset)Return a copy of ds with the julia transform (applied to each yielded observation) set to transform. If transform is nothing or identity, no transform is applied.
with_jltransform(d::IterableDatasetDict, transform)
with_jltransform(transform, d::IterableDatasetDict)Return a copy of d with the julia transform applied to each IterableDataset. transform may be a single callable (or nothing), applied to every split, or an AbstractDict mapping split names to per-split transforms.
HuggingFaceDatasets.set_jltransform! — Function
set_jltransform!(ds::Dataset, transform)
set_jltransform!(transform, ds::Dataset)Set the julia transform of ds to transform. Mutating version of with_jltransform.
set_jltransform!(d::DatasetDict, transform)
set_jltransform!(transform, d::DatasetDict)Set the transform of d to transform. Mutating version of with_jltransform.
transform may be a single callable (or nothing), applied to every split, or an AbstractDict mapping split names to per-split transforms (splits it omits fall back to identity).
set_jltransform!(ds::IterableDataset, transform)
set_jltransform!(transform, ds::IterableDataset)Set the julia transform of ds to transform. Mutating version of with_jltransform.
set_jltransform!(d::IterableDatasetDict, transform)
set_jltransform!(transform, d::IterableDatasetDict)Set the transform of d to transform. Mutating version of with_jltransform.
Transforming
Base.map — Method
map(f, ds::Dataset; kws...)Apply f to ds through datasets' map, bridging Julia values on both sides: each example (or batch, with batched=true) is converted with py2jl before f sees it, and f's return value is converted back to Python with jl2py. This lets you write pure-Julia transforms while still getting datasets' batching, caching, and multiprocessing.
Keyword arguments (batched, num_proc, remove_columns, ...) are forwarded to the Python map. The parent's julia format/transform is preserved on the returned Dataset.
ds.map(f; ...) is equivalent to this map(f, ds; ...) (the property call routes here, not to Python). If you need to hand map a raw Python callback instead, use the underlying ds.py.map(...).
See also filter.
Examples
julia> ds = with_format(Dataset((; label=[5, 0, 4])), "julia");
julia> ds2 = map(x -> Dict("label" => x["label"] .+ 100), ds; batched=true);
julia> ds2[1:3]["label"]
3-element Vector{Int64}:
105
100
104Base.filter — Method
filter(f, ds::Dataset; kws...)Filter ds through datasets' filter, bridging Julia values: each example (or batch, with batched=true) is converted with py2jl before f sees it, and f returns a Bool (or, when batched=true, a Vector{Bool}), converted back to Python with jl2py.
Keyword arguments are forwarded to the Python filter; the parent's julia format/transform is preserved on the returned Dataset.
ds.filter(f; ...) is equivalent to this filter(f, ds; ...); use the underlying ds.py.filter(...) for a raw Python callback.
See also map.
Base.map — Method
map(f, d::DatasetDict; kws...)Apply f to every example of every split of d through datasets' DatasetDict.map, bridging Julia values on both sides just like the Dataset version: each example (or batch, with batched=true) is converted with py2jl before f sees it, and f's return value is converted back with jl2py. Keyword arguments are forwarded to the Python map, and each split keeps its own julia format/transform.
d.map(f; ...) is equivalent to this map(f, d; ...); use d.py.map(...) for a raw Python callback.
See also filter.
Base.filter — Method
filter(f, d::DatasetDict; kws...)Filter every split of d by the Julia predicate f, applied per example (Python's DatasetDict.filter), bridging values with py2jl/jl2py exactly as map does. Returns a DatasetDict with the same splits, each keeping its own julia format/transform. d.filter(f; ...) is equivalent to this filter(f, d; ...).
Base.map — Method
map(f, ds::IterableDataset; kws...)Lazily apply f to every example of the stream through datasets' IterableDataset.map, bridging Julia values on both sides exactly like the Dataset version: each example (or batch, with batched=true) is converted with py2jl before f sees it, and f's return value is converted back to Python with jl2py. Nothing is materialized — the returned IterableDataset applies f on the fly as it is iterated.
ds.map(f; ...) is equivalent to this map(f, ds; ...); use ds.py.map(...) for a raw Python callback. See also filter.
Base.filter — Method
filter(f, ds::IterableDataset; kws...)Lazily filter the stream by the Julia predicate f through datasets' IterableDataset.filter, bridging values with py2jl/jl2py as map does. ds.filter(f; ...) is equivalent to this filter(f, ds; ...).
Base.map — Method
map(f, d::IterableDatasetDict; kws...)Lazily apply f to every example of every split, bridging Julia values on both sides like the IterableDataset version. d.map(f; ...) is equivalent to this map(f, d; ...).
Base.filter — Method
filter(f, d::IterableDatasetDict; kws...)Lazily filter every split by the Julia predicate f, applied per example, bridging values with py2jl/jl2py. Like DatasetDict's filter, this filters examples within every split (matching Python), not split entries.
Type conversion
HuggingFaceDatasets.py2jl — Function
py2jl(x)Convert Python types to Julia types. It will recursively traverse built-in python containers such as lists, tuples, dicts, and sets, and convert all nested objects. On the leaves, it will call either pyconvert(Any, x) or numpy2jl.
A datasets.Column (the lazy column view returned by dataset[column_name]) is wrapped in a lazy Column, whose elements are converted on access rather than all at once.
Examples
julia> py2jl(pylist([1, 2, 3]))
3-element Vector{Int64}:
1
2
3
julia> py2jl(pytuple((1, pylist([2, 3]))))
(1, [2, 3])HuggingFaceDatasets.jl2py — Function
jl2py(x)Convert Julia values to Python, the inverse of py2jl. Recursively traverses AbstractDict, NamedTuple, Tuple, and AbstractVector containers, converting the leaves. Multi-dimensional numeric AbstractArrays are converted with jl2numpy (copyless, with the documented axis reversal); other leaves are handed to PythonCall's default Py conversion.
This is the write-path dual of py2jl, used to bridge pure-Julia callbacks into the Python datasets API (see the Julia-friendly map / filter overloads).
Examples
julia> jl2py(Dict("label" => [1, 2, 3]))
Python: {'label': [1, 2, 3]}
julia> jl2py((1, "a", [2, 3]))
Python: (1, 'a', [2, 3])HuggingFaceDatasets.numpy2jl — Function
numpy2jl(x)Convert a numpy array to a Julia Array sharing memory zero-copy. Mutations to the Julia array are reflected in the numpy array (and vice versa). Since numpy is row-major and Julia is column-major, the returned array has permuted (reversed) dimensions.
Read-only or non-contiguous numpy buffers cannot be shared safely and are copied first.
This function is called by py2jl. See also jl2numpy.
Examples
julia> y = jl2numpy([1 2 3; 4 5 6]); # a 3×2 numpy array
julia> numpy2jl(y) # back to a 2×3 Julia array
2×3 Matrix{Int64}:
1 2 3
4 5 6HuggingFaceDatasets.jl2numpy — Function
jl2numpy(x)Convert a Julia array to a numpy array, sharing memory via the buffer protocol. The conversion is copyless, and mutations to the numpy array are reflected in the Julia array (and vice versa). The returned numpy array has permuted dimensions with respect to the input Julia array, since numpy is row-major and Julia is column-major.
See also numpy2jl.
Examples
julia> x = [1 2 3; 4 5 6]; # a 2×3 Julia array
julia> y = jl2numpy(x); # numpy is row-major, so the axes are reversed
julia> y.shape
Python: (3, 2)
julia> numpy2jl(y) == x
trueIndex
HuggingFaceDatasets.ClassLabelHuggingFaceDatasets.ColumnHuggingFaceDatasets.DatasetHuggingFaceDatasets.DatasetDictHuggingFaceDatasets.FeaturesHuggingFaceDatasets.IterableDatasetHuggingFaceDatasets.IterableDatasetDictHuggingFaceDatasets.ValueBase.filterBase.filterBase.filterBase.filterBase.mapBase.mapBase.mapBase.mapHuggingFaceDatasets.class_namesHuggingFaceDatasets.concatenate_datasetsHuggingFaceDatasets.featuresHuggingFaceDatasets.from_csvHuggingFaceDatasets.from_jsonHuggingFaceDatasets.from_parquetHuggingFaceDatasets.int2strHuggingFaceDatasets.interleave_datasetsHuggingFaceDatasets.jl2numpyHuggingFaceDatasets.jl2pyHuggingFaceDatasets.load_datasetHuggingFaceDatasets.load_from_diskHuggingFaceDatasets.numpy2jlHuggingFaceDatasets.py2jlHuggingFaceDatasets.reset_format!HuggingFaceDatasets.set_format!HuggingFaceDatasets.set_jltransform!HuggingFaceDatasets.str2intHuggingFaceDatasets.with_formatHuggingFaceDatasets.with_jltransform