Skip to content

Commit

Permalink
Add unlabel functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmCyan committed Aug 21, 2023
1 parent 921f6aa commit 98820e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Index searching to data manager.
* Search highlighting in data manager.
* "Unlabel" option to remove previously labeled data from training set.

### Fixed
* Data column sorting not working.
* Needing to render the notebook's first model view cell twice for ipyvuetify
stylesheets to propagate.
stylesheets to propagate. (Use `icat.initialize()` now, instead of
`pn.extension()`)



Expand Down
1 change: 1 addition & 0 deletions icat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def _handle_ipv_search_cleared(self, widget, event, data):
self.search_value = ""
self.search_box.success = False
self.search_box.error = False
self.search_box.label = "Search (use 'ID:X' to search index)"

def _handle_row_selected(self, point_id):
"""Event handler from table row select."""
Expand Down
28 changes: 11 additions & 17 deletions icat/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def __init__(
self.anchor_list.build_tfidf_features()

def _on_data_label(self, index: int | list[int], new_label: int | list[int]):
"""Event handler for datamanager."""
"""Event handler for datamanager.
if a -1 is passed for (or in the list of) new_label, remove it from the
training data, if found.
"""

# expand a single value pass to list for consistent handling below
if type(index) != list:
Expand All @@ -98,22 +102,12 @@ def _on_data_label(self, index: int | list[int], new_label: int | list[int]):
]
)

# update if it's a row that's already in the training data
# elif (
# index in self.training_data.index
# and self.training_data.loc[index, self.data.text_col]
# == self.data.active_data.loc[index, self.data.text_col]
# ):
# self.training_data.at[index, self.data.label_col] = new_label

# else:
# self.training_data = pd.concat(
# # self.training_data, pd.DataFrame(self.data.active_data[index, :])
# [
# self.training_data,
# pd.DataFrame([self.data.active_data.loc[index, :]]),
# ]
# )
# Remove any rows from the resulting table where the label_col is "-1", indicating an
# unlabelling operation
self.training_data = self.training_data.drop(
self.training_data[self.training_data[self.data.label_col] == -1].index
)

# note that we don't call fit because we don't need to re-featurize, only a label has changed
self._train_model()
self.view.refresh_data()
Expand Down
7 changes: 7 additions & 0 deletions icat/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def vue_applyAbsoluteLabelInteresting(self, point_id):
for callback in self._apply_label_callbacks:
callback(point_id, 1)

def vue_applyAbsoluteLabelUnlabeled(self, point_id):
for callback in self._apply_label_callbacks:
callback(point_id, -1)

def vue_addToExampleAnchor(self, point_id):
for callback in self._add_example_callbacks:
callback(point_id)
Expand Down Expand Up @@ -152,6 +156,9 @@ def _template(self):
<span>Add this instance to the current sample set.</span>
</v-tooltip>
<div v-html="item.labeled" />
<v-btn x-small v-if="item.labeled != ''" class="red darken-3" @click.stop="applyAbsoluteLabelUnlabeled(item.id)">
unlabel
</v-btn>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 98820e9

Please sign in to comment.