xorbits.datasets.Dataset.map#

Dataset.map(fn: Callable, **kwargs)[source]#

Apply fn to each row of the dataset.

Parameters
  • fn (Callable) – The callable object, the signature is function(example: Dict[str, Any]) -> Dict[str, Any].

  • kwargs – The kwargs are passed to the underlying engine, e.g. the **kwargs will be passed to datasets.Dataset.map if the Dataset is constructed from_huggingface, please refer to: datasets.Dataset.map.

Return type

Dataset

Examples

>>> import xorbits.datasets as xdatasets
>>> ds = xdatasets.from_huggingface("rotten_tomatoes", split="validation")
>>> def add_prefix(example):
...     example["text"] = "Review: " + example["text"]
...     return example
>>> ds = ds.map(add_prefix)