-
Notifications
You must be signed in to change notification settings - Fork 22
Model Server API
Lee Dong Ho edited this page Jul 24, 2019
·
17 revisions
AlpacaTag:
+ alpaca_client:
- __init__.py
- setup.py
- alpaca_server
- annotation
The best way to install the client is via setup.py install. move into alpaca_client directory and enter the command:
python setup.py install
Method | Description |
---|---|
.initiate(project_id) |
Model Initiate: If the model of same project id already exists in the directory, this method loads the model. If not, initiates the model |
.online_initiate(sentences, predefined_label) |
If the model is firstly initialized, it needs to make mappings of words, chars and labels to feature indices. (word_vocab, char_vocab, label_vocab) |
.online_learning(sentences, labels, epoch, batch) |
feeds annotated sentences into the model with specified epoch and batch size. |
.active_learning(sentences, acquire) |
Feeds the sentences into the model and get the most ambiguous instances by size of acquire |
.predict(sentences) |
Feeds the sentences and get the prediction |
from alpaca_serving.client import *
ac = AlpacaClient()
ac.initiate(1)
# 'MODEL INITIATED' if there is no existing model with same project_id = 1
# 'MODEL LOADED' if there is existing model with same project_id = 1
If 'MODEL INITIATED' appears, we should build word, label mappings before we use the model.
ac.online_initiate(sent,[['B-PER', 'I-PER', 'B-LOC', 'I-LOC', 'B-ORG', 'I-ORG', 'B-MISC', 'I-MISC', 'O']])
active_indices = ac.active_learning(sent, acquire=5)
active_sent = [sent[a_i] for a_i in active_indices]
active_label = [label[a_i] for a_i in active_indices]
ac.online_learning(active_sent,active_label, epoch=5, batch=5)
# 'Online learning completed'
ac.predict(‘New York and Paris’)
# {'words': ['Paris', 'and', 'New', 'York'], 'entities': [], 'tags': [['B-LOC', 'O', 'B-LOC', 'I-LOC']]}
It's because of resource overloaded in the server-side. Wait 2~3 seconds and Try request again.