Question about mounting drive/data path in colab for the python code to read in

In the Bert exercise, I run the code C4_W3_Colab_BERT_Loss_Model.ipynb as given in colab, and mounted the drive and path per the code:

from google.colab import drive

drive.mount(‘/content/drive/’, force_remount=True)
path = “/content/drive/My Drive/NLP_C4_W3_Colabs”

However when I run read datafile command line below I still get error saying the datafile is not found

FileNotFoundError Traceback (most recent call last)
in <cell line: 1>()
----> 1 example_jsons = list(map(ast.literal_eval, open(path + “/data/data.txt”)))
3 natural_language_texts = [example_json[‘text’] for example_json in example_jsons]
5 PAD, EOS, UNK = 0, 1, 2

FileNotFoundError: [Errno 2] No such file or directory: ‘/content/drive/My Drive/NLP_C4_W3_Colabs/data/data.txt’

Why is this?

How I do load my own data to colabs and allow it to be read by the python code? I tried creating a folder named “data” in my google drive “colab notebooks” folder but it still can’t find the data file in data/data.txt

Hi @PZ2004,

Have you followed all of the instructions as provided here ?

From the error you are getting, it seems like you didn’t create a short cut to NLP_C4_W3_Colabs folder which has all the relevant (data) files needed to run the lab.

Similarly, if you want the colab to read your own data, you’d first mount your drive and then include the file path to the files you want to read.


Hi Mubisi.
Here I am trying to following the instruction and add NLP_C4_W3_colabs fold, but I don’t see the option of “add shortcut” in my dropdown menu. do you know where it went wrong?

For me the confusing part is how to figure out the relative path in google drive when trying to mount. Here drive.mount(‘/content/drive/’, force_remount=True). how to figure out what is the root path of “/” in my google drive?

for example, here is the fold of “my coleb” in my google drive. how do I mount the “data” folder so that coleb can read files in it?

Hi @PZ2004,

After mounting your drive, your path would be "/content/drive/My Drive/Colab Notebooks/data"

Basically, "/content/drive/My Drive/" part would be the same, the rest would be how you have things in your drive.

Hi @PZ2004,

Thank you for bringing this to my attention. Looks like things have changed in the UI.

From the drop down, "Organise -> Add shortcut", when the pop up opens, select All Locations then select My Drive and then press Add.


Thanks. I got it to work.