Skip to content

Commit 361fcdc

Browse files
authored
Enable PyPI installation
* Fix or toggle off warnings (mostly TF deprecation warnings) * Update dependency to TF>=1.10.0 * Upgrade to version v0.2.2
2 parents 81cb96a + 26c119f commit 361fcdc

37 files changed

+122
-80
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
### Feature improvements
77

8+
### Fixes
9+
10+
## [v0.2.2](https://github.com/asyml/texar/releases/tag/v0.2.2) (2019-08-05)
11+
12+
### New features
13+
14+
* Enable installation from [Pypi](https://pypi.org/project/texar/). ([#186](https://github.com/asyml/texar/pull/186))
15+
16+
### Feature improvements
17+
818
* Use lazy import to be compatible with [texar-pytorch](https://github.com/asyml/texar-pytorch). ([#183](https://github.com/asyml/texar/pull/183))
919

1020
### Fixes

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
-----------------
66

7+
8+
[![pypi](https://img.shields.io/pypi/v/texar.svg)](https://pypi.python.org/pypi/texar)
79
[![Build Status](https://travis-ci.org/asyml/texar.svg?branch=master)](https://travis-ci.org/asyml/texar)
810
[![Documentation Status](https://readthedocs.org/projects/texar/badge/?version=latest)](https://texar.readthedocs.io/en/latest/?badge=latest)
911
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/asyml/texar/blob/master/LICENSE)
@@ -79,6 +81,13 @@ agent = tx.agents.SeqPGAgent(samples=outputs.sample_id,
7981
Many more examples are available [here](./examples)
8082

8183
### Installation
84+
Besides the packages in requirements.txt, Texar additionally requires:
85+
86+
* tensorflow >= 1.10.0 (but <= 2.0). Follow the tensorflow official instructions to install the appropriate version
87+
88+
* tensorflow_probability >= 0.3.0. Follow the tensorflow_probability official instractions to install.
89+
90+
After Tensorflow is installed, please run the following commands to install Texar:
8291
```
8392
git clone https://github.com/asyml/texar.git
8493
cd texar

examples/bert/bert_classifier_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def main(_):
107107
input_ids = batch["input_ids"]
108108
segment_ids = batch["segment_ids"]
109109
batch_size = tf.shape(input_ids)[0]
110-
input_length = tf.reduce_sum(1 - tf.to_int32(tf.equal(input_ids, 0)),
110+
input_length = tf.reduce_sum(1 - tf.cast(tf.equal(input_ids, 0), tf.int32),
111111
axis=1)
112112
# Builds BERT
113113
with tf.variable_scope('bert'):
@@ -198,7 +198,7 @@ def _train_epoch(sess):
198198
periodically.
199199
"""
200200
iterator.restart_dataset(sess, 'train')
201-
201+
202202
fetches = {
203203
'train_op': train_op,
204204
'loss': loss,

examples/bert/bert_classifier_main_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def main(_):
8585
input_ids = batch["input_ids"]
8686
segment_ids = batch["segment_ids"]
8787
batch_size = tf.shape(input_ids)[0]
88-
input_length = tf.reduce_sum(1 - tf.to_int32(tf.equal(input_ids, 0)),
88+
input_length = tf.reduce_sum(1 - tf.cast(tf.equal(input_ids, 0), tf.int32),
8989
axis=1)
9090
# Builds BERT
9191
hparams = {

examples/seq2seq_exposure_bias/interpolation_helper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import tensorflow as tf
2323
import numpy as np
2424

25+
from tensorflow_probability import distributions as tfpd
2526
from tensorflow.contrib.seq2seq import SampleEmbeddingHelper
2627
from texar.evals.bleu import sentence_bleu
2728
from rouge import Rouge
@@ -95,19 +96,19 @@ def sample(self, time, outputs, state, name=None):
9596
of 'state'([decoded_ids, rnn_state])
9697
"""
9798
sample_method_sampler = \
98-
tf.distributions.Categorical(probs=self._lambdas)
99+
tfpd.Categorical(probs=self._lambdas)
99100
sample_method_id = sample_method_sampler.sample()
100101

101102
truth_feeding = lambda: tf.cond(
102103
tf.less(time, tf.shape(self._ground_truth)[1]),
103-
lambda: tf.to_int32(self._ground_truth[:, time]),
104+
lambda: tf.cast(self._ground_truth[:, time], tf.int32),
104105
lambda: tf.ones_like(self._ground_truth[:, 0],
105106
dtype=tf.int32) * self._vocab.eos_token_id)
106107

107-
self_feeding = lambda : SampleEmbeddingHelper.sample(
108+
self_feeding = lambda: SampleEmbeddingHelper.sample(
108109
self, time, outputs, state, name)
109110

110-
reward_feeding = lambda : self._sample_by_reward(time, state)
111+
reward_feeding = lambda: self._sample_by_reward(time, state)
111112

112113
sample_ids = tf.cond(
113114
tf.logical_or(tf.equal(time, 0), tf.equal(sample_method_id, 1)),
@@ -207,9 +208,9 @@ def _get_rewards(time, prefix_ids, target_ids, ground_truth_length):
207208

208209
return result
209210

210-
sampler = tf.distributions.Categorical(
211+
sampler = tfpd.Categorical(
211212
logits=tf.py_func(_get_rewards, [
212213
time, state[0], self._ground_truth,
213214
self._ground_truth_length], tf.float32))
214215
return tf.reshape(
215-
sampler.sample(), (tf.shape(self._ground_truth)[0],))
216+
sampler.sample(), (tf.shape(self._ground_truth)[0],))

examples/text_style_transfer/ctrl_gen_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _build_model(self, inputs, vocab, gamma, lambda_g):
5555
label_connector = MLPTransformConnector(self._hparams.dim_c)
5656

5757
# Gets the sentence representation: h = (c, z)
58-
labels = tf.to_float(tf.reshape(inputs['labels'], [-1, 1]))
58+
labels = tf.cast(tf.reshape(inputs['labels'], [-1, 1]), tf.float32)
5959
c = label_connector(labels)
6060
c_ = label_connector(1 - labels)
6161
h = tf.concat([c, z], 1)
@@ -106,7 +106,7 @@ def _build_model(self, inputs, vocab, gamma, lambda_g):
106106
inputs=clas_embedder(ids=inputs['text_ids'][:, 1:]),
107107
sequence_length=inputs['length']-1)
108108
loss_d_clas = tf.nn.sigmoid_cross_entropy_with_logits(
109-
labels=tf.to_float(inputs['labels']), logits=clas_logits)
109+
labels=tf.cast(inputs['labels'], tf.float32), logits=clas_logits)
110110
loss_d_clas = tf.reduce_mean(loss_d_clas)
111111
accu_d = tx.evals.accuracy(labels=inputs['labels'], preds=clas_preds)
112112

@@ -115,7 +115,7 @@ def _build_model(self, inputs, vocab, gamma, lambda_g):
115115
inputs=clas_embedder(soft_ids=soft_outputs_.sample_id),
116116
sequence_length=soft_length_)
117117
loss_g_clas = tf.nn.sigmoid_cross_entropy_with_logits(
118-
labels=tf.to_float(1-inputs['labels']), logits=soft_logits)
118+
labels=tf.cast(1-inputs['labels'], tf.float32), logits=soft_logits)
119119
loss_g_clas = tf.reduce_mean(loss_g_clas)
120120

121121
# Accuracy on soft samples, for training progress monitoring

examples/transformer/transformer_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import random
2323
import os
2424
import importlib
25-
from torchtext import data
2625
import tensorflow as tf
26+
from torchtext import data
2727
import texar as tx
2828
from texar.modules import TransformerEncoder, TransformerDecoder
2929
from texar.utils import transformer_utils
@@ -74,10 +74,10 @@ def main():
7474
batch_size = tf.shape(encoder_input)[0]
7575
# (text sequence length excluding padding)
7676
encoder_input_length = tf.reduce_sum(
77-
1 - tf.to_int32(tf.equal(encoder_input, 0)), axis=1)
77+
1 - tf.cast(tf.equal(encoder_input, 0), tf.int32), axis=1)
7878

7979
labels = tf.placeholder(tf.int64, shape=(None, None))
80-
is_target = tf.to_float(tf.not_equal(labels, 0))
80+
is_target = tf.cast(tf.not_equal(labels, 0), tf.float32)
8181

8282
global_step = tf.Variable(0, dtype=tf.int64, trainable=False)
8383
learning_rate = tf.placeholder(tf.float64, shape=(), name='lr')

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
tensorflow >= 1.7.0
2-
tensorflow-gpu >= 1.7.0
1+
tensorflow >= 1.10.0
2+
tensorflow-gpu >= 1.10.0
33
tensorflow-probability >= 0.3.0
44
tensorflow-probability-gpu >= 0.3.0
5-
funcsigs >= 1.0.2
5+
funcsigs >= 1.0.2
6+
packaging

setup.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setuptools.setup(
1717
name="texar",
18-
version="0.2.1",
18+
version="0.2.2",
1919
url="https://github.com/asyml/texar",
2020

2121
description="Toolkit for Machine Learning and Text Generation",
@@ -26,19 +26,20 @@
2626
platforms='any',
2727

2828
install_requires=[
29-
'numpy',
29+
'numpy<1.17.0',
3030
'pyyaml',
3131
'requests',
32-
'funcsigs',
32+
'funcsigs>=1.0.2',
33+
'packaging'
3334
],
3435
extras_require={
3536
'tensorflow-cpu': [
36-
'tensorflow>=1.7.0',
37-
'tensorflow-probability >= 0.3.0'
37+
'tensorflow>=1.10.0,<2.0',
38+
'tensorflow-probability>=0.3.0'
3839
],
3940
'tensorflow-gpu': [
40-
'tensorflow-gpu>=1.7.0',
41-
'tensorflow-probability-gpu >= 0.3.0'
41+
'tensorflow-gpu>=1.10.0,<2.0',
42+
'tensorflow-probability-gpu>=0.3.0'
4243
]
4344
},
4445
package_data={

texar/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@
1919
from __future__ import division
2020
from __future__ import print_function
2121

22+
2223
# pylint: disable=wildcard-import
2324

2425
import sys
26+
from packaging import version
27+
import tensorflow as tf
28+
29+
30+
VERSION_WARNING = "1.13.2"
31+
32+
if version.parse(tf.__version__) <= version.parse(VERSION_WARNING):
33+
tf.logging.set_verbosity(tf.logging.ERROR)
34+
else:
35+
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
2536

2637
if sys.version_info.major < 3:
2738
# PY 2.x, import as is because Texar-PyTorch cannot be installed.

0 commit comments

Comments
 (0)