[Python] How to load dataset from huggingface to google colab?

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to load a training dataset in my Google Colab notebook but keep getting an error.

    Here is the code snippet which returns the error:

    from datasets import load_dataset

    ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset",download_mode="force_redownload")

    print(ds["train"].column_names)
    print(ds["train"][0])


    And, in Colab, this returns:

    OSError Traceback (most recent call last)
    /tmp/ipython-input-3556148243.py in <cell line: 0>()
    1 from datasets import load_dataset
    2
    ----> 3 ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset",download_mode="force_redownload")
    4
    5 print(ds["train"].column_names)

    26 frames
    /usr/local/lib/python3.12/dist-packages/huggingface_hub/file_download.py in http_get(url, temp_file, proxies, resume_size, headers, expected_size, displayed_filename, _nb_retries, _tqdm_bar)
    523
    524 if expected_size is not None and expected_size != temp_file.tell():
    --> 525 raise EnvironmentError(
    526 consistency_error_message.format(
    527 actual_size=temp_file.tell(),

    OSError: Consistency check failed: file should be of size 12021156 but has size 10804870 (1O4KGHbRt3M_0.avi).
    This is usually due to network issues while downloading the file. Please retry with `force_download=True`.


    I tried this:

    from datasets import load_dataset
    from huggingface_hub import snapshot_download
    import shutil
    import os

    cache_dir = "/root/.cache/huggingface/datasets" # default location in Colab
    shutil.rmtree(cache_dir, ignore_errors=True)


    hub_cache = "/root/.cache/huggingface/hub"
    shutil.rmtree(hub_cache, ignore_errors=True)


    ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset")

    print(ds)


    Still getting this error:

    ---------------------------------------------------------------------------
    OSError Traceback (most recent call last)
    /tmp/ipython-input-3570728603.py in <cell line: 0>()
    13
    14 # 3. Re-download the dataset fresh
    ---> 15 ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset")
    16
    17 print(ds)

    26 frames
    /usr/local/lib/python3.12/dist-packages/huggingface_hub/file_download.py in http_get(url, temp_file, proxies, resume_size, headers, expected_size, displayed_filename, _nb_retries, _tqdm_bar)
    523
    524 if expected_size is not None and expected_size != temp_file.tell():
    --> 525 raise EnvironmentError(
    526 consistency_error_message.format(
    527 actual_size=temp_file.tell(),

    OSError: Consistency check failed: file should be of size 12021156 but has size 10804870 (1O4KGHbRt3M_0.avi).
    This is usually due to network issues while downloading the file. Please retry with `force_download=True`.


    I asked gpt but it responded as: "That error isn’t about the dataset being broken — it’s just a download corruption issue (file didn’t fully download, so the checksum mismatched). Hugging Face datasets sometimes fail like this if Colab times out or the internet is slow."

    Please HELP!!

    Continue reading...

Compartilhe esta Página