course/videos/load_custom_dataset.ipynb (148 lines of code) (raw):

{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook regroups the code sample of the video below, which is a part of the [Hugging Face course](https://huggingface.co/course)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form" }, "outputs": [ { "data": { "text/html": [ "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/HyQgpJTkRdE?rel=0&amp;controls=0&amp;showinfo=0\" frameborder=\"0\" allowfullscreen></iframe>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#@title\n", "from IPython.display import HTML\n", "\n", "HTML('<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/HyQgpJTkRdE?rel=0&amp;controls=0&amp;showinfo=0\" frameborder=\"0\" allowfullscreen></iframe>')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Install the Transformers and Datasets libraries to run this notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "! pip install datasets transformers[sentencepiece]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!wget https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from datasets import load_dataset\n", "\n", "local_csv_dataset = load_dataset(\"csv\", data_files=\"winequality-white.csv\", sep=\";\")\n", "local_csv_dataset[\"train\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load the dataset from the URL directly\n", "dataset_url = \"https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv\"\n", "remote_csv_dataset = load_dataset(\"csv\", data_files=dataset_url, sep=\";\")\n", "remote_csv_dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset_url = \"https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt\"\n", "text_dataset = load_dataset(\"text\", data_files=dataset_url)\n", "text_dataset[\"train\"][:5]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset_url = \"https://raw.githubusercontent.com/hirupert/sede/main/data/sede/train.jsonl\"\n", "json_lines_dataset = load_dataset(\"json\", data_files=dataset_url)\n", "json_lines_dataset[\"train\"][:2]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset_url = \"https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v2.0.json\"\n", "json_dataset = load_dataset(\"json\", data_files=dataset_url, field=\"data\")\n", "json_dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://rajpurkar.github.io/SQuAD-explorer/dataset/\"\n", "data_files = {\"train\": f\"{url}train-v2.0.json\", \"validation\": f\"{url}dev-v2.0.json\"}\n", "json_dataset = load_dataset(\"json\", data_files=data_files, field=\"data\")\n", "json_dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "name": "Loading a custom dataset", "provenance": [] } }, "nbformat": 4, "nbformat_minor": 4 }