0% found this document useful (0 votes)
40 views

Ai & ML Week-12

Uploaded by

ಹರಿ ಶಂ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Ai & ML Week-12

Uploaded by

ಹರಿ ಶಂ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Artificial Intelligence and Machine Learning Code:20CS51I

NLP USE CASE - SENTIMENT ANALYSIS (SA)

With advancements in technology and fields like deep learning, sentiment analysis is
becoming more and more common for companies that want to gauge their customers’
sentiments.

Today, businesses use natural language processing, statistical analysis, and text analysis
to identify the sentiment and classify words into positive, negative, and neutral
categories.

The best companies understand the importance of understanding their customers’


sentiments – what they are saying, what they mean and how they are saying. You can use
sentiment analysis to identify customer sentiment in comments, reviews, tweets, or social
media platforms where people mention your brand.

As sentiment analysis is the domain of understanding emotions using software,

What is sentiment analysis?


Sentiment analysis is analytical technique that uses statistics, natural language
processing, and machine learning to determine the emotional meaning of
communications.
Sentiment analysis is often performed on textual data to help businesses monitor
brand and product sentiment in customer feedback and understand customer needs.
Recent advancements in machine learning and deep learning have increased the
efficiency of sentiment analysis algorithms. You can creatively use
advanced artificial intelligence and machine learning tools for doing research and
draw out the analysis.
For example, sentiment analysis can help you to automatically analyze 5000+
reviews about your brand by discovering whether your customer is happy or not
satisfied by your pricing plans and customer services. Therefore, you can say that
the application of sentiment is endless.

Search Educations Page 1


Artificial Intelligence and Machine Learning Code:20CS51I

Types of Sentiment Analysis

Depending on how you interpret customer feedback, you can classify them and meet your
sentiment analysis. However, below are some of the popular sentiment analysis
classifications:

1.Fine-grained Sentiment Analysis


If your business requires the polarity precisions, then you can classify your polarity
categories into the following parts:
Very positive Positive Neutral
Negative Very Negative
For polarity analysis, you can use the 5-star ratings as a customer review where
very positive refers to a five-star rating and very negative refers to a one-star
rating.

2.Emotion Detection
This type of sentiment analysis helps to detect customer emotions like happiness,
disappointment, anger, sadness, etc. Here, you can use sentiment lexicons or
complex machine learning algorithms to identify the customer’s feelings.
One of the disadvantages of using sentiment lexicons is that people tend to express
emotions in different ways. So, it may be confusing to understand human emotion
clearly while using it.

3.Aspect-based Sentiment Analysis


Let’s say that you are analyzing customer sentiment using fine-grained analysis.
You want to identify the particular aspect or features for which people are
mentioning positive or negative reviews.
Search Educations Page 2
Artificial Intelligence and Machine Learning Code:20CS51I

Here, aspect-based sentiment analysis comes into play.


For instance, in the review “The camera quality of this phone is getting worse with
time,” an aspect-based classifier will determine that the review expresses a
negative opinion from the customer for the phone’s camera feature.

4.Multilingual Sentiment Analysis


Multilingual sentiment analysis is complex compared to others as it includes many
preprocessing and resources available online (i.e., sentiment lexicons).
Businesses value the feedback of the customer regardless of their geography or
language. Therefore, multilingual sentiment analysis helps you identify customer
sentiment irrespective of location or language difference.

Why is Sentiment Analysis important?


Let us look at the overall benefits of sentiment analysis in detail:

Sort Data at Scale


There is too much business data to analyze daily. Can you imagine sorting all these
documents, tweets, customer support conversations, or surveys manually? Sentiment
analysis will help your business to process all this massive data efficiently and cost-
effectively.

Real-Time Analysis
Is your angry customer about to churn? Is a PR crisis on social media escalating?
Sentiment analysis will help you handle these situations by identifying critical real-time
situations and taking necessary action right away.

