前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >深度学习:如何理解tensorflow文本蕴含的原理

深度学习:如何理解tensorflow文本蕴含的原理

作者头像
AiTechYun
发布2018-03-02 16:21:47
1.9K0
发布2018-03-02 16:21:47
举报
文章被收录于专栏:ATYUN订阅号ATYUN订阅号

文本的entailment(蕴涵)是一个简单的逻辑练习,用来判断一个句子是否可以从另一个句子推断出来。承担了文本的entailment任务的计算机程序,试图将一个有序的句子分类为三个类别中的一种。第一类叫做“positive entailment”,当你用第一个句子来证明第二个句子是正确的时候就会出现。第二个类别,“negative entailment”,是positive entailment的反面。当第一个句子被用来否定第二个句子时,就会出现这种情况。最后,如果这两个句子没有关联,那么它们就被认为是“neutral entailment”。

作为应用程序的一个组成部分,文本的entailment是有用的。例如,问答系统可以使用文本的entailment来验证存储信息的答案。文本的entailment也可以通过过滤不包含新信息的句子来增强文档的摘要。其他自然语言处理系统(NLP)也发现类似的应用。

本文将引导你了解如何构建一个简单快捷的神经网络来执行使用TensorFlow.的文本的entailment。

在我们开始之前

除了安装 TensorFlow version 1.0之外,还要确保安装:

Jupyter

Numpy

Matplotlib

