def test_check_consistent_bilou_tagging( tags: List[Text], expected_tags: List[Text], debug_message: Optional[Text], caplog: LogCaptureFixture, ): with caplog.at_level(logging.DEBUG): actual_tags = bilou_utils.ensure_consistent_bilou_tagging(tags) if debug_message: assert len(caplog.records) > 0 assert debug_message in caplog.text else: assert len(caplog.records) == 0 assert actual_tags == expected_tags
def _tag_confidences( self, tokens: List[Token], predictions: Dict[Text, List[Dict[Text, float]]] ) -> Tuple[Dict[Text, List[Text]], Dict[Text, List[float]]]: """Get most likely tag predictions with confidence values for tokens.""" tags = {} confidences = {} for tag_name, predicted_tags in predictions.items(): if len(tokens) != len(predicted_tags): raise Exception( "Inconsistency in amount of tokens between crfsuite and message" ) _tags, _confidences = self._most_likely_tag(predicted_tags) if self.component_config[BILOU_FLAG]: _tags = bilou_utils.ensure_consistent_bilou_tagging(_tags) confidences[tag_name] = _confidences tags[tag_name] = _tags return tags, confidences