【AI 得学啊】makemore 02:用 MLP 构建字符级语言模型
本文承接上一篇 makemore 01。为便于单独运行,下文代码默认已执行下面的公共初始化;姓名数据集可从课程仓库的 names.txt 获取。 1 2 3 4 5 6 7 8 9 import torch import torch.nn.functional as F import matplotlib.pyplot as plt words = open("names.txt", "r").read().splitlines() chars = sorted(set("".join(words))) stoi = {s: i + 1 for i, s in enumerate(chars)} stoi["."] = 0 itos = {i: s for s, i in stoi.items()} N-gram 模型的局限性 上一节虽然我们使用神经网络代替了基于统计的 N-gram 模型实现,但其预测结果依然不够理想。 ...