Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(encoder): fix eager execution
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Aug 26, 2019
1 parent 3600c29 commit ff7926d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
7 changes: 5 additions & 2 deletions gnes/encoder/numeric/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def post_init(self):
self.torch = torch
elif self.backend == 'tensorflow':
import tensorflow as tf
tf.enable_eager_execution()
try:
tf.enable_eager_execution()
except ValueError:
pass
self.tf = tf

def mul_mask(self, x, m):
Expand All @@ -53,7 +56,7 @@ def masked_reduce_mean(self, x, m, jitter: float = 1e-10):
self.torch.sum(m.unsqueeze(2), dim=1) + jitter)
elif self.backend == 'tensorflow':
return self.tf.reduce_sum(self.mul_mask(x, m), axis=1) / (
self.tf.reduce_sum(m, axis=1, keepdims=True) + jitter)
self.tf.reduce_sum(m, axis=1, keepdims=True) + jitter)
elif self.backend == 'numpy':
return np.sum(self.mul_mask(x, m), axis=1) / (np.sum(m, axis=1, keepdims=True) + jitter)

Expand Down
41 changes: 0 additions & 41 deletions tests/test_elmo_encoder.py

This file was deleted.

0 comments on commit ff7926d

Please sign in to comment.