MCPcopy
hub / github.com/RasaHQ/rasa / align_entity_predictions

Function align_entity_predictions

rasa/nlu/test.py:1125–1163  ·  view source on GitHub ↗

Aligns entity predictions to the message tokens. Determines for every token the true label based on the prediction targets and the label assigned by each single extractor. Args: result: entity evaluation result extractors: the entity extractors that should be consid

(
    result: EntityEvaluationResult, extractors: Set[Text]
)

Source from the content-addressed store, hash-verified

1123
1124
1125def align_entity_predictions(
1126 result: EntityEvaluationResult, extractors: Set[Text]
1127) -> Dict:
1128 """Aligns entity predictions to the message tokens.
1129
1130 Determines for every token the true label based on the
1131 prediction targets and the label assigned by each
1132 single extractor.
1133
1134 Args:
1135 result: entity evaluation result
1136 extractors: the entity extractors that should be considered
1137
1138 Returns: dictionary containing the true token labels and token labels
1139 from the extractors
1140 """
1141 true_token_labels = []
1142 entities_by_extractors: Dict[Text, List] = {
1143 extractor: [] for extractor in extractors
1144 }
1145 for p in result.entity_predictions:
1146 entities_by_extractors[p[EXTRACTOR]].append(p)
1147 extractor_labels: Dict[Text, List] = {extractor: [] for extractor in extractors}
1148 extractor_confidences: Dict[Text, List] = {
1149 extractor: [] for extractor in extractors
1150 }
1151 for t in result.tokens:
1152 true_token_labels.append(_concat_entity_labels(t, result.entity_targets))
1153 for extractor, entities in entities_by_extractors.items():
1154 extracted_labels = _concat_entity_labels(t, entities, {extractor})
1155 extracted_confidences = _get_entity_confidences(t, entities, {extractor})
1156 extractor_labels[extractor].append(extracted_labels)
1157 extractor_confidences[extractor].append(extracted_confidences)
1158
1159 return {
1160 "target_labels": true_token_labels,
1161 "extractor_labels": extractor_labels,
1162 "confidences": extractor_confidences,
1163 }
1164
1165
1166def _concat_entity_labels(

Calls 3

_concat_entity_labelsFunction · 0.85
_get_entity_confidencesFunction · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…