Skip to content

Commit

Permalink
fix: LSDV-5222: custom weights reset following labeling interface cha…
Browse files Browse the repository at this point in the history
…nges (HumanSignal#4611)

* feat: LSDV-5222: Add ids to labels to allow for persistence of custom label weights when changing label names

* Revert changes related to using a label id and add fix for resetting labels set to 0

* Update get_label so it doesn't have to be called twice in comprehension

* Update so overall section is also covered when it is set to 0

* Fix fetching of overall weight as there are subtle issues with the default values
  • Loading branch information
dredivaris authored and Jalal Tabatabaee committed Sep 19, 2023
1 parent c2ec9cc commit 68a2d0a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions label_studio/projects/models.py
Expand Up @@ -589,14 +589,29 @@ def get_updated_weights(self):
outputs = self.get_parsed_config(autosave_cache=False)
control_weights = {}
exclude_control_types = ('Filter',)

def get_label(label):
label_value = self.control_weights.get(control_name, {}).get('labels', {}).get(label)
return label_value if label_value is not None else 1.0

def get_overall(name):
weights = self.control_weights.get(name, None)
if not weights:
return 1.0
else:
weight = weights.get('overall', None)
return weight if weight is not None else 1.0


for control_name in outputs:
control_type = outputs[control_name]['type']
if control_type in exclude_control_types:
continue

control_weights[control_name] = {
'overall': self.control_weights.get(control_name, {}).get('overall') or 1.0,
'overall': get_overall(control_name),
'type': control_type,
'labels': {label: self.control_weights.get(control_name, {}).get('labels', {}).get(label) or 1.0 for label in outputs[control_name].get('labels', [])},
'labels': {label: get_label(label) for label in outputs[control_name].get('labels', [])},
}
return control_weights

Expand Down

0 comments on commit 68a2d0a

Please sign in to comment.