Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kootenpv/spacy_api
Server/Client around Spacy to load spacy only once
https://github.com/kootenpv/spacy_api
api machine-learning nlp spacy
Last synced: 3 months ago
JSON representation
Server/Client around Spacy to load spacy only once
- Host: GitHub
- URL: https://github.com/kootenpv/spacy_api
- Owner: kootenpv
- Created: 2017-03-19T09:31:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-17T11:27:51.000Z (almost 7 years ago)
- Last Synced: 2024-10-01T14:50:04.295Z (3 months ago)
- Topics: api, machine-learning, nlp, spacy
- Language: Python
- Size: 37.1 KB
- Stars: 46
- Watchers: 5
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## spacy_api
Helps with loading models in a separate, dedicated process.
Caching happens on unique arguments.
#### Features
- ✓ Serve models separately
- ✓ Client- and Server-side caching
- ✓ CLI interface### Install
Should work with py2 and py3.
Assumes you have installed `spacy`.
Install:
pip install spacy_api[all]
### Example
Run the server:
spacy serve
Then open a python process and run code in the next section.
#### Single document
```python
from spacy_api import Clientspacy_client = Client() # default args host/port
doc = spacy_client.single("How are you")
doc
# [[How, are, you]]# iterate over sentences
for sentence in doc.sents:
for token in sentence:
print(token.text, token.pos_, token.lemma_)# iterate over a whole document
for token in doc:
print(token)
```#### Switch to running spacy within the process
Instead of
from spacy_api import Client
use
from spacy_api import LocalClient
#### Arguments
LocalClient/Client:
```python
# language/model
spacy_client = Client(model="en")# Using google pretrained vectors
spacy_client = Client(embeddings_path="en_google")
```To make a call:
```python
# Tell spacy which attributes to give back, comma separated
spacy_client.single("How are you", attributes="text,lemma_,pos,vector")
```Naturally, you can use any combination of these.
#### Bulk of documents
```python
docs = spacy_client.bulk(["How are you"]*100)
for doc in docs:
for sentence in doc.sents:
for token in sentence:
print(token.text, token.pos_, token.lemma_)```