Page 340 - AI Computer 10
P. 340
A computer also follows syntax and semantics in a programming language. Syntax refers to the rules for writing
valid code using keywords, punctuations, etc. Semantics in programming language help in understanding
whether a code achieves its intended purpose.
For example,
u Different syntax, same semantics: 5+4 and 4+5
Here, the two expressions are written in different way, but their meanings are same. Hence, both expressions
produce output 9.
u Different semantics, same syntax: 3/2 in Python 2.7 and 2/3 in Python 3
Here, the two expressions are written same, but their meanings are different. In Python 2.7, we will get 0 as
result, while in Python 3, we will get 0.6666666666666666 as result.
Knowledge Botwledge Bot
Kno
Semantics is what the language expression evaluates to.
Semantics: Understanding the Meanings of Words
Sometimes, a word or a sentence has multiple meanings. Let’s consider these three sentences:
u His face turned red when he heard that he failed. (What does this mean? Is he feeling ashamed because he
failed? Is he feeling angry because he did not work hard?)
u The red coloured car is my favourite. (Here, the colour of the car ‘red’ is stressed)
u His face turns red after consuming the medicine. (Is he having an allergic reaction? Or is he not able to bear
the taste of that medicine? )
In all the three statements, the word 'red' has been used.
However, the context of a statement or a sentence is important. In all three sentences, the word red has been
used in three different ways which according to the context of the statement changes its meaning completely.
Thus, in natural language, a word can have multiple meanings and the meanings fit into the statement according
to the context of it.
Pragmatics: Understanding The Purpose
Sometimes, a statement or a sentence is perfectly correct as per syntax, but it does not mean anything. For
example:
u Moon eats biscuits while the dog feeds tea.
This statement is correct grammatically but makes no sense. Thus, a perfect balance of syntax and semantics is
important in human language for understanding what the text is trying to achieve.
Language is complex in nature because its lexicon is constantly changing. Thus, these are some challenges that
we might have to face when we teach computers how to understand and interact in a human language.
HOW DOES NLP WORK?
Human able to understand any of these languages beings are able to talk in many languages such as English,
Hindi, French, Spanish etc. but computers are not. It understands only machine language. Thus, all the processes
in our computers and smart devices communicate via millions of zeros and ones to perform a particular function.
Now, let us understand how Natural Language Processing makes it possible for the machines to understand and
speak in the natural languages just like humans.
206
206