再读SRGNN论文之GRU与RNN和LSTM

hi主要是没太多时间用来思考,所以很多东西都不是太清楚,只会装逼,这样不好,要从理论/代码上理解到底说的是什么事情,这是科学问题:是什么和为什么?作为搬砖工还是有必要深入了解,不然真的只能搬砖了。可在我的主页搜索相关博文,不再挨个附上。【面试明明是技术面,却总是在问科学的问题,这很扯淡

For Recommendation in Deep learning QQ Group 102948747

For Visual in deep learning QQ Group 629530787

I'm here waiting for you

不接受这个网页的私聊/私信!!!

 

今年的目标没有实现——访客50万,总排名5000,明年三月份要实现这个东西。

之前实现了faiss召回,领导又问了,为啥采用IP的方式?其意义在哪里?卧槽,这是真的防不胜防啊,ytb中也是如此啊,但真的没有细致了解这玩意,这里还是很真探讨下这些问题。attention及GRU的作用是什么?为啥用GRU而不是LSTM,RNN?卧槽,随便一问就是面试题中的致命点,既是送分题,也是送命题。

【20210103续】

只要糖放得多,你就不会觉得生活有多苦,几块钱的事,非要百万来解决,何必为难自己。

试了下RNN,结果稍微差点,但绝对差不到一个百分点(HR一个为0.262,一个为0.268,MAP0.0506,一个为0.0532,好的结果是GRU的),昨晚也试了LSTM,但直接替换函数不对,卧槽,再改改吧,报错如下:

Traceback (most recent call last):
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 854, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/api.py", line 237, in wrapper
    raise e.ag_error_metadata.to_exception(e)
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: in converted code:
    relative to /data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python:

    ops/rnn_cell_impl.py:1017 call
        (c_prev, m_prev) = state
    framework/ops.py:547 __iter__
        self._disallow_iteration()
    framework/ops.py:543 _disallow_iteration
        self._disallow_in_graph_mode("iterating over `tf.Tensor`")
    framework/ops.py:523 _disallow_in_graph_mode
        " this function with @tf.function.".format(task))

    OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/logs/xulm1/myconda/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/data/logs/xulm1/myconda/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "video_update_rec_items.py", line 801, in run_train
    model = Model(node_count+1, checkpoint_path, **kwargs)
  File "video_update_rec_items.py", line 304, in __init__
    self.loss, self.session_state, self.logits = self.__forward()
  File "video_update_rec_items.py", line 345, in __forward
    node_state = self.ggnn(self.adj_in, self.adj_out, node_state, nw)
  File "video_update_rec_items.py", line 216, in __call__
    _, state = self.gru_cell(tf.reshape(gru_in, [-1, 2*self.hidden_size]), tf.reshape(state, [-1, self.hidden_size]))
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/ops/rnn_cell_impl.py", line 386, in __call__
    self, inputs, state, scope=scope, *args, **kwargs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/layers/base.py", line 548, in __call__
    outputs = super(Layer, self).__call__(inputs, *args, **kwargs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 861, in __call__
    str(e) + '\n"""')
TypeError: You are attempting to use Python control flow in a layer that was not declared to be dynamic. Pass `dynamic=True` to the class constructor.

我以为直接按照提示改就行了,卧槽。还是不行啊。咋整啊,

>>> import tensorflow as tf
>>> tf.compat.v1.nn.rnn_cell.LSTMCell(32,dynamic=True)
WARNING:tensorflow:From <stdin>:1: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.
<tensorflow.python.ops.rnn_cell_impl.LSTMCell object at 0x7fdacf531550>
>>> quit()

报错如下:这下好了,更没法改了

Traceback (most recent call last):
  File "/data/logs/xulm1/myconda/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/data/logs/xulm1/myconda/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "video_update_rec_items.py", line 801, in run_train
    model = Model(node_count+1, checkpoint_path, **kwargs)
  File "video_update_rec_items.py", line 304, in __init__
    self.loss, self.session_state, self.logits = self.__forward()
  File "video_update_rec_items.py", line 345, in __forward
    node_state = self.ggnn(self.adj_in, self.adj_out, node_state, nw)
  File "video_update_rec_items.py", line 216, in __call__
    _, state = self.gru_cell(tf.reshape(gru_in, [-1, 2*self.hidden_size]), tf.reshape(state, [-1, self.hidden_size]))
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/ops/rnn_cell_impl.py", line 386, in __call__
    self, inputs, state, scope=scope, *args, **kwargs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/layers/base.py", line 548, in __call__
    outputs = super(Layer, self).__call__(inputs, *args, **kwargs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 869, in __call__
    outputs = self._symbolic_call(inputs)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2158, in _symbolic_call
    output_shapes = self.compute_output_shape(input_shapes)
  File "/data/logs/xulm1/myconda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 646, in compute_output_shape
    raise NotImplementedError
NotImplementedError

还是搜索下LSTM与GRU的基本用法吧,看看是不是有所区别。好难哦,我看LSTM基本上都是和dynamic_rnn一起使用的,而我这里没有,加了这个就更难改了。

我看还是算了,这个就当实现了吧,问就是效果差点,,,,小明哥你不能这样,不讲武德。。。我特么源码给你,要不你帮我改成LSTM的,我跪谢。

实在是能力有限,改就伤筋动骨了,不好整。

【问题2:为啥用IP求内积/相似度/距离?两个embedding求IP的意义是什么?】(这才是领导问的,小声bb,其他的是我自己发问的)

这其实是一个问题,下面从头来过

将所有的会话图喂到ggnn中,得到所有节点的embedding,然后通过聚合得到会话的全局embedding,采用的是self-attention机制更好的表达。会话局部的embedding可简单直接认为就是最后一个点击的item的embedding。两个会话的embedding通过concat后线性转换得到最后会话表达。这是会话embedding的来源

为给每一个item计算score,只需将会话的embedding与所有的item的embedding相乘,然后取softmax就得到了下次点击item出现的概率。这也是训练和推理阶段相同的。如果你还不懂,不妨留个坑,待我看完ytb的详解后再次解答。

其实也无需再说,在ytb中得到的user和item的embedding,为何他们要相乘再softmax呢?这是一样的道理,只不过这里是会话的表达,你可以将会话表达看做是用户的兴趣/偏好表达。

拜拜,愿我们终有重逢之时,而你还记得我们曾经讨论的话题。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章