3

So i have this line of code using NLTK library

def autospell(text):
        spells = [spell(w) for w in (nltk.word_tokenize(text))]
        return " ".join(spells) 
train_data['Phrase'][:200].apply(autospell) 

And i got this error telling me that the name spell is not defined, i dont know whats that mean because i thought it was from the NLTK library, or am i missing something somewhere?

NameError                                 Traceback (most recent call last)
<ipython-input-119-582bf5662c88> in <module>()
      5         spells = [spell(w) for w in (nltk.word_tokenize(text))]
      6         return " ".join(spells)
----> 7 train_data['Phrase'][:200].apply(autospell)

2 frames
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-119-582bf5662c88> in <listcomp>(.0)
      3         correct the spelling of the word.
      4         """
----> 5         spells = [spell(w) for w in (nltk.word_tokenize(text))]
      6         return " ".join(spells)
      7 train_data['Phrase'][:200].apply(autospell)

NameError: name 'spell' is not defined
2
  • 1
    Well, the code is calling a function named spell(); where is it declared? Commented Nov 5, 2021 at 10:02
  • the previous function was this: ``` !pip install nltk from autocorrect import Speller def word_tokenize(text): return nltk.word_tokenize(text) ``` Im not sure of which that function spell was from the library or was it supposed to be from me? Commented Nov 5, 2021 at 10:14

1 Answer 1

4

Check out Spell Checker for Python, you should probably use the autocorrect library. Example code :

from autocorrect import Speller

spell = Speller(lang='en')

def autospell(text):
        spells = [spell(w) for w in (nltk.word_tokenize(text))]
        return " ".join(spells) 
train_data['Phrase'][:200].apply(autospell) 
Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes i missed 1 line thanks <3 spell = Speller(lang='en')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.