Exercise: Semantic Parsing with spaCy

Let's test the concepts we've learned with an exercise.

We'll cover the following

Problem:

You are tasked with building a chatbot that can extract multiple intents from user messages and provide appropriate responses. The chatbot should use the spaCy Matcher class to match user messages with predefined patterns and extract intents from them. Additionally, the chatbot should use a synonyms list to identify semantic similarities between user messages and predefined intents.

Your task is to write code for the chatbot that meets the following requirements:

  • Define three intents (greeting, buy_car, and book_flight) that the chatbot should be able to extract from user messages. For each intent, define a list of patterns that should match the intent.

  • Use the spaCy Matcher class to define patterns for each intent.

  • Define a synonyms list that the chatbot can use to identify semantic similarity between user messages and predefined intents. For example, if a user says, "I want to buy a car," the chatbot should recognize that this message is similar to the buy_car intent.

  • Write a function extract_intents that takes a user message as input, matches it with the predefined patterns using the spaCy Matcher class, and extracts the corresponding intents. The function should also use the synonyms list to identify semantic similarity between user messages and predefined intents.

Test your chatbot by providing different user messages and ensuring that the chatbot is able to extract the correct intents.

Sample input:

Get hands-on with 1200+ tech skills courses.