CS 4705 Regular Expressions and Automata in Natural Language Analysis CS 4705 Julia Hirschberg.

Slides:



Advertisements
Similar presentations
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Advertisements

4b Lexical analysis Finite Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1 Regular Expressions and Automata September Lecture #2.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
CS 4705 Regular Expressions and Automata in Natural Language Analysis CS 4705 Julia Hirschberg.
Using Rules Chapter 6. 2 Logic Programming (Definite) logic program: A  B 1, B 2, …, B m program clause (Horn) head body  A 1, A 2, …, A n goal clause.
Finite-state automata 2 Day 13 LING Computational Linguistics Harry Howard Tulane University.
Regular Expressions (RE) Used for specifying text search strings. Standarized and used widely (UNIX: vi, perl, grep. Microsoft Word and other text editors…)
1 Regular Expressions and Automata September Lecture #2-2.
Finite-State Automata Shallow Processing Techniques for NLP Ling570 October 5, 2011.
CS5371 Theory of Computation
CS 4705 Some slides adapted from Hirschberg, Dorr/Monz, Jurafsky.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
CS147 - Terry Winograd - 1 Lecture 14 – Agents and Natural Language Terry Winograd CS147 - Introduction to Human-Computer Interaction Design Computer Science.
CS 4705 Lecture 2 Regular Expressions and Automata in Language Analysis.
Computational Language Finite State Machines and Regular Expressions.
CMSC 723 / LING 645: Intro to Computational Linguistics September 8, 2004: Monz Regular Expressions and Finite State Automata (J&M 2) Prof. Bonnie J. Dorr.
Finite state automaton (FSA)
CS 4705 Regular Expressions and Automata in Natural Language Analysis CS 4705.
CS120: Lecture 17 MP Johnson Hunter
CS 4705 Some slides adapted from Hirschberg, Dorr/Monz, Jurafsky.
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
Regular Expressions and Automata Chapter 2. Regular Expressions Standard notation for characterizing text sequences Used in all kinds of text processing.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
CMSC 723: Intro to Computational Linguistics Lecture 2: February 4, 2004 Regular Expressions and Finite State Automata Professor Bonnie J. Dorr Dr. Nizar.
Finite-State Machines with No Output
Morphological Recognition We take each sub-lexicon of each stem class and we expand each arc (e.g. the reg-noun arc) with all the morphemes that make up.
Chapter 2. Regular Expressions and Automata From: Chapter 2 of An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition,
1 Chapter 3 Scanning – Theory and Practice. 2 Overview Formal notations for specifying the precise structure of tokens are necessary –Quoted string in.
Theory of Languages and Automata
March 1, 2009 Dr. Muhammed Al-mulhem 1 ICS 482 Natural Language Processing Regular Expression and Finite Automata Muhammed Al-Mulhem March 1, 2009.
1 Human-Computer Interaction Web Interface & Natural Language.
CS 100Lecture 281 CS100J Lecture 27 n Previous Lecture –Interfaces –Comparable –Reflection –super –Re-Reading: n Lewis & Loftus, Section 5.5 n Savitch,
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Natural Language Processing Lecture 2—1/15/2015 Susan W. Brown.
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
1 Regular Expressions and Automata CPE 641 Natural Language Processing from Kathy McCoy’s slides, CISC 882 Introduction to NLP
CS 321 Programming Languages and Compilers Lectures 16 & 17 Introduction to Formal Languages Regular Languages Lexical Analysis.
2. Regular Expressions and Automata 2007 년 3 월 31 일 인공지능 연구실 이경택 Text: Speech and Language Processing Page.33 ~ 56.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
Copyright © Curt Hill Finite State Automata Again This Time No Output.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
1 LING 6932 Spring 2007 LING 6932 Topics in Computational Linguistics Hana Filip Lecture 2: Regular Expressions, Finite State Automata.
1 Regular Expressions and Automata August Lecture #2.
CS 4705 Some slides adapted from Hirschberg, Dorr/Monz, Jurafsky.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Natural Language Processing Lecture 4 : Regular Expressions and Automata.
CS 4705 Lecture 2 Regular Expressions and Automata.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Deterministic Finite Automata Nondeterministic Finite Automata.
Theory of Computation Automata Theory Dr. Ayman Srour.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lexical analysis Finite Automata
Compilers Welcome to a journey to CS419 Lecture5: Lexical Analysis:
Chapter 2 FINITE AUTOMATA.
CSC NLP - Regex, Finite State Automata
4b Lexical analysis Finite Automata
Regular Expressions and Automata in Language Analysis
4b Lexical analysis Finite Automata
A User study on Conversational Software
Chapter 1 Regular Language
Presentation transcript:

CS 4705 Regular Expressions and Automata in Natural Language Analysis CS 4705 Julia Hirschberg

Statistical vs. Symbolic (Knowledge Rich) Techniques Some simple problems: –How much is Google worth? –How much is the Empire State Building worth? How much knowledge of language do our algorithms need to do useful NLP? –80/20 Rule: Claim: 80% of NLP can be done with simple methods When should we worry about the other 20%?

Today Review some simple representations of language and see how far they will take us –Regular Expressions –Finite State Automata Think about the limits of these simple approaches –When do we need something more? How much is Absolute Bagels worth? How much is a Columbia education worth? How much is the Statue of Liberty worth? How much is your life worth?

