Download presentation
Presentation is loading. Please wait.
1
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/22
2
Administrivia Reminder –LING 388 Homework #2 went out on Monday –is due next Monday September 27th (by midnight) –need help? –submit homework to sandiway@email.arizona.edusandiway@email.arizona.edu –use plain text if possible (easier for the grader) Homework #1 –everyone should have gotten email
3
Last Time Exercises on –FSA –Regular Grammars –including fragments of natural language the man that I saw that you heard that I met …
4
Today’s Topics more on natural language cases … –Finite State Transducers (FST) –Context-Free Grammars (CFG)
5
Finite State Transducers (FST) a Finite State Transducer (FST) –is just a finite state machine, like FSA, but –is not only an acceptor can also produce an output sequence as well as accepting input sequences Application: –We can use FST to map from one word form into another e.g. a rule of pluralization –technology technologies Also easy to implement in Prolog …
6
Finite State Transducers (FST) Example: (pluralization) convert word ending in –y to word ending in –ies technology technologies, boundary boundaries spy spies, fly flies, study studies *happy happies, *correctly correctlies Notes: : = separator between input and output characters is the empty character variable X can match any character Machine is non-deterministic sbac X:X y:i :e :s
7
Finite State Transducers (FST) In Prolog: (FSA) –s([X|L]) :- s(L). –s([y|L]) :- a(L). –a(L) :- b(L). –b(L) :- c(L). –c([]). sbac X:X y:i :e :s In Prolog: (FST) –s([X|L],[X|M]) :- s(L,M). –s([y|L],[i|M]) :- a(L,M). –a(L,[e|M]) :- b(L,M). –b(L,[s|M]) :- c(L,M). –c([],[]).
8
Finite State Transducers (FST) Computation tree –?- s([s,p,y],O).X=s L=[p,y] O=[X|M] –?- s([p,y],M).X’=p L’=[y] M=[X’|M’] –?- s([y],M’).X”=y L”=[] M’=[X”|M”] ?- s([],M”).No –?- s([y],M’).L”=[] M’=[i|M”] –?- a([],M”).L”’=[] M”=[e|M”’] –?- b([],M”).L””=[] M”’=[s|M””] –?- c([],M””).Yes M””=[] Answer –O = [s|[p|[i|[e|[s|[]]]]]] –O = [s,p,i,e,s] sbac X:X y:i :e :s 1.s([X|L],[X|M]) :- s(L,M). 2.s([y|L],[i|M]) :- a(L,M). 3.a(L,[e|M]) :- b(L,M). 4.b(L,[s|M]) :- c(L,M). 5.c([],[]). redo
9
Finite State Transducers (FST) sbac X:X y:i :e :s In Prolog: (FST simplified) –s([X|L],[X|M]) :- s(L,M). –s([y|L],[i,e,s|M]) :- c(L,M). –c([],[]). sc X:X y:ies In Prolog: (FST) –s([X|L],[X|M]) :- s(L,M). –s([y|L],[i|M]) :- a(L,M). –a(L,[e|M]) :- b(L,M). –b(L,[s|M]) :- c(L,M). –c([],[]).
10
Finite State Transducers (FST) Example: (pluralization) convert word ending in –y to word ending in –ies technology technologies, boundary boundaries spy spies, fly flies, study studies *happy happies, *correctly correctlies Counterexamples to the rule: boy boies, key keies say saies Revised Rule: convert word ending in –y to word ending in –ies in context C__ where C is a consonant sbac X:X y:i :e :s
11
Finite State Transducers (FST) Revised Rule: convert word ending in –y to word ending in –ies in context C__ where C is a consonant character sbac X:X y:i :e :s sbac X:X y:i :e :s z C:C boy boies, key keies say saies
12
Finite State Transducers (FST) Revised Rule: convert word ending in –y to word ending in –ies in context C__ where C is a consonant character sc X:X y:ies z C:C In Prolog: (simplified FST) –s([X|L],[X|M]) :- s(L,M). –s([y|L],[i,e,s|M]) :- c(L,M). –c([],[]). In Prolog: (revised rule, simplified FST) –s([X|L],[X|M]) :- s(L,M). –s([C|L],[C|M]) :- consonant(C), z(L,M). –z([y|L],[i,e,s|M]) :- c(L,M). –c([],[]). consonant(b). consonant(c). consonant(d). consonant(f). … consonant(z).
13
Context-Free Grammars Regular Grammars –Definite Clause Grammar (DCG) rules that obey special restrictions: x --> y, [t]. x --> [t]. (left recursive) x --> [t],y. x --> [t]. (right recursive) Context-Free Grammars (CFG) –have no restrictions on the number of symbols on the RHS x --> RHS. –you can mix many terminal and non-terminal symbols as you want Example of a Context-Free Grammar –non-regular grammar for language a n b n a --> [a], b. b --> [b]. b --> a, [b].
14
Context-Free Grammars Regular Grammars –Definite Clause Grammar (DCG) rules that obey special restrictions: x --> y, [t]. x --> [t]. (left recursive) x --> [t],y. x --> [t]. (right recursive) Context-Free Grammars (CFG) –have no restrictions on the number of symbols on the RHS x --> RHS. –you can mix many terminal and non-terminal symbols as you want Another example of a Context-Free Grammar –Sheeptalk ( baa! baaa! baaaa! …) - is a regular language –s --> [b], [a], a, [‘!’]. –a --> [a]. –a --> a, [a].
15
Context-Free Grammars Where do CFGs fit in? Chomsky Hierarchy: –Type-0 General rewrite rules Type-1 Context-sensitive rules a n b n c n –Type-2 Context-free rules – a n b n Pushdown Automata (PDA) »Type-3 Regular grammar rules » Regular Expressions a + b + » Finite State Automata (FSA)
16
Context-Free Grammars Regular Grammars FSA Regular Expressions DCG = Type-0 Type-3 Type-2 Type-1
17
Context-Free Grammars In Homework #2, we explored some natural language fragments using regular grammars the man that I saw (that you heard that I met …) (object relative clauses) But regular grammars are quite limited the man likes dogs the man that the cat saw likes dogs ?the man that the cat that the mouse hates saw likes dogs (center-embedding) CFGs are not only more powerful but are also more useful for writing natural language grammars Continued next time …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.