I'm playing with examples from Natural Language Processing with Python and this line:
lp = nltk.LogicParser()
produces
AttributeError: 'module' object has no attribute 'LogicParser'
error message. I imported several nltk modules and I can't figure out what is missing. Any clues?
It sounds like you've spotted the problem, but just in case: You are reading the first edition of the NLTK book, but evidently you have installed NLTK 3, which has many changes. Look at the current version of chapter 10 for the correct usage.
Related
Running into an issue with a project from here
Right off the bat when testing on Debian running python 3.7 it’s putting out errors, unfortunately I’m no coder and the devs don’t seem too responsive based on previous issues reported on their repos. I think it might be related to the float but what do I know.
def connect_tcp(host="127.0.0.1", port=8423, timeout: float = None) -> tuple[socket.socket, socket.socket]: TypeError: 'type' object is not subscriptable
Any pointers would be greatly appreciated
Not tried much as not sure what do to.
The issue comes from tuple[socket.socket, socket.socket].
This notation using tuple directly was implemented in python 3.9, for python up to 3.8 it was done through typing.Tuple.
You can add from __future__ import annotation (see __future__) at the top of that file to turn on the postponed evaluation of annotations, which will allow you to run with any python from 3.7.
I have found this code and I wanna see what is the object that im printing in the last line. im new in field of nlp so please help me fix this code, because it gives AttributeError: 'Field' object has no attribute 'vocab'error. by the way I have found out that torchtext has been changed and the error is probably related to these changes, and the code probably was working before.
import spacy
from torchtext.legacy.data import Field
spacy_eng = spacy.load("en")
def tokenize_eng(text):
return [tok.text for tok in spacy_eng.tokenizer(text)]
english = Field(
tokenize=tokenize_eng, lower=True, init_token="<sos>", eos_token="<eos>"
)
print([english.vocab.stoi["<sos>"]])
You have to build the vocabulary for the english Field before you try to access it. You will need a dataset to build the vocabulary, which will be the dataset you are looking to build a model for. You can use english.build_vocab(...). Here are the docs for build_vocab.
Also, if you would like to learn how to migrate what you are doing to the new version of torchtext, here is a good resource.
I am trying to use googletrans to translate some Spanish text to English. I am following the examples & below is my code.
from googletrans import Translator
translator = Translator()
txt = translator.translate('tener', src='es', dest='en')
I get the following error though,
AttributeError: 'NoneType' object has no attribute 'group'
What am I missing?
Seems like the issue is with Google, see the following stackoverflow post:
googletrans stopped working with error 'NoneType' object has no attribute 'group'
This solution worked for me (the accepted doesn't work for me):
https://stackoverflow.com/a/65113191/14676920
accuracy = tf.streaming_accuracy (y_pred,y_true,name='acc')
recall = tf.streaming_recall (y_pred,y_true,name='acc')
precision = tf.streaming_precision(y_pred,y_true,name='acc')
confusion = tf.confuson_matrix(Labels, y_pred,num_classes=10,dtype=tf.float32,name='conf')
For the above code, I have received the same error in past few days.
Isn't the syntax same as it is in the API documentation for tensorflow?
try to use this instead (in a fresh python file, I would suggest create a /tmp/temp.py and run that)
from tensorflow.contrib.metrics import streaming_accuracy
and if this doesn't work then
either there is an installation problem (In which case reinstall)
or you are importing the wrong tensorflow module.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 3 years ago.
I have a recent problem with random module
I dont understand why is that?
I showed the exact path that goes to random.py but it still didnt work.
python3.4 64bit
using pycharm 2016.2.2
First group is real error
Second group relates to help(random)
Sorry about confusion.
File "C:/Users/blueg/Google Drive/Programming/Python/PycharmProjects/LearningPython/Random Module/random.py", line 1, in <module>
import random File "C:\Users\blueg\Google Drive\Programming\Python\PycharmProjects\LearningPython\Random Module\random.py", line 4, in <module>
a = random.randint(1,6) AttributeError: 'module' object has no attribute 'randint'
Help on module random:
NAME random
FILE c:\users\blueg\google drive\programming\python\pycharmprojects\learningpython\random module\random.py
you have called your module random.py and thus you're importing your own module: rename it it will work (and also delete the random.pyc associated file or python will use that one in turn)
(I sometimes think that naming one's module in german, french or other avoids conflicts :))