Spacy on AWS Lambda

Hi, AWS community!

I’ve created lambda pack for natural language processing with spacy (https://spacy.io). Feel free to use and modify for any of your projects. I will be grateful for feedback and comments.

https://github.com/ryfeus/lambda-packs/tree/master/Spacy

Example code loads language model from S3 on cold start and then runs the process where it analyses single sentence.


Related discussions:

I am looking at this on github - I assume it uses the en_core_web_sm model - but I can’t see where or how it is specifying the model - or do I have do download in my code - I can’t find the example code you refer to - sorry to ask but a little more direction appreciated

Hi. I download the whole en_core_web_sm model in the line (https://github.com/ryfeus/lambda-packs/blob/master/Spacy/source2.7/index.py#L23). I keep the model itself in s3 bucket.

Have you also had problems with memory limits in AWS Lambda with SpaCy Lib? My SpaCY lib with en_core_web_sm is about 700 MB, which is obviously not fitting into Lambda’s 500 mb in memory limit.

Hi,

I am trying to use the Spacy pack. As the pack is for 2.7, I created a conda environment with python 2.7. But it keeps failing here when I try to run it. Traceback (most recent call last):

File “C:/Code/FCO/Pack2.7/index.py”, line 1, in

import spacy

File “C:\Code\FCO\Pack2.7\spacy\__init__.py”, line 4, in

from .cli.info import info as cli_info

File “C:\Code\FCO\Pack2.7\spacy\cli\__init__.py”, line 1, in

from .download import download

File “C:\Code\FCO\Pack2.7\spacy\cli\download.py”, line 10, in

from .link import link

File “C:\Code\FCO\Pack2.7\spacy\cli\link.py”, line 8, in

from ..compat import symlink_to, path2str

File “C:\Code\FCO\Pack2.7\spacy\compat.py”, line 9, in

from thinc.neural.util import copy_array

File “C:\Code\FCO\Pack2.7\thinc\neural\__init__.py”, line 1, in

from ._classes.model import Model

File “C:\Code\FCO\Pack2.7\thinc\neural\_classes\model.py”, line 2, in

from numpy import prod

File “C:\Code\FCO\Pack2.7\numpy\__init__.py”, line 142, in

from . import add_newdocs

File “C:\Code\FCO\Pack2.7\numpy\add_newdocs.py”, line 13, in

from numpy.lib import add_newdoc

File “C:\Code\FCO\Pack2.7\numpy\lib\__init__.py”, line 8, in

from .type_check import *

File “C:\Code\FCO\Pack2.7\numpy\lib\type_check.py”, line 11, in

import numpy.core.numeric as _nx

File “C:\Code\FCO\Pack2.7\numpy\core\__init__.py”, line 26, in

raise ImportError(msg)

ImportError:

Importing the multiarray numpy extension module failed. Most

likely you are trying to import a failed build of numpy.

If you’re working with a numpy git repo, try `git clean -xdf` (removes all

files not under version control). Otherwise reinstall numpy.

Original error was: cannot import name multiarray

I have reinstalled numpy a few times within the environment.

Would be great if you could shed some light on this.

Thanks,

Zinat.

I found the problem. Running it on lambda now :slight_smile:

Will look at building the Spacy pack for python 3.6 next.