Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wrapper for tensorflow 2.2.0 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SamarjeetKaur
Copy link

No description provided.

@idanmoradarthas
Copy link
Owner

First thank you so much on the pull request. I'm sorry it took me a long time to see it. For some reason GitHub didn't inform me.

Now the application doesn't need two tensorflow wrapper. If you like to bump up the tensorflow version please firstly update the requirements file. See my other CR in the file.
@SamarjeetKaur

import tensorflow_hub


class TensorFlowWrapper:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the original tensorflow_wrapper.py

# Import the Universal Sentence Encoder's TF Hub module
embedding_layer = tensorflow_hub.Module(embedding_layer_hub_name)

self._sts_input1 = tensorflow.compat.v1.placeholder(tensorflow.string, shape=None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tf.disable_v2_behavior() if you'd like to use tf1 behavior.
I suggest moving to tensorflow v2 behavior. Replace compat.v1.placeholder with their match in tf2 such as:
placeholder become Variable or keras.layers.Model.

See full guide here: https://www.tensorflow.org/guide/migrate

embedding_layer = tensorflow_hub.Module(embedding_layer_hub_name)

self._sts_input1 = tensorflow.compat.v1.placeholder(tensorflow.string, shape=None)
self._sts_input2 = tensorflow.compat.v1.placeholder(tensorflow.string, shape=None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tf.disable_v2_behavior() if you'd like to use tf1 behavior or migrate to tensorflow v2.

See previous remark.

axis=1)
clip_cosine_similarities = tensorflow.clip_by_value(cosine_similarities, -1.0, 1.0)
self._sim_scores = 1.0 - tensorflow.math.acos(clip_cosine_similarities)
init_op = tensorflow.group([tensorflow.compat.v1.global_variables_initializer(), tensorflow.compat.v1.tables_initializer()])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tf.disable_v2_behavior() if you'd like to use tf1 behavior or migrate to tensorflow v2.

See previous remark.

init_op = tensorflow.group([tensorflow.compat.v1.global_variables_initializer(), tensorflow.compat.v1.tables_initializer()])
g.finalize()

self._session = tensorflow.compat.v1.Session(graph=g)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tf.disable_v2_behavior() if you'd like to use tf1 behavior or migrate to tensorflow v2.

See previous remark.

Copy link
Owner

@idanmoradarthas idanmoradarthas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test file please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants