forked from HumanSignal/label-studio-ml-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_model.py
46 lines (37 loc) · 1.59 KB
/
dummy_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
from label_studio_ml.model import LabelStudioMLBase
class DummyModel(LabelStudioMLBase):
def __init__(self, **kwargs):
super(DummyModel, self).__init__(**kwargs)
# pre-initialize your variables here
from_name, schema = list(self.parsed_label_config.items())[0]
self.from_name = from_name
self.to_name = schema['to_name'][0]
self.labels = schema['labels']
def predict(self, tasks, **kwargs):
""" This is where inference happens:
model returns the list of predictions based on input list of tasks
:param tasks: Label Studio tasks in JSON format
"""
results = []
for task in tasks:
results.append({
'result': [{
'from_name': self.from_name,
'to_name': self.to_name,
'type': 'choices',
'value': {
'choices': [random.choice(self.labels)]
}
}],
'score': random.uniform(0, 1)
})
return results
def fit(self, completions, workdir=None, **kwargs):
""" This is where training happens: train your model given list of completions,
then returns dict with created links and resources
:param completions: aka annotations, the labeling results from Label Studio
:param workdir: current working directory for ML backend
"""
# save some training outputs to the job result
return {'random': random.randint(1, 10)}