Assigning exactly one label to each element in a sequence
In context of RNNs or other sequence models, example of one-to-one paradigm
(In the example: Universal Semantic Tags from Abzianidze and Bos (2017))
NN | noun, singular or mass | cat, rain |
NNS | noun, plural | cats, tables |
NNP | proper noun, singular | John, IBM |
NNPS | proper noun, plural | Muslims, Philippines |
Assign each word in a sentence its part-of-speech (POS) tag.
1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|
I | predict | that | it | will | rain | tonight |
PRP | VBP | IN | PRP | MD | VB | NN |
Let's look at the GMB (Groningen Meaning Bank) dataset, annotated with the Penn Treebank tag set
tokens, pos, ents = load_gmb_dataset('../data/gmb/GMB_dataset_utf8.txt')
pd.DataFrame([tokens[2], pos[2]])
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | They | marched | from | the | Houses | of | Parliament | to | a | rally | in | Hyde | Park | . |
1 | PRP | VBD | IN | DT | NNS | IN | NN | TO | DT | NN | IN | NNP | NNP | . |
sorted_tags_table[:10]
Tag | Count | Unique Tokens | Example | |
---|---|---|---|---|
0 | NN | 9307 | 2087 | 's special tribunal/NN has filed |
1 | NNP | 8189 | 2069 | the facility Saturday/NNP . |
2 | IN | 7759 | 94 | actions play into/IN the hands |
3 | DT | 6310 | 40 | Both/DT Eritrea and |
4 | JJ | 4875 | 1214 | says the ousted/JJ dictator has |
5 | NNS | 4803 | 1102 | has threatened sanctions/NNS against both |
6 | . | 2992 | 3 | as well ./. |
7 | VBD | 2429 | 470 | Mr. Annan said/VBD he has |
8 | VBN | 2060 | 588 | fighter were killed/VBN , when |
9 | , | 1953 | 1 | Jack Hooper ,/, the deputy |
plt.xticks(rotation=45, fontsize=7)
plt.bar(sorted(counts.keys(), key=counts.get), sorted(counts.values()))
<BarContainer object of 41 artists>
Model probability distributions over label sequences \y conditioned on input sequences \x
s\params(\x,\y)=\prob\params(\y|\x)Just like the conditional models from the text classification chapter
But the label space is exponential (as a function of sequence length)!
Most unique \y are never even seen in training
Might be useful to break it up?
A fully factorised or local model:
p\params(\y|\x)=n∏i=1p\params(yi|\x,i,y1,…,i−1)≈n∏i=1p\params(yi|\x,i)Does this remind you of anything you've seen in previous lectures?
Log-linear multiclass classifier p\params(y¯\x,i) to predict class for sentence \x and position i
p\params(y¯\x,i)≈1Z\xexp⟨\repr(\x,i),\paramsy⟩\repr(\x,i) is a feature function
Z\x>0 is a normalisation factor to ensure that ∑yp\params(y¯\x,i)=1
How far can we get with very simple features that only consider the word types (and no context)?
Bias: \repr0(\x,i)=1
Word at token to tag: \reprw(\x,i)={1 if xi=w0 else
def feat_1(x,i):
return {
'bias': 1.0,
'word:' + x[i]: 1.0,
}
train = list(zip(tokens[:-200], pos[:-200]))
dev = list(zip(tokens[-200:], pos[-200:]))
local_1 = seq.LocalSequenceLabeler(feat_1, train, class_weight='balanced')
We can assess the accuracy of this model on the development set.
seq.accuracy(dev, local_1.predict(dev))
0.8872215709261431
Many words are new, but we should still be able to tag them based on form or context:
’Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
(Jabberwocky by Lewis Carroll)
Look at confusion matrix
seq.plot_confusion_matrix(dev, local_1.predict(dev), normalise=True)
NN
receives a lot of wrong counts, often confused with NNP
util.Carousel(local_1.errors(dev,
filter_gold=lambda y: y=='NN',
filter_guess=lambda y: y=='NNP'))
The | walkout | will | shutdown | the | city |
DT | NN | MD | VB | DT | NN |
DT | NNP | MD | NN | DT | NN |
bias | word:walkout |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
, | and | throw | the | daily | commute | of | its | seven | million |
, | CC | VB | DT | JJ | NN | IN | PRP$ | CD | CD |
, | CC | VB | DT | RB | NNP | IN | PRP$ | CD | CD |
bias | word:commute |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Contract | talks | between | the | two |
NN | NNS | IN | DT | CD |
NNP | NNS | IN | DT | CD |
bias | word:Contract |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
deadlocked | over | such | issues | as | wage | increases | and | at | what |
VBN | IN | JJ | NNS | IN | NN | NNS | CC | IN | WP |
NNP | RP | PDT | NNS | IN | NNP | NNS | CC | IN | WP |
bias | word:wage |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
eligible | to | receive | a | full | pension | . |
JJ | TO | VB | DT | JJ | NN | . |
JJ | TO | VB | DT | JJ | NNP | . |
bias | word:pension |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Union | head | Roger | Toussaint | calls |
NN | NN | NNP | NNP | VBZ |
NNP | VB | NNP | NNP | VBZ |
bias | word:Union |
1.0 | 1.0 |
3.73 | -0.52 |
3.73 | 4.19 |
in | effect | to | prevent | massive | traffic | jams | on | New | York |
IN | NN | TO | VB | JJ | NN | NNS | IN | NNP | NNP |
IN | NN | TO | VB | JJ | NNP | NNP | IN | NNP | NNP |
bias | word:traffic |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
hope | Cambodia | can | be | a | model | for | the | rest | of |
NN | NNP | MD | VB | DT | NN | IN | DT | NN | IN |
VBP | NNP | MD | VB | DT | NNP | IN | DT | NN | IN |
bias | word:model |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Clinton | 's | visit | will | raise | awareness | about | H.I.V. | and | help |
NNP | POS | NN | MD | VB | NN | IN | NNP | CC | VB |
NNP | POS | VB | MD | VB | NNP | IN | NNP | CC | VB |
bias | word:awareness |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
all | acts | of | abuse | and | brutality | and | treats | allegations | of |
DT | NNS | IN | NN | CC | NN | CC | VBZ | NNS | IN |
PDT | NNS | IN | NN | CC | NNP | CC | NNP | NNS | IN |
bias | word:brutality |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
it | was | released | by | the | News | of | the | World | newspaper |
PRP | VBD | VBN | IN | DT | NN | IN | DT | NNP | NN |
PRP | VBD | VBN | IN | DT | NNP | IN | DT | NNP | NN |
bias | word:News |
1.0 | 1.0 |
3.73 | -0.39 |
3.73 | 2.51 |
is | head | of | Mogadishu | 's | ambulance | service | , | says | at |
VBZ | NN | IN | NNP | POS | NN | NN | , | VBZ | IN |
VBZ | VB | IN | NNP | POS | NNP | NN | , | VBZ | IN |
bias | word:ambulance |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
prompting | soldiers | to | launch | an | artillery | barrage | . |
VBG | NNS | TO | VB | DT | NN | NN | . |
VBG | NNS | TO | VB | DT | NNP | NNP | . |
bias | word:artillery |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
soldiers | to | launch | an | artillery | barrage | . |
NNS | TO | VB | DT | NN | NN | . |
NNS | TO | VB | DT | NNP | NNP | . |
bias | word:barrage |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
two | decades | of | violence | and | lawlessness | since | the | fall | of |
CD | NNS | IN | NN | CC | NN | IN | DT | NN | IN |
CD | NNS | IN | NN | CC | NNP | IN | DT | VB | IN |
bias | word:lawlessness |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
The | founder | of | Microsoft | , | Bill |
DT | NN | IN | NNP | , | NNP |
DT | NNP | IN | NNP | , | NNP |
bias | word:founder |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
university | students | eager | for | a | glimpse | of | the | world | 's |
NN | NNS | JJ | IN | DT | NN | IN | DT | NN | POS |
NN | NNS | NNP | IN | DT | NNP | IN | DT | NN | POS |
bias | word:glimpse |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
the | government | landed | a | high | tech | deal | when | leading | chipmaker |
DT | NN | VBD | DT | JJ | NN | NN | WRB | VBG | NN |
DT | NN | VBN | DT | JJ | NNP | NN | WRB | VBG | NNP |
bias | word:tech |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
high | tech | deal | when | leading | chipmaker | Intel | Corporation | announced | it |
JJ | NN | NN | WRB | VBG | NN | NNP | NNP | VBD | PRP |
JJ | NNP | NN | WRB | VBG | NNP | NNP | NNP | VBD | PRP |
bias | word:chipmaker |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
The | ingredient | , | called | artemisinin | , | is | extracted | from |
DT | NN | , | VBN | NN | , | VBZ | VBN | IN |
DT | NN | , | VBD | NNP | , | VBZ | VBN | IN |
bias | word:artemisinin |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
form | of | malaria | , | called | falciparum | . |
NN | IN | NN | , | VBD | NN | . |
VB | IN | NN | , | VBD | NNP | . |
bias | word:falciparum |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
using | the | euro | as | their | currency | have | not | done | as |
VBG | DT | NN | IN | PRP$ | NN | VBP | RB | VBN | RB |
VBG | DT | NN | IN | PRP$ | NNP | VBP | RB | VBN | IN |
bias | word:currency |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
do | not | yet | know | the | origin | of | the | dead | birds |
VBP | RB | RB | VB | DT | NN | IN | DT | JJ | NNS |
VB | RB | RB | VB | DT | NNP | IN | DT | JJ | NNS |
bias | word:origin |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
, | Valery | Sitnikov | , | said | bio-terrorism | can | not | be | ruled |
, | NNP | NNP | , | VBD | NN | MD | RB | VB | VBN |
, | NNP | NNP | , | VBD | NNP | MD | RB | VB | VBN |
bias | word:bio-terrorism |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
four | murders | and | was | the | co-founder | of | the | infamous | Crips |
CD | NNS | CC | VBD | DT | NN | IN | DT | JJ | NNP |
CD | NNS | CC | VBD | DT | NNP | IN | DT | NNP | NNP |
bias | word:co-founder |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
In | two | other | death | penalty | cases | he | has | refused |
IN | CD | JJ | NN | NN | NNS | PRP | VBZ | VBN |
IN | CD | JJ | NN | NNP | NNS | PRP | VBZ | VBN |
bias | word:penalty |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
After | the | registration | period | ends | , | applicants |
IN | DT | NN | NN | VBZ | , | NNS |
IN | DT | NNP | NN | VBZ | , | NNS |
bias | word:registration |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
, | which | will | determine | the | make-up | of | the | presidential | ballot |
, | WDT | MD | VB | DT | NN | IN | DT | JJ | NN |
, | WDT | MD | VB | DT | NNP | IN | DT | JJ | NN |
bias | word:make-up |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Competitive | diving | is | one | of | the |
JJ | NN | VBZ | CD | IN | DT |
NNP | NNP | VBZ | CD | IN | DT |
bias | word:diving |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Recreational | diving | is | also | a | growing |
JJ | NN | VBZ | RB | DT | VBG |
NNP | NNP | VBZ | RB | DT | VBG |
bias | word:diving |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
diving | is | also | a | growing | amateur | sport | in | the | U.S. |
NN | VBZ | RB | DT | VBG | NN | NN | IN | DT | NNP |
NNP | VBZ | RB | DT | VBG | NNP | NN | IN | DT | NNP |
bias | word:amateur |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Unfortunately | , | the | joy | of | jumping | off | the |
RB | , | DT | NN | IN | VBG | RP | DT |
NNP | , | DT | NNP | IN | NNP | RP | DT |
bias | word:joy |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
diving | board | at | the | local | swimming | pool | has | too | often |
VBG | NN | IN | DT | JJ | NN | NN | VBZ | RB | RB |
NNP | NN | IN | DT | JJ | NNP | NNP | VBZ | RB | RB |
bias | word:swimming |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
board | at | the | local | swimming | pool | has | too | often | been |
NN | IN | DT | JJ | NN | NN | VBZ | RB | RB | VBN |
NN | IN | DT | JJ | NNP | NNP | VBZ | RB | RB | VBN |
bias | word:pool |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
An | official | with | Canada | 's | spy | agency | has | said | that |
DT | NN | IN | NNP | POS | NN | NN | VBZ | VBN | IN |
DT | JJ | IN | NNP | POS | NNP | NN | VBZ | VBD | WDT |
bias | word:spy |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
before | Mr. | Chavez | 's | afternoon | departure | . |
IN | NNP | NNP | POS | NN | NN | . |
IN | NNP | NNP | POS | NN | NNP | . |
bias | word:departure |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
cancellations | on | the | pope | 's | schedule | , | but | did | not |
NNS | IN | DT | NN | POS | NN | , | CC | VBD | RB |
NNP | IN | DT | NN | POS | NNP | , | CC | VBD | RB |
bias | word:schedule |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
from | Parkinson | 's | disease | and | arthritis | , | but | continues | to |
IN | NNP | POS | NN | CC | NN | , | CC | VBZ | TO |
IN | NNP | POS | NN | CC | NNP | , | CC | VBZ | TO |
bias | word:arthritis |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
to | maintain | a | full | travel | schedule | , | hold | audiences | and |
TO | VB | DT | JJ | NN | NN | , | NN | NNS | CC |
TO | VB | DT | JJ | VB | NNP | , | VB | NNP | CC |
bias | word:schedule |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
hold | audiences | and | perform | his | papal | duties | . |
NN | NNS | CC | VB | PRP$ | NN | NNS | . |
VB | NNP | CC | VBP | PRP$ | NNP | NNS | . |
bias | word:papal |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Israel | completed | its | handover | of | the | West | Bank |
NNP | VBD | PRP$ | NN | IN | DT | NNP | NNP |
NNP | VBN | PRP$ | NNP | IN | DT | NNP | NNP |
bias | word:handover |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
armed | men | stormed | into | a | bar | in | western | Mexico | and |
JJ | NNS | VBD | IN | DT | NN | IN | JJ | NNP | CC |
JJ | NNS | VBD | IN | DT | NNP | IN | JJ | NNP | CC |
bias | word:bar |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
air | as | they | entered | the | bar | in | Michoacan | state | before |
NN | IN | PRP | VBD | DT | NN | IN | NNP | NN | IN |
NN | IN | PRP | VBD | DT | NNP | IN | NNP | NN | IN |
bias | word:bar |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
bar | in | Michoacan | state | before | dawn | Wednesday | . |
NN | IN | NNP | NN | IN | NN | NNP | . |
NNP | IN | NNP | NN | IN | NNP | NNP | . |
bias | word:dawn |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
The | group | also | left | a | note | saying | the | killings | were |
DT | NN | RB | VBD | DT | NN | VBG | DT | NNS | VBD |
DT | NN | RB | VBD | DT | NNP | VBG | DT | NNS | VBD |
bias | word:note |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
of | what | it | called | " | divine | justice | . | " |
IN | WP | PRP | VBD | `` | NN | NN | . | `` |
IN | WP | PRP | VBD | `` | NNP | NN | . | `` |
bias | word:divine |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
children | were | killed | in | a | stampede | in | the | southern | city |
NNS | VBD | VBN | IN | DT | NN | IN | DT | JJ | NN |
NNS | VBD | VBN | IN | DT | NNP | IN | DT | JJ | NN |
bias | word:stampede |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
were | waiting | to | get | free | flour | . |
VBD | VBG | TO | VB | JJ | NN | . |
VBD | VBG | TO | VB | VB | NNP | . |
bias | word:flour |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
group | was | giving | out | the | flour | in | honor | of | the |
NN | VBD | VBG | RP | DT | NN | IN | NN | IN | DT |
NN | VBD | VBG | RP | DT | NNP | IN | VB | IN | DT |
bias | word:flour |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
of | the | victims | died | of | suffocation | . |
IN | DT | NNS | VBD | IN | NN | . |
IN | DT | NNS | VBD | IN | NNP | . |
bias | word:suffocation |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
50 | members | of | Israel | 's | theater | community | have | signed | a |
CD | NNS | IN | NNP | POS | NN | NN | VBP | VBN | DT |
CD | NNS | IN | NNP | POS | NNP | NN | VBP | VBN | DT |
bias | word:theater |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
theater | community | have | signed | a | petition | to | boycott | performances | at |
NN | NN | VBP | VBN | DT | NN | TO | VB | NNS | IN |
NNP | NN | VBP | VBN | DT | NNP | TO | VB | NNS | IN |
bias | word:petition |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
boycott | performances | at | a | state-funded | theater | in | the | northern | West |
VB | NNS | IN | DT | JJ | NN | IN | DT | JJ | NNP |
VB | NNS | IN | DT | NNP | NNP | IN | DT | JJ | NNP |
bias | word:theater |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
Somalia | 's | transitional | government-in-exile | met | Tuesday | to | try |
NNP | POS | JJ | NN | VBD | NNP | TO | VB |
NNP | POS | JJ | NNP | VBD | NNP | TO | VB |
bias | word:government-in-exile |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
were | to | perform | the | minor | pilgrimage | known | as | Omra | . |
VBD | TO | VB | DT | JJ | NN | VBN | IN | NNP | . |
VBD | TO | VBP | DT | JJ | NNP | VBN | IN | NNP | . |
bias | word:pilgrimage |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
ranging | from | maintaining | the | status | quo | to | a | full | withdrawal |
VBG | IN | VBG | DT | NN | NN | TO | DT | JJ | NN |
VBG | IN | VBG | DT | NN | NNP | TO | DT | JJ | NN |
bias | word:quo |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
the | operation | to | either | an | observer | or | liaison | effort | . |
DT | NN | TO | DT | DT | NN | CC | NN | NN | . |
DT | NN | TO | RB | DT | NNP | CC | NNP | NN | . |
bias | word:observer |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
to | either | an | observer | or | liaison | effort | . |
TO | DT | DT | NN | CC | NN | NN | . |
TO | RB | DT | NNP | CC | NNP | NN | . |
bias | word:liaison |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
any | particular | option | and | said | none | offered | an | ideal | way |
DT | JJ | NN | CC | VBD | NN | VBD | DT | JJ | NN |
DT | NNP | NN | CC | VBD | NNP | VBN | DT | NNP | NN |
bias | word:none |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
In | this | photograph | released | by | the | Iraqi |
IN | DT | NN | VBN | IN | DT | JJ |
IN | DT | NNP | VBN | IN | DT | JJ |
bias | word:photograph |
1.0 | 1.0 |
3.73 | 0.00 |
3.73 | 0.00 |
The word has not appeared in the training set!
Proper nouns tend to be capitalised! Can we capture that with a feature?
def feat_2(x,i):
return {
'bias': 1.0,
'word:' + x[i].lower(): 1.0,
'first_upper:' + str(x[i][0].isupper()): 1.0,
}
local_2 = seq.LocalSequenceLabeler(feat_2, train)
seq.accuracy(dev, local_2.predict(dev))
0.9087924970691676
Are these results actually caused by improved NN
/NNP
prediction?
seq.plot_confusion_matrix(dev, local_2.predict(dev), normalise=True)
util.Carousel(local_2.errors(dev,
filter_gold=lambda y: y=='NN',
filter_guess=lambda y: y=='NNP'))
Contract | talks | between | the | two |
NN | NNS | IN | DT | CD |
NNP | NNS | IN | DT | CD |
bias | first_upper:True | word:contract |
1.0 | 1.0 | 1.0 |
6.71 | 3.72 | 2.25 |
6.73 | 8.41 | -0.01 |
Union | head | Roger | Toussaint | calls |
NN | NN | NNP | NNP | VBZ |
NNP | NN | NNP | NNP | VBZ |
bias | first_upper:True | word:union |
1.0 | 1.0 | 1.0 |
6.71 | 3.72 | 1.44 |
6.73 | 8.41 | 2.39 |
it | was | released | by | the | News | of | the | World | newspaper |
PRP | VBD | VBN | IN | DT | NN | IN | DT | NNP | NN |
PRP | VBD | VBN | IN | DT | NNP | IN | DT | NNP | NN |
bias | first_upper:True | word:news |
1.0 | 1.0 | 1.0 |
6.71 | 3.72 | 3.98 |
6.73 | 8.41 | 3.08 |
Polysemous words or homonyms have multiple senses. For example, back:
Noun:
He | is | treated | for | back | injury |
PRP | VBP | VBN | IN | NN | NN |
Adverb:
He | is | sent | back | to | prison |
PRP | VBP | VBN | RB | TO | NN |
Verb:
I | can | back | this | up |
PRP | MD | VB | DT | RP |
[Barack Obama]per was born in [Hawaii]gpe |
per = Person
gpe = Geopolitical Entity
... but this is not sequence labeling, is it?
Label tokens as beginning (B), inside (I), or outside (O) a named entity:
Barack | Obama | was | born | in | Hawaii |
B-per | I-per | O | O | O | B-gpe |
geo = Geographical Entity
org = Organization
per = Person
gpe = Geopolitical Entity
tim = Time indicator
art = Artifact
eve = Event
nat = Natural Phenomenon
Example sentence from GMB:
pd.DataFrame([tokens[12][:11], pos[12][:11], ents[12][:11]])
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | Iran | 's | new | President | Mahmoud | Ahmadinejad | said | Tuesday | that | European | incentives |
1 | NNP | POS | JJ | NNP | NNP | NNP | VBD | NNP | IN | JJ | NNS |
2 | B-gpe | O | O | B-per | I-per | I-per | O | B-tim | O | B-gpe | O |
sorted_ents_table
Entity Type | Count | Example | |
---|---|---|---|
0 | geo | 2070 | Ethiopia |
1 | org | 1237 | Security Council |
2 | gpe | 1230 | Iraqi |
3 | tim | 1160 | within |
4 | per | 1107 | Saddam |
5 | art | 53 | Magazine Us |
6 | eve | 45 | Summer Olympics |
7 | nat | 20 | H5N1 |
Can we run our simple local model on this?
train_ner = list(zip(tokens[:-200], ents[:-200]))
dev_ner = list(zip(tokens[-200:], ents[-200:]))
def feat_2(x,i):
return {
'bias': 1.0,
'word:' + x[i].lower(): 1.0,
'first_upper:' + str(x[i][0].isupper()): 1.0,
}
local_2 = seq.LocalSequenceLabeler(feat_2, train_ner)
seq.accuracy(dev_ner, local_2.predict(dev_ner))
0.9348182883939039
This seems great, but tag distribution is also highly skewed:
hist = Counter(tag for _, tags in dev_ner for tag in tags)
plt.bar(sorted(hist.keys(), key=hist.get), sorted(hist.values()))
<BarContainer object of 13 artists>
A baseline that always predicts O
is already pretty good:
only_o = [tuple(['O'] * len(tags)) for _, tags in dev_ner]
seq.accuracy(dev_ner, only_o)
0.8527549824150059
Tasks like NER are more commonly evaluated with...
Example:
pd.DataFrame([dev_ner[18][0], dev_ner[18][1], local_2_pred_dev[18]])
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | The | newspaper | says | the | tape | was | shot | in | 2004 | in | southern | Iraq | . |
1 | O | O | O | O | O | O | O | O | B-tim | O | B-geo | I-geo | O |
2 | O | O | O | O | O | O | O | O | B-tim | O | O | B-geo | O |
predicted = {2004, Iraq}
annotated = {2004, southern Iraq}
print_prf([dev_ner[18]], [local_2_pred_dev[18]])
precision: 0.50 recall: 0.50 f-score: 0.50
back to the full dev set...
local_2_pred_dev = local_2.predict(dev_ner)
print_prf(dev_ner, local_2_pred_dev)
precision: 0.73 recall: 0.59 f-score: 0.65
print_prf(dev_ner, only_o)
precision: 0.00 recall: 0.00 f-score: 0.00
We can use BiLSTMs for that!
Source: https://guillaumegenthial.github.io/sequence-tagging-with-tensorflow.html
A recurrent neural network (plain RNN, LSTM, GRU, ...) computes its output based on a hidden, internal state:
yt=RNN(\xt,ht)A bi-directional RNN is just two uni-directional RNNs combined:
→yt=→RNN(\xt,→ht)←yt=←RNN(\xt,←ht)yt=→yt⊕←ytTo predict label probabilities, we use the softmax function:
yt=→yt⊕←ytˆyt=softmax(Woyt)∈R|V|We can also use transformers such as BERT
Parts of speech are defined for words.
Tagger must output one tag per word even if using other tokenisation internally.
Remember the log-linear classifier:
p\params(y¯\x,i)=1Z\xexp⟨\repr(\x,i),\paramsy⟩A neural sequence model with a softmax layer on top is also modelling p\params(y¯\x,i)
So if you take \params to be the set of parameters of the neural network, then:
ˆyt=softmax(ˆht)=1Z\xexp⟨ˆht,\paramsy⟩What haven't we modelled yet?
Can you think about fitting words for this POS tag sequence?
DT | JJ | NN |
determiner | adjective | noun (singular or mass) |
What about this one?
DT | VB |
determiner | verb (base form) |
DT
), adjectives and nouns are much more likely than verbsutil.Carousel(local_2.errors(dev_ner,
filter_guess=lambda y: y.startswith("I-"),
filter_gold=lambda y: y.startswith("B-")))
Former | U.S. | president | Bill | Clinton | has | signed | an |
O | B-geo | O | B-per | I-per | O | O | O |
O | B-geo | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:bill |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.72 |
1.27 | 0.97 | 2.54 |
Monday | in | the | capital | , | Phnom | Penh | . |
B-tim | O | O | O | O | B-org | I-org | O |
B-tim | O | O | O | O | I-per | I-per | O |
bias | first_upper:True | word:phnom |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
The | former | president | is | in | Cambodia | to | tour | AIDS-related | projects |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | I-per | O |
bias | first_upper:True | word:cambodia |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
his | development | group | , | the | Clinton | Foundation | H.I.V./AIDS | Initiative | . |
O | O | O | O | O | B-per | I-per | I-per | I-per | O |
O | O | O | O | O | I-per | O | I-per | I-per | O |
bias | first_upper:True | word:clinton |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 2.71 |
1.27 | 0.97 | 3.70 |
He | said | there | is | hope | Cambodia | can | be | a | model |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:cambodia |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Cambodia | has | reduced | adult | infection |
B-geo | O | O | O | O |
I-per | O | O | O | O |
bias | first_upper:True | word:cambodia |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
in | the | city | 's | busy | Bakara | market | . |
O | O | O | O | O | B-geo | O | O |
O | O | O | O | O | I-per | O | O |
bias | first_upper:True | word:bakara |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Insurgent | groups | al-Shabab | and | Hizbul | Islam | are | trying | to |
O | O | O | O | B-per | I-per | O | O | O |
O | O | O | O | I-per | B-geo | O | O | O |
bias | first_upper:True | word:hizbul |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
The | founder | of | Microsoft | , | Bill | Gates | , |
O | O | O | B-org | O | B-per | I-per | O |
O | O | O | I-per | O | I-per | I-per | O |
bias | first_upper:True | word:microsoft |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
The | founder | of | Microsoft | , | Bill | Gates | , | has | received |
O | O | O | B-org | O | B-per | I-per | O | O | O |
O | O | O | I-per | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:bill |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.72 |
1.27 | 0.97 | 2.54 |
and | pushed | through | crowds | at | Hanoi | University | Saturday | , | where |
O | O | O | O | O | B-org | I-org | B-tim | O | O |
O | O | O | O | O | I-per | I-org | B-tim | O | O |
bias | first_upper:True | word:hanoi |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
Hanoi | University | Saturday | , | where | Gates | was | delivering | a | speech |
B-org | I-org | B-tim | O | O | B-per | O | O | O | O |
I-per | I-org | B-tim | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:gates |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.82 |
1.27 | 0.97 | 1.40 |
Earlier | , | Gates | met | Prime | Minister | Phan |
O | O | B-per | O | B-per | O | B-per |
O | O | I-per | O | B-per | I-per | I-per |
bias | first_upper:True | word:gates |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.82 |
1.27 | 0.97 | 1.40 |
, | Gates | met | Prime | Minister | Phan | Van | Khai | and | President |
O | B-per | O | B-per | O | B-per | I-per | I-per | O | B-per |
O | I-per | O | B-per | I-per | I-per | B-geo | I-per | O | B-per |
bias | first_upper:True | word:phan |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
, | the | Vietnamese | leaders | and | Gates | signed | an | agreement | to |
O | O | B-gpe | O | O | B-per | O | O | O | O |
O | O | B-gpe | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:gates |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.82 |
1.27 | 0.97 | 1.40 |
signed | an | agreement | to | use | Microsoft | software | in | Vietnam | 's |
O | O | O | O | O | B-org | O | O | B-geo | O |
O | O | O | O | O | I-per | O | O | B-geo | O |
bias | first_upper:True | word:microsoft |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
Gates | ' | trip | to | Hanoi |
B-per | O | O | O | B-geo |
I-per | O | O | O | I-per |
bias | first_upper:True | word:gates |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.82 |
1.27 | 0.97 | 1.40 |
Gates | ' | trip | to | Hanoi | is | seen | as | another |
B-per | O | O | O | B-geo | O | O | O | O |
I-per | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:hanoi |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
tech | deal | when | leading | chipmaker | Intel | Corporation | announced | it | was |
O | O | O | O | O | B-org | I-org | O | O | O |
O | O | O | O | O | I-per | I-org | O | O | O |
bias | first_upper:True | word:intel |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
Kandani | Ngwira | , | who | works |
B-per | I-per | O | O | O |
I-per | I-per | O | O | O |
bias | first_upper:True | word:kandani |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
A | Malawi | journalist | who | works | for |
O | B-gpe | O | O | O | O |
O | I-per | O | O | O | O |
bias | first_upper:True | word:malawi |
1.0 | 1.0 | 1.0 |
-2.95 | 3.91 | 0.00 |
1.27 | 0.97 | 0.00 |
Kandani | Ngwira | contacted | media | outlets |
B-per | I-per | O | O | O |
I-per | I-per | O | O | O |
bias | first_upper:True | word:kandani |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Ngwira | works | for | the | Weekly |
B-per | O | O | O | B-org |
I-per | O | O | O | O |
bias | first_upper:True | word:ngwira |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
, | a | newspaper | that | the | Malawian | government | tried | to | ban |
O | O | O | O | O | B-gpe | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:malawian |
1.0 | 1.0 | 1.0 |
-2.95 | 3.91 | 0.00 |
1.27 | 0.97 | 0.00 |
National | police | spokesman | , | Willy | Mwaluka | , | says | he |
O | O | O | O | B-per | I-per | O | O | O |
B-org | O | O | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:willy |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
he | had | no | information | about | Ngwira | 's | detention | . |
O | O | O | O | O | B-per | O | O | O |
O | O | O | O | O | I-per | O | O | O |
bias | first_upper:True | word:ngwira |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
says | he | was | arrested | in | Blantyre | and | transported | to | the |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:blantyre |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
transported | to | the | capital | , | Lilongwe | . |
O | O | O | O | O | B-geo | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:lilongwe |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Blantyre | Newspapers | Limited | , | which |
B-org | I-org | I-org | O | O |
I-per | O | O | O | O |
bias | first_upper:True | word:blantyre |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
is | providing | a | lawyer | for | Ngwira | . |
O | O | O | O | O | B-per | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:ngwira |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
follow | efforts | by | Palestinian | leader | Mahmoud | Abbas | to | persuade | militants |
O | O | O | B-gpe | O | B-per | I-per | O | O | O |
O | O | O | B-gpe | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:mahmoud |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 3.73 |
1.27 | 0.97 | 4.44 |
's | chief | veterinary | official | , | Valery | Sitnikov | , | said | bio-terrorism |
O | O | O | O | O | B-per | I-per | O | O | O |
O | O | O | O | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:valery |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Most | of | the | victims | were | Asians | . |
O | O | O | O | O | B-gpe | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:asians |
1.0 | 1.0 | 1.0 |
-2.95 | 3.91 | 0.00 |
1.27 | 0.97 | 0.00 |
's | Deputy | Foreign | Minister | , | Choe | Su | Hon | , | said |
O | O | O | O | O | B-org | I-org | I-org | O | O |
O | O | B-per | I-per | O | I-per | I-per | I-per | O | O |
bias | first_upper:True | word:choe |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
Meanwhile | , | Japan | 's | Kyodo | news | agency | reports | Pyongyang |
O | O | B-geo | O | B-geo | O | O | O | B-geo |
O | O | B-geo | O | I-per | O | O | O | B-tim |
bias | first_upper:True | word:kyodo |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Stanley | " | Tookie | " | Williams |
B-per | O | B-per | O | B-per |
I-per | O | I-per | O | I-per |
bias | first_upper:True | word:stanley |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Stanley | " | Tookie | " | Williams | has | been |
B-per | O | B-per | O | B-per | O | O |
I-per | O | I-per | O | I-per | O | O |
bias | first_upper:True | word:tookie |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Stanley | " | Tookie | " | Williams | has | been | convicted | of |
B-per | O | B-per | O | B-per | O | O | O | O |
I-per | O | I-per | O | I-per | O | O | O | O |
bias | first_upper:True | word:williams |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
the | co-founder | of | the | infamous | Crips | street | gang | . |
O | O | O | O | O | B-geo | O | O | O |
O | O | O | O | O | I-per | O | O | O |
bias | first_upper:True | word:crips |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
has | attracted | international | attention | because | Williams | is | the | author | of |
O | O | O | O | O | B-per | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:williams |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
the | books | are | evidence | that | Williams | has | turned | his | life |
O | O | O | O | O | B-per | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:williams |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
Williams | has | apologized | for | his |
B-per | O | O | O | O |
I-per | O | O | O | O |
bias | first_upper:True | word:williams |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
the | California | high | court | upheld | Williams | ' | conviction | . |
O | B-geo | O | O | O | B-per | O | O | O |
O | B-geo | O | O | O | I-per | O | O | O |
bias | first_upper:True | word:williams |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
Mr. | Schwarzenegger | 's | decision | on | clemency |
B-per | B-org | O | O | O | O |
B-per | I-per | O | O | O | O |
bias | first_upper:True | word:schwarzenegger |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
them | highly | favored | two-time | president | Akbar | Hashemi | Rafsanjani | . |
O | O | O | O | B-per | B-org | I-org | I-org | O |
O | O | O | O | O | I-per | I-per | I-per | O |
bias | first_upper:True | word:akbar |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
of | the | national | police | , | Bager | Qalibaf | , | and | the |
O | O | O | O | O | B-per | I-per | O | O | O |
O | O | O | O | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:bager |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
the | mayor | of | Tehran | , | Mahmoud | Ahmadinejad | , | are | also |
O | O | O | B-geo | O | B-geo | I-geo | O | O | O |
O | O | O | B-geo | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:mahmoud |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | -1.62 |
1.27 | 0.97 | 4.44 |
will | be | screened | by | the | Guardians | Council | , | which | will |
O | O | O | O | O | B-org | I-org | O | O | O |
O | O | O | O | O | I-per | I-org | O | O | O |
bias | first_upper:True | word:guardians |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
crowd | in | Beirut | Tuesday | , | Hassan | Nasrallah | accused | Mr. | Bush |
O | O | B-geo | B-tim | O | B-per | I-per | O | B-per | I-per |
O | O | B-geo | B-tim | O | I-per | I-per | O | B-per | I-per |
bias | first_upper:True | word:hassan |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.76 |
1.27 | 0.97 | 2.63 |
He | also | asserted | that | the | Bush | administration | ordered | Israel | to |
O | O | O | O | O | B-per | O | O | B-geo | O |
O | O | O | O | O | I-per | O | O | B-geo | O |
bias | first_upper:True | word:bush |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 3.09 |
1.27 | 0.97 | 3.80 |
of | a | security | conference | in | Munich | , | Mr. | Annan | said |
O | O | O | O | O | B-org | I-org | B-per | I-per | O |
O | O | O | O | O | I-per | O | B-per | I-per | O |
bias | first_upper:True | word:munich |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
a | large | audience | at | the | Summer | Olympics | in | Beijing | . |
O | O | O | O | O | B-eve | I-eve | O | B-geo | O |
O | O | O | O | O | I-eve | O | O | B-geo | O |
bias | first_upper:True | word:summer |
1.0 | 1.0 | 1.0 |
-0.46 | -0.41 | -0.03 |
-1.33 | 0.35 | 3.15 |
VOA | 's | Melinda | Smith | has | details | of |
B-org | O | B-per | I-per | O | O | O |
B-org | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:melinda |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
16 | prisoners | were | killed | at | Uribana | prison | when | rival | gangs |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:uribana |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Service | , | spoke | Monday | in | Ottawa | to | a | legislative | committee |
I-org | O | O | B-tim | O | B-geo | O | O | O | O |
O | O | O | B-tim | O | I-per | O | O | O | O |
bias | first_upper:True | word:ottawa |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Hooper | told | the | lawmakers | Canada |
B-per | O | O | O | B-geo |
I-per | O | O | O | B-org |
bias | first_upper:True | word:hooper |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Hooper | said | that | many | of |
B-per | O | O | O | O |
I-per | O | O | O | O |
bias | first_upper:True | word:hooper |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Saturday | before | Mr. | Chavez | 's | afternoon | departure | . |
B-tim | O | B-per | I-per | O | B-tim | O | O |
B-tim | O | B-per | I-per | O | I-tim | O | O |
bias | first_upper:False | word:afternoon |
1.0 | 1.0 | 1.0 |
0.65 | 2.77 | -0.14 |
0.38 | 2.72 | 4.59 |
send | election | observers | to | monitor | Suriname | 's | parliamentary | elections | to |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:suriname |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
The | OAS | and | Suriname | officials | agreed | to | the |
B-org | I-org | O | B-geo | O | O | O | O |
O | I-per | O | I-per | O | O | O | O |
bias | first_upper:True | word:suriname |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
The | ruling | coalition | in | Suriname | faces | opposition | from | the |
O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:suriname |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
its | leader | , | former | dictator | Desi | Bouterse | , | would | become |
O | O | O | O | O | B-per | I-per | O | O | O |
O | O | O | O | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:desi |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
has | warned | that | relations | with | Suriname | would | suffer | if | Bouterse |
O | O | O | O | O | B-geo | O | O | O | B-per |
O | O | O | O | O | I-per | O | O | O | I-per |
bias | first_upper:True | word:suriname |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
with | Suriname | would | suffer | if | Bouterse | takes | power | . |
O | B-geo | O | O | O | B-per | O | O | O |
O | I-per | O | O | O | I-per | O | O | O |
bias | first_upper:True | word:bouterse |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
He | was | convicted | in | the | Netherlands | six | years | ago | for |
O | O | O | O | O | B-geo | B-tim | O | O | O |
O | O | O | O | O | I-geo | O | O | O | O |
bias | first_upper:True | word:netherlands |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 2.26 |
0.33 | 0.24 | 3.73 |
was | never | sent | to | the | Netherlands | as | the | two | countries |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-geo | O | O | O | O |
bias | first_upper:True | word:netherlands |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 2.26 |
0.33 | 0.24 | 3.73 |
Bouterse | , | who | is | an |
B-per | O | O | O | O |
I-per | O | O | O | O |
bias | first_upper:True | word:bouterse |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
a | successful | military | coup | in | Suriname | in | 1980 | , | and |
O | O | O | O | O | B-geo | O | B-tim | O | O |
O | O | O | O | O | I-per | O | B-tim | O | O |
bias | first_upper:True | word:suriname |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
, | 84-year-old | pope | suffers | from | Parkinson | 's | disease | and | arthritis |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:parkinson |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
over | three | other | towns | - | Qalqiliya | , | Bethlehem | and | Ramallah |
O | O | O | O | O | B-geo | O | B-geo | O | B-geo |
O | O | O | O | O | I-per | O | I-per | O | B-geo |
bias | first_upper:True | word:qalqiliya |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
other | towns | - | Qalqiliya | , | Bethlehem | and | Ramallah | . |
O | O | O | B-geo | O | B-geo | O | B-geo | O |
O | O | O | I-per | O | I-per | O | B-geo | O |
bias | first_upper:True | word:bethlehem |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
build | 3,500 | new | homes | in | Maale | Adumin | , | the | largest |
O | O | O | O | O | B-geo | I-geo | O | O | O |
O | O | O | O | O | I-per | I-per | O | O | O |
bias | first_upper:True | word:maale |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
they | entered | the | bar | in | Michoacan | state | before | dawn | Wednesday |
O | O | O | O | O | B-geo | O | O | O | B-tim |
O | O | O | O | O | I-per | O | O | O | B-tim |
bias | first_upper:True | word:michoacan |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Mexico | 's | President-elect | Felipe | Calderon | has | vowed | to |
B-geo | O | O | B-per | I-per | O | O | O |
B-geo | O | I-per | I-per | I-per | O | O | O |
bias | first_upper:True | word:felipe |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 1.74 |
1.27 | 0.97 | 2.23 |
Prime | Minister | Benjamin | Netanyahu | told | his | Cabinet |
B-per | O | B-per | I-per | O | O | O |
B-per | I-per | I-per | I-per | O | O | O |
bias | first_upper:True | word:benjamin |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | -0.28 |
1.27 | 0.97 | 2.04 |
The | regional | bloc | - | IGAD | - | has | decided | to |
O | O | O | O | B-org | O | O | O | O |
O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:igad |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
to | the | holy | city | of | Mecca | , | where | some | of |
O | O | O | O | O | B-geo | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:mecca |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
the | minor | pilgrimage | known | as | Omra | . |
O | O | O | O | O | B-geo | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:omra |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
Only | Muslims | are | allowed | in | Mecca | . |
O | O | O | O | O | B-geo | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:mecca |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
the | terrorist | group | has | targeted | Westerners | in | the | past | . |
O | O | O | O | O | B-org | O | O | O | O |
O | O | O | O | O | I-per | O | O | O | O |
bias | first_upper:True | word:westerners |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 0.00 |
1.27 | 0.97 | 0.00 |
authorities | say | former | Prime | Minister | Yvon | Neptune | and | former | Interior |
O | O | O | B-per | O | B-per | I-per | O | O | O |
O | O | O | B-per | I-per | I-per | I-per | O | O | B-per |
bias | first_upper:True | word:yvon |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
Neptune | and | former | Interior | Minister | Jocelerme | Privert | are | back | in |
I-per | O | O | O | O | B-per | I-per | O | O | O |
I-per | O | O | B-per | I-per | I-per | I-per | O | O | O |
bias | first_upper:True | word:jocelerme |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
are | accused | of | violence | against | Aristide | opponents | . |
O | O | O | O | O | B-per | O | O |
O | O | O | O | O | I-per | O | O |
bias | first_upper:True | word:aristide |
1.0 | 1.0 | 1.0 |
0.60 | 1.13 | 0.00 |
1.27 | 0.97 | 0.00 |
The | Security | Council | has | threatened | sanctions |
O | B-org | I-org | O | O | O |
O | I-org | I-org | O | O | O |
bias | first_upper:True | word:security |
1.0 | 1.0 | 1.0 |
0.84 | 0.88 | 1.27 |
0.97 | 0.50 | 3.60 |
of | dozens | of | villagers | in | Dujail | . |
O | O | O | O | O | B-geo | O |
O | O | O | O | O | I-per | O |
bias | first_upper:True | word:dujail |
1.0 | 1.0 | 1.0 |
1.34 | 0.51 | 0.00 |
1.27 | 0.97 | 0.00 |
In the IOB tagging scheme:
I-[label]
can logically only appear after B-[label]
!The following can never be valid tag sequences:
O I-per
B-per I-geo
Remember that
p\params(\y|\x)=n∏i=1p\params(yi|\x,i,y1,…,i−1)What if we went from this...
≈n∏i=1p\params(yi|\x,i)...to this?
≈n∏i=1p\params(yi|\x,yi−1,i)Does this remind you of anything you've seen in previous lectures?
Log-linear version with access to previous label:
p\params(yi|\x,yi−1,i)=1Z\x,yi−1,iexp⟨\repr(\x,yi−1,i),\paramsyi⟩where Z\x,yi−1,i=∑yexp⟨\repr(\x,yi−1,i),\paramsyi⟩ is a local per-token normalisation factor.
Decomposes nicely: ∑(\x,\y)∈\train|\x|∑i=1log\prob\params(yi|\x,yi−1,i)
Easy to train
However...
Replace local with global normalisation.
Instead of normalising across all possible next states yi+1 given a current state yi and observation \x,
the CRF normalises across all possible sequences \y given observation \x.
Formally:
p\params(yi|\x,yi−1,i)=1Z\xexp⟨\repr(\x,yi−1,i),\paramsyi⟩where Z\x=∑\y|\x|∏iexp⟨\repr(\x,yi−1,i),\paramsyi⟩ is a global normalisation constant depending on \x.
Notably, each term exp⟨\repr(\x,yi−1,i),\paramsyi⟩ in the product can now take on values in [0,∞) as opposed to the MEMM terms in [0,1].
The best of both worlds?
(from Lample et al., 2016)
To predict the best label sequence, find a \y∗ with maximal conditional probability
\y∗=\argmax\y\prob\params(\y|\x).Simplest option:
But...
We cannot simply choose each label in isolation because decisions depend on each other.
Keep a "beam" of the best β previous solutions
Many problems can be cast as sequence labelling
Models are similar to sequence classifiers but are sequential
CRFs model label dependencies