TensorFlow练习25: 使用深度学习做阅读理解+完形填空

记的在学生时代,英语考试有这么一种类型的题,叫:阅读理解。首先让你读一段洋文材料,然后回答一些基于这个洋文材料提的问题。

我先给你出一道阅读理解

Big Panda learned to code when he was 21. He live in China and have no life, feel like a big loser. But here is one thing Panda want you to remember…it´s never too late! You can do anything if you put your heart on it!

____ is the loser.(下划线处该填什么呢?)

我出的这道填空题,对人来说轻而易举,但是要让机器回答就很难了。机器阅读和理解人类语言是非常有挑战性的。

本帖就使用TensorFlow练习一个阅读理解,看看准确率能到什么程度。

使用的数据集

本帖只使用”非死不可”提供的《Children’s Book Test》数据集。

TensorFlow练习25: 使用深度学习做阅读理解+完形填空

数据预处理

生成的文件:vocab.data词汇表、train.vec、valid.vec数据的向量表示。

训练

TensorFlow练习25: 使用深度学习做阅读理解+完形填空
https://arxiv.org/pdf/1606.02245v4.pdf

我只想说,这个东西比我水平高!至少在速度上能甩我十条大街。

如要转载,请保持本文完整,并注明作者@斗大的熊猫和本文原始地址:http://blog.topspeedsnail.com/archives/11062

相关文章

《TensorFlow练习25: 使用深度学习做阅读理解+完形填空》有11个想法

  1. Traceback (most recent call last):
    File “data_training.py”, line 157, in
    train_neural_attention()
    File “data_training.py”, line 113, in train_neural_attention
    X_attentions = neural_attention()
    File “data_training.py”, line 73, in neural_attention
    outputs, output_states = tf.nn.bidirectional_dynamic_rnn(gru_cell, gru_cell, encoded_X, sequence_length=X_lens, dtype=tf.float32, swap_memory=True)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 376, in bidirectional_dynamic_rnn
    time_major=time_major, scope=bw_scope)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 553, in dynamic_rnn
    dtype=dtype)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 720, in _dynamic_rnn_loop
    swap_memory=swap_memory)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py”, line 2623, in while_loop
    result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py”, line 2456, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py”, line 2406, in _BuildLoop
    body_result = body(*packed_vars_for_body)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 703, in _time_step
    skip_conditionals=True)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 177, in _rnn_step
    new_output, new_state = call_cell()
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py”, line 691, in
    call_cell = lambda: cell(input_t, state)
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py”, line 146, in __call__
    with _checked_scope(self, scope or “gru_cell”, reuse=self._reuse):
    File “/usr/lib/python2.7/contextlib.py”, line 17, in __enter__
    return self.gen.next()
    File “/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py”, line 77, in _checked_scope
    type(cell).__name__))
    ValueError: Attempt to reuse RNNCell with a different variable scope than its first use. First use of cell was with scope ‘encode/X/bidirectional_rnn/fw/gru_cell’, this attempt is with scope ‘encode/X/bidirectional_rnn/bw/gru_cell’. Please create a new instance of the cell if you would like it to use a different set of weights. If before you were using: MultiRNNCell([GRUCell(…)] * num_layers), change to: MultiRNNCell([GRUCell(…) for _ in range(num_layers)]). If before you were using the same cell instance as both the forward and reverse cell of a bidirectional RNN, simply create two instances (one for forward, one for reverse). In May 2017, we will start transitioning this cell’s behavior to use existing stored weights, if any, when it is called with scope=None (which can lead to silent model degradation, so this error will remain until then.)

    这问题怎么解决呢?
    >>> tf.__version__
    ‘1.1.0’
    是版本太新了吗?

  2. 博主,啥时候出出和文本相关的啊,最近闲的无事想试试给一篇文章判断文章是否为色情的,给打分。但是不会写,求博主老师出教程,真心感谢博主。

  3. 楼主,代码运行出现错误提示:
    Traceback (most recent call last):
    File “train.py”, line 156, in
    train_neural_attention()
    File “train.py”, line 112, in train_neural_attention
    X_attentions = neural_attention()
    File “train.py”, line 96, in neural_attention
    _, q_glimpse = glimpse(W_q, b_q, encoded_Q, infer_state)
    File “train.py”, line 59, in glimpse
    attention = tf.nn.softmax(tf.squeeze(attention, -1))
    File “/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py”, line 2646, in squeeze
    squeeze_dims=squeeze_dims, name=name)
    File “/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py”, line 638, in apply_op
    raise TypeError(“Expected list for attr ” + key)
    TypeError: Expected list for attr squeeze_dims

    如何解决?谢谢

发表评论

电子邮件地址不会被公开。 必填项已用*标注