Chatbot Song Recommender System: Chapter 1: Introduction
Chatbot Song Recommender System: Chapter 1: Introduction
Chatbot Song Recommender System: Chapter 1: Introduction
CHAPTER 1: INTRODUCTION
The purpose of chat bots is to support and scale business teams in their relations with
customers. It could live in any major chat applications like Facebook Messenger, Slack,
Telegram, Text Messages, etc. Chatbot applications streamline interactions between people
and services, enhancing customer experience. At the same time, they offer companies new
opportunities to improve the customers engagement process and operational efficiency by
reducing the typical cost of customer service. This project is focussed on building a custom
chatbot that will be your fundamental step of the learning curve of building your own
professional chatbots.
But you must be tired of the weird chat bots out there in the world which are made for
mainly business purposes? In this project, we would be building an extensive Chatbot
service, to which you can talk to. And talking to a chatbot wouldn't be business-driven. It
would just be casual conversations. Further, on top of it, the chatbot would also be
recommending songs to the user based on the tone of the user. This song recommendation
feature employs the use of Last.fm API, very much similar to the popular Spotify API. Also
for tone/emotion analysis of the conversation we will be using the IBM Tone Analyzer API.
Collaborating with these types of APIs is very much critical as in today's world the popular
chatbots do much more than simply having a data-driven conversation; to supplement
additional user-oriented features. Also the reason to choose python to build the chatbot is
because python boasts a wide array of open-source libraries for chatbots, including
scikitlearn and TensorFlow. It is great for small data sets and more simple analyses; also
Python's libraries are much more practical.
PAGE 2
Product Architecture
• Setting up an open-source project locally and handling the errors being faced
• Using multiple services to build up a new service over them.
• Having a real-world chatbot, to which you can literally chat like you chatting to a real
person and enjoying the music recommended by the system.
• Run and test the Cakechat Server as specified here • If you see the following
error:-
have a look
Expected Outcome
• By the end, you will be having a running Cakechat Chatbot Server on your system and
you would be able to get a response based on a conversation like shown below:-
• Check this website to have an idea of what IBM Tone Analyzer API would be doing.
• Create an account on IBM Cloud (It's free)
• Enable the Tone Analyzer Service for your account from here.
• Try running the Python code for analyzing the conversation from here and don't forget
to replace {apikey} and {url} with the apikey and url you received by enabling Tone
Analyser Service for your account.
• After running the code, tone Analyser Service, you would have the analysis of the text
on your system which looks similar to this. Here as the top is the tone of the entire app
and below is the tone of every sentence.
PAGE 7
{
"document_tone": {
"tones": [
{
"score": 0.6165,
"tone_id": "sadness",
"tone_name": "Sadness"
},
{
"score": 0.829888,
"tone_id": "analytical",
"tone_name": "Analytical"
}
]
},
"sentences_tone": [
{
"sentence_id": 0,
"text": "Team, I know that times are tough!",
"tones": [
{
"score": 0.801827,
"tone_id": "analytical",
"tone_name": "Analytical"
}
]
},
{
"sentence_id": 1,
"text": "Product sales have been disappointing for the past three
quarters.",
"tones": [
{
"score": 0.771241,
"tone_id": "sadness",
"tone_name": "Sadness"
},
{
"score": 0.687768,
"tone_id": "analytical",
"tone_name": "Analytical"
}
]
},
{
"sentence_id": 2,
"text": "We have a competitive product, but we need to do a better
job of selling it!",
"tones": [
{
"score": 0.506763,
"tone_id": "analytical",
"tone_name": "Analytical"
}
]
}
]
}
So, now for any given phrase or sentence, you can analyze the tone of that. We would be
using this code ahead to analyze the tone of the conversation.
Expected Outcome
• By the end of this milestone, you would have seen the response of both the
abovespecified API's
Try using mbid instead of just using track name and artist for finding songs similar to a
given song.
We would be implementing this approach manually to get started right away by building
the chatbot in the next milestone.
Requirements
• Let's start the conversation with a good mood tone:
Hey there!! What's up? How's the day?
• Now let's send this text for Emotional Analysis. And we get the following response:
"document_tone": {
"tones": [
{
"score": 0.66525,
"tone_id": "joy",
"tone_name": "Joy"
}
]
},
"sentences_tone": [
{
"sentence_id": 0,
"text": "Hey there!! What's up?",
"tones": []
},
{
"sentence_id": 1,
"text": "How's the day?",
"tones": []
}
]
}
PAGE 12
• Now send the request to the chatbot server with the emotion of the chatbot using the
following mapping:
{
"anger": "anger",
"fear":"sadness",
"joy":"joy",
"sadness":"sadness",
"analytical":"neutral",
"confident":"neutral",
"tentative":"neutral"
}
Why this mapping? Because the Cakechat chatbot supports conversation in limited
emotions only.
Just wondering... how can you have an analytical conversation? ... but still,
you can have an analytical tone ... Therefore we are mapping Analytical tone
to Neutral conversation.
• Now, send the request to the cakechat server with the conversation and the emotion of
the chat.
Request:
"context": [
"Hey there!! What's up? How's the day?"
],
{ } "emotion": "joy"
Response:
As you can see we got the response. So, you can continue further with the conversation
appended in the context variable.
• Now, it's time to get a song recommendation. Have a look and analyze the number of
songs of a particular tag using last.fm tag.gettoptracks API.
{
"tracks": {
"track": [ {...},
{...}
],
"@attr": {
"tag": "analytical",
"page": "1",
"perPage": "5",
"totalPages": "1",
"total": "2"
}}
}
You would have seen here also that we were only able to find 2 songs corresponding to the
analytical tag. So, instead of using the tags returned by the Emotional API, we can map
them using the mapping defined earlier above.
• Now, once a user would click on a particular song, we also need to recommend similar
songs to that particular song. This can also be done using the last.fm's
track.getsimilar API using the track and the artist of the song.
By now, you have a complete system and a good understanding of the project's flow, which
is satisfied by the above requirements.
list of songs
○ /simmilarsongs ■
input:
● the song name ● the artist name ■ output:
● list of songs
Here, on the left, I have the songs recommended to the user, and on the right-hand side are
the songs which were recommended based on one of the songs which I clicked on.
Further, the emotion of the chat is shown at the top
PAGE 15
The chat app provides a better and more flexible chat system. Developed with the latest
technology in the way of providing a reliable system. The main advantage of the system
is instant messaging, real-world communication, added security, group chat, etc. This
application may find the best demand in the market for most organizations that aim to
have independent applications.
FUTURE SCOPE.
The future of chatbots is transforming the way businesses interact with their customers.
From handling customer inquiries and offering real-time support to providing
personalized product recommendations, chatbots are becoming increasingly important
for all types of businesses in the digital age.