Traitement linguistique 100 coups 2015 ["Chapitre 6: Traitement de texte anglais"](http: //www.cl.ecei) Il s'agit de l'enregistrement de la 56ème «analyse de co-référence» de .tohoku.ac.jp / nlp100 / # ch6). Jusqu'à la dernière fois au chapitre 6, le niveau de l'exercice préparatoire était simple, mais il est temps d'y réfléchir.
Lien | Remarques |
---|---|
056.Analyse de co-référence.ipynb | Lien GitHub du programme de réponse |
100 coups de traitement du langage amateur:56 | Copiez et collez la source de nombreuses pièces source |
Officiel PNL de Stanford Core | Premier coup d'oeil à la page PNL de Stanford Core |
type | version | Contenu |
---|---|---|
OS | Ubuntu18.04.01 LTS | Il fonctionne virtuellement |
pyenv | 1.2.16 | J'utilise pyenv car j'utilise parfois plusieurs environnements Python |
Python | 3.8.1 | python3 sur pyenv.8.J'utilise 1 Les packages sont gérés à l'aide de venv |
Stanford CoreNLP | 3.9.2 | Je l'ai installé il y a un an et je ne me souviens pas en détail ... C'était le dernier même après un an, donc je l'ai utilisé tel quel |
openJDK | 1.8.0_242 | J'ai utilisé le JDK qui a été installé à d'autres fins tel quel |
Un aperçu des différentes technologies de base pour le traitement du langage naturel grâce au traitement de texte anglais à l'aide de la PNL Stanford Core.
Stanford Core NLP, Stemming, Part-word tagging, Unique expression extraction, Co-reference analysis, Dependency analysis, Clause structure analysis, S expression
Effectuez le traitement suivant sur le texte anglais (nlp.txt).
Sur la base des résultats de l'analyse de co-référence de Stanford Core NLP, remplacer la référence dans la phrase par la mention représentative. Cependant, lors du remplacement, veillez à ce que l'expression de référence d'origine puisse être comprise, telle que «expression de référence représentative (expression de référence)».
La coréférence semble se référer à la même directive dans la nomenclature. L'image sur Stanford CoreNLP Official est facile à comprendre. Le mécanisme de Stanford Core NLP est détaillé dans Deterministic Coreference Resolution System.
import xml.etree.ElementTree as ET
#Analyser le xml du résultat de l'analyse
root = ET.parse('./nlp.txt.xml')
#Créer un dictionnaire d'informations de localisation qui énumère les coréférences et les remplace par des expressions de référence représentatives
#Le dictionnaire est{(sentence id,ID de jeton de démarrage), (ID de jeton de fin,Expression de référence représentative)}...
replaces = {}
for coreference in root.iterfind('./document/coreference/coreference'):
#Acquisition d'une expression de référence représentative
representative = coreference.findtext('./mention[@representative="true"]/text')
#Mentionnez une énumération autre que les expressions de référence représentatives, ajoutée au dictionnaire
for mention in coreference.iterfind('./mention'):
if mention.get('representative') == None:
sentence_id = mention.findtext('sentence')
start = mention.findtext('start')
end = int(mention.findtext('end')) - 1 #fin de décalage
#Mettez à jour sans vous soucier même s'il est déjà dans le dictionnaire(Gagner après)
replaces[(sentence_id, start)] = (end, representative)
#Afficher tout en remplaçant le texte par des remplacements
for sentence in root.iterfind('./document/sentences/sentence'):
sentence_id = sentence.get('id')
for token in sentence.iterfind('./tokens/token'):
token_id = token.get('id')
#Début de remplacement
if (sentence_id, token_id) in replaces:
#Extraire la position finale et l'expression de référence représentative du dictionnaire
(end, representative) = replaces[(sentence_id, token_id)]
#Expression de référence représentative + insérer des parenthèses(end=''Aucun saut de ligne)
print('「' + representative + '」 (', end='')
#sortie de jeton(end=''Aucun saut de ligne)
print(token.findtext('word'), end='')
#Insérer des parenthèses fermantes à la fin du remplacement(end=''Aucun saut de ligne)
if int(token_id) == end:
print(')', end='')
end = 0
#Fin de phrase(période)Je me fiche de l'espace ajouté avant(end=''Aucun saut de ligne)
print(' ', end='')
print() #Sauts de ligne dans les unités de phrase
Ce qui suit est un mappage des chemins de fichiers XML et des informations de co-référence. Ce n'est pas une erreur que les mêmes coordonnées se trouvent dans les 3e et 4e couches (bien que la 3e couche soit généralement des «coréférences» ...). Si l'attribut «représentant» est vrai dans la balise «mention» de la 5ème couche, il s'agit d'une «expression de référence représentative». D'autres sont des référents.
production | 1er niveau | Deuxième niveau | Troisième niveau | 4ème niveau | 5ème niveau | 6ème niveau |
---|---|---|---|---|---|---|
Identifiant de phrase de co-référence | root | document | coreference | coreference | mention | sentence |
Début de l'identifiant du jeton de co-référence | root | document | coreference | coreference | mention | start |
ID de jeton de fin de co-référence | root | document | coreference | coreference | mention | end |
Texte de co-référence | root | document | coreference | coreference | mention | text |
Le fichier XML est [GitHub](https://github.com/YoheiFukuhara/nlp100/blob/master/06.%E8%8B%B1%E8%AA%9E%E3%83%86%E3%82%AD% E3% 82% B9% E3% 83% 88% E3% 81% AE% E5% 87% A6% E7% 90% 86 / nlp.txt.xml).
xml:nlp.txt.xml(Extrait)
<root>
<document>
<docId>nlp.txt</docId>
<sentences>
--Omission--
<coreference>
<coreference>
<mention representative="true">
<sentence>1</sentence>
<start>7</start>
<end>16</end>
<head>12</head>
<text>the free encyclopedia Natural language processing -LRB- NLP -RRB-</text>
</mention>
<mention>
<sentence>1</sentence>
<start>17</start>
<end>22</end>
<head>18</head>
<text>a field of computer science</text>
</mention>
Nous avons créé une variable de dictionnaire nommée replace
pour stocker les données.
{(ID de phrase, ID de jeton de début), (ID de jeton de fin, expression de référence représentative)}
Comment saisir des données. Il peut y avoir des clés en double dans le dictionnaire, mais nous utilisons la méthode second-win (l'enregistrement qui vient plus tard écrase l'enregistrement qui était plus tôt).
python
#Créer un dictionnaire d'informations de localisation qui énumère les coréférences et les remplace par des expressions de référence représentatives
#Le dictionnaire est{(sentence id,ID de jeton de démarrage), (ID de jeton de fin,Expression de référence représentative)}...
replaces = {}
for coreference in root.iterfind('./document/coreference/coreference'):
#Acquisition d'une expression de référence représentative
representative = coreference.findtext('./mention[@representative="true"]/text')
#Mentionnez une énumération autre que les expressions de référence représentatives, ajoutée au dictionnaire
for mention in coreference.iterfind('./mention'):
if mention.get('representative') == None:
sentence_id = mention.findtext('sentence')
start = mention.findtext('start')
end = int(mention.findtext('end')) - 1 #fin de décalage
#Mettez à jour sans vous soucier même s'il est déjà dans le dictionnaire(Gagner après)
replaces[(sentence_id, start)] = (end, representative)
Après cela, en lisant le texte de la partie phrases
, s'il y a une expression de référence, je la remplace et ajoute des parenthèses.
python
#Afficher tout en remplaçant le texte par des remplacements
for sentence in root.iterfind('./document/sentences/sentence'):
sentence_id = sentence.get('id')
for token in sentence.iterfind('./tokens/token'):
token_id = token.get('id')
#Début de remplacement
if (sentence_id, token_id) in replaces:
#Extraire la position finale et l'expression de référence représentative du dictionnaire
(end, representative) = replaces[(sentence_id, token_id)]
#Expression de référence représentative + insérer des parenthèses(end=''Aucun saut de ligne)
print('「' + representative + '」 (', end='')
#sortie de jeton(end=''Aucun saut de ligne)
print(token.findtext('word'), end='')
#Insérer des parenthèses fermantes à la fin du remplacement(end=''Aucun saut de ligne)
if int(token_id) == end:
print(')', end='')
end = 0
#Fin de phrase(période)Je me fiche de l'espace ajouté avant(end=''Aucun saut de ligne)
print(' ', end='')
print() #Sauts de ligne dans les unités de phrase
Lorsque le programme est exécuté, les résultats suivants sont affichés.
Résultat de sortie
Natural language processing From Wikipedia , the free encyclopedia Natural language processing -LRB- NLP -RRB- is a field of computer science) , artificial intelligence , and linguistics concerned with the interactions between computers and human -LRB- natural -RRB- languages .
As such , 「NLP」 (NLP) is related to the area of humani-computer interaction .
Many challenges in 「NLP」 (NLP) involve natural language understanding , that is , enabling computers to derive meaning from human or natural language input , and others involve natural language generation .
History The history of 「NLP」 (NLP) generally starts in the 1950s , although work can be found from earlier periods .
In 1950 , Alan Turing published an article titled `` Computing Machinery and Intelligence '' which proposed what is now called the Turing test as a criterion of intelligence .
The Georgetown experiment in 1954 involved fully automatic translation of more than sixty Russian sentences into English .
The authors claimed that within three or five years , machine translation would be a solved problem .
However , real progress was much slower , and after the ALPAC report in 1966 , which found that ten year long research had failed to fulfill the expectations , funding for 「machine translation」 (machine translation) was dramatically reduced .
Little further research in 「machine translation」 (machine translation) was conducted until the late 1980s , when the first statistical machine translation systems were developed .
Some notably successful NLP systems developed in the 1960s were SHRDLU , a natural language system working in restricted `` blocks worlds '' with restricted vocabularies , and ELIZA , a simulation of a Rogerian psychotherapist , written by Joseph Weizenbaum between 1964 to 「1966」 (1966) .
Using almost no information about human thought or emotion , ELIZA sometimes provided a startlingly human-like interaction .
When the `` patient '' exceeded the very small knowledge base , 「ELIZA」 (ELIZA) might provide a generic response , for example , responding to `` My head hurts '' with `` Why do you say 「My head」 (your head) hurts ? ''
.
During the 1970s many programmers began to write ` conceptual ontologies ' , which structured real-world information into computer-understandable data .
Examples are MARGIE -LRB- Schank , 1975 -RRB- , SAM -LRB- Cullingford , 1978 -RRB- , PAM -LRB- Wilensky , 「1978」 (1978) -RRB- , TaleSpin -LRB- Meehan , 1976 -RRB- , QUALM -LRB- Lehnert , 1977 -RRB- , Politics -LRB- Carbonell , 1979 -RRB- , and Plot Units -LRB- Lehnert 1981 -RRB- .
During this time , many chatterbots were written including PARRY , Racter , and Jabberwacky .
Up to the 1980s , most 「NLP」 (NLP) systems were based on complex sets of hand-written rules .
Starting in the late 1980s , however , there was a revolution in 「NLP」 (NLP) with the introduction of machine learning algorithms for language processing .
This was due to both the steady increase in computational power resulting from Moore 's Law and the gradual lessening of the dominance of Chomskyan theories of linguistics -LRB- e.g. transformational grammar -RRB- , whose theoretical underpinnings discouraged the sort of corpus linguistics that underlies the machine-learning approach to language processing .
Some of the earliest-used machine learning algorithms , such as decision trees , produced systems of hard if-then rules similar to existing hand-written rules .
However , Part of speech tagging introduced the use of Hidden Markov Models to NLP , and increasingly , research has focused on statistical models , which make soft , probabilistic decisions based on attaching real-valued weights to the features making up the input data .
The cache language models upon which many speech recognition systems now rely are examples of such statistical models .
Such models are generally more robust when given unfamiliar input , especially input that contains errors -LRB- as is very common for real-world data -RRB- , and produce more reliable results when integrated into a larger system comprising multiple subtasks .
Many of the notable early successes occurred in the field of machine translation , due especially to work at IBM Research , where successively more complicated statistical models were developed .
「many speech recognition systems」 (These systems) were able to take advantage of existing multilingual textual corpora that had been produced by the Parliament of Canada and the European Union as a result of laws calling for the translation of all governmental proceedings into all official languages of the corresponding systems of government .
However , most other systems depended on corpora specifically developed for the tasks implemented by these systems , which was -LRB- and often continues to be -RRB- a major limitation in the success of 「many speech recognition systems」 (these systems) .
As a result , a great deal of research has gone into methods of more effectively learning from limited amounts of data .
Recent research has increasingly focused on unsupervised and semi-supervised learning algorithms .
Such algorithms are able to learn from data that has not been hand-annotated with the desired answers , or using a combination of annotated and non-annotated data .
Generally , this task is much more difficult than supervised learning , and typically produces less accurate results for a given amount of input data .
However , there is an enormous amount of non-annotated data available -LRB- including , among other things , the entire content of the World Wide Web -RRB- , which can often make up for the inferior results .
NLP using machine learning Modern NLP algorithms are based on machine learning , especially statistical machine learning .
「The machine-learning paradigm」 (The paradigm of machine learning) is different from that of most prior attempts at language processing .
Prior implementations of language-processing tasks typically involved the direct hand coding of large sets of rules .
The machine-learning paradigm calls instead for using general learning algorithms - often , although not always , grounded in statistical inference - to automatically learn such rules through the analysis of large corpora of typical real-world examples .
A corpus -LRB- plural , `` corpora '' -RRB- is a set of documents -LRB- or sometimes , individual sentences -RRB- that have been hand-annotated with the correct values to be learned .
Many different classes of machine learning algorithms have been applied to 「NLP」 (NLP) tasks .
「machine learning algorithms」 (These algorithms) take as input a large set of `` features '' that are generated from 「the input data」 (the input data) .
Some of 「machine learning algorithms」 (the earliest-used algorithms) , such as decision trees , produced systems of hard if-then rules similar to the systems of hand-written rules that were then common .
Increasingly , however , research has focused on statistical models , which make soft , probabilistic decisions based on attaching real-valued weights to each input feature .
Such models have the advantage that 「Such models」 (they) can express the relative certainty of many different possible answers rather than only one , producing more reliable results when such a model is included as a component of a larger system .
Systems based on machine-learning algorithms have many advantages over hand-produced rules : The learning procedures used during machine learning automatically focus on the most common cases , whereas when writing rules by hand it is often not obvious at all where the effort should be directed .
Automatic learning procedures can make use of statistical inference algorithms to produce models that are robust to unfamiliar input -LRB- e.g. containing words or structures that have not been seen before -RRB- and to erroneous input -LRB- e.g. with misspelled words or words accidentally omitted -RRB- .
Generally , handling such input gracefully with hand-written rules -- or more generally , creating systems of hand-written rules that make soft decisions -- extremely difficult , error-prone and time-consuming .
Systems based on automatically learning 「hand-written rules --」 (the rules) can be made more accurate simply by supplying more input data .
However , systems based on hand-written rules can only be made more accurate by increasing the complexity of the rules , which is a much more difficult task .
In particular , there is a limit to the complexity of systems based on hand-crafted rules , beyond which 「many speech recognition systems」 (the systems) become more and more unmanageable .
However , creating more data to input to machine-learning systems simply requires a corresponding increase in the number of man-hours worked , generally without significant increases in the complexity of the annotation process .
The subfield of 「NLP」 (NLP) devoted to learning approaches is known as Natural Language Learning -LRB- NLL -RRB- and 「NLP」 (its) conference CoNLL and peak body SIGNLL are sponsored by ACL , recognizing also their links with Computational Linguistics and Language Acquisition .
When the aims of computational language learning research is to understand more about human language acquisition , or psycholinguistics , 「NLL」 (NLL) overlaps into the related field of Computational Psycholinguistics .
Recommended Posts