Chapter13: Exercise 10-d. tf.RaggedTensor.to_tensor() have no Argument "shape" in tf2.0 version
- Dominant language
- Jupyter Notebook
- Stars
- 30k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
In the Cell142:
```python
def preprocess(X_batch, n_words=50):
shape = tf.shape(X_batch) * tf.constant([1, 0]) + tf.constant([0, n_words])
Z = tf.strings.substr(X_batch, 0, 300)
Z = tf.strings.lower(Z)
Z = tf.strings.regex_replace(Z, b"", b" ")
Z = tf.strings.regex_replace(Z, b"[^a-z]", b" ")
Z = tf.strings.split(Z)
return Z.to_tensor(shape=shape, default_value=b"")
X_example = tf.constant(["It's a great, great movie! I loved it.", "It was terrible, run away!!!"])
preprocess(X_example)
```
I can't run it with tf2.0 , so I want create a empty matrix use `tmp = tf.fill(dims=shape, b'')` and then convert `tmp` to `tf.Variable` ,use `assign` function for assignment finally. But when I test this `tmp[0,0].assign(2)` , there is some error like this:
`Cannot convert 2 to EagerTensor of dtype string`
So how to change its shape. THANK U
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.