thanks @TMosh, I have installed tensorflow and the code does work when I execute the code.
Why does visual studio code complain though that the package is not available. Because of this issue the intellisense does not work as well which makes it cumbersome to explore the tensorflow objects and methods.
Just an update. I am able to fix this issue by using the following code. Seems like keras is not a package under tensorflow which is why vsc complains, though still not sure as to how the code execution works and finds the correct keras submodules. I saw that there is some code to lazy-load keras v2/3 in the init.py module of tensorflow, but do not understand how this works and if this is what makes the code execution work.