Consistent Criteria
According to research, customers only agree for 60-65% while determining the sentiment
of the particular text. Tagging text is highly subjective, influenced by thoughts and
beliefs, and also includes personal experience. Therefore, you can apply criteria and
filters to all your data, improve their accuracy, and gain better insights using sentiment
analysis.

Business applications for Sentiment Analysis


 Reputation management and online brand monitoring
 Monitoring your own message
 Investment intelligence
 Market research and competition monitoring
 Crime prevention

Search Educations Page 3


Artificial Intelligence and Machine Learning Code:20CS51I

NLP USE CASE - SENTIMENT ANALYSIS (SA)

How does sentiment analysis work?


There are different algorithms that you can use to perform sentiment analysis

Rule-based Approaches
Usually, a rule-based system uses a set of human-crafted rules to help identify
subjectivity, polarity, or the subject of an opinion.
These rules may include various NLP techniques developed in computational
linguistics, such as:
 Stemming, tokenization, part-of-speech tagging and parsing.
 Lexicons (i.e. lists of words and expressions).

Here’s a basic example of how a rule- based system works:

1. Defines two lists of polarized words


(e.g. negative words such as bad, worst, ugly,
etc and positive Words such as good, best,
beautiful, etc).
2. Counts the number of positive and negative
words that appear in a given text.
3. If the number of positive word appearances
is greater than the number of negative word
appearances, the system returns a positive
sentiment, and vice versa. If the numbers are even,
the system will return a neutral sentiment.

Search Educations Page 4


Artificial Intelligence and Machine Learning Code:20CS51I

Rule-based systems are very naive since they don't take into account how words
are combined in a sequence. Of course, more advanced processing techniques
can
be used, and new rules added to support new expressions and vocabulary.
However, adding new rules may affect previous results, and the whole system
can
get very complex. Since rule-based systems often require fine-tuning
and maintenance, they’ll also need regular investments.

Automatic Approaches
Automatic methods, contrary to rule-based systems, don't rely on manually crafted rules,
but on machine learning techniques. A sentiment analysis task is usually modeled as a
classification problem, whereby a classifier is fed a text and returns a category,
e.g. positive, negative, or neutral.

Here’s how a machine learning classifier can be implemented:

Search Educations Page 5


Artificial Intelligence and Machine Learning Code:20CS51I

a]Feature Extraction from Input Text


Machine learning text classifiers will transform the text extraction using the
classical approach of bag-of-words or bag-of-n-grams with their frequency. A new
feature extraction system is created on word embeddings known as word vectors.

This kind of representation helps to improve the performance of classifiers by


making it possible for words with similar meanings to have similar presentations

b]Training and Prediction


In the training process, your model links with a particular input(i.e., text) to the
corresponding output based on the test sample. The feature extractor will help to
transfer the input to the feature vector.
These pairs of feature vectors and the tags provided are transferred to the machine
learning algorithm to generate a model.
In the prediction process, the feature extractor transforms the unidentified text
inputs into feature vectors. Further, these feature vectors generate the predicted
tags like positive, negative, and neutral.

Classification Algorithms
Various classification algorithms involve statistical modelings like naive Bayes,
support vector machines, deep learning, or logistic regression. Let us discuss them
in detail below:
Naive Bayes: It is a family of probabilistic algorithms that predict the category of a
text by using the Bayes theorem.
Support Vector Machines: It is a non-probabilistic model that uses a representation
of the input text as a point in multi-dimensional space. Different text categories
map to distinct regions within the space because the new texts are categorized
based on the similarity with the existing text and the region they are mapping.
Deep Learning: A family of algorithms that attempts to mimic the human brain
with the help of artificial neural networks to process the data.
Linear Regression: A family of algorithms in statistics that helps to predict some
value (y) for a given set of features (x).
Hybrid Sentiment Analysis Algorithms:The hybrid model is the combination of
elements of the rule-based approach and automatic approach into one system. A
massive advantage of this approach is that the results are often more accurate and
precise than the rule-based and automated approaches.

