Previously, we understood the basics of Natural Language Processing ranging from sentence segmentation to parsing. These essential fundamentals form the foundation for understanding how systems work with and manipulate sentences. If you haven't read the blog, you can read it here.
Moving forward we'll dive into understanding chatbots and building them using RASA.
Contents of this blog:
- Chatbots and development
- What is RASA?
- RASA core.
- Featurizers and Classifiers.
- Pipelines.
Definitions
Intents: An intent is a specific grouping of messages which the module can anticipate being used to map responses to.
Classifiers: Classifiers essentially take features produced by featurizers and make predictions.
Entity: An entity is a piece of information that the chatbot extracts from the user to perform some action.
Slots: Slots are temporary variables used to hold data from conversations.
Chatbot and development
Chatbots are basic response systems used for providing answers to queries. Although they are meant to be consistent, we can add dynamism by consider the methods by which they are developed.
Effectively chatbot development consisted of linking specified answers to questions based on the user needs. Most commonly these were used as assistants within web services, however utility doesn't just end there. With the introduction of Artificial Intelligence development of chatbots has becoming scarcer, as people prefer building LLMs with neural networks the considerations of chatbot or chat models has recently dwindled.
However, this doesn't make it ancient tech, rather a better understanding of preset response systems can help newer developers better understand the grounds for LLM development in general.
So how does one develop chatbots?
The development of chatbot varies a lot, for some a simple if-else structure leading to varying website responses can be a chatbot. For others a chatbot should be dynamic enough to be syntactically intelligent while also being consistent in its answering.
Chatbot development can be divided into static type and dynamic type (very broadly) based on this user need.
As previously stated, a simple if-else clause handling a 'y/n' response can be considered as partly a chatbot. Only in this case the answers are preloaded in the form of links or redirects to relevant pages.
In recent years the web-dev scene has moved closer to adopting syntactical analysers and add a sense of dynamism while keeping consistency by using such logical iterators. These are the basis of website helpers or assistants, nearly intelligent yet partly logical.
Query: Hey, Mind redirecting me to the Home page? I can't seem to find the link.
Assistant (internal): Hey, Mind redirecting me to the Home page? (Question)
I can't seem to find the link. (sentence)
Assistant (syntactical handling): ['Redirect'(action), 'me'(user), 'Home page'(location), 'can't find link' (reason)]
System response: https://Link_for_loc.org (some worded response)
This way the developer has complete control over the prompt responses which offers flexibility when developing large scalable websites. This reduces the 'black-box' from neural network training and add more transparency within the system itself.
What is RASA?
Now that we've established the need for response control with syntactical analysis one might question what RASA even is.
It's exactly that, RASA is a python package providing syntactical intelligence to systems. This allows for an ML based input system which has the ability of understanding synonyms as well as complete sentence variation.
For this the RASA module utilizes to core sub-modules which are responsible for handling this ability.
- RASA core
- RASA NLU
For this blog's we'll set our focus on what the RASA core is and does. Specifically looking at Featurizers, Classifiers, Pipelines and Policies.
What is RASA core?
RASA core can be considered as the responder to the user queries. The queries are commonly handled by the NLU (Natural Language Understanding) engine, whereas the responses are managed by the core.
RASA core is a state machine, i.e. it keeps track of the conversation, what the user intends from a sentence and finds the appropriate response for the query. Now we'll be covering NLU in the upcoming blog, I'll briefly explain how it works, as an understanding of intents is crucial for understanding response generation.
Simply stated, the RASA NLU utilizes a file known as 'domain.yml'. Essentially it is a yaml file which is used to declare all the types of intents. Within the file, being headed as 'intents' all the relevant group titles are declared under it.
intents:
- greet
- goodbye
- affirm
This essentially tells the model that there will be some queries which you may expect of the type 'greet' or 'goodbye'.
Now the text is as is partly due to yaml coding, it uses python like indentations followed by dashes to declare subtype.
These intents are then "initialised" similarly to how variable initialisation works, under the file named 'nlu.yml' we declare all the examples of what 'greet' may look like (if it is difficult understanding it, imagine a super class called greet which holds all methods: examples of greetings)
- intent: greet
examples: |
- hey
- hello
- hi
Once all of these examples have been added we map these groups to their respective responses within a rules file, which maps the responses as steps which are to be performed once a query is asked.
As we understand how the model understands and handles data inputs let's move onto the actual reason behind why it is able to understand varying degrees of similar sentence intentions.
Features and Classifiers
Featurizers: Featurizers convert user messages (text) into numerical representations (features) that machine-learning models can understand.
Effectively taken the parsed input and producing vector representation internally. This allows the model to understand patterns, capture the meaning and obtain a sense of 'What do you mean?'
There are multiple featurizers but they are all dependent on the user's requirement.
- Whitespace tokenizer: Used to form tokens, the mode of tokenization is every space between two words forms the definitions for where another token begins.
within: stories.yml
language: en
pipeline:
- name: WhitespaceTokenizer
intent_tokenization_flag: true
intent_split_symbol: "_"
- Regex Featurizer: In Rasa, the RegexFeaturizer is a lightweight feature extractor that adds binary features based on whether parts of a user message match predefined regular expression. It does not extract entities by itself, and it does not classify intents. Instead, it helps classifiers (like DIETClassifier) by giving them strong signals.
within: stories.yml
- name: RegexFeaturizer
- Lexical Syntactic Featurizer: In Rasa, the Lexical Syntactic Featurizer (officially LexicalSyntacticFeaturizer) is a token-level featurizer that adds linguistic pattern features based on the form and position of each token in a sentence. It helps classifiers and entity extractors recognize structural patterns, not meaning.
within: stories.yml
- name: LexicalSyntacticFeaturizer
And many more!
Classifiers:
In Rasa, classifiers are machine-learning components that take the numeric features produced by featurizers and use them to predict labels from user messages.
Those labels are mainly:
- Intents (what the user wants)
- Entities (important structured values in the text)
What a classifier does
- Receives features (sparse + dense) from featurizers
- Learns patterns from labeled training data
- Predicts labels for new user messages
In short:
Text → Features → Classifier → Intent / Entities
Some common classifiers are DIETClassifiers and Entity Synonym Mapper. These are essentially used to classify entities from the user queries.
DIETClassifiers
DIET stands for Dual Intent Entity Transformer classifier. It is used for both intent classification and entity extraction within a singular model in the place of using two varying models.
Featurizers such as Regex (pattern), Lexical Syntactical (Wording), and Count vectors (vectorization) preprocess the initial inputs. With DIET receiving embeds as inputs transformer modules such as BERT uses self-attention. This allows it to learn contextual meaning.
Entity Synonym Mapper
Used for normalising entity values. Used for synonymous words consideration for varying user inputs. This effectively translates:
I need a heart doctor -> I need a cardiologist.
These changes can be spotted by the synonym mapper, but they are handled by slots and mapped within the 'domain.yml' file.
slots:
patient_name:
type: text
mappings:
- type: from_entity
entity: patient_name
Pipelines
Pipelines are the architectural ordering which is used to process sentences. Pipelines are largely task specific, for this purpose RASA itself provides prebuilt packages of pipelines. These are mostly open-source projects, this promotes development of their own sequencing based on tasks, this is quite essential when developers prefer flexibility.
For e.g.
SpaCy Pipeline, Bert Pipeline or Bio-Bert Pipelines.
SpaCy Pipeline:
SpaCy is an NLP library with pre-trained embeddings for multiple languages. It provides embeddings with POS tagging with lemmatization and some NER.
Bert Pipeline: Provides a deep contextual embedding i.e. understands meaning from context. For RASA, the HF transformer NLP or DIET are integrated into the pipeline.
Bio-Bert: Domain specific version of BERT pretrained on biomedical text, this module is better for medical terminology. Accurate NER and useful for symptom checker based on disease names and drugs. This version is also useful in appointment scheduling for specified specialist.
These modules basically form the backbone of response generation and information outputting. In the following blogs I'll dive deeper into the rules, policies and stories which will inform you how the rules for what to output are formed.
Until next time!
The next blog: To be decided
Top comments (0)