Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Quick fix for TensorFlow 2.0.0 or greater users #1

Open
richardmark opened this issue Feb 5, 2020 · 0 comments
Open

Quick fix for TensorFlow 2.0.0 or greater users #1

richardmark opened this issue Feb 5, 2020 · 0 comments

Comments

@richardmark
Copy link

Minor fix for TensorFlow 2.0.0 or greater users

import tensorflow as tf
if int(tf.version[0]) > 1:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
 
plot_emb_list = []
with tf.Graph().as_default():
embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder/2")
messages = tf.placeholder(dtype=tf.string, shape=[None])
output = embed(messages)
with tf.Session() as session:
session.run([tf.global_variables_initializer(), tf.tables_initializer()])
for plot in tqdm_notebook(df['Plot']):
sent_list = sent_tokenize(plot)
clean_sent_list = clean_plot(sent_list)
sent_embed = session.run(output, feed_dict={messages: clean_sent_list})
plot_emb_list.append(sent_embed.mean(axis=0).reshape(1,512))

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

No branches or pull requests

1 participant