为了在网络培训中获得更好的进步感,欢迎你安装 TQDM,但这不是必需的。请访问GitHub上的这篇文章的代码和Jupyter笔记本(链接为https://github.com/Steven-Hewitt/Entailment-with-Tensorflow)。我们将使用斯坦福的SNLI数据集来进行我们的训练,但是我们将使用Jupyter Notebook中的代码下载并提取我们需要的数据,所以你不需要手动下载它。如果这是你第一次使用TensorFlow,我建议你看看Aaron Schumacher的文章“Hello, Tensorflow”。

我们将从所有必要的输入开始,利用Jupyter Notebook在笔记本上显示图表和图像。

代码语言:js
复制
%matplotlib inline

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import urllib
import sys
import os
import zipfil

文本的entailment示例

在本节中,我们将通过一些文本entailment的例子来说明positive, negative和 neutral entailment。首先,我们来看看positive entailment——例如,当你读到“Maurita and Jade both were at the scene of the car crash”时,你可以推断“Multiple people saw the accident”。在这个例句中,我们可以用第一个句子(也称为“文本”)证明第二句(也称为“假设”),这代表是positive entailment。鉴于莫丽塔和杰德都看到车祸,说明有多人看到。注意:“车祸”和“事故”有相似的意思,但它们不是同一个词。事实上,entailment并不总是意味着句子里有相同的单词,就像在这句话中可以看到的相同的词只有“the”。

让我们考虑另一个句子对。“在公园里和老人一起玩的两只狗”推导出“那天公园里只有一只狗”。第一句话说有“两只狗”,那么公园至少要有两只狗,第二句话与这个观点相矛盾,所以是negative entailment。

最后,为了阐明neutral entailment,我们看“我和孩子们打棒球”和“孩子们爱吃冰淇淋”这两句话,打棒球和爱吃冰淇淋完全没有任何关系。我可以和冰淇淋爱好者打棒球,我也可以和不喜欢冰淇淋的人打棒球(两者都是可能的)。因此,第一句话没有说明第二句话的真实或虚假。

数字矢量化表示单词

对于神经网络来说,它们主要是处理数值。为了解决这个问题,我们需要用数字来表示我们的单词。理想情况下,这些数字意味着什么,例如,我们可以使用字母的字符编码一个词,但这并没有告诉我们任何关于它的意义(这意味着TensorFlow不得不做大量的工作来说明“dog”和“canine”是接近相同的概念)。将类似的意义转化为神经网络可以理解的过程,这个过程被称为矢量化。

创建 word vectorization的常用方法是让每个单词表示一个非常高维空间中的一个点。具有相似表示法的单词应该在这个空间中相对接近。例如,每种颜色都有一个通常与其他颜色非常相似的表示;这一点的演示在关于 word vectorization的TensorFlow教程中可以找到(链接地址是https://www.tensorflow.org/tutorials/word2vec)。

使用斯坦福的GloVe word vectorization+ SNLI数据集

为了我们的目的,我们不需要创建一个新的用数字表现形式。如果通用数据不够用,可以用已经存在的一些非常出色的通用矢量表示,以及用于培训更专业的材料的方法。

这篇文章的相关笔记本(链接地址为https://github.com/Steven-Hewitt/Entailment-with-Tensorflow)是为斯坦福的GloVe word vectorization的预先训练的数据(链接地址为http://nlp.stanford.edu/projects/glove/)而设计的。我们将使用60亿的Wikipedia 2014 + Gigaword 5向量,因为它是最小并且最容易下载的。我们将以编程方式下载该文件,运行它可能需要一段时间(这是一个相当大的文件)。

与此同时,我们收集我们的textual entailment数据集:斯坦福大学SNLI数据集。

代码语言:js
复制
glove_zip_file= "glove.6B.zip"
glove_vectors_file= "glove.6B.50d.txt"

snli_zip_file= "snli_1.0.zip"
snli_dev_file= "snli_1.0_dev.txt"
snli_full_dataset_file= "snli_1.0_train.txt"
from six.moves.url.lib.requestimport urlretrieve

#large file - 862 MB
if (not os.path.isfile(glove_zip_file)and
    not os.path.isfile(glove_vectors_file)):
    urlretrieve ("http://nlp.stanford.edu/data/glove.6B.zip",
                 glove_zip_file)

#medium-sized file - 94.6 MB
if (not os.path.isfile(snli_zip_file)and
    not os.path.isfile(snli_dev_file)):
    urlretrieve ("https://nlp.stanford.edu/projects/snli/snli_1.0.zip",
                 snli_zip_file)
def unzip_single_file(zip_file_name, output_file_name):
    """
        If the outFile is already created, don't recreate
        If the outFile does not exist, create it from the zipFile
    """
    if not os.path.isfile(output_file_name):
        withopen(output_file_name,'wb') as out_file:
            with zipfile.ZipFile(zip_file_name) as zipped:
                for infoin zipped.infolist():
                    if output_file_namein info.filename:
                        with zipped.open(info) as requested_file:
                            out_file.write(requested_file.read())
                            return

unzip_single_file(glove_zip_file, glove_vectors_file)
unzip_single_file(snli_zip_file, snli_dev_file)
# unzip_single_file(snli_zip_file, snli_full_dataset_file)

现在我们已经下载了GloVe 向量,我们可以将它们加载到内存中,将空间分隔的格式序列化为Python字典:

代码语言:js
复制
glove_wordmap= {}
withopen(glove_vectors_file,"r") as glove:
    for linein glove:
        name, vector= tuple(line.split(" ",1))
        glove_wordmap[name]= np.fromstring(vector, sep=" ")

一旦我们有了words,就需要我们的输入来包含整个句子,并通过一个神经网络来处理它。从制作这个序列开始:

代码语言:js
复制
def sentence2sequence(sentence):
    """

    - Turns an input sentence into an (n,d) matrix,
        where n is the number of tokens in the sentence
        and d is the number of dimensions each word vector has.

      Tensorflow doesn't need to be used here, as simply
      turning the sentence into a sequence based off our
      mapping does not need the computational power that
      Tensorflow provides. Normal Python suffices for this task.
    """
    tokens= sentence.lower().split(" ")
    rows= []
    words= []
    #Greedy search for tokens
    for tokenin tokens:
        i= len(token)
        while len(token) >0 and i >0:
            word= token[:i]
            if wordin glove_wordmap:
                rows.append(glove_wordmap[word])
                words.append(word)
                token= token[i:]
                i= len(token)
            else:
                i= i-1
    return rows, words

当计算机研究句子的时会看到什么

为了更好地理解word vectorization过程,以及看到计算机研究句子时所看到的东西,我们可以将这些向量表示为图像。使用notebook ,可视化自己的句子。每一行表示一个词,而列表示矢量化字的个体维度。矢量化是在根据与其他单词的关系进行训练的,实际上表示的含义是含糊不清的。计算机能理解这种向量语言,这是最重要的部分。一般来说,在相同的位置上包含相似颜色的两个向量表示单词在意义上相似。

代码语言:js
复制
def visualize(sentence):
    rows, words= sentence2sequence(sentence)
    mat= np.vstack(rows)

    fig= plt.figure()
    ax= fig.add_subplot(111)
    shown= ax.matshow(mat, aspect="auto")
    ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
    fig.colorbar(shown)

    ax.set_yticklabels([""]+words)
    plt.show()

visualize("The quick brown fox jumped over the lazy dog.")
visualize("The pretty flowers shone in the sunlight.")

与图像不同的是,句子有固有的顺序,不受大小的约束,所以我们需要一种新的网络类型,而不是完全连接前馈网络,因为前馈网络占据一个输入值并且只需运行到产生一个输出。而我们需要循环。

Vanilla循环网络

Recurrent neural networks(RNNs)是神经网络的一种序列学习工具。这种类型的神经网络只有一层的隐藏输入,它被重新用于序列中的每个输入,以及传递给下一个输入计算的“memory”。这些是用矩阵乘法计算的,其中矩阵索引是训练的权重,就像它们在完全连接的层中一样。

对序列中的每一个输入重复同样的计算,这意味着一个Recurrent neural networks的一个“层”可以被展开成许多层。事实上,将有与序列中的输入一样多的层。这使得网络能够处理一个非常复杂的句子。TensorFlow包含了它自己的一个简单RNN cell,BasicRNNCell的实现,它可以添加到你的TensorFlow中,如下图:

代码语言:js
复制
rnn_size= 64
rnn= tf.contrib.rnn.BasicRNNCell(rnn_size)

梯度消失问题

从理论上讲,网络将能够记住来自第一层的东西,更早的在句子中,甚至在句子的末尾。这种循环形式的主要问题是:在实践中,早期的数据完全被更新的输入和信息完全淹没,而这些输入和信息并不是那么重要。Recurrent neural networks,或者是带有标准隐藏单位的神经网络,在很长一段时间内都不能保持信息。这个故障被称为梯度消失问题。

最简单的方法就是通过示例可视化。在最简单的情况下,输入和“memory”大致相同。数据的第一个输入将影响第一个输出的大约一半(另一半是启动“memory”),第二次输出的四分之一,然后是第三输出的八分之一,等等。

这意味着我们不能使用vanilla循环网络,如果我们想要对这两个句子进行追踪。解决方案是使用不同类型的循环网络层。也许最简单的就是长短期记忆层,也就是LSTM。

利用LSTM

在LSTM中,代替计算当前储存器时每次都使用相同方式的输入(xt),网络可以通过“输入门”(it)决定当前值对储存器的影响程度做出一个决定,通过被命名为“忘记门”(ft)遗忘的存储器(ct)做出另外一个决定,根据储存器将某些部分通过“输出门”(ot)发送到下一个时间步长(ht)做第三个决定。

这三个门的组合创造了一个选择:一个单一的LSTM节点,可以将信息保存在长期储存器中,也可以将信息保存在短期储存器中,但同时不能同时进行。短期记忆LSTMs训练的是相对开放的输入门,让大量的信息进来,也经常忘记很多,而长期记忆LSTMs有紧密的输入门,只允许非常小的,非常具体的信息进入。这种紧密性意味着它不会轻易失去它的信息,允许更长的保存时间。

总的来说,LSTMs是非常神秘的。不同LSTM节点在同一个网络可能会有截然不同的门,彼此依赖,比如可能有短期门记住“not”这个词在句子“ohn did not go to the store”,当“go”这个词出现,长期门能记住“not go”,而不是“go”。当然,这是一个人为的例子,在实践中,这些关系非常复杂,以至于无法辨认。

为我们的网络定义常量

由于我们不打算在我们的网络中使用一个普通RNN层,所以我们会清除图表并添加一个LSTM层,默认情况下也包含TensorFlow。因为这将是我们实际网络的第一部分,定义我们需要的网络的所有常数:

代码语言:js
复制
#Constants setup
max_hypothesis_length, max_evidence_length= 30,30
batch_size, vector_size, hidden_size= 128,50,64

lstm_size= hidden_size

weight_decay= 0.0001

learning_rate= 1

input_p, output_p= 0.5,0.5

training_iterations_count= 100000

display_step= 10

def score_setup(row):
    convert_dict= {
      'entailment':0,
      'neutral':1,
      'contradiction':2
    }
    score= np.zeros((3,))
    for xin range(1,6):
        tag= row["label"+str(x)]
        if tagin convert_dict: score[convert_dict[tag]]+= 1
    return score/ (1.0*np.sum(score))

def fit_to_size(matrix, shape):
    res= np.zeros(shape)
    slices= [slice(0,min(dim,shape[e]))for e, dimin enumerate(matrix.shape)]
    res[slices]= matrix[slices]
    return res
def split_data_into_scores():
    import csv
    withopen("snli_1.0_dev.txt","r") as data:
        train= csv.DictReader(data, delimiter='\t')
        evi_sentences= []
        hyp_sentences= []
        labels= []
        scores= []
        for rowin train:
            hyp_sentences.append(np.vstack(
                    sentence2sequence(row["sentence1"].lower())[0]))
            evi_sentences.append(np.vstack(
                    sentence2sequence(row["sentence2"].lower())[0]))
            labels.append(row["gold_label"])
            scores.append(score_setup(row))

        hyp_sentences= np.stack([fit_to_size(x, (max_hypothesis_length, vector_size))
                          for xin hyp_sentences])
        evi_sentences= np.stack([fit_to_size(x, (max_evidence_length, vector_size))
                          for xin evi_sentences])

        return (hyp_sentences, evi_sentences), labels, np.array(scores)

data_feature_list, correct_values, correct_scores= split_data_into_scores()

l_h, l_e= max_hypothesis_length, max_evidence_length
N, D, H= batch_size, vector_size, hidden_size
l_seq= l_h+ l_e

我们还将重新设置图表,不包括我们之前添加的RNN单元,因为我们不会在这个网络中使用它:

代码语言:javascript
复制
tf.reset_default_graph()

有了这两种方法,我们就可以使用TensorFlow定义我们的LSTM,它的使用方式如下:

代码语言:javascript
复制
lstm= tf.contrib.rnn.BasicLSTMCell(lstm_size)

实现dropout正则化

如果我们只是简单地使用了LSTM层,而没有更多的东西,那么这个网络可能会读到很多关于普通的,但无关紧要的词,比如“a”、“the”、和“and”。如果一个句子使用“an animal”这个短语,而另一个句子使用“the animal”,即使这些短语指的是同一个对象,网络也可能错误地认为它已经找到了negative entailment。

为了解决这个问题,我们需要调整一下,看看个别单词最终是否对整体有重要意义,我们通过一个叫“dropout”的过程来实现。dropout是神经网络设计中的一种正则化模式,它围绕着随机选择的隐藏和可见的单位。随着神经网络的大小增加,用来计算最终结果的参数个数也随着增加,如果一次训练全部,每个参数都有助于过度拟合。为了规范这一点,在训练中随机抽取网络中包含的部分,并在训练时临时调零,在实际使用过程中,它们的输出被适当地缩放。

“标准”(即完全连接)层上的dropout也是有用的,因为它有效地训练了多个较小的网络,然后在测试时间内组合它们。机器学习中的一个常数使自己比单个模型更好的方法就是组合多个模型,并且 dropout 用于将单个神经网络转换为共享一些节点的多个较小的神经网络。

一个dropout 层有一个称为p的超参数,它仅仅是每个单元被保存在网络中进行迭代训练的概率。被保存的单位将其输出提供给下一层,而不被保存的单位则没有提供任何东西。下面是一个例子,展示了一个没有dropout的完全连接的网络和一个在迭代训练过程中dropout的完全连接的网络之间的区别:

用于复发层的Tensorflow的DropoutWrapper

dropout 在LSTM层的内部门上并没有特别好。某些关键记忆的丢失意味着,一阶逻辑所需的复杂关系很难与一个dropout形成,所以对于我们的LSTM层,我们将跳过在内部的门上的dropou,而不是在其他的东西上使用它。值得庆幸的是,这是Tensorflow的 DropoutWrapper对于循环层的默认实现。

代码语言:javascript
复制
lstm_drop=  tf.contrib.rnn.DropoutWrapper(lstm, input_p, output_p)

完成我们的模型

有了所有的解释,我们可以完成我们的模型。第一步是标记化,用我们的GloVe字典把两个输入的句子变成一个向量序列。由于我们不能有效地使用在LSTM中传递的信息,我们将使用从单词和最终输出的功能上的dropout,而不是在展开的LSTM网络部分的第一层和最后一层有效地使用dropout。

您可能注意到我们使用了一个双向RNN,它有两个不同的LSTM单元。这种形式的循环网络既向前又向后地运行输入数据,这使得网络既能够独立又能相互之间对假设和证据进行审查。

LSTMs最终的输出将被传递到一套完整的连接层,然后,我们将得到一个实值的分数表明每entailment的强度,我们用来选择最终结果,并确定我们的信心,结果。

代码语言:js
复制
# N: The number of elements in each of our batches,
#   which we use to train subsets of data for efficiency's sake.
# l_h: The maximum length of a hypothesis, or the second sentence.  This is
#   used because training an RNN is extraordinarily difficult without
#   rolling it out to a fixed length.
# l_e: The maximum length of evidence, the first sentence.  This is used
#   because training an RNN is extraordinarily difficult without
#   rolling it out to a fixed length.
# D: The size of our used GloVe or other vectors.
hyp= tf.placeholder(tf.float32, [N, l_h, D],'hypothesis')
evi= tf.placeholder(tf.float32, [N, l_e, D],'evidence')
y= tf.placeholder(tf.float32, [N,3],'label')
# hyp: Where the hypotheses will be stored during training.
# evi: Where the evidences will be stored during training.
# y: Where correct scores will be stored during training.

# lstm_size: the size of the gates in the LSTM,
#    as in the first LSTM layer's initialization.
lstm_back= tf.contrib.rnn.BasicLSTMCell(lstm_size)
# lstm_back:  The LSTM used for looking backwards
#   through the sentences, similar to lstm.

# input_p: the probability that inputs to the LSTM will be retained at each
#   iteration of dropout.
# output_p: the probability that outputs from the LSTM will be retained at
#   each iteration of dropout.
lstm_drop_back= tf.contrib.rnn.DropoutWrapper(lstm_back, input_p, output_p)
# lstm_drop_back:  A dropout wrapper for lstm_back, like lstm_drop.


fc_initializer= tf.random_normal_initializer(stddev=0.1)
# fc_initializer: initial values for the fully connected layer's weights.
# hidden_size: the size of the outputs from each lstm layer. 
#   Multiplied by 2 to account for the two LSTMs.
fc_weight= tf.get_variable('fc_weight', [2*hidden_size,3],
                            initializer= fc_initializer)
# fc_weight: Storage for the fully connected layer's weights.
fc_bias= tf.get_variable('bias', [3])
# fc_bias: Storage for the fully connected layer's bias.

# tf.GraphKeys.REGULARIZATION_LOSSES:  A key to a collection in the graph
#   designated for losses due to regularization.
#   In this case, this portion of loss is regularization on the weights
#   for the fully connected layer.
tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
                     tf.nn.l2_loss(fc_weight))

x= tf.concat([hyp, evi],1)# N, (Lh+Le), d
# Permuting batch_size and n_steps
x= tf.transpose(x, [1,0,2])# (Le+Lh), N, d
# Reshaping to (n_steps*batch_size, n_input)
x= tf.reshape(x, [-1, vector_size])# (Le+Lh)*N, d
# Split to get a list of 'n_steps' tensors of shape (batch_size, n_input)
x= tf.split(x, l_seq,)

# x: the inputs to the bidirectional_rnn


# tf.contrib.rnn.static_bidirectional_rnn: Runs the input through
#   two recurrent networks, one that runs the inputs forward and one
#   that runs the inputs in reversed order, combining the outputs.
rnn_outputs, _, _= tf.contrib.rnn.static_bidirectional_rnn(lstm, lstm_back,
                                                            x, dtype=tf.float32)
# rnn_outputs: the list of LSTM outputs, as a list.
#   What we want is the latest output, rnn_outputs[-1]

classification_scores= tf.matmul(rnn_outputs[-1], fc_weight)+ fc_bias
# The scores are relative certainties for how likely the output matches
#   a certain entailment:
#     0: Positive entailment
#     1: Neutral entailment
#     2: Negative entailment

展示TensorFlow如何计算准确度

为了测试精度并开始增加优化约束,我们需要展示TensorFlow如何计算准确预测标签的精度或百分比。

我们还需要确定一个损失,以显示网络的运行状况。由于我们有分类分数和最优分数,所以这里的选择是使用来自TensorFlow的softmax损失的变化:tf.nn.softmax_cross_entropy_with_logits。我们增加了正则化的损失以帮助过度拟合,然后准备一个优化器来学习如何减少损失。

代码语言:js
复制
with tf.variable_scope('Accuracy'):
    predicts= tf.cast(tf.argmax(classification_scores,1),'int32')
    y_label= tf.cast(tf.argmax(y,1),'int32')
    corrects= tf.equal(predicts, y_label)
    num_corrects= tf.reduce_sum(tf.cast(corrects, tf.float32))
    accuracy= tf.reduce_mean(tf.cast(corrects, tf.float32))

with tf.variable_scope("loss"):
    cross_entropy= tf.nn.softmax_cross_entropy_with_logits(
        logits= classification_scores, labels= y)
    loss= tf.reduce_mean(cro   ss_entropy)
    total_loss= loss+ weight_decay* tf.add_n(
        tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES))

optimizer= tf.train.GradientDescentOptimizer(learning_rate)

opt_op= optimizer.minimize(total_loss)

训练网络

最后,训练网络。如果你安装了TQDM,可以使用它来跟踪网络训练的进度。

代码语言:js
复制
# Initialize variables
init= tf.global_variables_initializer()

# Use TQDM if installed
tqdm_installed= False
try:
    from tqdmimport tqdm
    tqdm_installed= True
except:
    pass

# Launch the Tensorflow session
sess= tf.Session()
sess.run(init)

# training_iterations_count: The number of data pieces to train on in total
# batch_size: The number of data pieces per batch
training_iterations= range(0,training_iterations_count,batch_size)
if tqdm_installed:
    # Add a progress bar if TQDM is installed
    training_iterations= tqdm(training_iterations)

for iin training_iterations:

    # Select indices for a random data subset
    batch= np.random.randint(data_feature_list[0].shape[0], size=batch_size)

    # Use the selected subset indices to initialize the graph's
    #   placeholder values
    hyps, evis, ys= (data_feature_list[0][batch,:],
                      data_feature_list[1][batch,:],
                      correct_scores[batch])

    # Run the optimization with these initialized values
    sess.run([opt_op], feed_dict={hyp: hyps, evi: evis, y: ys})
    # display_step: how often the accuracy and loss should
    #   be tested and displayed.
    if (i/batch_size)% display_step== 0:
        # Calculate batch accuracy
        acc= sess.run(accuracy, feed_dict={hyp: hyps, evi: evis, y: ys})
        # Calculate batch loss
        tmp_loss= sess.run(loss, feed_dict={hyp: hyps, evi: evis, y: ys})
        # Display results
        print("Iter " + str(i/batch_size)+ ", Minibatch Loss= " + \
              "{:.6f}".format(tmp_loss)+ ", Training Accuracy= " + \
              "{:.5f}".format(acc))

网络现在被训练。应该看到大约50 – 55%的准确性,可以通过仔细修改超参数和增加数据集的大小以包括整个训练集来改进。通常,这将与训练时间的增加相对应。

通过插入自己的句子,修改在notebook上代码:

代码语言:js
复制
evidences= ["Maurita and Jade both were at the scene of the car crash."]

hypotheses= ["Multiple people saw the accident."]

sentence1= [fit_to_size(np.vstack(sentence2sequence(evidence)[0]),
                         (30,50))for evidencein evidences]

sentence2= [fit_to_size(np.vstack(sentence2sequence(hypothesis)[0]),
                         (30,50))for hypothesisin hypotheses]

prediction= sess.run(classification_scores, feed_dict={hyp: (sentence1* N),
                                                        evi: (sentence2* N),
                                                        y: [[0,0,0]]*N})
print(["Positive","Neutral","Negative"][np.argmax(prediction[0])]+
      " entailment")

最后,我们完成了模型的操作,结束会话以释放系统资源。

代码语言:javascript
复制
sess.close()

本文为编译作品,作者 Steven Hewitt,原网址为

https://www.oreilly.com/learning/textual-entailment-with-tensorflow

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-07-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 ATYUN订阅号 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 在我们开始之前
  • 文本的entailment示例
  • 数字矢量化表示单词
  • 使用斯坦福的GloVe word vectorization+ SNLI数据集
  • 当计算机研究句子的时会看到什么
  • Vanilla循环网络
  • 梯度消失问题
  • 利用LSTM
  • 为我们的网络定义常量
  • 实现dropout正则化
  • 用于复发层的Tensorflow的DropoutWrapper
  • 完成我们的模型
  • 展示TensorFlow如何计算准确度
  • 训练网络
相关产品与服务
NLP 服务
NLP 服务(Natural Language Process,NLP)深度整合了腾讯内部的 NLP 技术,提供多项智能文本处理和文本生成能力,包括词法分析、相似词召回、词相似度、句子相似度、文本润色、句子纠错、文本补全、句子生成等。满足各行业的文本智能需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档