Tabla de Contenidos

Trabajo Práctico 3 - Etiquetado de Secuencias

(volver a la página principal)

En este trabajo práctico implementaremos varios modelos de etiquetado de secuencias y realizaremos algunos experimentos con ellos.

Instrucciones

El código base para el proyecto se encuentra en el repositorio de la materia. La entrega del proyecto es a través de github. Por lo tanto, deben hacer un “fork” del repositorio dentro de sus cuentas de github.

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 tagging.

Criterios de Evaluación:

Ejercicio 1: Corpus AnCora: Estadísticas de etiquetas POS

Programar un script stats.py que muestre la siguiente información del corpus:

Uso del script:

$ python tagging/scripts/stats.py

Documentación:

Ejercicio 2: Baseline Tagger

Interfaz de BaselineTagger en baseline.py:

class BaselineTagger:
 
    def __init__(self, tagged_sents, default_tag='nc0s000'):
        """
        tagged_sents -- training sentences, each one being a list of pairs.
        default_tag -- tag for unknown words.
        """
 
    def tag(self, sent):
        """Tag a sentence.
 
        sent -- the sentence.
        """
 
    def tag_word(self, w):
        """Tag a word.
 
        w -- the word.
        """
 
    def unknown(self, w):
        """Check if a word is unknown for the model.
 
        w -- the word.
        """

Tests:

$ nosetests tagging/tests/test_baseline.py 

Ejemplo de uso de los scripts:

$ python tagging/scripts/train.py -o baseline
$ python tagging/scripts/eval.py -i baseline

Documentación:

Ejercicio 3: Entrenamiento y Evaluación de Taggers

Ejemplo de uso de los scripts:

$ python tagging/scripts/train.py -o baseline
$ python tagging/scripts/eval.py -i baseline

Documentación:

Ejercicio 4: Hidden Markov Models y Algoritmo de Viterbi

Interfaz de HMM y ViterbiTagger en hmm.py:

class HMM:
 
    def __init__(self, n, tagset, trans, out):
        """
        n -- n-gram size.
        tagset -- set of tags.
        trans -- transition probabilities dictionary.
        out -- output probabilities dictionary.
        """
 
    def tagset(self):
        """Returns the set of tags.
        """
 
    def trans_prob(self, tag, prev_tags):
        """Probability of a tag.
 
        tag -- the tag.
        prev_tags -- tuple with the previous n-1 tags (optional only if n = 1).
        """
 
    def out_prob(self, word, tag):
        """Probability of a word given a tag.
 
        word -- the word.
        tag -- the tag.
        """
 
    def tag_prob(self, y):
        """
        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, y):
        """
        Log-probability of a tagging.
 
        y -- tagging.
        """
 
    def log_prob(self, x, y):
        """
        Joint log-probability of a sentence and its tagging.
 
        x -- sentence.
        y -- tagging.
        """
 
    def tag(self, sent):
        """Returns the most probable tagging for a sentence.
 
        sent -- the sentence.
        """
 
 
class ViterbiTagger:
 
    def __init__(self, hmm):
        """
        hmm -- the HMM.
        """
 
    def tag(self, sent):
        """Returns the most probable tagging for a sentence.
 
        sent -- the sentence.
        """

Tests:

$ nosetests tagging/tests/test_hmm.py 
$ nosetests tagging/tests/test_viterbi_tagger.py 

Documentación:

Ejercicio 5: HMM POS Tagger

Interfaz de MLHMM en hmm.py:

class MLHMM:
 
    def __init__(self, n, tagged_sents, addone=True):
        """
        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):
        """Count for an n-gram or (n-1)-gram of tags.
 
        tokens -- the n-gram or (n-1)-gram tuple of tags.
        """
 
    def unknown(self, w):
        """Check if a word is unknown for the model.
 
        w -- the word.
        """
 
    """
       Todos los métodos de HMM.
    """

Tests:

$ nosetests tagging/tests/test_ml_hmm.py 

Documentación:

Ejercicio 6: Clasificador "three words"

Interfaz de ClassifierTagger en classifier.py:

class ClassifierTagger:
    """Simple and fast classifier based tagger.
    """
 
    def __init__(self, tagged_sents, clf='lr'):
        """
        clf -- classifying model, one of 'svm', 'lr' (default: 'lr').
        """
 
    def fit(self, tagged_sents):
        """
        Train.
        tagged_sents -- list of sentences, each one being a list of pairs.
        """
 
    def tag_sents(self, sents):
        """Tag sentences.
        sent -- the sentences.
        """
 
    def tag(self, sent):
        """Tag a sentence.
        sent -- the sentence.
        """
 
    def unknown(self, w):
        """Check if a word is unknown for the model.
        w -- the word.
        """

Tests:

$ nosetests tagging/tests/test_classifier.py 

Ejercicio 7: Clasificador con Word Embeddings fastText

Documentación:

Ejercicio 8: Análisis de Error y Nuevos Features

TBA

Ejercicio 9: Red Neuronal Recurrente

TBA