Search Educations Page 6


Artificial Intelligence and Machine Learning Code:20CS51I

ETHICS IN AI
What is AI Ethics ?
AI ethics is a set of guidelines that advise on the design and outcomes of artificial
intelligence

The ethics of AI is important to engineers and scientists who have become enthusiastic
about using this technology to solve engineering-related problems.

Ethics in AI ensures that the AI initiatives of the organization or entity maintain human
dignity and do not in any way cause harm to people.

Importance of AI ethics

Some ethical frameworks can minimize AI risks and ensure a safe, fair, and human-
centered AI. We will discuss some feature of Ethical AI that would tell us better than how
they make AI systems more safe and fair:

Social Well-being:
Ethical AI makes the system available for the individual, society, and the
environment’s sake. It will work for the benefit of mankind.

Avoid Unfair Bias:


The AI system that is designed is ethically fair. It will not do any unfair
discrimination against individuals or groups. It provides equitable access and
treatment. It detects and reduces unfair biases based on race, gender, nationality,
etc.

Privacy and Security:


AI systems keep data security at the top. Ethical AI-designed systems provide
proper data governance and model management systems. Privacy and preserving
AI principles help to keep the data secure.
Search Educations Page 7
Artificial Intelligence and Machine Learning Code:20CS51I

Reliable and Safe:


The AI system works only for the intended purpose, thus reducing unknown
mishappening chances.

Transparency and Explainability:


Ethical system explains each prediction and output. It provides transparency for the
logic of the model. Users get to know the contribution of data for the output. This
disclosure justifies the output and builds trust.
Akira AI systems obey the principles of Explainable AI; therefore, it provides
complete transparency and explainability of systems that build users' trust.

Governable:
We are designing a system that works on intended tasks. It detects and avoids
unintended consequences.

Value Alignment:
Humans are making decisions by considering universal values. Ethical frameworks
help to consider those universal values.

Human-Centered:
Ethical AI system values human diversity, freedom, autonomy, and rights. It serves
humans by respecting human values. The system is not performing any unfair and
unjustified actions. It respects individual freedom and autonomy. Our systems are
fair and protected. Our system respects the rights of individuals.

Search Educations Page 8


Artificial Intelligence and Machine Learning Code:20CS51I

Ethical challenges of AI

Today, artificial intelligence is essential across a wide range of industries, including


healthcare, retail, manufacturing, and even government.
But there are ethical challenges with AI, and as always, we need to stay vigilant about
these issues to make sure that artificial intelligence isn’t doing more harm than good.

Here are some of the biggest ethical challenges of artificial intelligence.


Biases
Control and the Morality of AI
Privacy
Power Balance
Ownership
Humanity

Biases
We need data to train our artificial intelligence algorithms, and we need to do
everything we can to eliminate bias in that data.
We know that Bias is possible when you favour one side and for that you need to
think. This means that to be biased we need to have thinking ability and Machines
do not have that.

So How can machines be Biased ?


Well, This is possible because as machines can't think but the developer can. The
person who developed the machine can have his own biases.
The biases of a developer can transfer into the machine through the Algorithms.

Control and the Morality of AI


As we use more and more artificial intelligence, we are asking machines to make
increasingly important decisions.

The same is true for autonomous cars. They need to react immediately if a child
runs out on the road, so it’s important that the AI is in control of the situation. This
creates interesting ethical challenges around AI and control.

Privacy
Privacy (and consent) for using data has long been an ethical dilemma of AI. We
need data to train AIs, but where does this data come from, and how do we use it?

Search Educations Page 9


Artificial Intelligence and Machine Learning Code:20CS51I

