Illegal grammar chunk error -

Summery of the report:
Course: build chatbots with python - rule-based chatbots - Discover Insights into Classic Texts

On the “Discover Insights to Classis Texts” activity I am getting the following error "ValueError: Illegal chunk pattern: {


The code that is causing the issue is:

vp_chunk_grammar = “VP: {


The chunk pattern I used in my code matches the code that is in the hint, and I have already reported the bug a number of times using the on-screen bug reporting option within the actual exercise. No one has responded.

Course URL:

Steps to Reproduce:
run this code:

from nltk import pos_tag, RegexpParser

from tokenize_words import word_sentence_tokenize

from chunk_counters import np_chunk_counter, vp_chunk_counter

import text of choice here

text = open(“dorian_gray.txt”, encoding=“utf-8”).read().lower()

sentence and word tokenize text here

word_tokenized_text = word_sentence_tokenize(text)

store and print any word tokenized sentence here

single_word_tokenized_sentence = word_tokenized_text[0]


create a list to hold part-of-speech tagged sentences here

pos_tagged_text =

create a for loop through each word tokenized sentence here

for i in word_tokenized_text:


part-of-speech tag each sentence and append to list of pos-tagged sentences here

store and print any part-of-speech tagged sentence here

single_pos_sentence = pos_tagged_text[0]


define noun phrase chunk grammar here

np_chunk_grammar = “NP: {


create noun phrase RegexpParser object here

np_chunk_parser = RegexpParser(np_chunk_grammar)

define verb phrase chunk grammar here

vp_chunk_grammar = “VP: {


create verb phrase RegexpParser object here

create a list to hold noun phrase chunked sentences and a list to hold verb phrase chunked sentences here

create a for loop through each pos-tagged sentence here

chunk each sentence and append to lists here

store and print the most common NP-chunks here

store and print the most common VP-chunks here

Fix or Workaround:

There is no workaround at the moment. I can’t see any way to display the correct solution.


I’m afraid I’m not too familiar with nltk but your error points to Line 39 which is where np_chunk_grammar is assigned. Looking at the expression it appears there is a } missing from your pattern. Try adding that in and seeing if it solves your error. I don’t think it involves vp_chunk_grammar at all.

If (and only if) this fixes the issue could you confirm it so that CC don’t treat this as a bug report.

thanks a lot. you were right, there was a missing bracket on a different line than the one I thought was causing the problem. I was able to advance thanks to your fix.

side question… I have reported my bug 2-3 times over the last couple weeks using the integrated bug report tool directly within the exercise and no one from codecademy ever responded in any way. Is that normal? Why do they offer that method for reporting bugs if no one responds?

I’m afraid I don’t know the details of how they prioritise bug reports. It’s possible they act on the most prevalent reports (say if multiple users had encountered an issue) but I don’t think it’s even possible to directly respond to individual bug reports through that portal. I’d hazard a guess they’re just too frequent and in many cases are not fixable but I must stress that’s just a guess :stuck_out_tongue:.

If you’re encountering an issue that isn’t 100% an obvious bug in the future consider posing it as a question on the community forums. Definitely worth having a read of the linked FAQ for writing queries though (especially the section on formatting code as we all appreciate properly formatted code) for the best chance of a helpful reply.