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

[example/nlp] neural_machine_translation_with_transforme does not run successfuly. #1665

Closed
Mingbo-Lee opened this issue Dec 1, 2023 · 3 comments

Comments

@Mingbo-Lee
Copy link

Issue Type

Bug

Source

source

Keras Version

Keras 2.14.0

Custom Code

Yes

OS Platform and Distribution

Linux Ubuntu 22.04.3 LTS

Python version

3.10

GPU model and memory

NVIDIA T4

Current Behavior?

When run the example neural_machine_translation_with_transformer on Google Colab directly , I got error.
image

Standalone code to reproduce the issue or tutorial link

import os

os.environ["KERAS_BACKEND"] = "tensorflow"

import pathlib
import random
import string
import re
import numpy as np

import tensorflow.data as tf_data
import tensorflow.strings as tf_strings

import keras
from keras import layers
from keras import ops
from keras.layers import TextVectorization

Relevant log output

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-13-5bf91004141f>](https://localhost:8080/#) in <cell line: 25>()
     23 import keras
     24 from keras import layers
---> 25 from keras import ops
     26 from keras.layers import TextVectorization

ImportError: cannot import name 'ops' from 'keras' (/usr/local/lib/python3.10/dist-packages/keras/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
@sachinprasadhs
Copy link
Collaborator

Hi, Thanks for reporting the issue.

The tutorial works on Keras 3, colab has precompiled Keras 2, till colab comes with precompiled Keras 3,, you need to install it before importing.

!pip install keras==3.0.0 fixes the issue.

@Mingbo-Lee
Copy link
Author

Thank you for your suggestion. I run this script in my local environment successfully based keras3. What'more, I also run this tutorial in Colab successfuuly by add a code cell !pip install keras==3.0.0

@sachinprasadhs
Copy link
Collaborator

Thanks for confirming, could you please close the issue as well.

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

No branches or pull requests

2 participants