From f920dbfabdf1b1a29cbe8a1825e1dbbf37148a02 Mon Sep 17 00:00:00 2001 From: Lars Klein Date: Wed, 17 Aug 2022 20:33:36 +0200 Subject: [PATCH 1/2] converting to tf 1.* --- model.py | 4 ++-- naga/shared/trainer.py | 2 +- tfrnn/hooks.py | 4 ++-- train.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model.py b/model.py index d59f46b..bebe445 100644 --- a/model.py +++ b/model.py @@ -119,13 +119,13 @@ def __init__(self, model_params, num_emoji, embeddings_array, use_embeddings=Tru v_col = tf.nn.dropout(v_col, (1 - model_params.dropout)) # Calculate the predicted score, a.k.a. dot product (here) - self.score = tf.reduce_sum(tf.mul(v_row, v_col), 1) + self.score = tf.reduce_sum(tf.multiply(v_row, v_col), 1) # Probability of match self.prob = tf.sigmoid(self.score) # Calculate the cross-entropy loss - self.loss = tf.nn.sigmoid_cross_entropy_with_logits(self.score, self.y) + self.loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=self.score, labels=self.y) # train the model using the appropriate parameters def train(self, kb, hooks, session): diff --git a/naga/shared/trainer.py b/naga/shared/trainer.py index b1351f9..d5b16ff 100644 --- a/naga/shared/trainer.py +++ b/naga/shared/trainer.py @@ -20,7 +20,7 @@ def __call__(self, batcher, placeholders, loss, model=None, session=None): session = tf.Session() close_session_after_training = True # no session existed before, we provide a temporary session - init = tf.initialize_all_variables() + init = tf.global_variables_initializer() session.run(init) epoch = 1 iteration = 1 diff --git a/tfrnn/hooks.py b/tfrnn/hooks.py index 16f4b32..e2873d8 100644 --- a/tfrnn/hooks.py +++ b/tfrnn/hooks.py @@ -25,8 +25,8 @@ def __call__(self, sess, epoch, iteration, model, loss): raise NotImplementedError def update_summary(self, sess, current_step, title, value): - cur_summary = tf.scalar_summary(title, value) - merged_summary_op = tf.merge_summary([cur_summary]) # if you are using some summaries, merge them + cur_summary = tf.summary.scalar(title, value) + merged_summary_op = tf.summary.merge([cur_summary]) # if you are using some summaries, merge them summary_str = sess.run(merged_summary_op) self.summary_writer.add_summary(summary_str, current_step) diff --git a/train.py b/train.py index 0c4e1d9..c264514 100644 --- a/train.py +++ b/train.py @@ -101,7 +101,7 @@ def train_save_evaluate(params, kb, train_set, dev_set, ind2emoji, embeddings_ar else: # For visualizing using tensorboard - summary_writer = tf.train.SummaryWriter(model_folder + '/board', graph=sess.graph) + summary_writer = tf.summary.FileWriter(model_folder + '/board', graph=sess.graph) # Keep track of how the model is training hooks = [ From f09ba78e1f14cb728ba21681eb0132fce99b076b Mon Sep 17 00:00:00 2001 From: Lars Klein Date: Wed, 17 Aug 2022 20:34:49 +0200 Subject: [PATCH 2/2] adding a conda env that can execute this code --- environment.yml | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 environment.yml diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..a2e62e1 --- /dev/null +++ b/environment.yml @@ -0,0 +1,74 @@ +name: emoji2vec +channels: + - defaults +dependencies: + - _libgcc_mutex=0.1=main + - _openmp_mutex=5.1=1_gnu + - _tflow_select=2.3.0=mkl + - absl-py=0.15.0=pyhd3eb1b0_0 + - astor=0.8.1=py36h06a4308_0 + - blas=1.0=mkl + - c-ares=1.18.1=h7f8727e_0 + - ca-certificates=2022.07.19=h06a4308_0 + - certifi=2021.5.30=py36h06a4308_0 + - coverage=5.5=py36h27cfd23_2 + - cython=0.29.24=py36h295c915_0 + - dataclasses=0.8=pyh4f3eec9_6 + - gast=0.5.3=pyhd3eb1b0_0 + - google-pasta=0.2.0=pyhd3eb1b0_0 + - grpcio=1.36.1=py36h2157cd5_1 + - h5py=2.10.0=py36hd6299e0_1 + - hdf5=1.10.6=hb1b8bf9_0 + - importlib-metadata=4.8.1=py36h06a4308_0 + - intel-openmp=2022.0.1=h06a4308_3633 + - joblib=1.0.1=pyhd3eb1b0_0 + - keras-applications=1.0.8=py_1 + - keras-preprocessing=1.1.2=pyhd3eb1b0_0 + - ld_impl_linux-64=2.38=h1181459_1 + - libffi=3.3=he6710b0_2 + - libgcc-ng=11.2.0=h1234567_1 + - libgfortran-ng=7.5.0=ha8ba4b0_17 + - libgfortran4=7.5.0=ha8ba4b0_17 + - libgomp=11.2.0=h1234567_1 + - libprotobuf=3.17.2=h4ff587b_1 + - libstdcxx-ng=11.2.0=h1234567_1 + - markdown=3.3.4=py36h06a4308_0 + - mkl=2018.0.3=1 + - mkl_fft=1.0.6=py36h7dd41cf_0 + - mkl_random=1.0.1=py36h4414c95_1 + - ncurses=6.3=h5eee18b_3 + - numpy=1.15.4=py36h1d66e8a_0 + - numpy-base=1.15.4=py36h81de0dd_0 + - openssl=1.1.1q=h7f8727e_0 + - pandas=1.1.5=py36h2531618_0 + - pip=21.2.2=py36h06a4308_0 + - protobuf=3.17.2=py36h295c915_0 + - python=3.6.13=h12debd9_1 + - python-dateutil=2.8.2=pyhd3eb1b0_0 + - pytz=2021.3=pyhd3eb1b0_0 + - readline=8.1.2=h7f8727e_1 + - scikit-learn=0.23.2=py36h0573a6f_0 + - scipy=0.19.1=py36h9976243_3 + - setuptools=58.0.4=py36h06a4308_0 + - six=1.16.0=pyhd3eb1b0_1 + - sqlite=3.39.2=h5082296_0 + - tbb=2021.5.0=hd09550d_0 + - tbb4py=2021.3.0=py36hd09550d_0 + - tensorboard=1.14.0=py36hf484d3e_0 + - tensorflow=1.14.0=mkl_py36h2526735_0 + - tensorflow-base=1.14.0=mkl_py36h7ce6ba3_0 + - tensorflow-estimator=1.14.0=py_0 + - termcolor=1.1.0=py36h06a4308_1 + - threadpoolctl=2.2.0=pyh0d69192_0 + - tk=8.6.12=h1ccaba5_0 + - typing_extensions=4.1.1=pyh06a4308_0 + - werkzeug=2.0.3=pyhd3eb1b0_0 + - wheel=0.37.1=pyhd3eb1b0_0 + - wrapt=1.12.1=py36h7b6447c_1 + - xz=5.2.5=h7f8727e_1 + - zipp=3.6.0=pyhd3eb1b0_0 + - zlib=1.2.12=h7f8727e_2 + - pip: + - gensim==0.13.4.1 + - smart-open==6.0.0 +prefix: /home/lhk/anaconda3/envs/emoji2vec