34
Corpora and Linguistic Annotation L645 Advanced NLP Autumn 2009

Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Embed Size (px)

Citation preview

Page 1: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpora and Linguistic Annotation

L645Advanced NLPAutumn 2009

Page 2: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Outline

• Corpus design: representativeness, balance, & sampling

• Preprocessing

• Markup encoding

• Annotation and Annotation schemes

2

Page 3: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designReference and Monitor Corpora

• Reference corpora, like the Brown Corpus, are fixed data sources; we know exactlywhat it is

– Very useful for computational experiments, so people can compare with oneanother

• Monitor corpora, like the Collins Bank of English, are continually growing

– Very useful for lexicographic purposes

• Some corpora fall in-between, like AP Newswire: it changes, but not as often

3

Page 4: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designRepresentativeness

Representativeness: the extent to which a sample includes the full range of variabilityin a population

• distinguishes corpora from archives

• allows findings to be generalized to a particular variety of language

A corpus is a sample of language use (i.e., from a particular population)

• balance: types of genres

• sampling: how the text is selected

4

Page 5: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designInternal & external criteria

Different kinds of criteria:

• external criteria: defined situationally (cf. genres, registers)

• internal criteria: defined linguistically (text types)

– Internal criteria often used to define representativeness– e.g., distributions of words or grammatical constructions

5

Page 6: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designGeneral & specialized corpora

• General corpora = designed to provide an overall description of a language

– The British National Corpus (BNC) is supposed to represent modern BritishEnglish as a whole

– Such corpora need to be balanced w.r.t. different text types

• Specialized corpora = domain or genre specific

– Also need to be balanced within the particular domain– Representativeness represented by ‘closure’ or ‘saturation’: is the concept

represented completely?∗ Divide corpus into equal segments: if a new, equally sized segment has the

same number of lexical items, corpus is saturated

6

Page 7: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designBalance

What should be covered in a balanced corpus?

• balanced = covers a range of text categories

– Definition depends upon the intended uses– No real objective measure of balance– Usually based on proportional sampling (discussed later)

• Balance can be based on a text typology, a classification of text types

7

Page 8: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designBalance in the BNC

The British National Corpus (BNC), a corpus of 100 million words, is generallybalanced

• 90% written, 10% spoken

– Written texts selected based on: domain (subject field), time, & medium (books,periodicals, etc.)

– Spoken texts selected based on demographics and context (meetings, lectures,radio broadcasts)

Aim is to represent contemporary British English

8

Page 9: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designSampling

To achieve representativeness & balance, we have to sample language (since we cannotexhaustively describe it)

• The sample should be representative of the larger population

To properly sample, need to define:

• sampling unit: book, periodical, newspaper, articles, chapters, . . .

• sampling frame: list of all possible units, from which that actual ones are selected

– Brown corpus sampling frame: list of books & periodicals in Brown UniversityLibrary & Providence Athenaeum

– Supposed to represent written English text published in 1961

9

Page 10: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designSampling issues

• Ways to sample:

– simple random sampling: sample from all sampling units– stratified random sampling: organize units by category and then sample∗ Can organize by demographic parameters or whatever is desirable for

representativeness∗ Sampling proportions: should the categories be weighted?

• Sample size: e.g., full text units or text chunks?

10

Page 11: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus designCorpus size

Generally speaking, the bigger the corpus the better, but ...

• If you include annotation, you only want as much text as you can handle

– It is simply not possible to have 100 billion words with high-quality linguisticannotation without a significant number of errors

• Regardless of annotation, can you process that much data in a sensible and efficientmanner?

11

Page 12: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Preprocessing

Some issues arise as the corpus is being built:

• Segmentation: what counts as a sentence for this corpus?

• Tokenization: what counts as a word for this corpus?

• Lemmatization: do we include word stems for each word in the corpus?

12

Page 13: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

PreprocessingSegmentation

• Intuitively, anything ending in a ., ?, or ! is a sentence.

– But :, ;, and — often also end sentences– And periods are also abbreviation markers (as we will see)

• Quotation marks also vary in their consistency of use

• If we are dealing with spoken language data, we have the further complication ofseparating utterances from sentences

Usually, a heuristic-based algorithm attempts to find sentence boundaries (and mightwork in tandem with a tokenizer)—see figure 4.1, p. 135

13

Page 14: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

