Accenture / AmpliGraph

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

Var ent_emb already exsists when trying to fit multiple models in a single file #218

Closed Nsharma96 closed 3 years ago

Nsharma96 commented 4 years ago

Description

Whenever we try to model.fit multiple models in single notebook it gives

Variable ent_emb already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

  File "/usr/local/lib/python3.6/dist-packages/ampligraph/latent_features/models/EmbeddingModel.py", line 502, in _initialize_parameters
    dtype=tf.float32)
  File "/usr/local/lib/python3.6/dist-packages/ampligraph/latent_features/models/EmbeddingModel.py", line 931, in fit
    self._initialize_parameters()
  File "/usr/local/lib/python3.6/dist-packages/ampligraph/latent_features/models/TransE.py", line 265, in fit
    super().fit(X, early_stopping, early_stopping_params)
  File "<ipython-input-14-31c840e2c70d>", line 5, in <module>
    model_t.fit(X_train)
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

Steps to Reproduce

Create multiple models.

model_t = TransE(batches_count=100,
                 seed=0,
                 epochs=100,
                 k=150,
                 loss='multiclass_nll',
                 embedding_model_params={'corrupt_sides':['s', 'o']},
                 verbose = True)

model_d = DistMult(batches_count=100, 
                   seed=1, 
                   epochs=100, 
                   k=150,
                   loss='multiclass_nll',
                  #  loss_params={'margin':5},
                   embedding_model_params={'corrupt_sides':['s', 'o']},
                   verbose = True)

Try to fit them.

model_t.fit()
model_d.fit()

Work Arounds