我正在尝试使用 Jupyter 笔记本创建聊天机器人,当我运行脚本时出现此错误;
block 引用>WARNING:tensorflow:From C:\Users\ASUS\anaconda3\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term
我不知道如何解决这个问题。我的代码是:
import nltk from nltk.stem.lancaster import LancasterStemmer stemmer = LancasterStemmer() import numpy import tflearn import tensorflow import random import json with open("D:\intents.json") as file: data = json.load(file) words = [] labels = [] docs_x = [] docs_y = [] for intent in data["intents"]: for pattern in intent["patterns"]: wrds = nltk.word_tokenize(pattern) words.extend(wrds) docs_x.append(wrds) docs_y.append(intent["tag"]) if intent["tag"] not in labels: labels.append(intent["tag"]) words = [stemmer.stem(w.lower()) for w in words if w != "?"] words = sorted(list(set(words))) labels = sorted(labels) training = [] output = [] out_empty = [0 for _ in range(len(labels))] for x, doc in enumerate(docs_x): bag = [] wrds = [stemmer.stem(w.lower()) for w in doc] for w in words: if w in wrds: bag.append(1) else: bag.append(0) output_row = out_empty[:] output_row[labels.index(docs_y[x])] = 1 training.append(bag) output.append(output_row) training = numpy.array(training) output = numpy.array(output)
最佳答案
当您使用旧版本的 Tensrflow(例如 1.x)或者您使用自动化从 Tensrflow 1.x
迁移到 Tensorflow 2.x
时,通常会出现此警告脚本。
如果您使用的是 Tensorflow 1.x
,可以考虑升级到 Tensorflow 2.x
,因为它与旧版本相比有很多性能优势,并且会很稳定从长远来看。
在 Tensorflow 2.x 中,使用 tf.Variable 默认创建一个 Resource 变量,并且默认启用急切执行。
出现警告 tf.compat.v1.disable_resource_variables()
已贬值,您可以在 tf.get_variable()
中提及 use_resource= False
code> 当 Tensorflow 2.x
中默认启用急切执行时,该值将被强制为 true。
关于python - 长期不支持非资源变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65782933/