PreprocessingTokenization

• Intuitively, a word is anything between whitespace

• But punctuation can cause problems because they mean multiple things

– Periods: sentence enders or abbreviations (or both, e.g., etc.)?– Apostrophes: contractions treated as one word (phonetically, I’m) or two (two

syntactic classes, I ’m)?– Hyphens: can cause two otherwise similar words to be distinct (co-operate vs.

cooperate)

• Whitespace not indicating a break: data base, the New York-New Haven railroad

• Speech: fillers (uh, um), meta-information ([cough])

Word segmentation in other languages is even more complicated.

14

Page 15: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

PreprocessingLemmatization

Corpora often also contain the lemma for each word, the base form or stem of a word

• Need to be able to do this accurately: e.g., what is the lemma of lying? lie or lay?

• Not clear how useful the lemma information is for different tasks

15

Page 16: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Corpus mark-up schemes

We need some way to add linguistic properties to a corpus: we’ll look mostly at XML(eXtensible Markup Language)

• in contrast to HTML, XML does not have built-in “meaning” for labels: you mustdefine your own tags

Benefits of XML:

• Pretty standard internationally and across fields

• Lots of good tools available and convenient for a lot of programs

• Widely used in real text processing

• Handles multilinguality very well

16

Page 17: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

XML example

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><corpus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="small" ><head external="file:wsj_generated_header.xml"/><body><s id="s1" ><graph root="s1_500" ><terminals><t id="s1_1" word="Pierre" pos="NNP" /><t id="s1_2" word="Vinken" pos="NNP" /><t id="s1_3" word="," pos="," /><t id="s1_4" word="61" pos="CD" />...

</terminals></graph>

</s>...

17

Page 18: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

XML tags

In the previous example, there are several things to note about the tags, i.e., the thingsin angled brackets (<...>):

• There has to be one root tag—in this case, <corpus> is the root tag

• Every (opening) tag needs a closing tag:

• Along with that, tags must be properly nested:<b><i>word</i></b> is legitimate; <b><i>word</b></i> is not

So, you’ll wind up with a structure like:

<root><child><subchild>.....</subchild>

</child></root>

18

Page 19: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Attributes

Each tag (or element) can have a variety of attributes (provided such attributes havebeen declared; see below)

• Attributes are noted within an element tag; there can be multiple attributes & canbe put in different orders

<t id="s1_1" word="Pierre" pos="NNP" /><t word="Pierre" pos="NNP" id="s1_1" />

• Attribute values are put in quotes after the attribute

• <t XYZ /> is the same as <t XYZ></t>

19

Page 20: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Attributes

In general, putting data in attributes needs to be done with care:

• attributes cannot contain multiple values (child elements can)

• attributes are not easily expandable (for future changes)

• attributes cannot describe structures (child elements can)

• attributes are more difficult to manipulate by program code

• attribute values are not as easy to test against a Document Type Definition (DTD)- which is used to define the legal elements of an XML document

However, converting all attributes to elements can result in an inflated structure

20

Page 21: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Child & Attribute possibilities

<terminal tag="NN">dog</terminal>

<terminal word="dog" tag="NN"></terminal><!-- or: <terminal word="dog" tag="NN"/> -->

<terminal><word>dog</word><tag>NN</tag>

</terminal>

21

Page 22: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Validation & Documentation

A particular XML scheme used for a corpus:

• has either a Document Type Defintion (DTD) or an XML Schema (XSD) to validatethe XML files

– It tells us what the valid elements are; what children those elements can have;what attributes; etc.

• Such files are often also good places to look for documentation about what toexpect in an XML file

– They should be able to tell us what we need to know for processing complexentries

22

Page 23: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

XSD example

<?xml version="1.0"?><xs:schema xmlns:xs="http://..." targetNamespace="http://..."xmlns="http://..." elementFormDefault="qualified">

<xs:element name="note"><xs:complexType><xs:sequence><xs:element name="to" type="xs:string"/><xs:element name="from" type="xs:string"/><xs:element name="heading" type="xs:string"/><xs:element name="body" type="xs:string"/>

</xs:sequence></xs:complexType>

</xs:element>

</xs:schema>23

Page 24: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

XML for “raw” text

New York Times data from the English Gigaword corpus:

