我正在使用WALS方法来执行矩阵分解。最初在tensorflow 1.13中,我可以使用
from tensorflow.contrib.factorization.python.ops import factorization_ops 如文档所述
可以从factorization_ops调用Wals模型。
factorization_ops.WALSModel在tensorflow 2.0中使用相同的命令给出以下错误
'tensorflow.contrib.factorization ModuleNotFoundError:没有名为的模块
通过问题,似乎没有办法在tensorflow 2.0+中使用WALSModel。
另外,在tensorflow版本更新中也提到了这里,tf.contrib已被废弃,功能要么迁移到核心TensorFlow API,要么迁移到生态系统项目,如tensorflow/addons或tensorflow/io,或者完全删除。
如何在tensorflow 2.0中使用WALS模型(目前我在windows机器上使用2.0.0-rc0 )?是WALSModel被删除了,还是我遗漏了一些信息?
发布于 2019-09-24 13:21:01
发布于 2019-09-24 11:13:09
我也有同样的问题,但不幸的是,我没有时间自己写一个库。我正在考虑几种可能的选择:
from tensorflow.keras.layers import Input, Embedding, Flatten, Dot, Dense
from tensorflow.keras.models import Model
#import tensorflow.distribute
def get_compiled_model(n_users, n_items, embedding_dims=20):
# Product embedding
prod_input = Input(shape=[1], name="Item-Input")
prod_embedding = Embedding(n_items+1, embedding_dims, name="Item-Embedding")(prod_input)
prod_vec = Flatten(name="Flatten-Product")(prod_embedding)
# User embedding
user_input = Input(shape=[1], name="User-Input")
user_embedding = Embedding(n_users+1, embedding_dims, name="User-Embedding")(user_input)
user_vec = Flatten(name="Flatten-Users")(user_embedding)
# The output is the dot product of the two, i.e. a one-hot vector
dot_product = Dot(name="Dot-Product", axes=1)([prod_vec, user_vec])
# compile - uncomment these two lines to make training distributed
# dist_strat = distribute.Strategy()
# with dist_strat.scope():
model = Model(inputs = [user_input, prod_input], outputs = dot_product)
model.compile(
optimizer='adam',
loss='mean_squared_error'
)
return model发布于 2019-12-06 15:24:36
在计算资源和准确性(https://github.com/gtsoukas/cfzoo)方面,我已经将WALS的Tensorflow实现与其他实现进行了比较。比较表明,隐式package (https://github.com/benfred/implicit)是一个很好的替代品,提供了更好的性能。
https://stackoverflow.com/questions/57902387
复制相似问题