ServaDataset reads a folder of .serva files and returns each file’s raw bytes as a tensor. There is no decoding: the model trains on the encoded bytes directly. It behaves like torchvision's ImageFolder, so you point it at a directory and go.
PyTorch ships with the
serva package, so ServaDataset works after a plain
pip install serva.Folder layout
How you lay out the directory decides what each item returns.- Class subfolders give you
(tensor, label), ready for a classifier. The label comes from the folder name. - A flat folder of
.servafiles gives you just the tensor, for text or any other unlabeled data.
Custom labels
When the label does not live in the folder name, for example a regression target or a value from a CSV, passlabel_fn. It is any function from a file path to a label.
Sample length
Every.serva file has a different byte length, but a batch needs every sample the same size to stack. By default ServaDataset pads or truncates each file to a fixed length (262144 bytes) so batches stack with no extra work.
length=None and batch with pad_collate. It pads each batch only to its own longest file and returns a mask marking the real bytes, so the model can ignore the padding.
How it fits your model
ServaDataset has one job turn a .serva file into a tensor, plus a label when there is one. It knows nothing about your model. Anything model specific, such as reshaping or retyping the tensor and how batches are formed, is plain PyTorch that you control:
transforma function you pass to reshape or retype each tensor.collate_fnon the DataLoader, how items are grouped into a batch.

