Im using this hacky workaround:
import tensorflow as tf
# im trying to import tf.keras .
# but vscode ide cannot detect the type hint due to tf lazy loading.
# Im using this hacky way to make it work.
# how to make this into a type hint, like a jsdoc, instead of a real import?
import typing
# The `typing.TYPE_CHECKING` constant is `True` during static type checking and `False` at runtime.
if typing.TYPE_CHECKING:
import keras
# from keras.api._v2 import keras
# from keras._tf_keras import keras
tf.keras = keras
embedding_layer = tf.keras.layers.Embedding(input_dim=100, output_dim=32)
embedding_layer(tf.constant([0, 1, 2]))
print(embedding_layer.weights)
(Another answer post is good, but not working for me. And I rather to not change the lib package file.)
Some ppl suggest just directly use keras. But Idk, the version compatibility is a mess to me...
Related: