【问题标题】:Matrix Factorization in tensorflow 2.0 using WALS Method使用 WALS 方法在 tensorflow 2.0 中进行矩阵分解
【发布时间】:2020-01-14 01:49:42
【问题描述】:

我正在使用 WALS 方法来执行矩阵分解。最初在 tensorflow 1.13 中,我可以使用

导入 factorization_ops
from tensorflow.contrib.factorization.python.ops import factorization_ops 

documentation中所述

Wals 模型可以使用 factorization_ops 调用

factorization_ops.WALSModel

在 tensorflow 2.0 中使用相同的命令给我以下错误

ModuleNotFoundError:没有名为“tensorflow.contrib.factorization”的模块

通过issue 似乎没有办法在 tensorflow 2.0+ 中使用 WALSModel。

在 tensorflow 发布更新中还提到 here 已弃用 tf.contrib,并且功能已迁移到核心 TensorFlow API、生态系统项目(例如 tensorflow/addons 或 tensorflow/io),或者完全删除。

如何在 tensorflow 2.0 中使用 WALS 模型(目前我在 windows 机器上使用 2.0.0-rc0)? WALSModel 是否已被删除或我遗漏了一些信息?

【问题讨论】:

    标签: python tensorflow tensorflow2.0 matrix-factorization


    【解决方案1】:

    相信TF 2.0不支持WALS...官方推荐型号为Neural Collaborative Filter (NCF)

    我希望这会有所帮助。

    M

    【讨论】:

    • 谢谢,这会在其他方面有所帮助:)
    【解决方案2】:

    我有同样的问题,但不幸的是我真的没有时间自己写一个库。我正在考虑几个潜在的选择:

    1. 坚持使用 TF1.X,直到有人创建库

    2. 切换到使用 lightfm 以继续使用 WALS

    3. 使用带有 keras 的嵌入层和点积层切换到神经协同过滤。见这篇论文https://arxiv.org/abs/1708.05031,以及这段代码实现:

    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
    
    
    

    【讨论】:

      【解决方案3】:

      我将 WALS 的 Tensorflow 实现与其他实现在计算资源和准确性方面进行了比较 (https://github.com/gtsoukas/cfzoo)。比较表明 implicit Python 包 (https://github.com/benfred/implicit) 是一个很好的替代品,可提供卓越的性能。

      【讨论】:

        【解决方案4】:

        我认为 WALS 已被删除。作为tf.contrib 的一部分,TF2 不支持它,我认为它不适合任何核心或子项目。 您最好的选择可能是将其作为第三方库提供。

        我希望将它用于我的项目,但需要重新编写它(主要是复制 TF1 中的内容并使其作为与 TF2 兼容的单独库工作)降低了此任务的优先级...

        如果您开始编写代码,请告诉我们。谢谢。

        亚历克西斯。

        【讨论】:

        • 是的,我正在考虑写这篇文章,以防他们停止这样做,因为我在 TF 1.13 中部署了一个。有一个相同的错误打开。等待他们的最终声明。好像我们在同一页上。你想合作吗?
        猜你喜欢
        • 2021-02-12
        • 2018-06-16
        • 1970-01-01
        • 2017-02-26
        • 2020-01-31
        • 2015-06-18
        • 2018-04-20
        • 2016-08-25
        • 1970-01-01
        相关资源
        最近更新 更多