module 'tensorflow' has no attribute 'variable' in google Colaboratory - python

I'm trying to create a variable tensor in google Collaboratory with this code, but error because TensorFlow doesn't have a module about variables. what's the solution?
import tensorflow as tf
var_1 = tf.variable(tf.ones([2,3]))
Error:
AttributeError Traceback (most recent call last)
<ipython-input-2-2666f49bf801> in <module>()
----> 1 var_1 = tf.variable(tf.ones([2,3]))```
AttributeError: module 'tensorflow' has no attribute 'variable'

There is a typo error. Use capital letter V for Variable.
You can refer below code for the same.
import tensorflow as tf
var_1 = tf.Variable(tf.ones([2,3]))
var_1
Click here, for more details

Related

"module 'torchtext.data' has no attribute 'Field'"

import torchtext
ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-2a3d11c77e7d> in <module>
----> 1 ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
AttributeError: module 'torchtext.data' has no attribute 'Field'
It won't import torchtext.data.Field for some reason even though that's whats in the docs
[BC Breaking] Legacy
In v0.9.0 release, we move the following legacy code to torchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed in Issue #664:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
We have a migration tutorial to help users switch to the torchtext datasets in v0.9.0 release. For the users who still want the legacy components, they can add legacy to the import path.
Try it with ENGLISH = torchtext.legacy.data.field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")

tensorflow scope lost in Jupyter lab

I'm having trouble splitting up tensorflow code that runs fine in 1 cell in jupyter lab (v2.1.5). As a simple test I did this:
import tensorflow as tf
a=2
print(a,tf.__version__)
result:
2 2.3.0-rc0
cell2:
print(a)
print(tf.__version__)
result:
2
AttributeError Traceback (most recent call last)
<ipython-input-2-d9c2549c3ca0> in <module>
1 print(a)
----> 2 print(tf.__version__)
AttributeError: 'NoneType' object has no attribute '__version__'
Any toughts what's missing?

I can import function but not class with error "AttributeError: module 'XXXX' has no attribute 'YYYY' "

I can't load class I defined in another file. It is strange behavior that I CAN load function defined in the same file.
XXXX.py
def hoge():
print('hoge')
class YYYY:
def hoge(self):
print('hoge')
I try to import and run XXXX as follow:
import XXXX
XXXX.hoge()
XXXX.YYYY
Then, I encountered the error
hoge
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-76-cbd9d0cb0faf> in <module>
2 XXXX.hoge()
----> 3 XXXX.YYYY
AttributeError: module 'XXXX' has no attribute 'YYYY'
I use Python 3.6
I've solved this problem.
This error occurs on jupyter-notebook.
But it works on terminal.
I don't know why this happens on jupyter.

Import module has no attribute

I'm using Python since few days and I'm trying to learn as much as possible from it. I'm using Jupyter notebook as well. I made a python file fibo.py where I code a function fib and I saved it. In the same folder I try to import that module and use the function fib
import pandas as pd
import numpy as np
import fibo
result = fibo.fib(10)
but I get the following error message :
AttributeError: module 'fibo' has no attribute 'fib'
Could you please give me some suggestions where the problem should be? Thank you in advance.
This is the code for fibo.py
# Fibonacci numbers module\n",
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
The error I get is here:
AttributeError Traceback (most recent call last)
<ipython-input-1-73202afd3146> in <module>
3
4 import fibo
----> 5 result = fibo.fib(10)
AttributeError: module 'fibo' has no attribute 'fib'
I tried also
from fibo import fib
And I get the following:
ImportError Traceback (most recent call last)
<ipython-input-2-b2d78eaf1dcb> in <module>
4 import fibo
5 #result = fibo.fib(10)
----> 6 from fibo import fib
ImportError: cannot import name 'fib' from 'fibo' (C:\Users\my_folder\Documents\JupyterWork\fibo.py)
Save the file as .py using any text editor other than jupyter notebook.
Because jupyter notebook file are stored in JSON format.

Importing & using HoltWinters from hardPredictions

I'm stuck on importing a module from hardPredictions. I can find documentation on installing the libraryand using the module module, but not how to import the module.
I've tried the following:
from hardPredictions import HoltWinters
model = HoltWinters()
This gives me an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-72e6928695cf> in <module>
----> 1 model = HoltWinters()
TypeError: 'module' object is not callable
This works, but then I can't pass my ts to the model:
from hardPredictions import HoltWinters
model = HoltWinters
model.fit(ts)
gives an error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-f40ff401465a> in <module>
1 model = HoltWinters
----> 2 model.fit(ts)
AttributeError: module 'hardPredictions.HoltWinters' has no attribute 'fit'
I've also tried running help() and dir() on HoltWinters, but think the main thing is I'm lacking the skill to ask the library how to import a model. Your advice is much appreciated!

Categories

Resources