Accenture / AmpliGraph

Python library for Representation Learning on Knowledge Graphs https://docs.ampligraph.org
Apache License 2.0
2.14k stars 251 forks source link

AttributeError: module 'tensorflow.math' has no attribute 'multiply' #52

Closed yoannapap closed 5 years ago

yoannapap commented 5 years ago

Description

I was trying to run the following example code for the wn18 dataset (I only changed the regularizer form None to L2 because it was also giving me an error):

Train and evaluate an embedding model

import numpy as np from ampligraph.datasets import load_wn18 from ampligraph.latent_features import ComplEx from ampligraph.evaluation import evaluate_performance, mrr_score, hits_at_n_score

def main():

# load Wordnet18 dataset:
X = load_wn18()

# Init a ComplEx neural embedding model with pairwise loss function:
# The model will be trained on 30 epochs.
# Turn stdout messages off with verbose=False
model = ComplEx(batches_count=10, seed=0, epochs=1, k=150, lr=.1, eta=10,
                loss='pairwise', regularizer='L2',
                optimizer='adagrad', verbose=True)

# Fit the model on training and validation set
model.fit(np.concatenate((X['train'], X['valid'])))

# The entire dataset will be used to filter out false positives statements
# created by the corruption procedure:
filter = np.concatenate((X['train'], X['valid'], X['test']))

# Run the evaluation procedure on the test set. Will create filtered rankings.
# To disable filtering: filter_triples=None
ranks = evaluate_performance(X['test'], model=model, filter_triples=filter,
                            verbose=True, splits=50)

# compute and print metrics:
mrr = mrr_score(ranks)
hits_10 = hits_at_n_score(ranks, n=10)
print("MRR: %f, Hits@10: %f" % (mrr, hits_10))

if name == "main": main()

Actual Behavior

And I have the following error:

------ Loss----- 2019-03-14 12:46:38,069 - ampligraph.latent_features.loss_functions - INFO - Name:pairwise Name: pairwise 2019-03-14 12:46:38,091 - ampligraph.latent_features.loss_functions - INFO - Parameters: Parameters: 2019-03-14 12:46:38,100 - ampligraph.latent_features.loss_functions - INFO - eta: eta : 10 2019-03-14 12:46:38,119 - ampligraph.latent_features.loss_functions - INFO - margin: margin : 1 ------ Regularizer----- 2019-03-14 12:46:38,149 - ampligraph.latent_features.regularizers - INFO - ------ Regularizer----- Name: L2 2019-03-14 12:46:38,158 - ampligraph.latent_features.regularizers - INFO - Name:L2 Parameters: 2019-03-14 12:46:38,162 - ampligraph.latent_features.regularizers - INFO - Parameters: 2019-03-14 12:46:38,163 - ampligraph.latent_features.regularizers - INFO - lambda:1e-05

lambda : 1e-05

AttributeError Traceback (most recent call last)

in 35 36 if __name__ == "__main__": ---> 37 main() in main() 17 18 # Fit the model on training and validation set ---> 19 model.fit(np.concatenate((X['train'], X['valid']))) 20 21 # The entire dataset will be used to filter out false positives statements c:\users\MY_USER\ampligraph\ampligraph\latent_features\models.py in fit(self, X, early_stopping, early_stopping_params) 1098 1099 """ -> 1100 super().fit(X, early_stopping, early_stopping_params) 1101 1102 def predict(self, X, from_idx=False): c:\users\MY_USER\ampligraph\ampligraph\latent_features\models.py in fit(self, X, early_stopping, early_stopping_params) 443 all_ent_tf = tf.squeeze(tf.constant(list(self.ent_to_idx.values()), dtype=tf.int32)) 444 #generate negatives --> 445 x_neg_tf = generate_corruptions_for_fit(x_pos_tf, all_ent_tf, self.eta, rnd=self.seed) 446 if self.loss.get_state('require_same_size_pos_neg'): 447 x_pos = tf.reshape(tf.tile(tf.reshape(x_pos_tf,[-1]),[self.eta]),[tf.shape(x_pos_tf)[0]*self.eta,3]) c:\users\MY_USER\ampligraph\ampligraph\evaluation\protocol.py in generate_corruptions_for_fit(X, all_entities, eta, corrupt_side, rnd) 273 replacements = tf.random_uniform([tf.shape(dataset)[0]],0,tf.shape(all_entities)[0], dtype=tf.int32, seed=rnd) 274 --> 275 subjects = tf.math.add(tf.math.multiply(keep_subj_mask,dataset[:,0]),tf.math.multiply(keep_obj_mask,replacements)) 276 logger.debug('Created corrupted subjects.') 277 relationships = dataset[:,1] AttributeError: module 'tensorflow.math' has no attribute 'multiply' Any clues on what should I do? Thank you!
PeruBhardwaj commented 5 years ago

This seems to be due to a different version of Tensorflow. I use version 1.12.0 and it works fine with that. (https://www.tensorflow.org/versions/r1.12/api_docs/python/tf/math)

sumitpai commented 5 years ago

Closing this issue. Please update the tensorflow version to 1.12 or above.