Quickstart
Last updated
Last updated
This quickstart is intended for developers who are ready to dive into the code and see an example of how to integrate ๐ Datasets into their model training workflow. If youโre a beginner, we recommend starting with our , where youโll get a more thorough introduction.
Each dataset is unique, and depending on the task, some datasets may require additional steps to prepare it for training. But you can always use ๐ Datasets tools to load and process a dataset. The fastest and easiest way to get started is by loading an existing dataset from the . There are thousands of datasets to choose from, spanning many tasks. Choose the type of dataset you want to work with, and letโs get started!
Check out of the BOINC AI course to learn more about other important topics such as loading remote or local datasets, tools for cleaning up a dataset, and creating your own dataset.
Start by installing ๐ Datasets:
Copied
๐ Datasets also support audio and image data formats:
To work with audio datasets, install the feature:
Copied
To work with image datasets, install the feature:
Copied
Besides ๐ Datasets, make sure your preferred machine learning framework is installed:
PytorchHide Pytorch contentCopied
TensorFlowHide TensorFlow contentCopied
Copied
Copied
Copied
4. Create a function to preprocess the audio array
with the feature extractor, and truncate and pad the sequences into tidy rectangular tensors. The most important thing to remember is to call the audio array
in the feature extractor since the array
- the actual speech signal - is the model input.
Copied
Copied
6. Set the dataset format according to the machine learning framework youโre using.
PytorchHide Pytorch content
Copied
TensorFlowHide TensorFlow content
Copied
Copied
Copied
3. Create a function to apply your transform to the dataset and generate the model input: pixel_values
.
Copied
Copied
5. Set the dataset format according to the machine learning framework youโre using.
PytorchHide Pytorch content
Copied
TensorFlowHide TensorFlow content
Before you start, make sure you have up-to-date versions of albumentations
and cv2
installed:
Copied
Copied
Copied
Copied
3. Create a function to tokenize the dataset, and you should also truncate and pad the text into tidy rectangular tensors. The tokenizer generates three new columns in the dataset: input_ids
, token_type_ids
, and an attention_mask
. These are the model inputs.
Copied
Copied
5. Set the dataset format according to the machine learning framework youโre using.
PytorchHide Pytorch content
Copied
TensorFlowHide TensorFlow content
Copied
This completes the ๐ Datasets quickstart! You can load any text, audio, or image dataset with a single function and get it ready for your model to train on.
Audio datasets are loaded just like text datasets. However, an audio dataset is preprocessed a bit differently. Instead of a tokenizer, youโll need a . An audio input may also require resampling its sampling rate to match the sampling rate of the pretrained model youโre using. In this quickstart, youโll prepare the dataset for a model train on and classify the banking issue a customer is having.
1. Load the MInDS-14 dataset by providing the function with the dataset name, dataset configuration (not all datasets will have a configuration), and a dataset split:
2. Next, load a pretrained model and its corresponding feature extractor from the ๐ library. It is totally normal to see a warning after you load the model about some weights not being initialized. This is expected because you are loading this model checkpoint for training with another task.
3. The dataset card indicates the sampling rate is 8kHz, but the Wav2Vec2 model was pretrained on a sampling rate of 16kHZ. Youโll need to upsample the audio
column with the function and feature to match the modelโs sampling rate.
Once you have a preprocessing function, use the function to speed up processing by applying the function to batches of examples in the dataset.
5. Use the function to rename the intent_class
column to labels
, which is the expected input name in :
Use the function to set the dataset format to torch
and specify the columns you want to format. This function applies formatting on-the-fly. After converting to PyTorch tensors, wrap the dataset in :
Use the method from ๐ Transformers to prepare the dataset to be compatible with TensorFlow, and ready to train/fine-tune a model, as it wraps a BOINC AI as a tf.data.Dataset
with collation and batching, so one can pass it directly to Keras methods like fit()
without further modification.
7. Start training with your machine learning framework! Check out the ๐ Transformers for an end-to-end example of how to train a model on an audio dataset.
Image datasets are loaded just like text datasets. However, instead of a tokenizer, youโll need a to preprocess the dataset. Applying data augmentation to an image is common in computer vision to make the model more robust against overfitting. Youโre free to use any data augmentation library you want, and then you can apply the augmentations with ๐ Datasets. In this quickstart, youโll load the dataset and get it ready for the model to train on and identify disease from the leaf images.
1. Load the Beans dataset by providing the function with the dataset name and a dataset split:
2. Now you can add some data augmentations with any library (, , ) you like. Here, youโll use to randomly change the color properties of an image:
4. Use the function to apply the data augmentations on-the-fly:
Wrap the dataset in . Youโll also need to create a collate function to collate the samples into batches:
Use the method from ๐ Transformers to prepare the dataset to be compatible with TensorFlow, and ready to train/fine-tune a model, as it wraps a BOINC AI as a tf.data.Dataset
with collation and batching, so one can pass it directly to Keras methods like fit()
without further modification.
6. Start training with your machine learning framework! Check out the ๐ Transformers for an end-to-end example of how to train a model on an image dataset.
Text needs to be tokenized into individual tokens by a . For the quickstart, youโll load the training dataset to train a model to determine whether a pair of sentences mean the same thing.
1. Load the MRPC dataset by providing the function with the dataset name, dataset configuration (not all datasets will have a configuration), and dataset split:
2. Next, load a pretrained model and its corresponding tokenizer from the ๐ library. It is totally normal to see a warning after you load the model about some weights not being initialized. This is expected because you are loading this model checkpoint for training with another task.
Use the function to speed up processing by applying your tokenization function to batches of examples in the dataset:
4. Rename the label
column to labels
, which is the expected input name in :
Use the function to set the dataset format to torch
and specify the columns you want to format. This function applies formatting on-the-fly. After converting to PyTorch tensors, wrap the dataset in :
Use the method from ๐ Transformers to prepare the dataset to be compatible with TensorFlow, and ready to train/fine-tune a model, as it wraps a BOINC AI as a tf.data.Dataset
with collation and batching, so one can pass it directly to Keras methods like fit()
without further modification.
6. Start training with your machine learning framework! Check out the ๐ Transformers for an end-to-end example of how to train a model on a text dataset.
For your next steps, take a look at our and learn how to do more specific things like loading different dataset formats, aligning labels, and streaming large datasets. If youโre interested in learning more about ๐ Datasets core concepts, grab a cup of coffee and read our !