<DOC id="NYT19940701.0001" type="story" ><HEADLINE>WITNESS SAYS O.J. SIMPSON BOUGHT KNIFE WEEKS BEFORE SLAYINGS</HEADLINE><DATELINE>LOS ANGELES (BC-SIMPSON-KILLINGS-1stLd-3Takes-Writethru-LADN)</DATELINE><TEXT><P>With the nation’s attention riveted again on a LosAngeles courtroom, a knife dealer testified that O.J. Simpsonbought a 15-inch knife five weeks before the slashing deaths of hisex-wife and her friend.</P>...<P>‘‘She frequented the restaurant quite often,’’ DeBello said.</P><P>(STORY CAN END HERE. OPTIONAL 2ND TAKE FOLLOWS.)</P></TEXT></DOC>

24

Page 25: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Part of Gigaword DTD

<!ELEMENT DOC - - (HEADLINE*,DATELINE*,TEXT*) >

<!-- fields of "DOC" --><!ELEMENT HEADLINE - - (#PCDATA) ><!ELEMENT DATELINE - - (#PCDATA) ><!ELEMENT TEXT - - (P* | #PCDATA)+ >

<!-- fields of "TEXT" --><!ELEMENT P - - (#PCDATA) >

<!--Entities --><!ENTITY amp "&" ><!ENTITY AMP "&" ><!ENTITY #DEFAULT SYSTEM >

<!ATTLIST DOC id CDATA #REQUIREDtype CDATA #REQUIRED >

]>

25

Page 26: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Annotation and annotation schemes

Now that we have text, we can add annotation

• Choose what to annotate

• Choose your markup scheme, character encoding, etc., and decide on storagemechanism that will not deteriorate

• Remember that annotation is almost always an opinion (even spelling “errors”), so:

– Use explicit guidelines– Use multiple annotators and specify how to resolve conflicts between annotators

• Keep everything! Never change your input text.

26

Page 27: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Grammatical tagging

One of the most common forms of annotation is that of part-of-speech classes, orgrammatical classes

• Part-of-speech tags are a combination of morphological and syntactic informationand occasionally require semantic distinctions to be made

• Tagsets differ in size and granularity, and there is not always a way to map betweentagsets

27

Page 28: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Brown corpus example

==================================

[ The/DT Fulton/NNP County/NNP Grand/NNP Jury/NNP ]said/VBD[ Friday/NNP ]

[ an/DT investigation/NN ]of/IN[ Atlanta/NNP ’s/POS recent/JJ primary/JJ election/NN ]produced/VBD ‘‘/‘‘[ no/DT evidence/NN ]’’/’’ that/IN[ any/DT irregularities/NNS ]took/VBD[ place/NN ]./.==================================

28

Page 29: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Syntactic annotation

• A common layer above POS is that of syntactic annotation, mostly meaning phrasestructure; a corpus with syntactic annotation is often called a treebank

• Again, we need a good annotation scheme

– Some would argue that we also need a corresponding grammar to go with it– Making a “theory-neutral” treebank is essentially impossible, although it can be

more or less theory-driven– NB: if empty elements are used, they should be added in such a way that the

original corpus data is not altered

• Dependency and function labeling are also quite common

29

Page 30: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Syntactic annotation example (Susanne)

A01:0010.03 - YB <minbrk> - [Oh.Oh]A01:0010.06 - AT The the [O[S[Nns:s.A01:0010.09 - NP1s Fulton Fulton [Nns.A01:0010.12 - NNL1cb County county .Nns]A01:0010.15 - JJ Grand grand .A01:0010.18 - NN1c Jury jury .Nns:s]A01:0010.21 - VVDv said say [Vd.Vd]A01:0010.24 - NPD1 Friday Friday [Nns:t.Nns:t]A01:0010.27 - AT1 an an [Fn:o[Ns:s.A01:0010.30 - NN1n investigation investigation .A01:0020.03 - IO of of [Po.A01:0020.06 - NP1t Atlanta Atlanta [Ns[G[Nns.Nns]A01:0020.09 - GG +<apos>s - .G]A01:0020.12 - JJ recent recent .A01:0020.15 - JJ primary primary .A01:0020.18 - NN1n election election .Ns]Po]Ns:s]A01:0020.21 - VVDv produced produce [Vd.Vd]A01:0020.24 - YIL <ldquo> - .A01:0020.27 - ATn +no no [Ns:o.A01:0020.30 - NN1u evidence evidence .A01:0020.33 - YIR +<rdquo> - .A01:0020.39 - CST that that [Fn.A01:0030.03 - DDy any any [Np:s.A01:0030.06 - NN2 irregularities irregularity .Np:s]A01:0030.09 - VVDv took take [Vd.Vd]A01:0030.12 - NNL1c place place [Ns:o.Ns:o]Fn]Ns:o]Fn:o]S]A01:0030.15 - YF +. - .O]

30

Page 31: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Syntactic annotation example (Brown part of PTB)

( (S (NP-SBJ-1 (NP Scotty ’s)father)

(VP sat(S-ADV (NP-SBJ *-1)

(VP sprawled(PP-LOC in

(NP his chair)))),(S-ADV (NP-SBJ *-1)

(ADJP-PRD (ADJP angular),(ADJP alert

(PP as(NP a cricket)))))

,(S-ADV (NP-SBJ *-1)

(VP looking(ADVP about)(PP at

(NP (NP the huge stainless-steel appointments)(PP of

(NP the room))))(PP with

(NP (NP an expression)(PP of

(NP proprietorship))))))).))

31

Page 32: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

Semantic annotation

• There are different kinds of semantic/pragmatic annotation one could in principlehave—word sense annotation, anaphoric relations, etc.

• One of the most popular forms of semantic annotation has been to label sentenceswith verbal semantic relations and the arguments of that relation

• In many respects, semantic annotation is at earlier stage than the other forms ofannotation, as it becomes even more difficult to decide:

– what to annotate– what constitutes a correct annotation

32

Page 33: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

PropBank example (standoff)

wsj/00/wsj_0001.mrg 0 8 gold join.01 vf--a 0:2-ARG0 7:0-ARGM-MOD 8:0-rel 9:1-ARG111:1-ARGM-PRD 15:1-ARGM-TMP

wsj/00/wsj_0001.mrg 1 10 gold publish.01 p---a 10:0-rel 11:0-ARG0wsj/00/wsj_0002.mrg 0 16 gold name.01 pp--p 16:0-rel 0:2*17:0-ARG1 18:2-ARG2wsj/00/wsj_0003.mrg 0 5 gold use.01 p---p 4:1-ARGM-TMP 5:0-rel 0:2*6:0-ARG17:2-ARG2-PNC

wsj/00/wsj_0003.mrg 0 9 gold make.01 i---a 7:0-ARG0 9:0-rel 10:1-ARG1wsj/00/wsj_0003.mrg 0 14 gold cause.01 pnp3a 0:3-ARG0 14:0-rel 15:2-ARG1wsj/00/wsj_0003.mrg 0 26 gold expose.01 p---p 26:0-rel 28:1-ARG2-to 30:3-ARGM-TMP22:1,24:0,25:1*27:0-ARG1

wsj/00/wsj_0003.mrg 0 37 gold report.01 vp--a 36:1-ARG0 37:0-rel 0:4*39:0-ARG1wsj/00/wsj_0003.mrg 1 11 gold enter.01 vn-3a 10:1-ARG0 11:0-rel 12:1-ARG1wsj/00/wsj_0003.mrg 1 21 gold cause.01 p---a 16:2-ARG0 21:0-rel 22:2-ARG1

33

Page 34: Corpora and Linguistic Annotation - Computational Linguisticscl.indiana.edu/~md7/09/645/slides/05-corpora/05-corpora.pdf · • The sample should be ... • sampling unit: book, periodical,

File it refers to

( (S(NP-SBJ(NP (NNP Pierre) (NNP Vinken) )(, ,)(ADJP(NP (CD 61) (NNS years) )(JJ old) )

(, ,) )(VP (MD will)(VP (VB join)(NP (DT the) (NN board) )(PP-CLR (IN as)(NP (DT a) (JJ nonexecutive) (NN director) ))

(NP-TMP (NNP Nov.) (CD 29) )))(. .) ))

( (S(NP-SBJ (NNP Mr.) (NNP Vinken) )(VP (VBZ is)(NP-PRD(NP (NN chairman) )(PP (IN of)(NP(NP (NNP Elsevier) (NNP N.V.) )(, ,)(NP (DT the) (NNP Dutch) (VBG publishing) (NN group) )))))

(. .) ))

34