For example, Barbie now has an AI-enabled doll that children can speak to.
What does this mean in terms of ethics? There is an algorithm that is collecting
data from child’s conversations with this toy. Where is this data going, and how is
it being used?
As we have seen a lot in the news recently, there are also many companies that
collect data and sell it to other companies. What are the rules around this kind of
data collection, and what legislation might need to be put in place to protect users’
private information?

Power Balance
Huge companies like Amazon, Facebook, Google, are using artificial intelligence
to squash their competitors and become virtually unstoppable in the marketplace.
Balancing that power is a serious challenge in the world of AI.

Ownership
Who is responsible for some of the things that AIs are creating?
We can now use artificial intelligence to create text, bots, or even deep fake videos
that can be misleading. Who owns that material, and what do we do with this kind
of fake news if it spreads across the internet?
We also have AIs that can create art and music. When an AI writes a new piece of
music, who owns it? Who has the intellectual property rights for it, and should
potentially get paid for it?

Humanity
Artificial intelligence has now gotten so fast, powerful, and efficient that it can
leave humans feeling inferior. This issue may challenge us to think about what it
actually means to be human.
These are some of the key ethical challenges that we all need to think about very
carefully when it comes to AI.

AI code of ethics
The Code of Ethics in the Field of Artificial Intelligence establishes the general
ethical principles and standards of conduct that should be followed by participants
in relation to the field of artificial intelligence in their activities, as well as the
mechanisms for the implementation of the provisions of this Code.

PRINCIPLES OF ETHICS AND RULES OF CONDUCT


The main priority of the development of AI technologies is protecting the interests and
rights of human beings collectively and as individuals

Search Educations Page 10


Artificial Intelligence and Machine Learning Code:20CS51I

Human-centered and humanistic approach.

1. In the development of AI technologies, the rights and freedoms of the individual


should be given the greatest value.
2. A human-centered and humanistic approach is the basic ethical principle and
central criterion for assessing the ethical behavior of AI developers.

Respect for human autonomy and freedom of will.

1. AI Actors should take all necessary measures to preserve the autonomy and free
will of a human‘s decision-making ability, the right to choose, and, in general, the
intellectual abilities of a human as an intrinsic value and a system-forming factor of
modern civilization.

Compliance with the law

1.AI developers must know and comply with the provisions of the legislation in all
areas of their activities and at all stages of the creation, development and use of AI
technologies, including in matters of the legal responsibility of AI Actors.

Non-discrimination

1. To ensure fairness and non-discrimination, AI developers should take measures to


verify that the algorithms, datasets and processing methods for machine learning
that are used to group and/or classify data concerning individuals or groups do not
intentionally discriminate.

Assessment of risks and humanitarian impact.

1.AI developers are encouraged to assess the potential risks of using an AIS, including
the social consequences for individuals, society and the state, as well as the
humanitarian impact of the AIS on human rights and freedoms at different stages,
including during the formation and use of datasets.

2.Need for conscious responsibility when creating and using AI

Search Educations Page 11


Artificial Intelligence and Machine Learning Code:20CS51I

Risk-based approach.
The level of attention to ethical issues in AI and the nature of the relevant actions
of AI developers should be proportional to the assessment of the level of risk posed
by specific technologies and AISs and the interests of individuals and society.
Risk-level assessment must take into account both the known and possible risks; in
this case, the level of probability of threats should be taken into account as well as
their possible scale in the short and long term.

Responsible attitude.
AI Actors should have a responsible approach to the aspects of AIS that influence
society and citizens at every stage of the AIS life cycle.
These include privacy; the ethical, safe and responsible use of personal data; the
nature, degree and amount of damage that may follow as a result of the use of the
AI; and the selection and use of companion hardware and software.

Search Educations Page 12


Artificial Intelligence and Machine Learning Code:20CS51I

DOCKER INSTALLATION

Docker is an OS-level virtualization software platform that helps users in building and
managing applications in the Docker environment with all its library dependencies.

Step-By-Step Docker Installation on Windows


