Christophe Cerisara
2023/2024
CM | Topic |
---|---|
07/12 | intro: get/build Lex Res |
08/01 | Overview of embeddings |
15/01 | WordNet + FrameNet |
22/01 | VerbNet + PropBank |
29/01 | Transformers 1 |
05/02 | Transformers 2 |
16/02 | Examen |
Manually: annotation guides, quality…
Scrap/curate texts, RDF extraction…
From XML files (SPARQL…)
1 They they PRON PRP Case=Nom|Number=Plur 2 nsubj 2:nsubj|4:nsubj
2 buy buy VERB VBP Number=Plur|Person=3|Tense=Pres 0 root 0:root
3 and and CONJ CC _ 4 cc 4:cc
4 sell sell VERB VBP Number=Plur|Person=3|Tense=Pres 2 conj 0:root|2:conj
5 books book NOUN NNS Number=Plur 2 obj 2:obj|4:obj
6 . . PUNCT . _ 2 punct 2:punct
item [1]:
class = "IntervalTier"
name = "sentence"
xmin = 0
xmax = 2.3
intervals: size = 1
intervals [1]:
xmin = 0
xmax = 2.3
text = "říkej ""ahoj"" dvakrát"
item [2]:
class = "IntervalTier"
name = "phonemes"
xmin = 0
xmax = 2.3
intervals: size = 3
intervals [1]:
xmin = 0
xmax = 0.7
text = "r̝iːkɛj"
intervals [2]:
xmin = 0.7
xmax = 1.6
text = "ʔaɦɔj"
<entry xml:id="a_1">
<form>
<orth>Bahnhof</orth>
</form>
<gramGrp>
<pos value="N" />
<gen value="masculine" />
</gramGrp>
<sense>
<def>...</def>
<cit>
<quote>der Zug fährt in den Bahnhof ein</quote>
</cit>
</sense>
<!-- ... -->
<sense>
<def>...</def>
</sense>
</entry>
<gramGrp>
<pos value="N"
dcr:datcat="http://hdl.handle.net/11459/CCR_C-5524_d8864ad4-1bdf-ee56-594e-784312129ea7"
dcr:valueDatcat="http://hdl.handle.net/11459/CCR_C-3347_7face0f5-7a72-7ec2-c988-7adba256cea9" />
</gramGrp>
<LexicalEntry>
<feat att="partOfSpeech" val="noun" />
<feat att="gender" val="masculine" />
<Lemma>
<feat att="writtenForm" val="Bahnhof" />
</Lemma>
<WordForm>
<feat att="writtenForm" val="Bahnhof" />
<feat att="grammaticalNumber" val="singular" />
</WordForm>
<WordForm>
<feat att="writtenForm" val="Bahnhöfe" />
<feat att="grammaticalNumber" val="plural" />
</WordForm>
<Sense id="s1">
</Sense>
<!-- ... -->
<Sense id="sn">
</Sense>
</LexicalEntry>
Main distributors:
European Open Science Cloud
(cf. course of Mathieu D’Aquin)
<LexicalEntry id ='w44919'>
<Lemma writtenForm='quantification' partOfSpeech='n'/>
<Sense id='w44919_01003570-n' synset='eng-10-01003570-n'/>
<Sense id='w44919_06165623-n' synset='eng-10-06165623-n'/>
</LexicalEntry> [...]
<Synset id='eng-10-01003570-n' baseConcept='3'>
<Definition gloss="the act of discovering or expressing the quantity of something"> </Definition>
<SynsetRelations>
<SynsetRelation targets='eng-10-00996969-n' relType='hype'/>
<SynsetRelation targets='eng-10-01003729-n' relType='hypo'/>
</SynsetRelations>
</Synset>
SPARQL to access RDF
ELEXIS project “European Lexicographic Infrastructure”
(Chiarcos, IWLTP’2020):
“Working with RDF normally requires a certain level of technical expertise, i.e., basic knowledge of SPARQL and at least one RDF format.”
https://livebook.manning.com/book/linked-data/chapter-2/1
400k LLMs available on Huggingface Hub !
… But WordNet has much richer relations (antonyms, hypernyms…) than list of words!
It’s not because it’s public that you can copy it !!
(Wait… doesn’t Google scrap the whole web since many years ?)
There are several ways to download corpora:
See course on basic NLP techniques (Yannick Parmentier)
See Claire Gardent’s course.
bzcat frwik.xml.bz2 | less
bzcat frwik.xml.bz2 | grep -n '<title>Nancy</title>'
bzcat frwik.xml.bz2 | tail -n +12872178 | less
<title>Nancy</title>
<ns>0</ns>
<id>271346</id>
<revision>
<id>29517974</id>
<parentid>28848867</parentid>
<timestamp>2021-06-10T00:19:11Z</timestamp>
<contributor>
<username>Lingua Libre Bot</username>
<id>229398</id>
</contributor>
<comment>Ajout d'un fichier audio de prononciation depuis Lingua Libre</comment>
<model>wikitext</model>
<format>text/x-wiki</format>
<text bytes="7282" xml:space="preserve">{{voir|nancy}}
== {{langue|fr}} ==
=== {{S|étymologie}} ===
: {{date|lang=fr|1073}} La première trace écrite de Nancy date du 29 avril 1073 (mention dans la charte de Pibon, évêque de Toul : « Olry, voué de Nancy » (« ''Odelrici advocati de Nanceio'' »). Le nom serait cependant d’origine celtique, car on le rapproche du gaulois ''{{lien|nantu-|gaulois}}''/''{{lien|nanto-|gaulois}}'', qui signifie « [[val]], [[vallée]] », ou de {{recons|lang-mot-vedette=fr|nantus|gaulois}} (« ruisseau »).
=== {{S|nom de famille|fr}} ===
'''Nancy''' {{pron|nɑ̃.si|fr}}
# Nom de famille.
=== {{S|nom propre|fr}} ===
{{fr-inv|nɑ̃.si|inv_titre=Nom propre}}
'''Nancy''' {{pron|nɑ̃.si|fr}}
# {{localités|fr|du département de la Meurthe-et-Moselle}} [[commune|Commune]], [[ville]] et [[chef-lieu de département]] [[français]], situé dans le département de la [[Meurthe-et-Moselle]].
#* '''''Nancy''' est une ville d’ordre et de lumières où dès le XVII{{e}} et le XVIII{{e}} siècle, des ducs intelligents furent, sans le savoir, les précurseurs heureux de nos urbanistes modernes.'' {{source|{{Citation/Ludovic Naudeau/La France se regarde/1931}}}}
#* ''La verrerie de '''Nancy''' est de fondation récente, puisqu’elle date de 1875 seulement.'' {{source|Gustave Fraipont; ''Les Vosges'', 1923}}
import wikipedia
print(wikipedia.summary("Nancy, France"))
Nancy is the capital of the northeastern French department of Meurthe-et-Moselle, the former capital of the Duchy of Lorraine, and then the French province of the same name. The metropolitan area of Nancy had a population of 511,257 inhabitants at the 2018 census, making it the 16th largest urban area in France and the Lorraine's largest. The population of the city of Nancy proper is 104,885.
The motto of the city is Non inultus premor, Latin for '"I am not injured unavenged"'—a reference to the thistle, which is a symbol of Lorraine.
Place Stanislas, a large square built between March 1752 and November 1755 by Stanislaus I of Poland to link the medieval old town of Nancy and the new town built under Charles III in the 17th century, is a UNESCO World Heritage Site, the first place in France and in the top four in the world. The city also has many buildings listed as historical monuments and is one of the European centers of Art Nouveau thanks to the École de Nancy. Nancy is also one of the main university cities and, with the Centre Hospitalier Régional Universitaire de Brabois, the conurbation is home to one of the main health centers in Europe, renowned for its innovations in surgical robotics.
grep Nancy kaikki.org-dictionary-French.json
{"pos": "name", "heads": [{"template_name": "fr-proper noun"}], "word": "Nancy", "lang": "French", "lang_code": "fr", "sounds": [{"ipa": "/n\u0251\u0303.si/"}], "categories": ["Cities in France"], "senses": [{"categories": ["French female given names", "French given names"], "tags": ["feminine"], "glosses": ["A female given name from English borrowed from English."], "id": "Nancy-name"}]}
{"pos": "name", "heads": [{"template_name": "fr-proper noun"}], "categories": ["Cities in France"], "word": "Nancy", "lang": "French", "lang_code": "fr", "sounds": [{"ipa": "/n\u0251\u0303.si/"}], "senses": [{"glosses": ["Nancy (the city)."], "derived": [{"word": "nanc\u00e9ien"}, {"word": "Nanc\u00e9ien"}], "id": "Nancy-name"}]}
{"pos": "noun", "heads": [{"1": "m", "f": "Nanc\u00e9ienne", "template_name": "fr-noun"}], "forms": [{"form": "Nanc\u00e9iens", "tags": ["plural"]}, {"form": "Nanc\u00e9ienne", "tags": ["feminine"]}], "word": "Nanc\u00e9ien", "lang": "French", "lang_code": "fr", "senses": [{"tags": ["masculine"], "glosses": ["an inhabitant of the city of Nancy"], "categories": ["Demonyms"], "id": "Nanc\u00e9ien-noun"}]}
<title>Nancy</title>
<ns>0</ns>
<id>271346</id>
<revision>
<id>29517974</id>
<parentid>28848867</parentid>
<timestamp>2021-06-10T00:19:11Z</timestamp>
<contributor>
<username>Lingua Libre Bot</username>
<id>229398</id>
</contributor>
<comment>Ajout d'un fichier audio de prononciation depuis Lingua Libre</comment>
<model>wikitext</model>
<format>text/x-wiki</format>
<text bytes="7282" xml:space="preserve">{{voir|nancy}}
== {{langue|fr}} ==
=== {{S|étymologie}} ===
: {{date|lang=fr|1073}} La première trace écrite de Nancy date du 29 avril 1073 (mention dans la charte de Pibon, évêque de Toul : « Olry, voué de Nancy » (« ''Odelrici advocati de Nanceio'' »). Le nom serait cependant d’origine celtique, car on le rapproche du gaulois ''{{lien|nantu-|gaulois}}''/''{{lien|nanto-|gaulois}}'', qui signifie « [[val]], [[vallée]] », ou de {{recons|lang-mot-vedette=fr|nantus|gaulois}} (« ruisseau »).
=== {{S|nom de famille|fr}} ===
'''Nancy''' {{pron|nɑ̃.si|fr}}
# Nom de famille.
=== {{S|nom propre|fr}} ===
{{fr-inv|nɑ̃.si|inv_titre=Nom propre}}
'''Nancy''' {{pron|nɑ̃.si|fr}}
# {{localités|fr|du département de la Meurthe-et-Moselle}} [[commune|Commune]], [[ville]] et [[chef-lieu de département]] [[français]], situé dans le département de la [[Meurthe-et-Moselle]].
#* '''''Nancy''' est une ville d’ordre et de lumières où dès le XVII{{e}} et le XVIII{{e}} siècle, des ducs intelligents furent, sans le savoir, les précurseurs heureux de nos urbanistes modernes.'' {{source|{{Citation/Ludovic Naudeau/La France se regarde/1931}}}}
#* ''La verrerie de '''Nancy''' est de fondation récente, puisqu’elle date de 1875 seulement.'' {{source|Gustave Fraipont; ''Les Vosges'', 1923}}
import bz2
import xml.sax
class WikiXmlHandler(xml.sax.handler.ContentHandler):
def __init__(self):
xml.sax.handler.ContentHandler.__init__(self)
self._buffer = None
self._values = {}
self._current_tag = None
def characters(self, content):
"""Characters between opening and closing tags"""
if self._current_tag:
self._buffer.append(content)
def startElement(self, name, attrs):
"""Opening tag of element"""
if name in ('title', 'text'):
self._current_tag = name
self._buffer = []
def endElement(self, name):
"""Closing tag of element"""
if name == self._current_tag:
self._values[name] = ' '.join(self._buffer)
if name == 'page':
print(self._values['title'], self._values['text'])
handler = WikiXmlHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
with bz2.open("frwik.xml.bz2", "rt") as f:
for line in f:
parser.feed(line)
accueil {{voir|Accueil}}
== {{langue|fr}} ==
=== {{S|étymologie}} ===
: {{siècle|XII}} {{déverbal|de=accueillir|lang=fr|m=1}}.
=== {{S|nom|fr}} ===
{{fr-rég|a.kœj}}
'''accueil''' {{pron|a.kœj|fr}} {{m}}
# [[cérémonie|Cérémonie]] ou [[prestation]] réservée à un nouvel [[arrivant]], consistant généralement à lui [[souhaiter]] la [[bienvenue]] et à l’aider dans son [[intégration]] ou ses [[démarche]]s.
#* ''Nous réservâmes aux nouveaux venus un '''accueil''' qui fut cordial et empressé, mais le temps n’était pas aux effusions et d’un commun avis, il fallait agir vite.'' {{source|{{w|Jean-Baptiste Charcot}}, ''Dans la mer du Groenland'', 1928}}
#* ''Partout elle avait trouvé bon '''accueil''', prompt assentiment, mais elle se propose d’aller plus outre.'' {{source|{{Citation/Jean Rogissart/Passantes d’Octobre/1958|}}}}
#* ''Notre hôte, absent au moment de notre arrivée, ne tarde pas à paraître et me fait l’'''accueil''' auquel je m'attendais de sa part.'' {{source|{{w|Frédéric Weisgerber}}, ''Trois mois de campagne au Maroc : étude géographique de la région parcourue'', Paris : Ernest Leroux, 1904, page 38}}
import mwparserfromhell
title = mwparserfromhell.parse(title)
s=title.strip_code().strip()
print(s)
accueil
MediaWiki:Disclaimers
MediaWiki:Disclaimerpage
MediaWiki:Showhideminor
MediaWiki:Sitetitle
lire
encyclopédie
Discussion utilisateur:Romanito
Discussion utilisateur:Hippietrail
Utilisateur:Ryo
Utilisateur:Romanito
manga
Utilisateur:Ske
Utilisateur:Alno
Discussion utilisateur:Alno
Discussion utilisateur:Koxinga/2004-2008
ouvrage
import mwparserfromhell
title = mwparserfromhell.parse(title)
s=title.strip_code().strip()
if not ':' in s:
print("TITLE ",s)
wiki = mwparserfromhell.parse(text)
print(wiki)
DEF lire
WW {{voir/lire}}
== {{langue|fr}} ==
=== {{S|étymologie}} ===
: ([[#fr-verb|Verbe]]) Du {{étyl|la|fr|mot=lego|dif=lĕgĕre|sens=''id.''}}, proprement « recueillir »
: ([[#fr-nom|Nom]]) De l’{{étyl|it|fr|mot=lira}}, du {{étyl|la|fr|libra}} (« [[livre]] », le poids).
=== {{S|verbe|fr}} ===
[[File:Reading Jane Eyre.jpg|thumb|Jeune fille qui '''lit'''. (1)]]
[[File:USMC-120302-M-PG598-001.jpg|thumb|Une adulte '''lit''' une histoire à un groupe d'enfants. (6)]]
'''lire''' {{pron|liʁ|fr}} {{conjugaison|fr}} {{conjugaison|fr|grp=3}}
# [[interpréter|Interpréter]] des [[information]]s écrites sous forme de [[mot]]s ou de [[dessin]]s sur un [[suppo
rt]].
#* ''On '''lit''' ce livre absolument comme au bord de la cascade on entendrait, rêveur, le gazouillement des eaux
.'' {{source|{{w|Jules Michelet}}, ''Du prêtre, de la femme, de la famille'', 3{{e}} éd., Hachette & Paulin, 1845
, page 133}}
import re
import mwparserfromhell
etyl = re.compile(r'{{étyl\|([^\|]*)\|[^\|]*\|([^\|}]*)[^}]*}}')
def handleWikiMedia(title,text):
title = mwparserfromhell.parse(title)
s=title.strip_code().strip()
if not ':' in s:
print("DEF "+s)
wiki = mwparserfromhell.parse(text)
for l in str(wiki).split('\n'):
l = l.strip()
if l.startswith(':'):
l = etyl.sub("(\g<1>) \"\g<2>\"",l)
s=l[1:]
ss = mwparserfromhell.parse(s)
s = ss.strip_code(normalize=True, collapse=True, keep_template_params=False).strip()
if len(s)>0: print(" "+s)
print()
class WikiXmlHandler(xml.sax.handler.ContentHandler):
def __init__(self):
xml.sax.handler.ContentHandler.__init__(self)
self._buffer = None
self._values = {}
self._current_tag = None
def characters(self, content):
"""Characters between opening and closing tags"""
if self._current_tag:
self._buffer.append(content)
def startElement(self, name, attrs):
"""Opening tag of element"""
if name in ('title', 'text'):
self._current_tag = name
self._buffer = []
def endElement(self, name):
"""Closing tag of element"""
if name == self._current_tag:
self._values[name] = ' '.join(self._buffer)
if name == 'page':
# print(self._values['title'], self._values['text'])
handleWikiMedia(self._values['title'], self._values['text'])
DEF lire
(Verbe) Du (la) "mot=lego", proprement « recueillir »
(Nom) De l’(it) "mot=lira", du (la) "libra" (« livre », le poids).
Du (la) "mot=lyra".
DEF encyclopédie
Du (la) "encyclopaedia" forgé à la Renaissance sur la base du (grc) "ἐγκύκλιος" — voir — et soit le sens de «
ensemble de toutes les sciences ».
DEF manga
Du (ja) "漫画".
Le mot manga a aussi été considéré comme féminin, mais l’usage tend à préférer le masculin.
Du (ja) "漫画".
(Nom commun 1) Du (la) "manica".
(Nom commun 2) Du (ja) "漫画".
Du (ja) "漫画".
Du (la) "manica".
(Nom commun 1) Du (la) "manica".
(Nom commun 2) Du (ms) "mangga".
Du (ja) "漫画".
DEF ouvrage
Dérivé de ouvrer, ancienne forme de œuvrer, avec le suffixe -age.
Par dérive populaire puis effet stylistique, on peut rencontrer le genre féminin.
C’est de la belle ouvrage.
\[P(w) = \frac {N(w)} {N(*)}\]
\[P(b|a) = \frac {N(a,b)} {N(a,*)}\]
Note:
\[P(b|a) = \frac {P(a,b)}{P(a)} = \frac{\frac{N(a,b)}{N(*,*)}}{\frac{N(a)}{N(*)}}\]
\[P(w_t|w_{t-n+1},\dots,w_{t-1}) = \frac{N(w_{t-n+1},\dots,w_{t-1},w_t)}{N(w_{t-n+1},\dots,w_{t-1},*)}\]
We’ll use N-grams for:
\[P(w_t|w_{t-n+1},\dots,w_{t-1}) = \frac{1+N(w_{t-n+1},\dots,w_{t-1},w_t)}{\sum_x \left( 1+ N(w_{t-n+1},\dots,w_{t-1},x) \right)}\]