Regular Expression/Pattern Matching in NLP Simple but powerful tools for ‘shallow’ processing, e.g. of very large corpora –What word is most likely to begin a sentence? –What word is most likely to begin a question? –How often do people end sentences with prepositions? With other simple statistical tools, allow us to –Obtain word frequency and co-occurrence statistics What is this document ‘about’? What words typically modify other words? –Build simple interactive applications (e.g. Eliza)Eliza –Determine authorship: Who wrote Shakespeare’s plays? –Deception detection: Statement Analysis

Review A non-blank lineAny character/./ Not an NELower case word/ [^A-Z]/ Possible NECapitalized word/ [A-Z]/ Any l.c. letter/[a-z]/ Rhyme:/[bckmrs]i te/ Any char in set/[bckmsr]/ A ‘.’, a ‘?’/\./, /\?/ UsesMatchesRE Rhyme: /[a-z]ite/ A statement, a question

REDescriptionUses? /a*/Zero or more a’s/(very[ ])*/ /a+/One or more a’s/(very[ ])+/ /a?/Optional single a/(very[ ])?/ /cat|dog/‘cat’ or ‘dog’/[A-Z,a-z]* (cat|dog)/ /^[Nn]o$/A line with only ‘No’ or ‘no’ in it /\bun\B/PrefixesWords prefixed by ‘un’ (nb. union)

Patterns: happier and happier, fuzzier and fuzzier, classifier and classifier / (.+ier) and \1 / Morphological variants of ‘kitty’/kitt(y|ies|en|ens)/ E.G.RE plus

Eliza (Weizenbaum) Men are all alike. IN WHAT WAY? They're always bugging us about something or other. CAN YOU THINK OF A SPECIFIC EXAMPLE? Well, my boyfriend made me come here. YOUR BOYFRIEND MADE YOU COME HERE He says I'm depressed much of the time. I AM SORRY TO HEAR YOU ARE DEPRESSED It's true. I am unhappy DO YOU THINK COMING HERE WILL HELP YOU NOT TO BE UNHAPPY I need some help, that much seems certain. WHAT WOULD IT MEAN TO YOU IF YOU GOT SOME HELP Perhaps I could learn to get along with my mother. TELL ME MORE ABOUT YOUR FAMILY My mother takes care of me. WHO ELSE IN YOUR FAMILY TAKES CARE OF YOU My father. YOUR FATHER You are like my father in some ways.

Using Regular Expressions to Build Eliza Step 1: Replace first person with second person references –s/\bI(’m| am)\b/YOU ARE/g –s/\bmy\b/YOUR/g –S/\bmine\b/YOURS/g Step 2: Use regexps to generate replies –s/.*I AM (depressed|sad).*/I AM SORRY TO HEAR YOU ARE \1/ –s/.* I AM (depressed|sad).*/WHY DO YOU THINK YOU ARE \1/?

–s/.* always.*/CAN YOU THINK OF A SPECIFIC EXAMPLE?/ –s/.*mother*/TELL ME MORE ABOUT YOUR FAMILY./ Step 3: Can use scores to rank possible transformations How far can regular expressions+ let you go?

Regular Languages: Equivalences Regular Expressions Finite State Automata Regular Grammars

Formally FSA is a 5-tuple consisting of –Q: set of states {q0,q1,q2,q3,q4} –  : an alphabet of symbols {a,b,!} –q0: a start state in Q –F: a set of final states in Q {q4} –  (q,i): a transition function mapping Q x  to Q q0 q4 q1q2q3 ba a a!

FSA recognizes (accepts) strings of a regular language –baa! –baaa! –baaaa! –… Tape metaphor: will this input be accepted? baaa

Another View: A State Transition Table for SheepTalk SheepTalk Stat e Input ba! q0 q4 q1q2q3 ba a a!

FSA Recognition Goals –Determine whether a string should be accepted by a machine –Or… determine whether a string is in the language defined by the automaton –Or… determine whether a regular expression matches a string –Turing: process can be represented with a tape

Determinism vs. Non-Determinism Deterministic FSA are FSA s.t. at each point in the FSA there is always one unique thing to do (no choices) Non-Deterministic FSA contain at least one state with multiple transitions

Non-Deterministic FSAs for SheepTalk q0 q4 q1q2q3 ba a a! q0 q4 q1q2q3 baa! 

Problems of Non-Determinism At any choice point, we may follow the wrong arc Potential solutions: –Save backup states at each choice point –Look-ahead in the input before making choice –Pursue alternatives in parallel –Determinize our NFSAs (and then minimize) FSAs can be useful tools for recognizing – and generating – subsets of natural language –But they cannot represent all NL phenomena (e.g. center embedding: The mouse the cat chased died.)

What can we do with FSAs? E.g. Recognize Proper Names q2q4q5q0q3q1q6 therev mr dr hon patl.robinson ms mrs 

Will this FSA Recognize all Proper Names? If we want to extract all the proper names in the news, will this work? –What will it miss? –Will it accept something that is not a proper name? –How would you change it to accept all proper names without false positives? –Precision vs. recall….

Summing Up Regular expressions and FSAs are good at representing subsets of natural language Both may be difficult for humans to understand for any real (large) subset of a language –Can be hard to scale up: e.g., when many choices at any point (e.g. surnames) –But quick, powerful and easy to use for small problems –AT&T Finite State Toolkit does scale Next class: –Read Ch 3