1 / 99

Inteligencia Artificial Interpretación semántica

Inteligencia Artificial Interpretación semántica . Primavera 2009 profesor: Luigi Ceccaroni. CFG recognition using difference lists. An efficient implementation of CFGs can be obtained by making use of difference lists: a sophisticated Prolog technique.

karik
Télécharger la présentation

Inteligencia Artificial Interpretación semántica

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inteligencia Artificial Interpretación semántica Primavera 2009 profesor: Luigi Ceccaroni

  2. CFG recognition using difference lists • An efficient implementation of CFGs can be obtained by making use of difference lists: a sophisticated Prolog technique. • The key idea underlying difference lists is to represent the information about grammatical categories not as a single list, but as the difference between two lists. • For example, instead of representing a woman shoots a man as [a,woman,shoots,a,man] we might represent it as the pair of lists [a,woman,shoots,a,man] [ ].  

  3. CFG recognition using difference lists • Think of the first list as what needs to be consumed (or if you prefer: the input list), and the second list as what we should leave behind (or: the output list). • Viewed from this (rather procedural) perspective the difference list [a,woman,shoots,a,man] [ ].  • represents the sentence a woman shoots a man because it says: If I consume all the symbols on the left, and leave behind the symbols on the right, I have the sentence I am interested in.

  4. CFG recognition using difference lists • The sentence we are interested in is the difference between the contents of the two lists. • Difference representations are not unique. • In fact, we could represent a woman shoots a man in infinitely many ways. • For example, we could also represent it as [a,woman,shoots,a,man,ploggle,woggle]  [ploggle,woggle]. • Again the point is: if we consume all the symbols on the left, and leave behind the symbols on the right, we have the sentence we are interested in.

  5. s(X,Z) :- np(X,Y), vp(Y,Z).np(X,Z) :- det(X,Y), n(Y,Z).vp(X,Z) :-  v(X,Y), np(Y,Z).vp(X,Z) :-  v(X,Z).s(X,Z) :- np(X,Y), vp(Y,Z).np(X,Z) :- det(X,Y), n(Y,Z).vp(X,Z) :-  v(X,Y), np(Y,Z).vp(X,Z) :-  v(X,Z). det([the|W],W).det([a|W],W).n([woman|W],W).n([man|W],W).v([shoots|W],W). CFG recognition using difference lists • If we bear the idea of consuming something, and leaving something behind in mind, we obtain the following recognizer (Prolog notation): The s rule says: I know that the pair of lists X and Z represents a sentence if (1) I can consume X and leave behind a Y, and the pair   X and Y represents a noun phrase, and (2) I can then go on to consume Y leaving Z behind, and the pair Y Z represents a verb phrase.

  6. CFG recognition using difference lists • The idea underlying the way we handle the words is similar. • The code n([man|W],W). • means we are handling man as the difference between [man|W] and W. • Intuitively, the difference between what I consume and what I leave behind is precisely the word man.

  7. CFG recognition using difference lists • How do we use such grammars? Here's how to recognize sentences: s([a,woman,shoots,a,man],[]). yes • This asks whether we can get an s by consuming the symbols in [a,woman,shoots,a,man], leaving nothing behind.

  8. CFG recognition using difference lists • Similarly, to generate all the sentences in the grammar, we ask s(X,[]). • This asks: what values can you give to X, such that we get an s by consuming the symbols in X, leaving nothing behind? • The queries for other grammatical categories also work the same way. • For example, to find out if a woman is a noun phrase we ask: np([a,woman],[]).

  9. CFG recognition using difference lists • And we generate all the noun phrases in the grammar as follows: np(X,[]). • It has to be admitted that this recognizer is not as easy to understand, at least at first, and it's a pain having to keep track of all those difference list variables. • This is where DCGs come in.

  10. Formalismos de unificación • La unificación se usa como mecanismo básico de composición entre constituyentes en gramáticas lógicas. • Història: • Q-Systems (Colmerauer, 1972) • Prolog (Colmerauer, 1973) • Gramàtiques de Metamorfosi (Colmerauer, 1975) • Gramàtiques de Clàusules Definides (DCGs) (Pereira, Warren, 1980)

  11. Análisis gramatical con unificación • Gramática (1) oració (X,Y) :- gnom(X,Z), gver(Z,Y) (2) gnom(X,Y) :- art(X,Z), nom(Z,Y) (3) gver(X,Y) :- ver(X,Y) • Lexicón (4) art(X,Y) :- el(X,Y) (5) nom(X,Y) :- gos(X,Y) (6) ver(X,Y) :- borda(X,Y)

  12. Análisis gramatical con unificación (7) el(1,2) (8) gos(2,3) (9) borda(3,4) Frase a analizar: oració(1,4) el gos borda 1 2 3 4

  13. Análisis gramatical con unificación oració(1,4) (R1) (X  1, Y 4) por unificación gnom (1,Z), gver(Z,4) (R2) aplicada a gnom(1,Z) art(1,U), nom(U,Z), gver(Z,4) el gos borda 1 2 3 4

  14. Análisis gramatical con unificación art(1,U), nom(U,Z), gver(Z,4) (R4) aplicada a art(1,U) el(1,U), nom(U,Z), gver(Z,4) (R7) (U  2) el(1,2), nom(2,Z), gver(Z,4) nom(2,Z), gver(Z,4) el gos borda 1 2 3 4

  15. Análisis gramatical con unificación nom(2,Z), gver(Z,4) (R5) gos(2,Z), gver(Z,4) (R8) (Z  3) gos(2,3), gver(3,4) gver(3,4) el gos borda 1 2 3 4

  16. Análisis gramatical con unificación gver(3,4) (R3) ver(3,4) (R6) borda(3,4) (R9): Fin el gos borda 1 2 3 4

  17. Análisis semántico • Consiste en construir una representación de las frases en algún sistema formal. • En general es un problema intratable. • Se simplifica suponiendo que la semántica de una frase se pueda construir a partir de la semántica de sus partes: semántica compositiva. • Algunas características del lenguaje se tienen que tratar a parte: referencias, omisiones, contexto…

  18. Estrategias de análisis • Dos maneras de plantear la interpretación semántica: • Secuencial (sintáctica → semántica) • Paralela (sintáctica + semántica)

  19. Interpretación secuencial • Problemas de ambigüedad • Es posible que haya más de una interpretación sintáctica. • Hay que considerarlas todas, para poder comprobar sucesivamente cuáles son las semánticamente posibles. • Principal ventaja • El análisis semántico parte de un análisis sintáctico correcto.

  20. Interpretación paralela • Principal problema • No se sabe si la interpretación sintáctica es correcta hasta el final. • Principal ventaja • Poder descartar interpretaciones sintácticas correctas (o parcialmente correctas) que no tengan interpretación semántica asociada. • Las reglas sintácticas incluyen la información semántica asociada. • Se obtiene como resultado un árbol de análisis y una o varias interpretaciones.

  21. Sistema de representación • El sistema de representación tiene que permitir: • Manejar cuantificación, predicación, negación, modalidad (creencias) • Resolver la ambigüedad tanto léxica (polisemia) como sintáctica • Manejar inferencias (herencia, razonamiento por omisión) • Importante a la hora de resolver problemas que involucren el contexto o el conocimiento del dominio.

  22. Sistema de representación • Los sistemas que no se basan en la sintaxis para la interpretación suelen utilizar sistemas tipo ontologías. • Por lo general, se utiliza una variedad de la lógica de primer orden adecuada al dominio de aplicación. • El elemento básico de representación es el lexema: raíz de un grupo de palabras que son diferentes formas de “la misma palabra” (ej.: ir, ido, yendo).

  23. Sistema de representación • Ejemplos • Los nombres propios corresponden a constantes. • Los verbos intransitivos a predicados unarios: Juan ríe ríe(juan) • Los verbos transitivos a predicados de aridad superior: Juan lee el Quijote lee(juan, quijote) • Los nombres genéricos a predicados sobre variables: El hombre hombre(X) • Los adjetivos a predicados unarios: La casa grande grande(X) ∧ casa(X)

  24. Sistema de representación La representación consiste normalmente en un árbol de análisis y una función de composición que construye la interpretación de los elementos asociados. semS = fS(semNP, semVP) semNP = fNP(semART, semN) semART = fART(sem el) S VP NP NAME NP V ART N menja el bacallà Adrià

  25. La representación del significado: ejemplo entrada: Qui dirigeix el PSOE? forma lògica: (pregunta (referent (X)) (X instancia (X, persona) (el1 (Y instancia(Y, partit_polític) nom(Y, "PSOE")) (Z instancia(Z, dirigir) present(Z) valor_prop(Z, agent, X) valor_prop(Z, pacient,Y)))))

  26. La representación del significado • En la anterior forma lógica aparecen 4 tipos diferentes de información: • Estructura lógica • Contenido conceptual (semántico) • Indicación de los actos del discurso • Anotaciones pragmáticas • El formalismo de representación debería proporcionar una capacidad expresiva suficiente para garantizar la descripción de estos 4 tipos de información.

  27. Posibles representaciones del significado • Lógica de predicados de primer orden • Otros formalismos lógicos • Ontologías

  28. Representaciones basadas en lógica • Un vocabulario de predicados de los que hay que indicar la aridad (el número de argumentos y su tipo) • Un vocabulario de constantes y variables. • Un conjunto de conectores lógicos. • Un vocabulario de funciones de las que hay que indicar la aridad • Un conjunto de cuantificadores que actúan sobre los predicados que pueden ser cuantificados.

  29. Semántica y forma lógica • Semantics = theories of meaning • Introduction of a level of context-independent meaning called the logical form. • It can be produced directly from the syntactic structure of a sentence. • It does not contain the results of any analysis that requires interpretation of the sentence in context.

  30. Semántica y forma lógica • Precisely defining the notions of semantics and meaning is surprisingly difficult. • The terms are used for several different purposes in natural and technical usage. • There is a use of the verb mean that has nothing to do with language: This fire means someone camped here last night.

  31. Semántica y forma lógica This fire means someone camped here last night. • In this example, the fire is evidence for (or implies) the conclusion. • The meaning we are interested in is not this one. • It is closer to the usage when defining a word.

  32. Semántica y forma lógica “Amble” means to walk slowly. • This defines the meaning of a word in terms of other words. • We are interested in specifying meaning without having to refer back to natural language itself. • But even if we can do this, defining a notion of sentence meaning is difficult.

  33. Semántica y forma lógica A guard at the airport: “Do you know what gate you are going to?” • If we interpret this as asking whether we know where we are going, we answer yes. • But the response can be based on a misunderstanding, if the guard then asks: “Which gate is it?”

  34. Semántica y forma lógica “Do you know what gate you are going to?” • This sentence then appears to mean different things in different contexts. • Can we define a notion of sentence meaning that is independent of context? • Is there a level at which this sentence has a single meaning, but may be used for different purposes?

  35. Semántica y forma lógica • Separating sentence meaning from sentence usage is complex, but there are many advantages, primarily modularity. • If sentences have no context-independent meaning, then we may not be able to separate: • the study of language • the study of general human reasoning and context

  36. Semántica y forma lógica • We use the term meaning in a context-independent sense. • We use the term usage for the context-dependent aspects. • The representation of context-independent meaning is called the logical form.

  37. Semántica y forma lógica • The process of mapping a sentence to its logical form is called semantic interpretation. • The process of mapping the logical form to the final knowledge representation language is called contextual interpretation.

  38. Semántica y forma lógica S Syntactic analysis semantic interpretation Logical form (ROJA1 <LA b1 PELOTA>) contextual interpretation Final representation Roja(BO73) VP NP ART N ADJP la pelota V roja es

  39. Interpretación semántica: función de composición • Interpretación a través de evaluaciones lambda: (lambda (x) (. . .)) = = ((x) (. . .)) • Gramática: Oracio  GN FV (2 1) GN  np (1) FV  vi (1) Fv  vt GN (1 2) • Lexicón: Pere  np, pere Maria  np, maria riu  vi, ((x) (riu(x)) estima  vt , (((x) ((y), estima(y, x))))

  40. Función de composición: ejemplo

  41. Función de composición: ejemplo

  42. Gramáticas de cláusulas definidas (DCGs) • Las DCGs permiten escribir gramáticas en forma de programas como, por ejemplo, Prolog. • Prolog es un lenguaje de reglas que usa razonamiento hacia atrás como método de resolución. • Se define una sintaxis especial que permite diferenciar los elementos gramaticales de los procedimientos que se usan para tener en cuenta el contexto.

  43. Gramáticas de cláusulas definidas (DCGs): sintaxis • Las reglas usan variables para pasarse información, hacer las comprobaciones que exige la gramática o construir un resultado. • Se puede introducir código Prolog, entre llaves: aaa(W) --> [W], bbb(W), {number(W)}

  44. Gramáticas de cláusulas definidas (DCGs): sintaxis • Para ejecutar una DCG se llama al símbolo principal de la gramática con dos parámetros: una lista con las palabras de la frase y una lista vacía: frase([el,gat,menja,bacalla],[])

  45. Gramáticas de cláusulas definidas (DCGs): ejemplo analisis(X,Y):- asercion(X,Y). asercion --> sn, verb,compl. compl --> []. compl --> prep,sn. compl--> sn. sn--> npr. sn--> det,n. verb--> [W],{verbo(W)}. npr--> [W],{npropio(W)}. n--> [W],{nombre(W)}. det--> [W],{determ(W)}. prep--> [W],{prepo(W)}. npropio(clara). npropio(maria). npropio(barcelona). nombre(hombre). nombre(profesor). nombre(libro). determ(un). determ(el). verbo(esta). verbo(rie). verbo(piensa). verbo(habla). verbo(lee). prepo(en). prepo(con). prepo(de).

  46. What are definite clause grammars? • Definite Clause Grammars (DCGs) are convenient ways to represent grammatical relationships for various parsing applications. • They can be used for natural language work, for creating formal command and programming languages. • Quite simply, they are a nice notation for writing grammars that hides the underlying difference list variables.

  47. DCGs • A little grammar written as a DCG: s --> np, vp.np --> det, n.vp --> v, np.vp --> v.det --> [the].det --> [a].n --> [woman].n --> [man].v --> [shoots]. • How do we use this DCG? In fact, we use it in exactly the same way as we used the difference list recognizer.

  48. DCGs • For example, to find out whether a woman shoots a man is a sentence, we pose the query: s([a,woman,shoots,a,man],[]). • That is, just as in the difference list recognizer, we ask whether we can get an s by consuming the symbols in [a,woman,shoots,a,man], leaving nothing behind.

  49. DCGs • Similarly, to generate all the sentences in the grammar, we pose the query: s(X,[]). • This asks what values we can give to X, such that we get an s by consuming the symbols in X, leaving nothing behind. • Moreover, the queries for other grammatical categories also work the same way. For example, to find out if a woman is a noun phrase we pose the query: np([a,woman],[]).

  50. DCGs • We generate all the noun phrases in the grammar as follows: np(X,[]). • Quite simply, this DCG is a difference list recognizer! • That is, DCG notation is essentially syntactic sugar: user friendly notation that lets us write grammars in a natural way.

More Related