Sei sulla pagina 1di 18

No.

URL Method Input Parameters


1 api/tags/{id} POST RequestBody: CreateTagRequest
{"description": ""}
PathVariable: id

2 api/tags/{id}/train POST RequestBody: TrainTagRequest


{}
PathVariable: id
RequestParam: limit
RequestParam: balanced

3 api/tags/train POST RequestBody: TrainAllRequest


{}
RequestParam: limit
RequestParam: balanced
4 api/tags/{id}/traininfo GET RequestParam: param
PathVariable: id

5 api/tags/{id}/has POST RequestBody: EvaluateTagForDocumentRequest


{"body": ""}
PathVariable: id

RequestParam: threshold
RequestBody: EvaluateDocumentRequest
6 api/tags/ POST {"body": ""}
RequestParam: pagesize
RequestParam: page
RequestParam: sort (id/created/name/last_label_change)
RequestParam: contains
7 api/tags/ GET RequestParam: order (asc, desc)

RequestBody: CreateLabelRequest
{"body": "",
"value": 0.0,
"title": "",
"meta": "",
"externalId": ""}
8 api/tags/{id}/labels POST PathVariable: id

RequestBody: AddLabelRequest
{"value": 0.0,
"externalId": ""}
9 api/tags/{id}/labeldocument POST PathVariable: id

RequestBody: AddLabelsRequest
{ "labels": {
"entry": [
{
"key": "",
"value": 0.0
}
]
}
}
10 api/tags/{id}/labeldocuments POST PathVariable: id
11 api/tags/{id}/labels GET PathVariable: id
Output Description
HttpStatus.CREATED (201, "Created") API to create a new Tag Object into
database

HttpStatus.OK (200, "OK") API that training a list of Label as data


with a specific algorithm

HttpStatus.OK (200, "OK") API that training a list of Label from a


list all of tag stored in database as
data with a specific algorithm
HttpStatus.NOT_FOUND (404, "Not Found") Getting training information in
HttpStatus.OK (200, "OK") with body as Database from tag name
TrainInfo:
{"lastTrained": "2019-08-12",
"lastChanged": "2019-08-12",
"statistics": "",
"training": true}

HttpStatus.NOT_FOUND (404, "Not Found")


HttpStatus.OK (200, "OK") with body as
Evaluation:
{"tagName": "",
"isClass": true,
"score": 0.0,
"positiveScore": 0.0,
"negativeScore": 0.0}

HttpStatus.OK (200, "OK") with body as List of


Evaluation
HttpStatus.OK (200, "OK") with body as Page of
Tag:
{"totalRows": 10,
"pageNumber": 1,
"totalPages": 1,
"count": 1;
"rows": [
{"id": 1,
"created": "2019-08-12"
"name": "",
"description": "",
"lastLabelChanged": "2019-08-12",
"modelDescription": ""}
]
}

HttpStatus.CREATED (201, "Created")

HttpStatus.CREATED (201, "Created")

HttpStatus.CREATED (201, "Created")


HttpStatus.OK (200, "OK") with body as List of
Label:
{"id": 1,
"label": 0.0,
"sampleId": 1;
"sampleTitle": "",
"sample":
{"id": 1,
"title": "",
"body" : "",
"meta": "",
"language": "EN"},
"tagId": 1,
"tagName": ""}
Business logic
call method createTag(String name,CreateTagRequest request)
Step 1: Create new Tag Object with basic fields(name, description,created,lastLabelChanged).
Step 2: Call TagRepository service with create method and save it into database.

call method trainTag(String tagName, String type, Integer limit, Boolean balanced)
Step1: Get a list of Label from tagName param.
-> Select * from Label where Tag.name = "tagName";
Step2: Check that if(limit != null || balanced) == true
-> truncate data from list of Label from #Step1. (spilt data set into negative and positive
with the same size limited by the limit param to perform the training process.)
Step3: Create instance of Tag by tagName param got from database.
-> Select * from Tag whe name = "tagName";
Step4: Create new TagBinaryClassifier instance and call method
createBinaryClassifierForTagName(tagName, trainingData, ClassifierType.DL4J_MLP)
-> Create new ClassifierType instance as param passed and set BatchSize, Epochs (control
how the algorithm work through and evaluate the entire training dataset)
-> Call method setTrainingData(trainingData) by classifier instance.(setup step for our
training dataset before train)
-> call method train by classifier as long as training dataset size.
Step5: Set classifier into Tag object and save it into database

call method trainAll(TrainAllRequest request, Integer limit, Boolean balanced)


Step1: Get all of Tag from database as a list
Step2: Make a for loop and call trainTag(String tagName, String type, Integer limit, Boolean
balanced) as one by one Tag from list
Call method trainInfoForTag(id, param) in TagService
Step 1: get Tag object in DB by id
select t.* from tags t where t.name=?id
If there is no result in step#1, then return NULL. If not, go to step#2

Step 2: get Training object in DB by tagId in step#1


select tr.* from trainings tr where tr.tag_id = ?tagId order by started desc limit 1
If there is no result in step#2, then return NULL. If not, go to step#3

Step 3: create TrainInfo with values:


lastChanged = tag.getLastLabelChanged()
training = (training.getCompleted() == null) || training.getStarted().after(completed)
lastTrained = training.getCompleted()
statistics = training.getStatistics()

Step 4:
If NULL is returned, then return HttpStatus.NOT_FOUND
If TrainInfo in step#3 is returned, then return HttpStatus.OK with body
Step 1: validate request body
If it is missing, then return ApiRequiredFieldIsMissingException
Step 2: Call method evaluateTag(id, requestBody) in TagService
Step 2.1: Get TagBinaryClassifier from tagName (id in URL)
Step 2.2: get Tag object in existing map(binaryClassifierMap) or DB by tagName
select t.* from tags t where t.name=?tagName
Step 2.3: If classifier in step#2.1 is NULL, then get classifier from Tag in step 2.2
deserialize Classifier from tag.getModel()
set tokenizerFactory for classifier
store
Note

truncate ->this mean we have to prepare


data before training for our tag, because
we should only need a smaller
representative sample of the selected data
that may be much faster for exploring and
prototyping solutions before considering
the whole dataset
batchSize and epochs -> The batch size is a
hyperparameter that defines the number
of samples to work through before
updating the internal model parameters.
The number of epochs is a hyperparameter
that defines the number times that the
learning algorithm will work through the
entire training dataset
TODO
Overview
Model
Repository
Overview

Potrebbero piacerti anche