





























Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!






























Natural language processing (NLP) is a field of artificial intelligence (AI) that allows machines to read, derive meaning from text, and produce documents. It works in the background of many services, from chatbots through virtual assistants to social media tracking.
History of natural language processing:
· 1950-1960: prehistory, scientific knowledge regarding artificial intelligence and linguistics extremely limited. · 1960-1990: symbolic models, rules handwritten by experts, very limited coverage · 1990-2010: statistical models, machine learning on data annotated by experts, good coverage. · 2010-present: neural models, machine learning on non-annotated data, excellent coverage.
Text data is fundamentally discrete. But new words can always be created. Few words are very frequent, and there is a long tail of rare words. Out-of-vocabulary words are always being discovered. Language is ambiguous: units can have different meanings. Language is compositional: meaning of a unit defined as a function of the meaning of its components. Language is recursive: units can be repeatedly combined. Language unveils hidden structure: local changes in a sentence might have global effects.
NLP applications are based on ideas and tools such as: deep learning & optimisation, dynamic programming, grammars & automata, probability and information theory.
Rationalism: A significant part of the knowledge in the human mind is not derived by the senses but is fixed in advance, presumably by genetic inheritance. Generative linguists have argued for the existence of a language faculty in all human beings, which encodes a set of abstractions specially designed to facilitate learning, understanding and production of language.
Empiricism: The view that there is no such thing as innate knowledge, and that knowledge is instead derived from experience, either sensed via the five senses or reasoned via the brain or mind. At the time of writing, many statistical NLP techniques work very well on texts, without the need to use special bias representing linguistic knowledge or mental representation of language.
Many natural language processing problems can be written mathematically in the form of optimization 𝑦 = arg max 𝑦∈𝑌 𝑥
𝛹 𝑥,𝑦;𝛩 where
· 𝑥 is the input, which is an element of a set 𝑋. · 𝑦 is the output, which is an element of a set 𝑌 𝑥. · 𝛹 is a scoring function, also called the model, which maps from the set 𝑋 × 𝑌 to the real numbers. · 𝛩 is a vector of parameters for 𝛹.
· 𝑦 is the predicted output, which is chosen to maximize the scoring function.
The search module is responsible for finding the candidate output 𝑦 with the highest score relative to the input 𝑥. The learning module is responsible for finding the model parameters 𝛩 that maximizes the predictive performance.
Linguistics is the scientific study of language, and in particular the relationship between language form and language meaning. Besides form and meaning, another important subject of study for linguistics is how language is used in context.
Phonology studies the rules that organize patterns of sounds in human languages. Phonology is different from phonetics , which is concerned with the production, transmission and perception of sounds, without prior knowledge of the language being spoken. Morphology is the study of how words are composed by morphemes, which are the smallest meaningful units of language. Inflectional morphology: no change in the grammatical category. Derivational morphology: change in the grammatical category. Syntax studies the rules and constraints that govern how words can be organized into sentences. A part of speech (PoS) is a category for words that play similar roles within the syntactic structure of a sentence. PoS can be defined distributionally or functionally. There are several representations for syntactic structure; most common are phrase structure and dependency tree. A phrase structure is a tree-like representation with leaf nodes representing sentence words and internal nodes representing word groupings called phrases. A dependency tree is a tree-like representation where nodes represent words (and punctuation) in the sentence and arcs represent grammatical relations between a head and a dependent. Semantics is the study of the meaning of linguistic expressions such as words, phrases, and sentences. The linguistic study of word meaning is called lexical semantics. The internal semantic structure of a word refers to the similarity with other words. The external semantic structure of a word refers to the allowability to combine with other words. Principle of compositionality: the meaning of a whole expression is a function of the meanings of its parts and of the way they are syntactically combined. Syntax provides the scaffolding for semantic composition: the meaning of a sentence isn’t just the amalgamation of the meaning of its component words. Pragmatics studies the way linguistic expressions with their semantic meanings are used for specific communicative goals. In contrast to semantics, pragmatics explicitly asks the question what an expression means in a given context. Discourse analysis studies written and spoken language in relation to its social context. Discourse refers to a piece of text with multiple sub-topics and coherence relations between them,
· Collection process: How big is the data and how was it sampled? How was the data pre- processed, and what metadata is available? · Annotation: What are the specifics of the used annotation? How was the data annotated? How were the annotators trained?
Text normalization is the process of transforming a text into some predefined standard form. This consists of several tasks. There is no all-purpose normalization procedure: text normalization depends on what type of text is being normalized and what type of NLP task needs to be carried out afterwards. Language identification is the task of detecting the source language for the input text. Spell checkers correct grammatical mistakes in text. Spell checkers use approximate string matching algorithms such as Levenshtein distance to find correct spellings. Presence of contracted forms, abbreviations and slang is managed using a dictionary of contractions and abbreviations with their corresponding expansions. Punctuation marks in text need to be isolated and treated as if they were separate words. This is critical for finding sentence boundaries and for identifying some aspects of meaning.
Tokenization is the process of segmenting text into units called tokens. Tokenization techniques can be grouped into three families: word tokenization, character tokenization and subword tokenization. Tokens are then organized into a vocabulary and, depending on the specific NLP application, may later be mapped into natural numbers. Word tokenization is a very common approach for European languages. There are certain language-independent tokens that require specialized processing → use of regular expressions is recommended in these cases. Major east Asian languages write text without any spaces between words. For most Chinese NLP tasks, character tokenization works better than word tokenization because each character generally represents a single unit of meaning and word tokenization results in huge vocabulary, with large number of very rare words.
Many NLP systems need to deal with unknown words, that is, words that are not in the vocabulary of the system. To deal with the problem of unknown words, modern tokenizers automatically induce sets of tokens that include tokens smaller than words, called subwords. Subword tokenization reduces vocabulary size, and has become the most common tokenization method for large language modelling and neural models in general. Subword tokenization schemes consists of three different algorithms:
· The token learner takes a raw training corpus and induces a set of tokens, called vocabulary. · The token segmenter (encoder) takes a vocabulary and a raw test sentence, and segments the sentence into the tokens in the vocabulary. · The token merger (decoder) takes a token sequence and reconstructs the original sentence.
Three algorithms are widely used for subword tokenization:
· Byte-pair encoding (BPE) tokenization. · Unigram tokenization. · WordPiece tokenization.
The BPE token learner is usually run inside words, not merging across word boundaries. To this end, use a special end-of-word marker. The algorithm iterates through the following steps:
· Begin with a vocabulary composed by all individual characters. · Choose the two symbols 𝐴, 𝐵 that are most frequently adjacent. · Add a new merged symbol 𝐴𝐵 to the vocabulary. · Replace every adjacent 𝐴, 𝐵 in the corpus with 𝐴𝐵.
Stop when the vocabulary reaches size 𝑘, a hyperparameter.
Two versions of BPE token segmenter (encoder): apply merge rules in frequency order all over the data set or for each word, left-to-right, match longest token from vocabulary (eager).
BPE token merger: To decode, we have to concatenate all the tokens together to get the whole word and use the end-of-word marker to solve possible ambiguities.
WordPiece is a subword tokenization algorithm used by the large language model BERT. Like BPE, WordPiece starts from the initial alphabet and learns merge rules. The main difference is the way
pair 𝐴, 𝐵 is selected to be merged: (^) 𝑓 𝑓𝐴^ 𝐴,𝐵×𝑓 𝐵 , with 𝑓 𝑋 frequency of token 𝑋. The algorithm
prioritizes the merging of pairs where the individual parts are less frequent in the vocabulary.
Text normalization also includes sentence segmentation: breaking up a text into individual sentences. This can be done using cues like periods, question marks, or exclamation points. Lower casing is very useful to standardize words and before stop words removal.
Stop word removal includes getting rid of common articles, pronouns, prepositions and coordinations. Stop word removal heavily depends on the task at hand, since it can wipe out relevant information. Stemming refers to the process of slicing a word with the intention of removing affixes. Stemming is problematic in the linguistic perspective, since it sometimes produces words that are not in the language, or else words that have a different meaning. Lemmatization has the objective of reducing a word to its base form, also called lemma, therefore grouping together different forms of the same word. Lemmatization and stemming are mutually exclusive, and the former is much more resource- intensive than the latter.
The linguistic study of word meaning is called lexical semantics. A word-form can have multiple meanings; each meaning is called a word sense, or sometimes a synset. Lexical semantic relationship between words are important components of word meaning (synonyms, similar, related, antonyms, …).
Distributional semantics develops methods for quantifying semantic similarities between words based on their distributional properties, meaning their neighboring words. Linguistic items with similar distributions have similar meanings → similar words are mapped into “close enough” vectors called word embeddings. Vector semantics is the standard way to represent word meaning in NLP. We discuss two families of word embeddings:
problem: min 𝐔∈ℝ V^ ×K 𝐒∈ℝK×K 𝐕∈ℝ V^ ×K
𝐹
, where 𝑼 are the target embeddings, 𝑺𝑽𝑇^ are the context
embeddings.
Word embeddings can also be computed using neural networks with these properties: small number of dimensions, vectors are dense, the dimensions don’t have a clear interpretation, components can be negative. Static neural word embeddings such as Word2vec, FastText and GloVe learn one fixed embedding for each word in the vocabulary.
Word2vec includes two different algorithms for learning word embeddings: skip-gram with negative sampling (SGNS) and continuous bag-of-words (CBOW). SGNS algorithm: ∀𝑤𝑡∈𝑉, treat 𝑤𝑡 and any neighboring context word 𝑤𝑐 as positive examples, then randomly sample other words 𝑤𝑛∈𝑉 (noise words) to produce negative examples for 𝑤𝑡. Use logistic regression to train a
classifier with Pr + 𝑤,𝑢 = 𝜎 𝑒𝑡 𝑤 ∙𝑒𝑐 𝑢 = 1 1+exp −𝑒𝑡 𝑤 ∙𝑒𝑐 𝑢 probability that 𝑢∈𝑉 is a context
word for target word 𝑤, 𝑒𝑡 𝑤 ∈ℝ𝑑^ target embedding, 𝑒𝑐 𝑤 ∈ℝ𝑑^ context embedding and Pr − 𝑤,𝑢 = 1 − Pr + 𝑤,𝑢. Use the learned weights as the embeddings; considering that all the context words are independent, we have that minimizing the inverse of the log-likelihood of the data 𝐿𝐿𝑤 = log Pr + 𝑤,𝑢 ∏𝑘𝑖=1 Pr − 𝑤,𝑣𝑘 we obtain the cross-entropy loss function 𝐿𝐶𝐸 = −
log 𝜎 𝑒𝑡 𝑤 ∙𝑒𝑐 𝑢 −∑𝑘𝑖=1 log (1 − 𝜎 𝑒𝑡 𝑤 ∙𝑒𝑐 𝑣𝑘. To update 𝐿𝐶𝐸 we force an increase in
similarity between 𝑒𝑡 𝑤 and 𝑒𝑐 𝑢 or force a decrease in similarity between 𝑒𝑡 𝑤 and 𝑒𝑐 𝑣𝑘. We train the model with stochastic gradient descent.
The process of discarding occurrences of words like “the”, “of” and “for”, by means of some probability distribution is called subsampling. Discard occurrence 𝑤𝑖 pith probability Pr 𝑤𝑖 = 1 − 𝑡 𝑓 𝑤𝑖
Discussion regarding the ratio 𝑘 between the positive and the negative examples, the choice of hyperparameter 𝐿 specifying the window size.
FastText is an embedding that deals with unknown words and sparsity in languages with rich morphology, by using subword models. Each word in fastText is represented by itself plus a bag of character 𝑁-grams, for bounded values of 𝑁. Global Vectors, or GloVe for short, is an embedding that accounts for global corpus statistics. Word embeddings can be used to visualize the meaning of a word 𝑤.
Most commonly used methods to visualize the meaning of a word 𝑤 are listing the words in 𝑉 with highest cosine similarity with 𝑤 and project the 𝑑-dimensions of a word embedding down into 2 -dimensions.
Semantic properties:
· Both sparse and dense vectors are sensible to the context window size used to collect counts, controlled by hyperparameter 𝐿. If small provides semantically similar words with the same parts of speech, if large provides words that are topically related but not similar.
· Ability to capture relational meanings → can solve analogy problems using parallelogram model.
Word embeddings also reproduce the implicit biases and stereotypes that are latent in the text. This could result in what is called allocational harm, when a system allocates resources (jobs or credit) unfairly to different groups.
The evaluation of word embeddings can be:
· Extrinsic evaluation: Use the model to be evaluated in some end-to-end application (as for instance sentiment analysis, machine translation, etc.) and measure performance. o Most common evaluation metric. · Intrinsic evaluation: Look at performance of model in isolation, with respect to a given evaluation measure. Three types:
Cross-lingual word embeddings encode words from two or more languages in a shared high- dimensional space. Vectors representing words with similar meaning are closely located, regardless of language. Useful in comparing the meaning of words across languages, key to applications like machine translation, enable model transfer between resource-rich and low- resource languages. The class of objective functions minimized by most cross-lingual word embedding methods can be formulated as 𝐽 = 𝐿^1 + … + 𝐿𝑙^ + Ω, where 𝐿𝑖^ is the monolingual loss of the 𝑖-th language and Ω a regularization term. The choice of multilingual parallel data sources is more important for the model performance than the actual underlying architecture. Two methods: type of text alignment (words, sentences, or documents) and type of text comparability (exact translations, weak translation, or similar meaning). Extending the learning process from bilingual to multilingual settings improves results. Ambiguity for word 𝑤 in one language does not transfer to the translation of 𝑤 in another language → variation in ambiguity.
Language modeling is the task of predicting which word comes next in a sequence of words. More formally, given a sequence of words 𝑤 1 𝑤 2 …𝑤𝑡 → 𝑤1:𝑡 we want to know the probability of the next word 𝑤𝑡+1: Pr 𝑤𝑡+1 𝑤 1 𝑤 2 …𝑤𝑡. Language models can be viewed as generative models: probability of a sequence can be expressed as a product of conditional probabilities Pr 𝑤1:𝑛 =
The more probability we are taking away from observed outcomes, the higher the perplexity on the training data.
Backoff combines fine grained models (large 𝑁) with coarse grained models (low 𝑁). With very large text collections → stupid backoff: for small 𝜆,
𝑃𝑆 𝑤𝑡 𝑤𝑡−𝑁+1:𝑡−1 =
Pr 𝑤𝑡 𝑤𝑡−𝑁+1:𝑡−1 = 𝐶 𝑤𝑡−𝑁+1:𝑡 𝐶 𝑤𝑡−𝑁+1:𝑡−
In simple linear interpolation, we combine different order N-grams by linearly interpolating all the models, with ∑𝑗 𝜆𝑗 = 1.
Unknown words, also called out of vocabulary words, are words we haven’t seen before. Replace by new word token < 𝑈𝑁𝐾 > all words that occur fewer than 𝑑 times in the training set, 𝑑 some small number.
Limitations of N-gram models:
· Scaling to larger N-grams sizes is problematic. · Smoothing techniques are intricate and require careful engineering. · Unable to share statistical strength across similar words.
Neural language models can incorporate arbitrarily distant contextual information, while remaining computationally and statistically tractable, can generalize better over contexts of similar words and are more accurate at word-prediction, but they are more complex, slower, need time to train and are less interpretable. General architecture:
Also feed-forward NLM uses approximation Pr 𝑤𝑡 𝑤1:𝑡−1 ≈ Pr 𝑤𝑡 𝑤𝑡−𝑁+1:𝑡−1. ∀𝑤∈𝑉, 𝑖𝑛𝑑 𝑤 ∈ 1… 𝑉 is the index associated with 𝑤. Each input word 𝑤𝑡 represented as one-hot vector 𝒙𝑡. For inference task, in the first layer we convert one-hot vectors in embeddings of size 𝑑, then we concatenate them: 𝒆𝑡 = 𝑬𝒙𝑡−𝑁+1;…;𝑬𝒙𝑡−1. Equations for remaining layers: 𝒉𝑡 = 𝑔 𝑾𝒆𝑡 + 𝒃 , 𝒛𝑡 = 𝑼𝒉𝑡, 𝒚𝑡 = 𝑠𝑜𝑓𝑡𝑚𝑎𝑥 𝒛𝑡.
In training, the parameters of the model are 𝜃 = 𝑬, 𝑾, 𝑼, 𝒃.We use true distribution 𝒚𝑡 and cross- entropy loss to train the model: 𝐿𝐶𝐸 𝒚𝑡,𝒚𝑡 = − log 𝒚𝑡 𝑖𝑛𝑑 𝑤𝑡 , with 𝒚𝑡 𝑖𝑛𝑑 𝑤𝑡 = Pr 𝑤𝑡 𝑤𝑡−𝑁+1:𝑡−.
Recurrent Neural Networks language models process the input one word at a time, predicting the next word from the current word and the previous hidden state, predicting the next word without the 𝑁 − 1 window approximation. The model equations are 𝒆𝑡 = 𝑬𝒙𝑡, 𝒉𝑡 = 𝑔 𝑼𝒉𝑡−1 + 𝑾𝒆𝑡 , 𝒚𝑡 = 𝑠𝑜𝑓𝑡𝑚𝑎𝑥 𝑽𝒉𝑡. The number of parameters of the model are 𝑂 𝑉 , since 𝑑 is constant. We use true distribution 𝒚𝑡 and cross-entropy as loss function to predict the next word 𝑤𝑡+1 in the training sequence: 𝐿𝐶𝐸 𝒚𝑡,𝒚𝑡 = − log 𝒚𝑡 𝑖𝑛𝑑 𝑤𝑡+1 , with 𝒚𝑡 𝑖𝑛𝑑 𝑤 = Pr 𝑤𝑡+1 = 𝑤 𝑤1:𝑡. The idea that we always give the model the correct history sequence to predict the next word is called teacher forcing.
Character-level NLM improves modeling of uncommon and unknown words and reduces training parameters due to the small softmax. A variety of solutions that combine character and word level information have been proposed, called character-aware LM.
encoder. Input is segmented using subword tokenization and combined with positional embeddings. Then input is passed through a series of standard transformer blocks consisting of self-attention and feed-forward layers, augmented with residual connections and layer normalization.
The model learns to perform a fill-in-the-blank task using masked language modeling (MLM) approach: at random 15% of token are replaced with token 𝑀𝐴𝑆𝐾 , replaced with another randomly sampled token or left unchanged.
In order to train a model that understands sentence relationships, BERT introduces a second learning objective called next sentence prediction (NSP). It is a binary decision task that produces sentence embeddings that can be used for tasks involving relationship between pairs of sentences. Model is presented with pairs of sentences with token 𝐶𝐿𝑆 prepended to the first sentence, token 𝑆𝐸𝑃 placed between the two sentences and after the rightmost token of the second sentence, and segment embeddings marking the first and second sentences are added to each word and positional embeddings. Each pair consists of an actual pair of adjacent sentences from the training corpus and a pair of unrelated sentences randomly selected (for contrastive learning).
A language model is called large language model if it has a neural network architecture based on transformer, a number of parameters larger than 1 billion, is pre-trained on vast amount of textual data and can be adapted to a wide range of downstream tasks.
GPT-n (generative pre-training transformer):
· GPT-2 is a left-to-right (causal) language model based on transformer’s decoder-only, no cross-attention layer. Layer normalization moved to the input of each sub-block. · GPT-3 has the same architecture, but the model adds several optimization techniques, including attention sparsity. · GPT-4 is a multimodal large language model. The model is capable of processing image and text inputs and producing text outputs and fine-tuned using RLHF.
Other LLMs:
· T5 (text-to-text transfer transformer) is an encoder-decoder based on the transformer architecture. · OPT (open pre-trained transformer) suite of decoder-only pre-trained transformers. · Gopher is an autoregressive (decoder-only) language model smaller but significantly more accurate than some ultra-large language software. · PaLM (pathways language model) is an encoder-decoder architecture using pathways. · LaMDA (Language Models for Dialog Applications) is a family of conversational large language models. · Orca: aiming at enhancing the capability of smaller models through imitation learning, drawing on the outputs generated by larger LM.
Open LLMs:
· LLaMA (Large Language Model Meta AI) is a family of decoder-only LLMs. · Falcon 7B. · Mistral 7B.
LLMs could be:
· Encoder-only. · Decoder-only. · Encoder-Decoder.
Multilingual large language models (MLLMs) are typically based on the encoder part of the transformer architecture. It is pretrained using large amounts of unlabeled data from multiple languages → useful in transfer learning (mBERT, XLM, mT5, BLOOM). During pre-training they use large monolingual corpora in individual languages or parallel corpora between some languages:
· Objective functions can be based on monolingual data alone by pooling together monolingual corpora from multiple languages and applying masked language modeling (MLM) → encoder learns word representations across languages that are aligned without any parallel corpora. · Objective functions based on parallel corpora explicitly force representations of corresponding words across languages to be close to each other in the multilingual encoder space → predict a masked word 𝑀𝐴𝑆𝐾 for a language 𝐴 the system can rely on words for language 𝐴 surrounding 𝑀𝐴𝑆𝐾 and rely on an aligned word that has not been masked, that is, a word representing a translation in language 𝐵 of the masked word. Curse of multilinguality : the more languages a model is pre-trained on, the less model capacity is available to learn representations for each language.
A prompt is a piece of text inserted in the input examples, so that the original task can be formulated as a masked language modeling problem. In prompt learning (or in-context learning) we give the LM a few example prompts to demonstrate a task. We then append a test prompt and ask the LM to make a prediction, conditionally to the example prompts. Advantage is that a single LM trained in an unsupervised fashion can be used to solve several tasks → necessity of prompt engineering. This works because prompt examples help locating tasks already learned during pre-training, induce a concept so that LM generates coherent next tokens and the learning performance is highly correlated with term frequencies during pre-training. The advantages of prompt learning w.r.t. fine-tuning:
· The gap between the pre-training stage and the downstream task can be significant: the objectives are different. · For the downstream tasks, we need to introduce new parameters. · When you only have a dozen training examples for a new downstream task, it is hard to fine-tune.
Retrieval-augmented generation (RAG) is a two-step process combining external knowledge search with prompting. Retrieval: given a query, some information retrieval neural model fetches relevant documents/passages. Generation: fetched documents are wrapped into a prompt and passed to the LLM to generate relevant response. Advantages: flexibility (external knowledge source with recent/specific information), efficiency (works well also with small-size LLMs) and updatability (external knowledge source can be updated, no retrain).
Contextual language models can generate toxic language and can leak information about their training data → mitigating all these harms is an important but unsolved research problem in NLP.
Stage Pretraining Supervised Finetuning
Reward Modeling
Reinforcement Learning
Dataset Raw internet: text trillions of words low-quality, large quantity
Demonstrations: ideal assistant responses, ~10- 100K (prompt, response) written by
Comparisons: 100K -1M comparisons written by contractors. Low quantity,
Prompts: ~10K-100K prompts written by contractors low quantity, high quality
contractors. Low quantity, high quality
high quality
Algorithm Language modeling: predict the next token
Language modeling: predict the next token
Binary classification: predict rewards consistent with preferences
Reinforcement Learning: generate tokens that maximize the reward
Model Base model SFT model RM model RL model
Part-of-speech (POS) tags are lexical categories such as noun, verb, adjective, etc. We call tagset the set of all POS tags used by some model. POS tags can be in an open class (new words appear almost always in this class, group of nouns, verbs, adjectives, and adverbs) or in closed class (new words are rarely coined, group of prepositions, pronouns, etc.).
Words are ambiguous: depending on the context in which they appear, they may have different tags. The task of part-of-speech tagging involves the assignment of the proper (unique) POS tag to each word in an input sentence → done in the context of an entire sentence using grammatical relationship of a word with neighboring words. Input: sequence 𝑥 1 ,𝑥 2 ,…𝑥𝑛 of tokenized words. Output: sequence 𝑦 1 ,𝑦 2 ,…,𝑦𝑛 of tags.
The accuracy of a part-of-speech tagger is the percentage of test set tags that match human gold labels. Most Frequent Class baseline: assigning each token to the class it occurred in most often in the training set.
Hidden Markov Model is a generative model: it models how a class could generate some input data. Let 𝑤1:𝑛 be an input sequence of words and 𝑦 𝑤1:𝑛 be the set of all possible tags 𝑡1:𝑛. The goal of POS tagging is to choose the most probable tag sequence 𝑡1:𝑛, that with Bayes rule is 𝑡1:𝑛 = arg max 𝑡1:𝑛∈𝑦 𝑤1:𝑛
Pr (𝑤1:𝑛 𝑡1:𝑛 ∙ Pr 𝑡1:𝑛 , where Pr 𝑤1:𝑛 is constant so removed from denominator,
Pr 𝑡1:𝑛 prior probability, Pr 𝑤1:𝑛 𝑡1:𝑛 likelihood of words given tags. HMM models 𝑡1:𝑛 ≈ arg max 𝑡1:𝑛∈𝑦 𝑤1:𝑛
∏𝑛𝑖=1 Pr 𝑤𝑖 𝑡𝑖 ∙ Pr 𝑡𝑖 𝑡𝑖−1 using two simplifying
assumptions:
Probability estimation is done combining transition probability and emission probability (defined with the 𝐶 ∙ function).
We can formally define an HMM as a special type of probabilistic finite state automaton which generates sentences. The states represent Zhidden’ information, that is, the POS tags which are
state 𝑞, 𝑐 𝑞 is the expectation of each state 𝑞. The algorithm starts with some initial assignment Θ, and updates Θ by iterating the following steps: E-step (expectation) computes feature expectations 𝑐 𝑞,𝑞′ , 𝑐 𝑞,𝑢 and 𝑐 𝑞 on the basis of Pr Θ
∙ , M-step (maximization) estimates a new assignment Θ, in a way that maximizes the log-
likelihood of the training data. The algorithm stops when the parameters do not change much anymore.
Conditional random fields (CRF) are discriminative sequence models based on log-linear models. Discriminative classifiers learn what features from the input are most useful to discriminate between the different possible classes. CRFs solve the problem 𝑦1:𝑛 = arg max y1:n∈y x1:n
Pr y1:n|x1:n.
In contrast to HMM, the CRF does not compute a probability for each tag at each time step. Instead, at each time step the CRF computes log-linear functions over a set of relevant local features, and these features are aggregated and normalized to produce a global probability.
Let us assume we have 𝐾 global feature functions 𝐹𝑘 x1:n,y1:n , and weights 𝑤𝑘 for each feature.
We define Pr y1:n|x1:n =
exp ∑ 𝐾𝑘=1 𝑤𝑘𝐹𝑘 x1:n,y1:n ∑ (^) y′ 1:n∈𝑦^ x1:n
exp ∑ 𝐾𝑘=1 𝑤𝑘𝐹𝑘 x1:n,y′ 1:n
(denominator is the partition
function 𝑍 𝑥1:𝑛 , a normalization term that only depends on input sequence 𝑥1:𝑛).
We compute the global features by decomposing into a sum of local features, for each position 𝑖 in y1:n → 𝐹𝑘 𝑥1:n|y1:n =∑𝑛𝑖=0 𝑓𝑘 yi−1,y𝑖,𝑥1:n,𝑖. Each local feature depends on the current and
previous output tokens, y𝑖 and y𝑖−1 respectively, characterizing the linear chain CRF. This limitation makes it possible to use Viterbi algorithm.
To avoid feature handwriting, specific features are automatically instantiated from feature templates such as 〈𝑦𝑖,𝑥𝑖〉, 〈𝑦𝑖,𝑦𝑖−1〉, 〈𝑦𝑖,𝑥𝑖−1,𝑥𝑖+2〉. Word shape features are used to represent letter patterns. Prefix and suffix features are used to represent word morphological patterns.
Given a string to the inference problem, it gives back the best label sequence. It is expressed as 𝑦1:𝑛 = arg max y1:𝑛 ∈y 𝑥1:𝑛
Pr 𝑦1:𝑛|𝑥1:𝑛 = arg max y1:𝑛 ∈y 𝑥1:𝑛
∑𝑛𝑖=1 ∑𝐾𝑘=1 𝑤𝑘 𝑓𝑘 𝑦𝑖−1,𝑦𝑖,𝑥1:𝑛,𝑖. We can still
use the Viterbi algorithm, because the linear-chain CRF depends at each time-step on only one previous output token 𝑦𝑖−1. For CRF 𝑣𝑡 𝑡,𝑖 = max t′^
The parameters 𝑤𝑖 in CRF can be learned in a supervised way as in the method of logistic regression. We minimize the negative log-likelihood as our objective function. As in the case of multinomial logistic regression, L1 or L2 regularization is important. To optimize the objective function, we use stochastic gradient descent.
In neural network approaches to POS tagging, we construct distributed feature representations (dense vectors) for each tagging decision, based on the word and its context. We mainly use two approaches: local search (neural networks can perform POS tagging as a per-token classification decision) and global search (feature representations can be combined with the Viterbi algorithm to tag the entire sequence globally).
Local search methods:
· Fixed-window neural model uses a feedforward neural network to implement local search. The fixed-window model is very efficient, since it limits the context from which information can be extracted. Sliding windows makes it difficult for network to learn systematic patterns arising from phenomena like constituency, since patterns are shifted to different positions.
· Recurrent neural model : let 𝑥 1 ,…,𝑥𝑛 be input word, 𝑦 1 ,…,𝑦𝑛 associated output POS tags, 𝑒 1 ,…,𝑒𝑛 word embeddings for the 𝑥’s. Recurrent neural networks can be generally described as implementing the following recursive relation ℎ𝑡 = 𝑓 𝑊ℎ^ ℎ𝑡−1 + 𝑊𝑒^ 𝑒𝑡 + 𝑏 for 𝑡 = 1,…,𝑛, 𝑓 some nonlinear component and 𝑊ℎ,𝑊𝑒,𝑏 learnable parameters. We score each POS tag 𝑦 by means of a linear scalar function of hidden state vector ℎ𝑡, and then retrieve the highest score tag for 𝑥𝑡:𝑦𝑡 = arg max y
𝜓 𝑦,ℎ𝑡 , with 𝜓 𝑦,ℎ𝑡 = 𝛽𝑦∙ℎ𝑡.
𝜓 𝑦,ℎ𝑡 can also be converted into a probability using the softmax operation Pr 𝑦|𝑥1:𝑡 = exp 𝜓 𝑦,ℎ𝑡 ∑ (^) 𝑦′ exp 𝜓 𝑦′,ℎ𝑡
· Recurrent bidirectional model : Hidden state vector ℎ𝑡 encodes left context up to position 𝑡 but it ignores subsequent tokens, which might be relevant to 𝑦𝑡 as well. Bidirectional RNN are used to address this problem: ℎ𝑡 = 𝑔 𝑒𝑡,ℎ𝑡−1 , ℎ𝑡 = 𝑔′^ 𝑒𝑡,ℎ𝑡+1 , ℎ𝑡 = ℎ𝑡;ℎ𝑡. The scoring function 𝜓 𝑦,ℎ𝑡 is then applied to the concatenation of the two vectors.