脑脑之家AI智能体与大模型落地应用-知识点002-one hot编码
one-hot手把手代码实操
import torch# 假设我们有三个类别: 0, 1, 2
num_classes 3# 样本标签
labels torch.tensor([0, 2, 1, 0])# 将标签转换为 One-Hot 编码
one_hot_labels torch.nn.functional.one_hot(labels, num_classes)print("Labels:")
print(labels)
…
2026/8/9 2:26:24