I ran (in IDLE 3.5.2) the Brill tagger demo at <
http://www.nltk.org/_modules/nltk/tbl/demo.html>. Next, I tried to rerun it and save the trained tagger. I made the simplest change, True instead of None in one definition:
def postag(
#[...]
serialize_output=True,
#[...]
Now I am getting a runtime error.
Traceback (most recent call last):
File "
nltk.tbl.demo.py", line 382, in <module>
demo_learning_curve()
File "
nltk.tbl.demo.py", line 111, in demo_learning_curve
postag(incremental_stats=True, separate_baseline_data=True, learning_curve_output="learningcurve.png")
File "
nltk.tbl.demo.py", line 300, in postag
pickle.dump(brill_tagger, print_rules)
TypeError: write() argument must be str, not bytes
The relevant lines 297-304:
if serialize_output is not None:
taggedtest = brill_tagger.tag_sents(testing_data)
with open(serialize_output, 'w') as print_rules:
pickle.dump(brill_tagger, print_rules)
print("Wrote pickled tagger to {0}".format(serialize_output))
with open(serialize_output, "r") as print_rules:
brill_tagger_reloaded = pickle.load(print_rules)
print("Reloaded pickled tagger from {0}".format(serialize_output))
I see nothing wrong here. I tried to change 'w' to 'wb' (no error now) and "r" to 'rb' (a new error):
File "
nltk.tbl.demo.py", line 302, in postag
with open(serialize_output, 'rb') as print_rules:
OSError: [Errno 9] Bad file descriptor
The same error appears if I keep "r".
Please help!
Stan