def from_protobuf( cls: "NLPMetrics", message: NLPMetricsMessage, ): nlp_met = NLPMetrics() nlp_met.wer = NumberTracker.from_protobuf(message.wer) nlp_met.wil = NumberTracker.from_protobuf(message.wil) nlp_met.mer = NumberTracker.from_protobuf(message.mer) return nlp_met
def test_merge(): x = NumberTracker() for v in [10, 11, 13]: x.track(v) merged = x.merge(x) assert merged.ints.count == 6 assert merged.floats.count == 0 assert merged.histogram.get_n() == 6 assert merged.histogram.get_max_value() == 13.0 assert merged.histogram.get_min_value() == 10.0 msg = merged.to_protobuf() NumberTracker.from_protobuf(msg)
def test_merge(): x = NumberTracker() for v in [10, 11, 13]: x.track(v) merged = x.merge(x) assert merged.ints.count == 6 assert merged.floats.count == 0 assert merged.histogram.get_n() == 6 assert merged.histogram.get_max_value() == 13.0 assert merged.histogram.get_min_value() == 10.0 expected_freq = [ (10, 2, 2, 2), (11, 2, 2, 2), (13, 2, 2, 2), ] compare_frequent_items(expected_freq, merged.frequent_numbers.get_frequent_items()) msg = merged.to_protobuf() NumberTracker.from_protobuf(msg)
def test_protobuf_roundtrip(): x0 = NumberTracker() for v in [10, 11, 13]: x0.track(v) msg = x0.to_protobuf() roundtrip = NumberTracker.from_protobuf(msg) assert x0.ints.count == roundtrip.ints.count assert x0.floats.count == roundtrip.floats.count assert x0.histogram.get_n() == roundtrip.histogram.get_n() assert x0.histogram.get_min_value() == roundtrip.histogram.get_min_value() assert x0.histogram.get_max_value() == roundtrip.histogram.get_max_value()
def from_protobuf(message): """ Load from a protobuf message Returns ------- column_profile : ColumnProfile """ return ColumnProfile( message.name, counters=CountersTracker.from_protobuf(message.counters), schema_tracker=SchemaTracker.from_protobuf(message.schema), number_tracker=NumberTracker.from_protobuf(message.numbers), string_tracker=StringTracker.from_protobuf(message.strings), frequent_items=FrequentItemsSketch.from_protobuf( message.frequent_items), cardinality_tracker=HllSketch.from_protobuf( message.cardinality_tracker), )
def from_protobuf( cls, message: ScoreMatrixMessage, ): if message.ByteSize() == 0: return None labels = message.labels num_labels = len(labels) matrix = np.array( [NumberTracker.from_protobuf(score) for score in message.scores]).reshape( (num_labels, num_labels)) if num_labels > 0 else None cm_instance = ConfusionMatrix( labels=labels, prediction_field=message.prediction_field, target_field=message.target_field, score_field=message.score_field) cm_instance.confusion_matrix = matrix return cm_instance