报错详情:
p15_rnn_onehot_1pre1.py 报错AttributeError: ‘NoneType’ object has no attribute ‘dtype’
问题描述:
在观看北大曹建老师的TensorFlow2笔记视频,涉及class6中代码报错,查阅好心人解决,现记录如下,源代码:
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Dense, SimpleRNN
import matplotlib.pyplot as plt
import os
input_word = "abcde"
w_to_id = {
'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4} # 单词映射到数值id的词典
id_to_onehot = {
0: [1., 0., 0., 0., 0.], 1: [0., 1., 0., 0., 0.], 2: [0., 0., 1., 0., 0.], 3: [0., 0., 0., 1., 0.],
4: [0., 0., 0., 0., 1.]} # id编码为one-hot
x_train = [id_to_onehot[w_to_id