materias:pln:practico2
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previa | |||
materias:pln:practico2 [2018/08/10 03:03] – external edit 127.0.0.1 | materias:pln:practico2 [2019/02/05 19:43] (actual) – removed francolq | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
- | ====== Trabajo Práctico 2 - Etiquetado de Secuencias ====== | ||
- | |||
- | [[materias: | ||
- | |||
- | En este trabajo práctico implementaremos varios modelos de etiquetado de | ||
- | secuencias y realizaremos algunos experimentos con ellos. | ||
- | |||
- | * Repositorio: | ||
- | * Fecha de entrega: 18/05 a las 23:59. | ||
- | |||
- | |||
- | ===== Instrucciones ===== | ||
- | |||
- | El código base para el proyecto se encuentra en el [[https:// | ||
- | La entrega del proyecto es a través de github. Por lo tanto, deben **hacer un " | ||
- | |||
- | Además del código fuente, **deben elaborar un README** con una breve explicación de lo que hicieron en cada ejercicio. El README puede estar en texto plano (txt), markdown (md) o restrucured text (rst), y debe estar incluído dentro de la carpeta '' | ||
- | |||
- | Criterios de Evaluación: | ||
- | |||
- | * Estilo de codificación (chequeado con flake8 y a ojo). | ||
- | * Diseño del código: uso de clases, herencia, etc. | ||
- | * Uso y aprobación de tests (provistos y definidos por uds.). | ||
- | * Uso apropiado de git (commits granulares, logs informativos). | ||
- | * Resultados. | ||
- | * README. | ||
- | |||
- | |||
- | ===== Ejercicio 1: Corpus AnCora: Estadísticas de etiquetas POS ===== | ||
- | |||
- | Programar un script '' | ||
- | |||
- | * Estadísticas básicas: | ||
- | * Cantidad de oraciones. | ||
- | * Cantidad de ocurrencias de palabras. | ||
- | * Cantidad de palabras (vocabulario). | ||
- | * Cantidad de etiquetas (vocabulario de tags). | ||
- | * Etiquetas más frecuentes: Una tabla con las 10 etiquetas más frecuentes y la siguiente información para cada una: | ||
- | * Cantidad de veces que aparece (frecuencia), | ||
- | * Cinco palabras más frecuentes con esa etiqueta. | ||
- | * En el README, agregar a mano una breve descripción del significado de la etiqueta. | ||
- | * Niveles de ambigüedad de las palabras: Una figura similar a la Figura 5.10 de Jurafsky & Martin (2008). Para cada nivel de ambigüedad (de 1 a 9) mostrar: | ||
- | * Cantidad de palabras y porcentaje del total. | ||
- | * Cinco palabras más frecuentes. | ||
- | * Incluir todas las estadísticas en el README. | ||
- | |||
- | Uso del script: | ||
- | |||
- | $ python tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * [[http:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | |||
- | |||
- | ===== Ejercicio 2: Baseline Tagger ===== | ||
- | |||
- | * Programar un etiquetador baseline, que elija para cada palabra su etiqueta más frecuente observada en entrenamiento. | ||
- | * Para las palabras desconocidas, | ||
- | |||
- | Interfaz de '' | ||
- | |||
- | <code python> | ||
- | class BaselineTagger: | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | tagged_sents -- training sentences, each one being a list of pairs. | ||
- | """ | ||
- | |||
- | def tag(self, sent): | ||
- | """ | ||
- | |||
- | sent -- the sentence. | ||
- | """ | ||
- | |||
- | def tag_word(self, | ||
- | """ | ||
- | |||
- | w -- the word. | ||
- | """ | ||
- | |||
- | def unknown(self, | ||
- | """ | ||
- | |||
- | w -- the word. | ||
- | """ | ||
- | </ | ||
- | |||
- | Tests: | ||
- | |||
- | $ nosetests tagging/ | ||
- | |||
- | |||
- | ===== Ejercicio 3: Entrenamiento y Evaluación de Taggers ===== | ||
- | |||
- | * Programar un script '' | ||
- | * Programar un script '' | ||
- | * // | ||
- | * // | ||
- | * Matriz de confusión, como se explica en la sección 5.7.1 (//Error Analysis//) de Jurafsky & Martin. | ||
- | * Entrenar y evaluar el modelo baseline del ejercicio anterior. Reportar los resultados en el README. | ||
- | * **Bonus**: Graficar la matriz de confusión como un mapa de calor (ver documentación abajo). | ||
- | |||
- | Ejemplo de uso de los scripts: | ||
- | |||
- | $ python tagging/ | ||
- | $ python tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * http:// | ||
- | |||
- | ===== Ejercicio 4: Hidden Markov Models y Algoritmo de Viterbi ===== | ||
- | |||
- | * Implementar un Hidden Markov Model cuyos parámetros son las probabilidades de transición entre estados (las etiquetas) y de emisión de símbolos (las palabras). | ||
- | * Implementar el algoritmo de Viterbi que calcula el etiquetado más probable de una oración. | ||
- | |||
- | Interfaz de '' | ||
- | |||
- | <code python> | ||
- | class HMM: | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | n -- n-gram size. | ||
- | tagset -- set of tags. | ||
- | trans -- transition probabilities dictionary. | ||
- | out -- output probabilities dictionary. | ||
- | """ | ||
- | |||
- | def tagset(self): | ||
- | """ | ||
- | """ | ||
- | |||
- | def trans_prob(self, | ||
- | """ | ||
- | |||
- | tag -- the tag. | ||
- | prev_tags -- tuple with the previous n-1 tags (optional only if n = 1). | ||
- | """ | ||
- | |||
- | def out_prob(self, | ||
- | """ | ||
- | |||
- | word -- the word. | ||
- | tag -- the tag. | ||
- | """ | ||
- | |||
- | def tag_prob(self, | ||
- | """ | ||
- | Probability of a tagging. | ||
- | Warning: subject to underflow problems. | ||
- | |||
- | y -- tagging. | ||
- | """ | ||
- | |||
- | def prob(self, x, y): | ||
- | """ | ||
- | Joint probability of a sentence and its tagging. | ||
- | Warning: subject to underflow problems. | ||
- | |||
- | x -- sentence. | ||
- | y -- tagging. | ||
- | """ | ||
- | |||
- | def tag_log_prob(self, | ||
- | """ | ||
- | Log-probability of a tagging. | ||
- | |||
- | y -- tagging. | ||
- | """ | ||
- | |||
- | def log_prob(self, | ||
- | """ | ||
- | Joint log-probability of a sentence and its tagging. | ||
- | |||
- | x -- sentence. | ||
- | y -- tagging. | ||
- | """ | ||
- | |||
- | def tag(self, sent): | ||
- | """ | ||
- | |||
- | sent -- the sentence. | ||
- | """ | ||
- | |||
- | |||
- | class ViterbiTagger: | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | hmm -- the HMM. | ||
- | """ | ||
- | |||
- | def tag(self, sent): | ||
- | """ | ||
- | |||
- | sent -- the sentence. | ||
- | """ | ||
- | </ | ||
- | |||
- | Tests: | ||
- | |||
- | $ nosetests tagging/ | ||
- | $ nosetests tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * [[http:// | ||
- | |||
- | |||
- | ===== Ejercicio 5: HMM POS Tagger ===== | ||
- | |||
- | * Implementar en una clase '' | ||
- | * La clase debe tener **la misma interfaz que '' | ||
- | * Agregar al script de entrenamiento (train.py) una opción de línea de comandos que permita utilizar la MLHMM con distintos valores de '' | ||
- | * Entrenar y evaluar para varios valores de '' | ||
- | |||
- | Interfaz de '' | ||
- | |||
- | <code python> | ||
- | class MLHMM: | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | n -- order of the model. | ||
- | tagged_sents -- training sentences, each one being a list of pairs. | ||
- | addone -- whether to use addone smoothing (default: True). | ||
- | """ | ||
- | |||
- | def tcount(self, | ||
- | """ | ||
- | |||
- | tokens -- the n-gram or (n-1)-gram tuple of tags. | ||
- | """ | ||
- | |||
- | def unknown(self, | ||
- | """ | ||
- | |||
- | w -- the word. | ||
- | """ | ||
- | |||
- | """ | ||
- | Todos los métodos de HMM. | ||
- | """ | ||
- | </ | ||
- | |||
- | Tests: | ||
- | |||
- | $ nosetests tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * [[http:// | ||
- | |||
- | ===== Ejercicio 6: Features para Etiquetado de Secuencias ===== | ||
- | |||
- | * Implementar en '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * También implementar los siguientes features paramétricos: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Interfaz de los features paramétricos en '' | ||
- | |||
- | <code python> | ||
- | class NPrevTags(Feature): | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | |||
- | n -- number of previous tags to consider. | ||
- | """ | ||
- | |||
- | def _evaluate(self, | ||
- | """ | ||
- | |||
- | h -- a history. | ||
- | """ | ||
- | |||
- | |||
- | class PrevWord(Feature): | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | |||
- | f -- the feature. | ||
- | """ | ||
- | |||
- | def _evaluate(self, | ||
- | """ | ||
- | |||
- | h -- the history. | ||
- | """ | ||
- | </ | ||
- | |||
- | Tests: | ||
- | |||
- | $ nosetests tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * [[http:// | ||
- | |||
- | |||
- | ===== Ejercicio 7: Maximum Entropy Markov Models ===== | ||
- | |||
- | * Implementar un MEMM con el siguiente // | ||
- | * Vectorizador ('' | ||
- | * Clasificador de máxima entropía ('' | ||
- | * Implementar un algoritmo de tagging en el método '' | ||
- | * Agregar al script de entrenamiento (train.py) una opción de línea de comandos que permita utilizar el MEMM con distintos valores de '' | ||
- | * Entrenar y evaluar para varios valores de '' | ||
- | * Probar también los siguientes clasificadores: | ||
- | * '' | ||
- | * '' | ||
- | * Reportar los resultados en el README. Reportar también tiempo de evaluación. | ||
- | * **Bonus**: Inventar y agregar features que mejoren la calidad del tagger. | ||
- | |||
- | Interfaz de '' | ||
- | |||
- | <code python> | ||
- | class MEMM: | ||
- | |||
- | def __init__(self, | ||
- | """ | ||
- | n -- order of the model. | ||
- | tagged_sents -- list of sentences, each one being a list of pairs. | ||
- | """ | ||
- | |||
- | def sents_histories(self, | ||
- | """ | ||
- | Iterator over the histories of a corpus. | ||
- | |||
- | tagged_sents -- the corpus (a list of sentences) | ||
- | """ | ||
- | |||
- | def sent_histories(self, | ||
- | """ | ||
- | Iterator over the histories of a tagged sentence. | ||
- | |||
- | tagged_sent -- the tagged sentence (a list of pairs (word, tag)). | ||
- | """ | ||
- | |||
- | def sents_tags(self, | ||
- | """ | ||
- | Iterator over the tags of a corpus. | ||
- | |||
- | tagged_sents -- the corpus (a list of sentences) | ||
- | """ | ||
- | |||
- | def sent_tags(self, | ||
- | """ | ||
- | Iterator over the tags of a tagged sentence. | ||
- | |||
- | tagged_sent -- the tagged sentence (a list of pairs (word, tag)). | ||
- | """ | ||
- | |||
- | def tag(self, sent): | ||
- | """ | ||
- | |||
- | sent -- the sentence. | ||
- | """ | ||
- | |||
- | def tag_history(self, | ||
- | """ | ||
- | |||
- | h -- the history. | ||
- | """ | ||
- | |||
- | def unknown(self, | ||
- | """ | ||
- | |||
- | w -- the word. | ||
- | """ | ||
- | </ | ||
- | |||
- | Tests: | ||
- | |||
- | $ nosetests tagging/ | ||
- | |||
- | Documentación: | ||
- | |||
- | * Introducción a scikit-learn para clasificación de textos: | ||
- | * http:// | ||
- | * [[http:// | ||
- | * Beam inference: | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | |||
- | |||
- | ===== Ejercicio 8 (punto bonus): Algoritmo de Viterbi para MEMMs (con Beam) ===== | ||
- | |||
- | Implementar el algoritmo de Viterbi para obtener la secuencia de tags de máxima probabilidad de acuerdo a un MEMM: | ||
- | |||
- | * Para obtener las probabilidades de los tags, usar el método '' | ||
- | * Beam: En cada paso del Viterbi, guardar sólo los '' | ||
- | * Evaluar para varios clasificadores ('' | ||
materias/pln/practico2.1533870219.txt.gz · Última modificación: 2018/08/10 03:03 por 127.0.0.1