Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install models/download packages on Google Colab?

I am using text analytics library "Spacy". I've installed spacy on Google Colab notebook without any issue. But for using it I need to download "en" model.

Generally, that command should look like this:

python -m spacy download en

I tried few ways but I am not able to get it to install on the notebook. Looking for help.

Cheers

like image 206
disp_name Avatar asked Mar 13 '18 15:03

disp_name


People also ask

How do I import a module in Google Colab?

Instead of clicking the GUI, you can also use Python code to upload files. You can import files module from google. colab . Then call upload() to launch a “File Upload” dialog and select the file(s) you wish to upload.

How do I download a model from Google Colab?

How to Download Folders from Colab. The command is !zip followed by r which means “recursive”, then we write the file path of the zipped file (i.e. /content/sample_data. zip ) and finally, we write the folder that we want to zip (i.e. /content/sample_data ) and voila, the zip file is generated :-).


1 Answers

If you have a Python interpreter but not a teriminal, you could try:

import spacy.cli
spacy.cli.download("en_core_web_sm")

More manual alternatives can be found here: https://spacy.io/usage/models#download-pip

Fundamentally what needs to happen is the model file needs to be downloaded, unzipped, and placed into the appropriate site-packages directory. You should be able to find a convenient way to do that, e.g. by pip installing the model package directly. But if you get really stuck, you can get the path by looking at the __file__ variable of any module you have installed, e.g. print(spacy.__file__) . That should tell you where on your file-system the site-packages directory is.

like image 151
syllogism_ Avatar answered Oct 30 '22 11:10

syllogism_