GithubHelp home page GithubHelp logo

ines / spacy-js Goto Github PK

View Code? Open in Web Editor NEW
190.0 190.0 23.0 658 KB

🎀 JavaScript API for spaCy with Python REST API

Home Page: https://spacy.io

License: MIT License

Python 19.28% JavaScript 80.72%
javascript natural-language-processing nlp python rest-api spacy

spacy-js's People

Contributors

ines avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacy-js's Issues

spaCy-js in browser

@ines Hello!
I was wondering if there was a client-side spaCy implementation in javascript. Please do let me know!

Support for multi-language model (xx_ent_wiki_sm)

When actually running, there is this issue:

ERROR:waitress:Exception when serving /parse
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/waitress/channel.py", line 336, in service
    task.service()
  File "/usr/local/lib/python3.7/site-packages/waitress/task.py", line 175, in service
    self.execute()
  File "/usr/local/lib/python3.7/site-packages/waitress/task.py", line 452, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/usr/local/lib/python3.7/site-packages/hug/api.py", line 423, in api_auto_instantiate
    return module.__hug_wsgi__(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/falcon/api.py", line 244, in __call__
    responder(req, resp, **params)
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 793, in __call__
    raise exception
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 766, in __call__
    self.render_content(self.call_function(input_parameters), context, request, response, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 703, in call_function
    return self.interface(**parameters)
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 100, in __call__
    return __hug_internal_self._function(*args, **kwargs)
  File "api/server.py", line 111, in parse
    json.append(doc2json(doc, model))
  File "api/server.py", line 51, in doc2json
    } for sent in doc.sents]
  File "api/server.py", line 48, in <listcomp>
    sents = [{
  File "doc.pyx", line 535, in __get__
ValueError: [E030] Sentence boundaries unset. You can add the 'sentencizer' component to the pipeline with: nlp.add_pipe(nlp.create_pipe('sentencizer')) Alternatively, add the dependency parser, or set sentence boundaries by setting doc[i].is_sent_start.

If I had to guess, it seems related to the fact that the xx model does not do syntax parsing.

Is xx supposed to work? Or am I doing something wrong?
The other models load fine.

spacy info

Info about spaCy

spaCy version      2.0.18         
Location           /usr/local/lib/python3.7/site-packages/spacy
Platform           Darwin-18.2.0-x86_64-i386-64bit
Python version     3.7.2          
Models             pt, es, en, xx 

node -v
v10.15.2

TypeError: process_response() takes 4 positional arguments but 5 were given

ERROR:waitress:Exception while serving /parse
Traceback (most recent call last):
  File "/home/shamoon/.local/share/virtualenvs/olive-ml-W0P_C03Z/lib/python3.6/site-packages/waitress/channel.py", line 356, in service
    task.service()
  File "/home/shamoon/.local/share/virtualenvs/olive-ml-W0P_C03Z/lib/python3.6/site-packages/waitress/task.py", line 176, in service
    self.execute()
  File "/home/shamoon/.local/share/virtualenvs/olive-ml-W0P_C03Z/lib/python3.6/site-packages/waitress/task.py", line 447, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/shamoon/.local/share/virtualenvs/olive-ml-W0P_C03Z/lib/python3.6/site-packages/hug/api.py", line 497, in api_auto_instantiate
    return module.__hug_wsgi__(*args, **kwargs)
  File "falcon/api.py", line 289, in falcon.api.API.__call__
  File "falcon/api.py", line 286, in falcon.api.API.__call__
TypeError: process_response() takes 4 positional arguments but 5 were given

`punycode` module is deprecated

If I install (locally), a subfolder called spacy is generated with its modules, an outdated one.

spacy-js/node_modules/whatwg-url

node_modules/spacy/node_modules/whatwg-url/lib/url-state-machine.js:2:18

const punycode = require("punycode");

If I replace the folder manually the error is fixed.

Full error:

npm install spacy

added 5 packages in 815ms
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> 
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> require("spacy")
{
  Doc: [Getter],
  Token: [Getter],
  Span: [Getter],
  default: { load: [Function: load] }
}
> (node:522363) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:104:7)
    at Module._load (node:internal/modules/cjs/loader:999:17)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/mnt/sda2/otro/js/spacy-js/node_modules/whatwg-url/lib/url-state-machine.js:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)

(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 
 ~/Desktop/otro/js/spacy-js 
npm install whatwg-url

added 4 packages, changed 3 packages, and audited 10 packages in 10s

found 0 vulnerabilities
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> require("spacy")
{
  Doc: [Getter],
  Token: [Getter],
  Span: [Getter],
  default: { load: [Function: load] }
}
> (node:522527) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:104:7)
    at Module._load (node:internal/modules/cjs/loader:999:17)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/mnt/sda2/otro/js/spacy-js/node_modules/node-fetch/node_modules/whatwg-url/lib/url-state-machine.js:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)

