decodeEmbedding function
Decodes one embedding head: its float values or its scalar-quantized bytes, as typed arrays or JSON lists.
Implementation
Embedding decodeEmbedding(Map<Object?, Object?> json) => Embedding(
floatEmbedding: switch (json['floatEmbedding']) {
final Float32List values => values,
final List values => Float32List.fromList([
for (final value in values) (value as num).toDouble(),
]),
_ => null,
},
quantizedEmbedding: switch (json['quantizedEmbedding']) {
final Uint8List values => values,
final List values => Uint8List.fromList([
for (final value in values) (value as num).toInt(),
]),
_ => null,
},
headIndex: (json['headIndex'] as num?)?.toInt() ?? 0,
headName: decodeLabel(json['headName']),
);