geffy / tffm

TensorFlow implementation of an arbitrary order Factorization Machine
MIT License
780 stars 176 forks source link

Issue with tensorflow 2.0: module 'tensorflow_core._api.v2.train' has no attribute 'AdamOptimizer' #51

Open hugocool opened 4 years ago

hugocool commented 4 years ago

pip install tensorflow==2.0 import numpy as np import tensorflow as tf

from tffm import TFFMClassifier

gives error:

AttributeError Traceback (most recent call last)

in ----> 1 from tffm import TFFMClassifier ~/anaconda3/lib/python3.7/site-packages/tffm/__init__.py in ----> 1 from .models import TFFMClassifier, TFFMRegressor 2 3 __all__ = ['TFFMClassifier', 'TFFMRegressor'] ~/anaconda3/lib/python3.7/site-packages/tffm/models.py in 2 3 import numpy as np ----> 4 from .base import TFFMBaseModel 5 from .utils import loss_logistic, loss_mse, sigmoid 6 ~/anaconda3/lib/python3.7/site-packages/tffm/base.py in 1 import tensorflow as tf ----> 2 from .core import TFFMCore 3 from sklearn.base import BaseEstimator 4 from abc import ABCMeta, abstractmethod 5 import six ~/anaconda3/lib/python3.7/site-packages/tffm/core.py in 4 5 ----> 6 class TFFMCore(): 7 """This class implements underlying routines about creating computational graph. 8 ~/anaconda3/lib/python3.7/site-packages/tffm/core.py in TFFMCore() 94 """ 95 def __init__(self, order=2, rank=2, input_type='dense', loss_function=None, ---> 96 optimizer=tf.train.AdamOptimizer(learning_rate=0.01), reg=0, 97 init_std=0.01, use_diag=False, reweight_reg=False, 98 seed=None): AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'AdamOptimizer'
Pager07 commented 4 years ago

FIX: Go to core.py file inside ttf folder. In the in the init function change optimizer to tf.keras.optimizers.Adam(....). Why? Read the following: https://stackoverflow.com/questions/55682718/module-tensorflow-api-v2-train-has-no-attribute-gradientdescentoptimizer

jamborta commented 4 years ago

I ported this to tf2, check it out here: https://github.com/jamborta/tffm2