Zeroshot Classifier
The Zeroshot classifier is a tool allowing to classify a document according to classes defined in configuration file This tools is a rest service. Tokenization depends on annotation model created by the tool stored in tkeir/thot/tasks/tokenizer/createAnnotationResouces.py This tools allows to create typed compound word list.
Zeroshot Classifier API
Zeroshot Classifier configuration
Example of Configuration:
{
"logger": {
"logging-level": "{{ project.loglevel }}"
},
"zeroshot-classification": {
"settings":{
"language":"en",
"use-cuda":false,
"cuda-device":0,
"model-path-or-name":"{{ project.path }}/resources/modeling/net"
},
"classes":[
{"label":"machine learning", "content":["machine learning","machine learning model", "bias metric","feature selection","data science"]},
{"label":"deep learning", "content":["deep learning","hidden layer","loss function", "neural network", "convolutional neural network", "perceptron"]},
{"label":"reinforcement learning", "content":["reinforcement learning","learning policy", "learning state", "advantage function","agent"]},
{"label":"robotic", "content":["robotic","robot","control engineering","cybernetics","haptic"]},
{"label":"computer vision", "content":["computer vision","images processing","anchor box","object detection","object segmentation"]},
{"label":"natural language processing", "content":["natural language processing","tagger","semantic","named entities","classification"]},
{"label":"internet of things", "content":["internet of things","devices","iot","embedded software","firmware","machine to machine"]},
{"label":"neuromorphic computing", "content":["neuromorphic computing","bio-inspired","personhood","human brain","biological computation"]}
],
"re-labelling-strategy":"max",
"network": {
"host":"0.0.0.0",
"port":10010,
"associate-environment": {
"host":"CLASSIFICATION_HOST",
"port":"CLASSIFICATION_PORT"
}
},
"runtime":{
"request-max-size":100000000,
"request-buffer-queue-size":100,
"keep-alive":true,
"keep-alive-timeout":500,
"graceful-shutown-timeout":15.0,
"request-timeout":600,
"response-timeout":600,
"workers":1
}
}
}
Zeroshot Classifier is an aggreation of network configuration, serialize configuration, runtime configuration (in field converter), logger (at top level). The zeroshot-classification configuration is a table containing classes configuration:
- settings/language: define classifier language [en | fr]
- settings/use-cuda: use cuda device
- settings/cuda-device: device number (multiple graphic cards)
- [classes]/label: label of classes
- [classes]/content: possible value for the classe (can view view as synonyms or sublasses)
- re-labelling-strategy : * sum : master class is the sum of the scores of subclasses (synonyms) * mean : master class is the mean of the scores of subclasses (synonyms) * max : master class is the max of the scores of subclasses (synonyms)
Configure classifier logger
Logger is configuration at top level of json in logger field.
Example of Configuration:
The logger fields is:
- logging-level
It can be set to the following values:
- debug for the debug level and developper information
- info for the level of information
- warning to display only warning and errors
- error to display only error
- critical to display only error
Configure classifier Network
Example of Configuration:
{
"network": {
"host":"0.0.0.0",
"port":8080,
"associate-environment": {
"host":"HOST_ENVNAME",
"port":"PORT_ENVNAME"
},
"ssl":
{
"certificate":"path/to/certificate",
"key":"path/to/key"
}
}
}
The network fields:
-
host : hostname
-
port : port of the service
-
associated-environement : is the "host" and "port" associated environment variables that allows to replace the default one. This field is not mandatory.
-
"host" : associated "host" environment variable
-
"port" : associated "port" environment variable
-
ssl : ssl configuration IN PRODUCTION IT IS MANDATORY TO USE CERTIFICATE AND KEY THAT ARE *NOT* SELF SIGNED
-
cert : certificate file
- key : key file
Configure classifier runtime
Example of Configuration:
{
"runtime":{
"request-max-size":100000000,
"request-buffer-queue-size":100,
"keep-alive":true,
"keep-alive-timeout":5,
"graceful-shutown-timeout":15.0,
"request-timeout":60,
"response-timeout":60,
"workers":1
}
}
The Runtime fields:
-
request-max-size : how big a request may be (bytes)
-
request-buffer-queue-size: request streaming buffer queue size
-
request-timeout : how long a request can take to arrive (sec)
-
response-timeout : how long a response can take to process (sec)
-
keep-alive: keep-alive
-
keep-alive-timeout: how long to hold a TCP connection open (sec)
-
graceful-shutdown_timeout : how long to wait to force close non-idle connection (sec)
-
workers : number of workers for the service on a node
-
associated-environement : if one of previous field is on the associated environment variables that allows to replace the default one. This field is not mandatory.
-
request-max-size : overwrite with environement variable
- request-buffer-queue-size: overwrite with environement variable
- request-timeout : overwrite with environement variable
- response-timeout : overwrite with environement variable
- keep-alive: overwrite with environement variable
- keep-alive-timeout: overwrite with environement variable
- graceful-shutdown_timeout : overwrite with environement variable
- workers : overwrite with environement variable
Zeroshot Classifier service
To run the command type simply from tkeir directory:
or if you install tkeir wheel:
A light client can be run through the command
python3 thot/zeroshotclassifier_client.py --config=<path to configuration file> --input=<input directory> --output=<output directory>
or if you install tkeir wheel:
tkeir-zeroshotclassifier-client.py --config=<path to configuration file> --input=<input directory> --output=<output directory>
Zeroshot Classifier Tests
The converter service come with unit and functional testing.
Zeroshot Classifier Unit tests
Unittest allows to test Zeroshot Classifier classes only.
python3 -m unittest thot/tests/unittests/TestZeroshotClassifierConfiguration.py
python3 -m unittest thot/tests/unittests/TestZeroshotClassifier.py