(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 
 ~/Desktop/otro/js/spacy-js 
npm install node-fetch

added 9 packages, removed 3 packages, changed 1 package, and audited 16 packages in 6s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> require("spacy")
{
  Doc: [Getter],
  Token: [Getter],
  Span: [Getter],
  default: { load: [Function: load] }
}
> (node:522554) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:104:7)
    at Module._load (node:internal/modules/cjs/loader:999:17)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/mnt/sda2/otro/js/spacy-js/node_modules/spacy/node_modules/whatwg-url/lib/url-state-machine.js:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)

(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 
 ~/Desktop/otro/js/spacy-js 
ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules/whatwg-url
'node_modules/spacy/node_modules/whatwg-url/whatwg-url' -> '../../../whatwg-url'
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> require("spacy")
{
  Doc: [Getter],
  Token: [Getter],
  Span: [Getter],
  default: { load: [Function: load] }
}
> (node:522601) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:104:7)
    at Module._load (node:internal/modules/cjs/loader:999:17)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/mnt/sda2/otro/js/spacy-js/node_modules/spacy/node_modules/whatwg-url/lib/url-state-machine.js:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)

(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 
 ~/Desktop/otro/js/spacy-js 
ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules
ln: node_modules/spacy/node_modules/whatwg-url: no se puede sobreescribir un directorio
 ~/Desktop/otro/js/spacy-js 
rm && node_modules/spacy/node_modules/w ; ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules
webidl-conversions/ whatwg-url/         
 ~/Desktop/otro/js/spacy-js 
rm && node_modules/spacy/node_modules/whatwg-url && ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules
rm: falta un operando
Pruebe 'rm --help' para más información.
 ~/Desktop/otro/js/spacy-js 
rm node_modules/spacy/node_modules/whatwg-url && ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules
rm: no se puede borrar 'node_modules/spacy/node_modules/whatwg-url': Es un directorio
 ~/Desktop/otro/js/spacy-js 
rm -rvf node_modules/spacy/node_modules/whatwg-url && ln -svfr node_modules/whatwg-url node_modules/spacy/node_modules
'node_modules/spacy/node_modules/whatwg-url/README.md' borrado
'node_modules/spacy/node_modules/whatwg-url/LICENSE.txt' borrado
'node_modules/spacy/node_modules/whatwg-url/lib/URL-impl.js' borrado
'node_modules/spacy/node_modules/whatwg-url/lib/public-api.js' borrado
'node_modules/spacy/node_modules/whatwg-url/lib/URL.js' borrado
'node_modules/spacy/node_modules/whatwg-url/lib/url-state-machine.js' borrado
'node_modules/spacy/node_modules/whatwg-url/lib/utils.js' borrado
removed directory 'node_modules/spacy/node_modules/whatwg-url/lib'
'node_modules/spacy/node_modules/whatwg-url/package.json' borrado
removed directory 'node_modules/spacy/node_modules/whatwg-url'
'node_modules/spacy/node_modules/whatwg-url' -> '../../whatwg-url'
 ~/Desktop/otro/js/spacy-js 
node --trace-deprecation
Welcome to Node.js v21.7.2.
Type ".help" for more information.
> require("spacy")
{
  Doc: [Getter],
  Token: [Getter],
  Span: [Getter],
  default: { load: [Function: load] }
}
> 
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 

How to import Matcher

I need to work with token-based matching, but
require(‘spacy.matcher’)
or
require(‘matcher’)
both give me an error.
So how can I use spacy matcher with spacy-js?

Error fetching data from API: http://localhost:8080

Unless I've set up the server incorrectly, it seems as though there's a bug accessing the server. Running python api/server.py loads the model and says that the server works, but running the example js code gives the error in the title. I've tried upgrading the pip packages to their latest versions, but this causes python api/server.py command to fail.

This might be a waitress error since the stack trace suggests
ERROR:waitress:Exception while serving /parse
...
TypeError: process_response() takes 4 positional arguments but 5 were given

Feature: Add TypeScript support

description

Currently, Spacy.js does not have official Typescript support, making it difficult for developers using Typescript to integrate Spacy.js into their projects.

The addition of Typescript support would greatly improve the developer experience and make it easier to use Spacy.js in Typescript projects.

Does anybody know how to deploy spacy-js server with node.js/express web app on heroku?

So the spacy-js server specifically runs on port 8080, and I don't know whether heroku will recognize this port. My spacy-js is currently in node_modules, with all my other modules installed through npm. My web app works perfectly locally but the app keeps crashing on heroku. Does anyone have any tips or method to deploy the spacy-js server with the node.js/express web app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.