1. Go to the website https://docs.docker.com/docker-for-windows/install/ and
download the docker file.
2. Note: A 64-bit processor and 4GB system RAM are the hardware prerequisites
required to successfully run Docker on Windows 10.
3. Then, double-click on the Docker Desktop Installer.exe to run the installer
4. Note: Suppose the installer (Docker Desktop Installer.exe) is not downloaded; you
can get it from Docker Hub and run it whenever required.
5. Once you start the installation process, always enable Hyper-V Windows Feature
on the Configuration page.
6. Then, follow the installation process to allow the installer and wait till the process
is done.
7. After completion of the installation process, click Close and restart.

Start Docker for Windows


Docker does not start automatically after installation. To start it, search for Docker,
select Docker for Windows in the search results, and click it (or hit Enter).

Search Educations Page 13


Artificial Intelligence and Machine Learning Code:20CS51I

When the whale in the status bar stays steady, Docker is up-and-running, and accessible
from any terminal window.

Dockerfile:
Dockerfile is a simple text file that consists of instructions to build Docker images.
Dockerfile consists of specific commands that guide you on how to build a specific
Docker image.

The specific commands you can use in a dockerfile are:

FROM, PULL, RUN, and CMD


• FROM - Creates a layer from the ubuntu:18.04
• PULL - Adds files from your Docker repository
• RUN - Builds your container
• CMD - Specifies what command to run within the container

Search Educations Page 14


Artificial Intelligence and Machine Learning Code:20CS51I

Mentioned below is an example of the dockerfile with the important commands


FROM ubuntu:18.04 PULL. /file
RUN make /file
CMD python /file/file.py
Have a look at the diagrammatic representation of how a dockerfile looks in a docker
image:

let’s go through some of the most common Docker commands used while creating
dockerfiles.

List of Docker Commands for Creating a Dockerfile with example

ENTRYPOINT allows specifying a command along with the parameters Syntax:


ENTRYPOINT application "arg, arg1".
Example:
ENTRYPOINT echo "Hello, $name".

ADD command helps in copying data into a Docker image Syntax:


ADD /[source]/[destination]
Example:
ADD /root_folder/test_folder

ENV provides default values for variables that can be accessed within the container
Syntax:
ENV key value
Example:
ENV value_1

Search Educations Page 15


Artificial Intelligence and Machine Learning Code:20CS51I

MAINTAINER declares the author field of the images Syntax:


MAINTAINER [name]
Example:
MAINTAINER author_name

How to Build a Docker Image and Docker Container Using Dockerfile? First of all,
you should create a directory in order to store all the Docker images you build.
•Now, we will create a directory named ‘simplidocker’ with the command:
mkdir simplidocker
•Move Docker image into that directory and create a new empty file (Dockerfile) in it:
cd simplidocker touch Dockerfile
•Open the file with the editor. In this example, we opened the file using vi:
vi Dockerfile
•Then, add the following content:
FROM ubuntu MAINTAINER simpli RUN apt-get update
CMD ["echo", "Welcome to Simplilearn"]
•Save and exit the file.

Build a Docker Image with Dockerfile

Let’s first declare the path where we will be storing the dockerfile simplidocker
docker build [OPTIONS] PATH | URL | -

Now, let’s build a basic image using a Dockerfile:


docker build [location of your dockerfile]

Now, by adding -t flag, the new image can be tagged with a name:
docker build -t simpli_image

Once the Docker image is created, you can verify by executing the command:
docker images

The output should show simpli_docker available in the repository.

Search Educations Page 16


Artificial Intelligence and Machine Learning Code:20CS51I

Create a Docker container from Docker image


Now, create a Docker container from the Docker image we created in the previous step.

Let’s name the container “simplilearn” and create it with the command:
docker run --name simplilearn simpli_docker

The message ‘Welcome to Simplilearn’ should appear in the command line.


Congratulations, you just created a Docker image and a Docker container using a
Dockerfile.

Search Educations Page 17

You might also like