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.
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]
print(single_word_tokenized_sentence)
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:
pos_tagged_text.append(pos_tag(i))
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]
print(single_pos_sentence)
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.
Screenshot: