1

I'm trying to use the solution code given in the following link: Unicode Tagging in Python NLTK

In the solution given by omerbp:

from nltk.corpus import indian
from nltk.tag import tnt

train_data = indian.tagged_sents('hindi.pos')
tnt_pos_tagger = tnt.TnT()
tnt_pos_tagger.train(train_data) #Training the tnt Part of speech tagger with hindi data

print tnt_pos_tagger.tag(nltk.word_tokenize(word_to_be_tagged))

I'm getting the following error:

'SyntaxError: Non-ASCII character '\xe0' in file q12.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details' in line 1.

Community
  • 1
  • 1
rushj22
  • 23
  • 3
  • This error message [seems to come up a lot here](https://stackoverflow.com/search?q=SyntaxError%3A+Non-ASCII+character+python) - are any of those links helpful? – halfer Mar 05 '16 at 11:55
  • 2
    Possible duplicate of [Python NLTK: SyntaxError: Non-ASCII character '\xc3' in file (Senitment Analysis -NLP)](http://stackoverflow.com/questions/26899235/python-nltk-syntaxerror-non-ascii-character-xc3-in-file-senitment-analysis) – CaptSolo Mar 05 '16 at 12:12

1 Answers1

1

Add these two lines on the top of your file:

#!/usr/bin/python
# -*- coding: utf-8 -*-

They will instruct the interpreter to encode every charater as UTF-8 instead of ASCII.

Alex
  • 6,849
  • 6
  • 19
  • 36