COMPUTER SCIENCE IN ACTION THE CHOMSKY HIERARCHY THE

  • Slides: 40
Download presentation
COMPUTER SCIENCE IN ACTION THE CHOMSKY HIERARCHY & THE COMPLEXITY OF THE ENGLISH LANGUAGE

COMPUTER SCIENCE IN ACTION THE CHOMSKY HIERARCHY & THE COMPLEXITY OF THE ENGLISH LANGUAGE jfrost@tiffin. kingston. sch. uk www. drfrostmaths. com @Dr. Frost. Maths Last modified: 9 th November 2017

Warning: This talk contains MATHS

Warning: This talk contains MATHS

WHAT DOES IT MEAN TO INTERPRET ‘LANGUAGE’? Stanford Natural Language Processing Group. Sentences consist

WHAT DOES IT MEAN TO INTERPRET ‘LANGUAGE’? Stanford Natural Language Processing Group. Sentences consist of a list of symbols from some fixed set (i. e. the dictionary!) These symbols (words) join together according to some set of rules, known as a grammar. If a sentence obeys these rules it’s possible to retrieve how these rules were applied (as above).

Not all ‘languages’ are human ones! My website has to take mathematical expressions (written

Not all ‘languages’ are human ones! My website has to take mathematical expressions (written in LATEX), ‘parse’ them (i. e. work out the structure of the expression, using the ‘grammar’ of mathematical expressions, e. g. BIDMAS), then apply different equivalence algorithms.

Programming languages are ‘languages’! while(i<32) { bar[i] = i*3. 7; print “BOSH”; } Tokenise

Programming languages are ‘languages’! while(i<32) { bar[i] = i*3. 7; print “BOSH”; } Tokenise while, (, i, <, 32, ), {, bar, [, i, ], =, i, *, 3. 7, ; , print, “BOSH”, ; , } Programming language interpreters/compilers first ‘tokenise’ the input into more manageable symbols. The ‘grammar’ of the language is the syntax of that particular language (e. g. while is followed by a condition then a statement)

What is a language? For the English language on a letter level: (mathematically speaking?

What is a language? For the English language on a letter level: (mathematically speaking? ) For mathematical expressions:

Often however, it’s better to make our ‘symbols’ full words (known as ‘tokens’) so

Often however, it’s better to make our ‘symbols’ full words (known as ‘tokens’) so that we can later make better rules (i. e. a ‘grammar’!) about how such symbols can join together. For the English language on a word level: For programming languages:

The cross product of two sets gives you all possible ‘pairs’ of symbols, with

The cross product of two sets gives you all possible ‘pairs’ of symbols, with the first in the pair from the first set and the second in the pair from the second set. We could more conveniently write this in ‘string’ form as “bd”

Similarly all 3 -symbol strings. The ‘empty string’, i. e. nothing! “Kleene Star”

Similarly all 3 -symbol strings. The ‘empty string’, i. e. nothing! “Kleene Star”

Similarly, this set contains all mathematical expressions, regardless of whether they are syntactically valid!

Similarly, this set contains all mathematical expressions, regardless of whether they are syntactically valid!

We therefore need some kind of grammatical rules that restricts strings/sentences to those which

We therefore need some kind of grammatical rules that restricts strings/sentences to those which we deem valid. Output: Set of all ‘valid’ string/sentences. i. e. The set of all ‘valid’ sentences is contained within the set of all theoretically possible sentences.

SO WHERE DOES THISCHOMSKY BLOKE COME IN? Regular expressions Context-free Context-sensitive Recursively enumerable The

SO WHERE DOES THISCHOMSKY BLOKE COME IN? Regular expressions Context-free Context-sensitive Recursively enumerable The Chomsky Hierarchy is effectively the most bad ass Venn Diagram of all time.

Regular expressions Context-free Context-sensitive Recursively enumerable ‘Regular expressions’, and so on, are the types

Regular expressions Context-free Context-sensitive Recursively enumerable ‘Regular expressions’, and so on, are the types of grammatical rules �� we can use to get our language �� (�� ). (We will explore what each mean shortly)

Regular Expressions The ‘least expressive’ category of language. Regularly used as part of programming

Regular Expressions The ‘least expressive’ category of language. Regularly used as part of programming languages or operating systems (e. g. Unix) to match text, e. g. spot an email address from within text. 3 operations Invented by this dude, Stephen Kleene. Examples

Challenge Time! All words with exactly one 1. Words that have at least one

Challenge Time! All words with exactly one 1. Words that have at least one 1. N Words that start and end in the same symbol.

Can different grammars give same language? Yes We can prove equivalence using something called

Can different grammars give same language? Yes We can prove equivalence using something called Kozen’s Axioms, but I will spare you this torture.

Chomsky Hierarchy Grammar Languages Automaton Recursively enumerable Turing machine Context-sensitive Linear-bounded non-deterministic Turing machine

Chomsky Hierarchy Grammar Languages Automaton Recursively enumerable Turing machine Context-sensitive Linear-bounded non-deterministic Turing machine Type-2 Context-free Non-deterministic pushdown automaton Type-3 Regular Finite state automaton Type-0 Type-1 Each category of language has an associated automaton, i. e. a sequential process that generates the same language of words…

Non-Deterministic Finite State Automata Each arrow allows us to generate a symbol in our

Non-Deterministic Finite State Automata Each arrow allows us to generate a symbol in our word. Arrow indicates start state. Double circle is ‘accepting state’: we can finish generating our word. What regular expression is this equivalent to? And this?

Challenge Time! 1 Find a regular expression to represent the following NFA. 2 The

Challenge Time! 1 Find a regular expression to represent the following NFA. 2 The Kleene Theorem states that every regular expression has an equivalent NFA, and vice versa.

So can all languages be represented using regular expressions? Underlying problem is that regular

So can all languages be represented using regular expressions? Underlying problem is that regular expressions have no ‘memory’. Can use the Pumping Lemma to prove a language is not Regular.

Languages Automaton Recursively enumerable Turing machine Context-sensitive Linear-bounded non-deterministic Turing machine Type-2 Context-free Non-deterministic

Languages Automaton Recursively enumerable Turing machine Context-sensitive Linear-bounded non-deterministic Turing machine Type-2 Context-free Non-deterministic pushdown automaton Type-3 Regular Finite state automaton Type-0 Type-1 Context Free Grammars (CFGs) to the rescue… CFG MAN Chomsky Hierarchy Grammar

Context Free Grammars Capital letters are non-terminals. These must always be replaced using one

Context Free Grammars Capital letters are non-terminals. These must always be replaced using one of the production rules listed. Lowercase letters are terminals (i. e. what ends up in our string). Example generation of a word: And we stop because we now have just terminals.

More Examples

More Examples

CFGs for English Language Chomsky was particularly instrumental, in the field of linguistics, for

CFGs for English Language Chomsky was particularly instrumental, in the field of linguistics, for his idea of a generative grammar for sentences in human languages, i. e. we can use a list of production rules (e. g. below) to ‘generate’ grammatically valid sentences in the language. S �NP VP NP �DT N NP �PN VP �VP PP VP �V NP NP ⟶ NP PP PP �P NP NP �NP CONJ NP DT �the DT �a N �monkey N �student N ⟶ telescope N ⟶ fork PN �Kyle P �with P �over CONJ �and CONJ �or V ⟶ saw V ⟶ ate Example generation of a sentence: NP represents a ‘noun phrase’. VP a ‘verb phrase’ DT a determiner, N a noun, PP a prepositional phrase. PN is a Proper Noun

Parsing Sometimes we want to do the opposite of generating sentences: taking an existing

Parsing Sometimes we want to do the opposite of generating sentences: taking an existing sentence and working out what rules were used to obtain it. This is known as parsing. The are multiple well known algorithms which take a grammar and an input sentence, and output all possible such ‘parse trees’. I’ve personally used the CYK algorithm and Earley Parser for code I’ve written in the past.

Ambiguity! “Kyle saw the monkey with the telescope” A grammar is ‘ambiguous’ if there

Ambiguity! “Kyle saw the monkey with the telescope” A grammar is ‘ambiguous’ if there are multiple possible parse trees for a single sentence. We have to use probabilistic techniques to help decide on the most likely.

So where does the English language fit into the Chomsky Hierarchy? Is it a

So where does the English language fit into the Chomsky Hierarchy? Is it a regular Expression? NO Chomsky demonstrates this by showing a particular part of English grammar that behaves akin to a palindrome. We saw earlier that palindromes are not regular. But there’s a nicer proof. . .

(Yngve 60) The cat likes tuna fish. The cat the dog chased likes tuna

(Yngve 60) The cat likes tuna fish. The cat the dog chased likes tuna fish. The cat the dog the rat bit chased likes tuna fish. The cat the dog the rat the elephant admired bit chased likes tuna fish. The number of nouns… …needs to match the number of verbs

Are CFGs ‘expressive’ enough for the English Language? PROBABLY Constituents in a sentence are

Are CFGs ‘expressive’ enough for the English Language? PROBABLY Constituents in a sentence are syntactically independent of each other, e. g. the NP “the monkey” doesn’t depend on the VP or PP surrounding it. i. e. Each constituent is not dependent on context, i. e. ‘context free’! So are there any human languages which are not Context Free?

The Germans naturally ruin things A number of languages, such as Dutch and Swiss

The Germans naturally ruin things A number of languages, such as Dutch and Swiss German, allow for cross-serial dependencies. English: “. . . we have wanted to let the children help Hans paint the house. ” . . . mer d’chind. . . we em Hans es huus haend wele the children/ACC Hans/DAT the house/ACC have laa halfe aastriiche wanted to let help paint. DAT = Dative noun: the indirect object of a verb (e. g. John gave Mary the book”). ACC = Accusative noun: the direct object of a verb (e. g. John gave Mary the book”).

Shieber (1985) notes that among such sentences, those with all accusative NPs preceding all

Shieber (1985) notes that among such sentences, those with all accusative NPs preceding all dative NPs, and all accusative-subcategorising verbs preceding all dative-subcategorising verbs are acceptable. English: “. . . we have wanted to let the children help Hans paint the house. ” . . . mer d’chind. . . we em Hans es huus haend wele the children/ACC Hans/DAT the house/ACC have laa halfe aastriiche wanted to let help paint. The number of verbs requiring dative objects (“halfe”) must equal the number of dative NPs (“em Hans”) and similarly for accusatives. Can therefore put in form: “Jan sait das mer an bm es huus haend wele cn dm aastriiche. ”

Grammar Swiss German Palindromes English Most programming languages Email addresses Languages Automaton Type-0 Recursively

Grammar Swiss German Palindromes English Most programming languages Email addresses Languages Automaton Type-0 Recursively enumerable Turing machine Type-1 Contextsensitive Linear-bounded nondeterministic Turing machine Type-2 Context-free Non-deterministic pushdown automaton Type-3 Regular Finite state automaton Summary Chomsky Hierarchy Parseltongue

A Few Quick Applications. .

A Few Quick Applications. .

Machine Translation Getting a computer to translate from one language to another. Synchronous Context

Machine Translation Getting a computer to translate from one language to another. Synchronous Context Free Grammars allow us to generate multiple sentences at the same time, one in each language. S → NP VP NP → I NP → the box VP → V NP V → open S → NP VP NP → watashi wa NP → hako wo VP → NP V V → akemasu This rule says that verbs come before the noun phrase in English, but after in Japanese. Stochastic Context Free Grammars assigns a probability to each production rule. It allows us to get a probability distribution over possible translations of a sentence. We would never want to hard code such rules/probabilities, so learn them from training data!

Question Answering

Question Answering

Predicting the Stock Market Sentiment Analysis determines whethere is positive or negative ‘sentiment’ (i.

Predicting the Stock Market Sentiment Analysis determines whethere is positive or negative ‘sentiment’ (i. e. emotion) in text. Negative sentiment about a company on Twitter can adversely affect its stock value.

Dialogue Systems o t d a h e v ’ re I And whe

Dialogue Systems o t d a h e v ’ re I And whe f… l e s y m e s par I once worked on a pedestrian robot with which you could ask about the surrounding environment and issue requests to be escorted to a destination of choice.

where

where

Algebraic Equivalence My online maths platform first generates parse trees of mathematical expressions/equations using

Algebraic Equivalence My online maths platform first generates parse trees of mathematical expressions/equations using an appropriate grammar. It then performs tree transformations so that expressions which are effectively the same end up with the same tree. Try it out! www. drfrostmaths. com/homework/algebra-demo. php

End. Questions? www. drfrostmaths. com @Dr. Frost. Maths

End. Questions? www. drfrostmaths. com @Dr. Frost. Maths