【问题标题】:non-resource variables are not supported in the long term长期不支持非资源变量
【发布时间】:2021-01-18 22:28:57
【问题描述】:

我正在尝试使用 Jupyter 笔记本创建聊天机器人,但当我运行脚本时出现此错误;

警告:tensorflow:来自 C:\Users\ASUS\anaconda3\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables(来自 tensorflow.python.ops.variable_scope) 已弃用,将在未来版本中删除。指示 用于更新:long 中不支持非资源变量 术语

我不知道如何解决这个问题。我的代码是:

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)

【问题讨论】:

    标签: python tensorflow jupyter-notebook


    【解决方案1】:

    当您使用较旧版本的 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,当Tensorflow 2.x 默认启用急切执行时,这将被强制为true。

    【讨论】:

      【解决方案2】:

      正如“Tech with Tim”在他的视频Python Chat Bot Tutorial - Chatbot with Deep Learning 中提到的那样,他说:

      Python 3.7 包含错误。

      所以只需从官方Python website 安装 Python 3.6。

      【讨论】:

        猜你喜欢
        • 2018-12-24
        • 2011-10-04
        • 2011-06-29
        • 2023-03-22
        • 1970-01-01
        • 2014-06-07
        • 2011-12-11
        • 2017-03-14
        相关资源
        最近更新 更多