hi主要是沒太多時間用來思考,所以很多東西都不是太清楚,只會裝逼,這樣不好,要從理論/代碼上理解到底說的是什麼事情,這是科學問題:是什麼和爲什麼?作爲搬磚工還是有必要深入瞭解,不然真的只能搬磚了。可在我的主頁搜索相關博文,不再挨個附上。【面試明明是技術面,卻總是在問科學的問題,這很扯淡】
For Recommendation in Deep learning QQ Group 102948747
For Visual in deep learning QQ Group 629530787
不接受這個網頁的私聊/私信!!!
今年的目標沒有實現——訪客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呢?這是一樣的道理,只不過這裏是會話的表達,你可以將會話表達看做是用戶的興趣/偏好表達。
拜拜,願我們終有重逢之時,而你還記得我們曾經討論的話題。