diff --git a/notebooks/TP5_m2LiTL_learningWithNN_SUJET_2425.ipynb b/notebooks/TP5_m2LiTL_learningWithNN_SUJET_2425.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..9d96e15d6054a21bd381f55d6243bfa11e747795
--- /dev/null
+++ b/notebooks/TP5_m2LiTL_learningWithNN_SUJET_2425.ipynb
@@ -0,0 +1,766 @@
+{
+  "nbformat": 4,
+  "nbformat_minor": 0,
+  "metadata": {
+    "colab": {
+      "provenance": [],
+      "toc_visible": true
+    },
+    "kernelspec": {
+      "name": "python3",
+      "display_name": "Python 3"
+    },
+    "language_info": {
+      "name": "python"
+    },
+    "accelerator": "GPU"
+  },
+  "cells": [
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# TP 5 : machine learning using neural network for text data\n",
+        "\n",
+        "In this practical session, we are going to build simple neural models able to classify reviews as positive or negative. The dataset used comes from AlloCine.\n",
+        "The goals are to understand how to use pretrained embeddings, and to correctly tune a neural model.\n",
+        "\n",
+        "you need to load:\n",
+        "- Allocine: Train, dev and test sets\n",
+        "- Embeddings: cc.fr.300.10000.vec (10,000 first lines of the original file)\n",
+        "\n",
+        "## Part 1- Pre-trained word embeddings\n",
+        "Define a neural network that takes as input pre-trained word embeddings (here FastText embeddings). Words are represented by real-valued vectors from FastText. A review is represented by a vector that is the average or the sum of the word vectors.\n",
+        "\n",
+        "So instead of having an input vector of size 5000, we now have an input vector of size e.g. 300, that represents the ‘average’, combined meaning of all the words in the document taken together.\n",
+        "\n",
+        "## Part 2- Tuning report\n",
+        "Tune the model built on pre-trained word embeddings by testing several values for the different hyper-parameters, and by testing the addition on an hidden layer.\n",
+        "\n",
+        "Describe the performance obtained by reporting the scores for each setting on the development set, printing the loss function against the hyper-parameter values, and reporting the score of the best model on the test set.\n",
+        "\n",
+        "-------------------------------------"
+      ],
+      "metadata": {
+        "id": "jShhTl5Mftkw"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Useful imports\n",
+        "\n",
+        "Here we also:\n",
+        "* Look at the availability of a GPU. Reminder: in Collab, you have to go to Edit/Notebook settings to set the use of a GPU\n",
+        "* Setting a seed, for reproducibility: https://pytorch.org/docs/stable/notes/randomness.html\n"
+      ],
+      "metadata": {
+        "id": "mT2uF3G6HXko"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "!pip install -q torchtext==0.14.1 torchdata==0.5.1"
+      ],
+      "metadata": {
+        "id": "KNlmj1qBZ_Kp"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "import time\n",
+        "import pandas as pd\n",
+        "import numpy as np\n",
+        "# torch and torch modules to deal with text data\n",
+        "import torch\n",
+        "import torch.nn as nn\n",
+        "import torchtext\n",
+        "from torchtext.data import get_tokenizer\n",
+        "#from torchtext.data.utils import get_tokenizer\n",
+        "from torchtext.vocab import build_vocab_from_iterator\n",
+        "from torch.utils.data import DataLoader\n",
+        "# you can use scikit to print scores\n",
+        "from sklearn.metrics import classification_report\n",
+        "\n",
+        "# For reproducibility, set a seed\n",
+        "torch.manual_seed(0)\n",
+        "\n",
+        "# Check for GPU\n",
+        "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
+        "print(device)"
+      ],
+      "metadata": {
+        "id": "nB_k89m8xAOt"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Paths to data:"
+      ],
+      "metadata": {
+        "id": "taGY9N-PJvWS"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Data files\n",
+        "train_file = \"allocine_train.tsv\"\n",
+        "dev_file = \"allocine_dev.tsv\"\n",
+        "test_file = \"allocine_test.tsv\"\n",
+        "# embeddings\n",
+        "embed_file='cc.fr.300.10000.vec'"
+      ],
+      "metadata": {
+        "id": "kGty4hWCJurB"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 1- Read and load the data\n"
+      ],
+      "metadata": {
+        "id": "Wv6H41YoFycw"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 1.1- The class Dataset (code given)"
+      ],
+      "metadata": {
+        "id": "eXiJRrw_zsFD"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Reminder from TP1, the simplest solution is to use the DataLoader from PyTorch:\n",
+        "\n",
+        "* the doc here https://pytorch.org/docs/stable/data.html and here https://pytorch.org/tutorials/beginner/basics/data_tutorial.html\n",
+        "* an example of use, with numpy array: https://www.kaggle.com/arunmohan003/sentiment-analysis-using-lstm-pytorch\n",
+        "\n",
+        "Here, we are going to define our own Dataset class instead of using numpy arrays. It allows for a finer definition of the behavior of our dataset, and it's easy to reuse.\n",
+        "\n",
+        "* Dataset is an abstract class in PyTorch, meaning it can't be used as is, it has to be redefined using inheritance https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset\n",
+        "* you must at least overwrite the __getitem__() method, supporting fetching a data sample for a given key.\n",
+        "* in practice, you also overwrite the __init__() to explain how to initialize the dataset, and the __len__ to return the right size for the dataset\n",
+        "\n",
+        "You can also find many datasets for text ready to load in pytorch on: https://pytorch.org/text/stable/datasets.html"
+      ],
+      "metadata": {
+        "id": "HaDS9RXBRWdQ"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "#### Read and load data (code given)\n",
+        "\n",
+        "Read the code below that allows to load the data, note that:\n",
+        "- we tokenize the text (here a simple tokenization based on spaces)\n",
+        "- we build the vocabulary corresponding to the training data:\n",
+        "  - the vocabulary corresponds to the set of unique tokens\n",
+        "  - only tokens in the training data are known by the system\n",
+        "  - the vocabulary here is a Torch specific object, more details in section 0.4 below\n",
+        "\n",
+        "▶▶ **Question:** why do we use only tokens in the training set to build the vocabulary? What do we do with the dev and test sets?"
+      ],
+      "metadata": {
+        "id": "pswfJ-YER4Qx"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Here we create a custom Dataset class that inherits from the Dataset class in PyTorch\n",
+        "# A custom Dataset class must implement three functions: __init__, __len__, and __getitem__\n",
+        "\n",
+        "\n",
+        "class Dataset(torch.utils.data.Dataset):\n",
+        "\n",
+        "    def __init__(self, tsv_file, vocab=None ):\n",
+        "      \"\"\" (REQUIRED) Here we save the location of our input file,\n",
+        "        load the data, i.e. retrieve the list of texts and associated labels,\n",
+        "        build the vocabulary if none is given,\n",
+        "        and define the pipelines used to prepare the data \"\"\"\n",
+        "      self.tsv_file = tsv_file\n",
+        "      self.data, self.label_list = self.load_data( )\n",
+        "      # splits the string sentence by space, can t make the fr tokenzer work\n",
+        "      self.tokenizer = get_tokenizer( None )\n",
+        "      self.vocab = vocab\n",
+        "      if not vocab:\n",
+        "        self.build_vocab()\n",
+        "      # pipelines for text and label\n",
+        "      self.text_pipeline = lambda x: self.vocab(self.tokenizer(x)) #return a list of indices from a text\n",
+        "      self.label_pipeline = lambda x: int(x) #simple mapping to self\n",
+        "\n",
+        "    def load_data( self ):\n",
+        "      \"\"\" Read a tsv file and return the list of texts and associated labels\"\"\"\n",
+        "      data = pd.read_csv( self.tsv_file, header=0, delimiter=\"\\t\", quoting=3)\n",
+        "      instances = []\n",
+        "      label_list = []\n",
+        "      for i in data.index:\n",
+        "        label_list.append( data[\"sentiment\"][i] )\n",
+        "        instances.append( data[\"review\"][i] )\n",
+        "      return instances, label_list\n",
+        "\n",
+        "    def build_vocab(self):\n",
+        "      \"\"\" Build the vocabulary, i.e. retrieve the list of unique tokens\n",
+        "      appearing in the corpus (= training set). Se also add a specific index\n",
+        "      corresponding to unknown words.  \"\"\"\n",
+        "      self.vocab = build_vocab_from_iterator(self.yield_tokens(), specials=[\"<unk>\"])\n",
+        "      self.vocab.set_default_index(self.vocab[\"<unk>\"])\n",
+        "\n",
+        "    def yield_tokens(self):\n",
+        "      \"\"\" Iterator on tokens \"\"\"\n",
+        "      for text in self.data:\n",
+        "        yield self.tokenizer(text)\n",
+        "\n",
+        "    def __len__(self):\n",
+        "      \"\"\" (REQUIRED) Return the len of the data,\n",
+        "      i.e. the total number of instances \"\"\"\n",
+        "      return len(self.data)\n",
+        "\n",
+        "    def __getitem__(self, index):\n",
+        "      \"\"\" (REQUIRED) Return a specific instance in a format that can be\n",
+        "      processed by Pytorch, i.e. torch tensors \"\"\"\n",
+        "      return (\n",
+        "            tuple( [torch.tensor(self.text_pipeline( self.data[index] ), dtype=torch.int64),\n",
+        "                    torch.tensor( self.label_pipeline( self.label_list[index] ), dtype=torch.int64) ] )\n",
+        "        )"
+      ],
+      "metadata": {
+        "id": "GdK1WAmcFYHS"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 1.2- Generate data batches and iterator (code given)\n",
+        "\n",
+        "Then, we use *torch.utils.data.DataLoader* with a Dataset object as built by the code above. DataLoader has an argument to set the size of the batches, but since we have variable-size input sequences, we need to specify how to build the batches. This is done by redefining the function *collate_fn* used by *DataLoader*.\n",
+        "\n",
+        "```\n",
+        "dataloader = DataLoader(dataset, batch_size=8, shuffle=False, collate_fn=collate_fn)\n",
+        "```\n",
+        "\n",
+        "Below:\n",
+        "* the text entries in the original data batch input are packed into a list and concatenated as a single tensor.\n",
+        "* the offset is a tensor of delimiters to represent the beginning index of the individual sequence in the text tensor\n",
+        "* Label is a tensor saving the labels of individual text entries.\n",
+        "\n",
+        "The offsets are used to retrieve the individual sequences in each batch (the sequences are concatenated).\n"
+      ],
+      "metadata": {
+        "id": "bG3T9LQFTD73"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# This function explains how we process data to make batches of instances\n",
+        "# - The list of texts / reviews that is returned is similar to a list of list:\n",
+        "# each element is a batch, ie. a ensemble of BATCH_SIZE texts. But instead of\n",
+        "# creating sublists, PyTorch concatenates all the tensors corresponding to\n",
+        "# each text sequence into one tensor.\n",
+        "# - The list of labels is the list of list of labels for each batch\n",
+        "# - The offsets are used to save the position of each individual instance\n",
+        "# within the big tensor\n",
+        "def collate_fn(batch):\n",
+        "    label_list, text_list, offsets = [], [], [0]\n",
+        "    for ( _text, _label) in batch:\n",
+        "         text_list.append( _text )\n",
+        "         label_list.append( _label )\n",
+        "         offsets.append(_text.size(0))\n",
+        "    label = torch.tensor(label_list, dtype=torch.int64) #tensor of labels for a batch\n",
+        "    offsets = torch.tensor(offsets[:-1]).cumsum(dim=0) #tensor of offset indices for a batch\n",
+        "    text_list = torch.cat(text_list) # <--- here we concatenate the reviews in the batch\n",
+        "    return text_list.to(device), label.to(device), offsets.to(device) #move the data to GPU"
+      ],
+      "metadata": {
+        "id": "oG0ZEYvYccBr"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 1.3- ▶ Exercise: Load the data\n",
+        "\n",
+        "#### ▶ (a) Load the training data\n",
+        "* Use the code above to load the training and dev data with a batch size of 2:\n",
+        "  * First create an instance of the Dataset class\n",
+        "  * Then use this instance to create an instance of the DataLoader class with a batch size of 2, with NO shuffling of the samples, and using the *collate_fn* function defined above. Recall that the DataLoader class has the following parameters:\n",
+        "  ```\n",
+        "  torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=None, collate_fn=None)\n",
+        "  ```\n",
+        "\n",
+        "#### ▶ (b) Print first training instances\n",
+        "\n",
+        "* Print the first two elements in the Dataset object built on the train set, and the first element in the DataLoader object built on the train. Print also the associated labels. Does it seem coherent?\n",
+        "\n",
+        "#### ▶ (c) Shuffling the data\n",
+        "\n",
+        "Once you checked that is seems ok, reload the data but this time, shuffle the data during loading.\n",
+        "\n",
+        "#### ▶ (d) Load the dev data\n",
+        "\n",
+        "Now load the dev data, remembering that you need to give the training vocabulary."
+      ],
+      "metadata": {
+        "id": "U0ueXxdpZcqx"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Load the training and development data\n",
+        "# ...\n"
+      ],
+      "metadata": {
+        "id": "KnCvGsrMsyhV"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 1.4- ▶ Exercise: understand the Vocab object\n",
+        "\n",
+        "Here the **vocabulary** is a specific object in Pytorch: https://pytorch.org/text/stable/vocab.html\n",
+        "\n",
+        "For example, the vocabulary directly converts a list of tokens into integers, see below.\n",
+        "\n",
+        "Now try to:\n",
+        "* Retrieve the indices of a specific word, e.g. 'mauvais'\n",
+        "* Retrieve a word from its index, e.g. 368\n",
+        "* You can also directly convert a sentence to a list of indices, using the *text_pipeline* defined in the *Dataset* class, try with:\n",
+        "  * 'Avant cette série, je ne connaissais que Urgence'\n",
+        "  * 'Avant cette gibberish, je ne connaissais que Urgence'\n",
+        "  * what happened when you use a word that is unknown?"
+      ],
+      "metadata": {
+        "id": "Tus9Kedas5dq"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Hints: look at these functions\n",
+        "* lookup_indices(tokens: List[str]) → List[int]\n",
+        "* lookup_token(index: int) → str"
+      ],
+      "metadata": {
+        "id": "BR-hQMJlUfPR"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "5XVazcDvs5kW"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "57PURu7Qs5mk"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "nvm3nlifs5pp"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 2- Using pre-trained embeddings (code given)\n",
+        "\n",
+        "The first option would be to use randomly initialized word embeddings.\n",
+        "It allows the use of dense, real-valued input, that could be updated during training.\n",
+        "However, we probably don't have enough data to build good representations for our problem during training.\n",
+        "One solution is to use pre-trained word embeddings, built over very big corpora with the aim of building good generic representations of the meaning of words.\n",
+        "\n",
+        "Upload the file *cc.fr.300.10000.vec': first 10,000 lines of the FastText embeddings for French, https://fasttext.cc/docs/en/crawl-vectors.html.\n",
+        "\n",
+        "* **Each word is associated to a real-valued and low-dimensional vector** (e.g. 300 dimensions). Crucially,  the  neural  network  will  also  learn / update the  embeddings  during  training (if not freezed):  the  embeddings  of  the network are also parameters that are optimized according to the loss function, allowing the model to learn a better representation of the words.\n",
+        "\n",
+        "* And **each review is represented by a vector** that should represent all the words it contains. One way to do that is to use **the average of the word vectors** (another typical option is to sum them). Instead of a bag-of-words representation of thousands of dimensions (the size of the vocabulary), we will thus end with an input vector of size e.g. 300, that represents the ‘average’, combined meaning of all the words in the document taken together.\n",
+        "\n",
+        "The functions to load the embeddings vectors and build the weight matrix are defined below."
+      ],
+      "metadata": {
+        "id": "RX2DkAqws1gU"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "#### 2.1 Load the vectors (code given)\n",
+        "\n",
+        "The function below loads the pre-trained embeddings, returning a dictionary mapping a word to its vector, as defined in the fasttext file.\n",
+        "\n",
+        "Note that the first line of the file gives the number of unique tokens (in the original file, here we only have 9,999 tokens) and the size of the embeddings.\n",
+        "\n",
+        "At the end, we print the vocabulary and the vector for a specific token."
+      ],
+      "metadata": {
+        "id": "uqzj4HrjUkpc"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "import io\n",
+        "\n",
+        "def load_vectors(fname):\n",
+        "    fin = io.open(fname, 'r', encoding='utf-8', newline='\\n', errors='ignore')\n",
+        "    n, d = map(int, fin.readline().split())\n",
+        "    print(\"Originally we have: \", n, 'tokens, and vectors of',d, 'dimensions') #here in fact only 10000 words\n",
+        "    data = {}\n",
+        "    for line in fin:\n",
+        "        tokens = line.rstrip().split(' ')\n",
+        "        data[tokens[0]] = [float(t) for t in tokens[1:]]\n",
+        "    return data\n",
+        "\n",
+        "vectors = load_vectors( embed_file )\n",
+        "print( 'Version with', len( vectors), 'tokens')\n",
+        "print(vectors.keys() )\n",
+        "print( vectors['de'] )\n",
+        "\n"
+      ],
+      "metadata": {
+        "id": "yd2EEjECv4vk"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 2.2- Build the weight matrix (code given)\n",
+        "\n",
+        "We have a list of words associated to vector.\n",
+        "Now we need to specifically retrieve the vectors for the words present in our data, there is no need to keep vectors for all the words.\n",
+        "We thus build a matrix over the dataset associating each word present in the dataset to its vector.\n",
+        "For each word in dataset’s vocabulary, we check if it is in FastText’s vocabulary:\n",
+        "* if yes: load its pre-trained word vector.\n",
+        "* else: we initialize a random vector.\n",
+        "\n",
+        "The code below will also examine the coverage, i.e.:\n",
+        "* print the number of tokens from FastText found in the training set\n",
+        "* and the number of unknown words."
+      ],
+      "metadata": {
+        "id": "NXFLV8kXU0AA"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Load the weight matrix: modify the code below to check the coverage of the\n",
+        "# pre-trained embeddings\n",
+        "emb_dim = 300\n",
+        "matrix_len = len(train.vocab)\n",
+        "weights_matrix = np.zeros((matrix_len, emb_dim))\n",
+        "words_found, words_unk = 0,0\n",
+        "\n",
+        "for i in range(0, len(train.vocab)):\n",
+        "    word = train.vocab.lookup_token(i)\n",
+        "    try:\n",
+        "        weights_matrix[i] = vectors[word]\n",
+        "        words_found += 1\n",
+        "    except KeyError:\n",
+        "        weights_matrix[i] = np.random.normal(scale=0.6, size=(emb_dim, ))\n",
+        "        words_unk += 1\n",
+        "weights_matrix = torch.from_numpy(weights_matrix).to( torch.float32)\n",
+        "print( \"Words found:\", weights_matrix.size() )\n",
+        "print( \"Unk words:\", words_unk )"
+      ],
+      "metadata": {
+        "id": "SZ4CRB6VUuk0"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 3- ▶ Exercise: Model definition\n",
+        "\n",
+        "#### (a) Define the embedding layer:\n",
+        "Now modify your model to add an embedding layer in the __init__() function below:\n",
+        "\n",
+        "* Define *self.embedding_bag*: a layer combining the word embeddings for the words. Here we just give the definition of the layer, i.e.:\n",
+        "  * we use pre initialized weights\n",
+        "  * we want to combine the embeddings by doing the average\n",
+        "See ```nn.EmbeddingBeg.from_pretrained( ..)```, https://pytorch.org/docs/stable/generated/torch.nn.EmbeddingBag.html\n",
+        "* Retrieve the *embedding dimensions* to be used as parameter for the first linear function (look at the *EnbeddingBag* class definition).\n",
+        "\n",
+        "#### (b) Use the embedding layer\n",
+        "Now you need to tell the model when to use this embedding layer, thus you need to modify the *forward()* function to say that it needs to first *embed* the input before going through the linear and non linear layers.\n",
+        "\n",
+        "Look at the example in the doc: https://pytorch.org/docs/stable/generated/torch.nn.EmbeddingBag.html\n",
+        "Note that this embedding layer needs the information about the offset, to retrieve the sequences / individual documents in the batch.\n",
+        "\n"
+      ],
+      "metadata": {
+        "id": "VcLWQgu877rQ"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "class FeedforwardNeuralNetModel(nn.Module):\n",
+        "    def __init__(self, hidden_dim, output_dim, weights_matrix):\n",
+        "        # calls the init function of nn.Module.  Dont get confused by syntax,\n",
+        "        # just always do it in an nn.Module\n",
+        "        super(FeedforwardNeuralNetModel, self).__init__()\n",
+        "\n",
+        "        # Embedding layer\n",
+        "        #self.embedding_bag = ...\n",
+        "\n",
+        "        embed_dim = self.embedding_bag.embedding_dim\n",
+        "\n",
+        "        # Linear function\n",
+        "        self.fc1 = nn.Linear(embed_dim, hidden_dim)\n",
+        "\n",
+        "        # Non-linearity\n",
+        "        self.sigmoid = nn.Sigmoid()\n",
+        "\n",
+        "        # Linear function (readout)\n",
+        "        self.fc2 = nn.Linear(hidden_dim, output_dim)\n",
+        "\n",
+        "    def forward(self, text, offsets):\n",
+        "        # Embedding layer\n",
+        "        #embedded = ...\n",
+        "\n",
+        "        # Linear function\n",
+        "        out = self.fc1(embedded)\n",
+        "\n",
+        "        # Non-linearity\n",
+        "        out = self.sigmoid(out)\n",
+        "\n",
+        "        # Linear function (readout)\n",
+        "        out = self.fc2(out)\n",
+        "        return out"
+      ],
+      "metadata": {
+        "id": "VfR2w-Z4V6Qq"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 4- Train and evaluation (code given)\n",
+        "\n",
+        "Look at the code below that performs the training and evaluation of your model.\n",
+        "Note that:\n",
+        "* one epoch is one iteration over the entire training set\n",
+        "* each *input* is here a batch of several documents (here 2)\n",
+        "* the model computes a loss after making a prediction for each input / batch. We accumulate this loss, and compute a score after seing each batch\n",
+        "* at the end of each round / epoch, we print the accumulated loss and accuracy:\n",
+        "  * A good indicator that your model is doing what is supposed to, is the loss: it should decrease during training. At the same time, the accuracy on the training set should increase.\n",
+        "* in the evaluation procedure, we have to compute score for batched of data, that's why we have slight modifications in the code (use of *extend* to have a set of predictions)\n",
+        "\n",
+        "Note: here we need to take into account the offsets in the training and evaluation procedures."
+      ],
+      "metadata": {
+        "id": "UsXmIGqApbxj"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "import matplotlib.pyplot as plt\n",
+        "import os\n",
+        "\n",
+        "def my_plot(epochs, loss):\n",
+        "    plt.plot(epochs, loss)\n",
+        "    #fig.savefig(os.path.join('./lossGraphs', 'train.jpg'))\n",
+        "\n",
+        "def training(model, train_loader, optimizer, num_epochs=5, plot=False ):\n",
+        "  loss_vals = []\n",
+        "  for epoch in range(num_epochs):\n",
+        "    train_loss, total_acc, total_count = 0, 0, 0\n",
+        "    for input, label, offsets in train_loader:\n",
+        "      # Step1. Clearing the accumulated gradients\n",
+        "      optimizer.zero_grad()\n",
+        "      # Step 2. Forward pass to get output/logits\n",
+        "      outputs = model( input, offsets ) # <---- argument offsets en plus\n",
+        "      # Step 3. Compute the loss, gradients, and update the parameters by\n",
+        "      # calling optimizer.step()\n",
+        "      # - Calculate Loss: softmax --> cross entropy loss\n",
+        "      loss = criterion(outputs, label)\n",
+        "      # - Getting gradients w.r.t. parameters\n",
+        "      loss.backward()\n",
+        "      # - Updating parameters\n",
+        "      optimizer.step()\n",
+        "      # Accumulating the loss over time\n",
+        "      train_loss += loss.item()\n",
+        "      total_acc += (outputs.argmax(1) == label).sum().item()\n",
+        "      total_count += label.size(0)\n",
+        "    # Compute accuracy on train set at each epoch\n",
+        "    print('Epoch: {}. Loss: {}. ACC {} '.format(epoch, train_loss/len(train), total_acc/len(train)))\n",
+        "    loss_vals.append(train_loss/len(train))\n",
+        "    total_acc, total_count = 0, 0\n",
+        "    train_loss = 0\n",
+        "  if plot:\n",
+        "    # plotting\n",
+        "    my_plot(np.linspace(1, num_epochs, num_epochs).astype(int), loss_vals)\n",
+        "\n",
+        "\n",
+        "def evaluate( model, dev_loader ):\n",
+        "    predictions = []\n",
+        "    gold = []\n",
+        "    with torch.no_grad():\n",
+        "        for input, label, offsets in dev_loader:\n",
+        "            probs = model(input, offsets) # <---- fct forward with offsets\n",
+        "            # -- to deal with batches\n",
+        "            predictions.extend( torch.argmax(probs, dim=1).cpu().numpy() )\n",
+        "            gold.extend([int(l) for l in label])\n",
+        "    print(classification_report(gold, predictions))\n",
+        "    return gold, predictions"
+      ],
+      "metadata": {
+        "id": "US_0JmN5phqs"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Set the values of the hyperparameters\n",
+        "hidden_dim = 4\n",
+        "learning_rate = 0.001\n",
+        "num_epochs = 5\n",
+        "criterion = nn.CrossEntropyLoss()\n",
+        "output_dim = 2"
+      ],
+      "metadata": {
+        "id": "Jod8FnWPs_Vi"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# Initialize the model\n",
+        "model_ffnn = FeedforwardNeuralNetModel( hidden_dim, output_dim, weights_matrix)\n",
+        "optimizer = torch.optim.SGD(model_ffnn.parameters(), lr=learning_rate)\n",
+        "model_ffnn = model_ffnn.to(device)\n",
+        "# Train the model\n",
+        "training( model_ffnn, train_loader, optimizer, num_epochs=5, plot=True )\n",
+        "# Evaluate on dev\n",
+        "gold, pred = evaluate( model_ffnn, dev_loader )"
+      ],
+      "metadata": {
+        "id": "1Xug7ygbpAhS"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 5- ▶ Exercise: Tuning your model\n",
+        "\n",
+        "The model comes with a variety of hyper-parameters. To find the best model, we need to test different values for these free parameters.\n",
+        "\n",
+        "Be careful:\n",
+        "* you always optimize / fine-tune your model on the **development set**.\n",
+        "* Then you compare the results obtained with the different settings on the dev set to choose the best setting\n",
+        "* finally you report the results of the best model on the test set\n",
+        "* you always keep a track of your experimentation, for reproducibility purpose: report the values tested for each hyper-parameters and the values used by your best model.\n",
+        "\n",
+        "In this part, you have to test different values for the following hyper-parameters:\n",
+        "\n",
+        "1. Batch size: 2, 10, 100\n",
+        "2. Max number of epochs: max 100\n",
+        "3. Size of the hidden layer: 10, 64, 512\n",
+        "4. Activation function: Sigmoid, Relu, HardTahn\n",
+        "5. Learning rate: 0.0001, 0.1, 0.5, 10\n",
+        "6. Optimizer: SGD, Adam, RMSProp\n",
+        "\n",
+        "\n",
+        "Inspect your model to give some hypothesis on the influence of these parameters on the model by inspecting how they affect the loss during training and the performance of the model.\n",
+        "\n",
+        "**Note:** (not done below) Here you are trying to make a report on the performance of your model. try to organise your code to keep track of what you're doing:\n",
+        "* give a different name to each model, to be able to run them again\n",
+        "* [Optional] save the results in a dictionnary of a file, to be able to use them later:  \n",
+        "  * think that you should be able to provide e.g. plots of your results (for example, plotting the accuracy for different value of a specific hyper-parameter), or analysis of your results (e.g. by inspecting the predictions of your model) so you need to be able to access the results."
+      ],
+      "metadata": {
+        "id": "1HmIthzRumir"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "ZOT8_Fr-tXw6"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "4AHHe9Q3tXz3"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "8Vi1UflytX2r"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 5.7- [Optional] Additional exercise\n",
+        "\n",
+        "Modify your model to test a variation on the architecture. Here you don't have to tune all your model again, just try for example when keeping the best values found previously for the hyper-parameters:\n",
+        "\n",
+        "* Try with 1 additional hidden layer"
+      ],
+      "metadata": {
+        "id": "VwGKy1zH0mYT"
+      }
+    }
+  ]
+}
\ No newline at end of file
diff --git a/notebooks/TP6_m2LiTL_transformers_data_2425_SUJET.ipynb b/notebooks/TP6_m2LiTL_transformers_data_2425_SUJET.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..2fca8e1fd946ac1a92e788326b8974b8be52d409
--- /dev/null
+++ b/notebooks/TP6_m2LiTL_transformers_data_2425_SUJET.ipynb
@@ -0,0 +1,812 @@
+{
+  "cells": [
+    {
+      "cell_type": "markdown",
+      "metadata": {
+        "id": "-bb49S7B50eh"
+      },
+      "source": [
+        "# TP 6: Introduction to transformers\n",
+        "\n",
+        "In this practical session, we will explore the Transformers library made available by HuggingFace 🤗\n",
+        "\n",
+        "We will focus on loading datasets, and preprocessing them through tokenization, for two tasks: text classification (*sequence classification* in HuggingFace) and sequence labelling (*token classification* in HuggingFace).\n",
+        "\n",
+        "We will use the HuggingFace library and langague models based on Transformers (e.g. BERT).  \n",
+        "\n",
+        "- https://huggingface.co/ : open-source library, with a very rich API to make use of varied architectures and pre-trained models for different problems, e.g. classification, sequence tagging, generation... but only based on Transformers architectures. Don' hesitate to explore the demos and existing models: https://huggingface.co/tasks/text-classification\n",
+        "- A large number of datasets are mave available through the API, for text, images, speech, cf the datasets here: https://huggingface.co/datasets documentation here: https://huggingface.co/docs/datasets/index\n",
+        "\n",
+        "The code below will install:\n",
+        "- The *transformers* module, allowing to access the language models https://pypi.org/project/transformers/\n",
+        "- The *datasets* module to access the datasets.\n"
+      ]
+    },
+    {
+      "cell_type": "code",
+      "execution_count": null,
+      "metadata": {
+        "id": "9UoSnFV250el"
+      },
+      "outputs": [],
+      "source": [
+        "!pip install -U transformers\n",
+        "!pip install datasets"
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Finally, if the installation is successful, we can import the transformers library:"
+      ],
+      "metadata": {
+        "id": "StClx_Hh9PDm"
+      }
+    },
+    {
+      "cell_type": "code",
+      "execution_count": null,
+      "metadata": {
+        "id": "ZBQcA9Ol50en"
+      },
+      "outputs": [],
+      "source": [
+        "import transformers\n",
+        "from transformers import pipeline\n",
+        "from datasets import load_dataset\n",
+        "import numpy as np"
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# 1- Pipeline abstraction\n",
+        "\n",
+        "Many NLP tasks are made easy to perform within HuggingFace using the Pipeline abstraction.\n",
+        "\n",
+        "Useful resource: course made available on HuggingFace website, e.g. part on pipelines: https://huggingface.co/course/chapter1/3?fw=pt#working-with-pipelines\n",
+        "\n",
+        "\n",
+        "For example for text classification, we can very simply have access to pretrained models for varied tasks, included sentiment analysis:\n",
+        "https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TextClassificationPipeline\n",
+        "\n",
+        "Let's try!\n",
+        "\n",
+        "Side note: These pipelines use models that have been fine-tuned on the target task, in addition to pre-training, in general using a large set of varied datasets. If you want to use a pipeline for a project, don't forget to check on which data is has been fine-tuned already. If you use the same dataset for evaluation, check that the evaluation set was not included in fine-tuning, and state clearly that the language model is already fine-tuned on the same data (as it makes a huge difference compared to a model fine-tuned on a small dataset only)."
+      ],
+      "metadata": {
+        "id": "4avqXNnF73M0"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "#### 1.1 ▶ Exercise: Default model\n",
+        "\n",
+        "You can test pipelines by simply specifying the task you want to perform, a model is chosen by default.\n",
+        "\n",
+        "Run the code below:\n",
+        "* what is the name of the chosen pretrained model?\n",
+        "* what language?\n",
+        "* run the next lines and look at the predictions of the model, does it seem alright? Can you produce an example that is not well predicted?"
+      ],
+      "metadata": {
+        "id": "TxAzsZLjA6P_"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "classifier = pipeline(\"sentiment-analysis\")"
+      ],
+      "metadata": {
+        "id": "y-Y4a8Dn_6n7"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "classifier(\"This movie is disgustingly good !\")"
+      ],
+      "metadata": {
+        "id": "nRDF7Sd4ArdG"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "classifier(\"This movie is not as good as expected !\")"
+      ],
+      "metadata": {
+        "id": "iNcy1YsjArko"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "90ORfXqjSQHt"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "#### 1.3 ▶ Exercise: Specifying a pretrained model for English\n",
+        "\n",
+        "You can specify the pretrained model you want to use.\n",
+        "HuggingFace makes available tons of models for NLP (and other domains).\n",
+        "You can browse them on this page, here restricted to English model for Text classification tasks: https://huggingface.co/models?language=en&pipeline_tag=text-classification&sort=downloads\n",
+        "\n",
+        "▶▶ Exercise: use the same model as before, but using the parameter of the pipeline to specify its name\n",
+        "\n",
+        "Hint: look at the doc https://huggingface.co/learn/nlp-course/chapter1/3?fw=pt#using-any-model-from-the-hub-in-a-pipeline"
+      ],
+      "metadata": {
+        "id": "ipX_Nwxi_q9D"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "qXLEYRSrSWEs"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 1.4 ▶ Exercise: use a pretrained model for French\n",
+        "\n",
+        "Now, take a look at the models page and find a suitable model for the task in French: we want to try an adapted version of **FlauBERT**.\n",
+        "\n",
+        "* Find the model in the database, look at the documentation: how has been built this model?\n",
+        "* load it. You will need to install sacremoses library using ```!pip install sacremoses```\n",
+        "* Then try it on a few examples."
+      ],
+      "metadata": {
+        "id": "dQo8pS93BJKf"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "!pip install sacremoses"
+      ],
+      "metadata": {
+        "id": "i5t_Ik688rIX"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "fQcEX6OCuOsg"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# 2- Exploring a dataset\n",
+        "\n",
+        "In this part, we will focus on exploring datasets that are part of the HuggingFace hub."
+      ],
+      "metadata": {
+        "id": "RLOpYtKavaio"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 2.1- ▶ Exercise: Load a dataset\n",
+        "\n",
+        "▶▶ Exercise: Find the dataset corresponding to IMDB and load it.\n",
+        "\n",
+        "Doc: https://huggingface.co/datasets and https://huggingface.co/docs/datasets/load_hub\n"
+      ],
+      "metadata": {
+        "id": "QVx1g9QN3CjG"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "m3tFe3fzSlP7"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 2.2 Print statistics on the dataset\n",
+        "\n",
+        "▶▶ Exercise:\n",
+        "* Print the number of classes\n",
+        "* Print the first 2 examples of the dataset (advice: shuffle the dataset..)\n",
+        "* Print the distribution\n",
+        "* Count the total number of tokens and unique tokens: simple naive approach here, by splitting on space (the dataset is not yet tokenized)\n",
+        "\n",
+        "Hint: start by simply 'printing' the dataset object, and the dataset for a specific split, it will show you the structure of this object.  "
+      ],
+      "metadata": {
+        "id": "5UAvXlgLvxvh"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "UksRQxWdvBom"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "Ix_za-YVvB1L"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# 3- Using a tokenizer\n",
+        "\n",
+        "The text in the dataset is not tokenized.\n",
+        "In fact, transformers models have been trained using a specifc tokenization, and it is crucial to rely on the same tokenization when using a transformer model.\n"
+      ],
+      "metadata": {
+        "id": "bBQ6u5i41ROT"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "pretrained_model = \"distilbert-base-uncased-finetuned-sst-2-english\""
+      ],
+      "metadata": {
+        "id": "12kiRBwPF-89"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 3.1- ▶ Exercise: Retrieve the tokenizer\n",
+        "\n",
+        "Note that the HuggingFace library defines *AutoClasses* allowing to automatically infer the required architecture depending on the problem type, as specified as an argument.\n",
+        "\n",
+        "For example here, the tokenizer will be specific to the DistilBERT model, fine-tuned on sentiment analysis. This tokenizer is similar to BERT tokenizer, and inherits many methods from *PreTrainedTokenizerFast*.\n",
+        "\n",
+        "The tokenizer is in charge of preparing the input data, especially for a BERT based tokenizer, to split the input into subtokens. It will assign ids to each subtokens, and it will allow to map from the original input to tokenized versions.\n",
+        "\n",
+        "\n",
+        "- *Auto Classes*: https://huggingface.co/docs/transformers/model_doc/auto\n",
+        "- Tokenizer in HuggingFace: https://huggingface.co/docs/transformers/v4.25.1/en/main_classes/tokenizer\n",
+        "- *Bert tokenizer*: https://huggingface.co/docs/transformers/v4.25.1/en/model_doc/bert#transformers.BertTokenizer\n",
+        "- Class *PreTrainedTokenizerFast*: https://huggingface.co/docs/transformers/v4.25.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast"
+      ],
+      "metadata": {
+        "id": "NUus9JUNB3Qq"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "▶▶ Exercise: Retrieve the tokenizer corresponding to the pretrained model: you need to use the method *from_pretrained* from the class *AutoTokenizer*."
+      ],
+      "metadata": {
+        "id": "FkzA_Go1398e"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "Ry1viplgS3eb"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 3.2- ▶ Exercise: Tester le tokenizer\n",
+        "\n",
+        "**Utiliser le tokenizer pour :**\n",
+        "- encoder une phrase (en anglais) :\n",
+        "- convertir dans l'autre sens : d'une liste d'ids de tokens en texte\n",
+        "  * que se passe-t-il dans le cas de mots longs ?\n",
+        "  * de mots inconnus ?\n",
+        "  * Que répresentent les éléments entre crochets ?\n",
+        "\n",
+        "\n",
+        "Hint: regardez les méthodes 'encode' et 'decode' dans la doc https://huggingface.co/docs/transformers/v4.25.1/en/main_classes/tokenizer (et éventuellement 'convert_ids_to_tokens()')."
+      ],
+      "metadata": {
+        "id": "V8C5djpXB3Qr"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "uO8UkY4yvksn"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "3pLoN8VHvkvb"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 3.3- ▶ Exercise: Compute the vocabulary using the tokenizer\n",
+        "\n",
+        "The function below will tokenize the entire dataset.\n",
+        "\n",
+        "**Note the use of the function *map* that allows to apply a function to an entire dataset, i.e. all examples of each split.**\n",
+        "\n",
+        "▶▶ Exercise:\n",
+        "* Run the code: you might see a warning message, telling that some sequences are too long for the model used. Transformers only accept input sequence of a specif length. The common solution is to cut all sequences to the maximum possible length, this is called *truncation*. In order to truncate the input, look for the right argument in the the doc: https://huggingface.co/docs/transformers/main_classes/tokenizer#transformers.PreTrainedTokenizer.__call__\n",
+        "* Once the dataset is tokenized, print the structure of the tokenized_datasets object: do you see new fields compared to datasets?\n",
+        "* Print the first example\n",
+        "* Convert the ids to token to retrieve the text tokens\n",
+        "* compute the total number of tokens and unique tokens."
+      ],
+      "metadata": {
+        "id": "0GNXQIm9vuNX"
+      }
+    },
+    {
+      "cell_type": "code",
+      "execution_count": null,
+      "metadata": {
+        "id": "-Kj0bW3_50et"
+      },
+      "outputs": [],
+      "source": [
+        "def tokenize_function(examples):\n",
+        "    return tokenizer(examples[\"text\"])\n",
+        "\n",
+        "tokenized_datasets = dataset.map(tokenize_function)"
+      ]
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "IQbG0-JaTDcF"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "qasGYjhATDsX"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# 4- Testing another model\n",
+        "\n",
+        "See full tutorial here: https://huggingface.co/learn/nlp-course/chapter6/3\n",
+        "\n"
+      ],
+      "metadata": {
+        "id": "WymXnC5p90Ui"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 4.1- Load a tokenizer\n",
+        "\n",
+        "The code below loads the tokenizer of a pretrained / not fine-tuned distilBERT model for English, then apply it to one sentence."
+      ],
+      "metadata": {
+        "id": "1sKJizQKIhFf"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "tokenizer = AutoTokenizer.from_pretrained(\"distilbert-base-uncased\")\n",
+        "example = \"My name is Sylvain and I work at Hugging Face in Brooklyn.\"\n",
+        "encoding = tokenizer(example)\n",
+        "print(type(encoding))"
+      ],
+      "metadata": {
+        "id": "qsrVvSOwDxNk"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Here we use a FastTokenizer, we can retrieve the tokens directly without converting the IDs back to tokens."
+      ],
+      "metadata": {
+        "id": "Nl23QbGQEsZB"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "encoding.tokens()"
+      ],
+      "metadata": {
+        "id": "qVNslUVWEsl7"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "The tokenizer keeps track of the tokens that have been split, with word ids:\n",
+        "\n",
+        "▶ How many subtokens? How many words?"
+      ],
+      "metadata": {
+        "id": "zL7TgBAQFHxz"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "encoding.word_ids()"
+      ],
+      "metadata": {
+        "id": "vwDxuBf0FEbD"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 4.2- Load a NER dataset"
+      ],
+      "metadata": {
+        "id": "yQ6rqf7HFXl9"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.2.1- ▶ Exercise: Load a dataset\n",
+        "* Look on the HuggingFace hub for the dataset corresponding to Conll2003, with labels for chunking, NER and POS tagging.\n",
+        "* Load the dataset\n",
+        "* Look at the fields\n"
+      ],
+      "metadata": {
+        "id": "ZRKMRstCIt5l"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "c1CJzHZpTIoz"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.2.2- ▶ Exercise: Print the first example\n",
+        "\n",
+        "Print the first example and its NER tags"
+      ],
+      "metadata": {
+        "id": "eEP7aUPII1Hk"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "mL7rgvg1TQJP"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "Note: We can access the correspondence between those integers and the label names by looking at the features attribute of our dataset as below.\n",
+        "We can use this list of label names to print the label names for each element in the sequence."
+      ],
+      "metadata": {
+        "id": "QoMbowvFHc0m"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "ner_feature = raw_datasets[\"train\"].features[\"ner_tags\"]\n",
+        "label_names = ner_feature.feature.names\n",
+        "label_names"
+      ],
+      "metadata": {
+        "id": "-Ke6bBpBHVuO"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "words = raw_datasets[\"train\"][0][\"tokens\"]\n",
+        "labels = raw_datasets[\"train\"][0][\"ner_tags\"]\n",
+        "line1 = \"\"\n",
+        "line2 = \"\"\n",
+        "for word, label in zip(words, labels):\n",
+        "    full_label = label_names[label]\n",
+        "    max_length = max(len(word), len(full_label))\n",
+        "    line1 += word + \" \" * (max_length - len(word) + 1)\n",
+        "    line2 += full_label + \" \" * (max_length - len(full_label) + 1)\n",
+        "\n",
+        "print(line1)\n",
+        "print(line2)"
+      ],
+      "metadata": {
+        "id": "Ecp8q5T0H4fF"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.2.3- ▶ Exercise:  Print example text and labels at index 4."
+      ],
+      "metadata": {
+        "id": "h-dXPPKtIFpT"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "VMAspq-DTUvn"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.2.4- ▶ Exercise: Print first example with POS tags"
+      ],
+      "metadata": {
+        "id": "coH48TTeJFRM"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "bXUwiVxxTXDK"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## 4.3- ▶ Tokenization\n",
+        "\n",
+        "As we can see from previous parts, the text is already tokenized here, and each label is attached to a specific token.\n",
+        "\n",
+        "To (BERT) tokenize a text that is already tokenized, you need to use the option *is_split_into_words=True* in the tokenizer: https://huggingface.co/docs/transformers/main_classes/tokenizer#transformers.PreTrainedTokenizer.__call__.is_split_into_words"
+      ],
+      "metadata": {
+        "id": "chEEx208IZST"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.3.1- ▶ Exercise: tokenize the example at index 4"
+      ],
+      "metadata": {
+        "id": "PLWHvlLDKROe"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "print(len(raw_datasets[\"train\"][4][\"tokens\"]))"
+      ],
+      "metadata": {
+        "id": "ZXkJt5vuTcAL"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "F8f3lpORTlVC"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.3.2- ▶ Exercise: Word ids\n",
+        "\n",
+        "▶ Exercise: print the corresponding word ids for the 4th sequence, how many words do you find?"
+      ],
+      "metadata": {
+        "id": "yIU9_KrGJ0hw"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "yn6fDLIuTn3B"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.3.3- ▶ Exercise: compare the number of tokens, words and NER tags for example at index 4"
+      ],
+      "metadata": {
+        "id": "dCoE3Cu2LeTR"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "print( raw_datasets[\"train\"][4][\"ner_tags\"])"
+      ],
+      "metadata": {
+        "id": "rZy7Sv3LLef2"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "afvARZv9TrUJ"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "### 4.3.4- ▶ Exercise: Aligning tokens and labels\n",
+        "\n",
+        "Before using these data for fine-tuning a model, we need to align the labels and the (sub)tokens, since we are dealing with a token labeling task.\n",
+        "\n",
+        "Visit the HuggingFace tutorial: https://huggingface.co/learn/nlp-course/chapter7/2 and copy the function proposed to align labels and tokens. Make sure you understand the problem and the solution!"
+      ],
+      "metadata": {
+        "id": "vebhKmHbJ0kR"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "OF4CIgHNM4Wz"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "▶ Try it on the example at index 4: do we have the right number of labels now? What happened to subtokens?"
+      ],
+      "metadata": {
+        "id": "PPO4961NJ0rn"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "8IHpD-mPTxib"
+      },
+      "execution_count": null,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# 5. Additional notes about HuggingFace dataset"
+      ],
+      "metadata": {
+        "id": "-bUnXTbbGp5e"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "#### Available corpora\n",
+        "\n",
+        "Note that many corpora are available directly from HuggingFace, for example for text classification tasks:\n",
+        "https://huggingface.co/models?pipeline_tag=text-classification&sort=downloads\n",
+        "\n",
+        "\n",
+        "In particular you can directly load the full AlloCine corpus:\n",
+        "https://huggingface.co/datasets/allocine"
+      ],
+      "metadata": {
+        "id": "bsbgcxgTJsW2"
+      }
+    }
+  ],
+  "metadata": {
+    "kernelspec": {
+      "display_name": "visual",
+      "language": "python",
+      "name": "visual"
+    },
+    "language_info": {
+      "codemirror_mode": {
+        "name": "ipython",
+        "version": 3
+      },
+      "file_extension": ".py",
+      "mimetype": "text/x-python",
+      "name": "python",
+      "nbconvert_exporter": "python",
+      "pygments_lexer": "ipython3",
+      "version": "3.9.5"
+    },
+    "colab": {
+      "provenance": []
+    },
+    "accelerator": "GPU",
+    "gpuClass": "standard"
+  },
+  "nbformat": 4,
+  "nbformat_minor": 0
+}
\ No newline at end of file
diff --git a/slides/MasterLiTL_2425_Course4_070124.pdf b/slides/MasterLiTL_2425_Course4_070124.pdf
new file mode 100644
index 0000000000000000000000000000000000000000..ece275215fc2cae0074ccc95b99e5bd38b801255
Binary files /dev/null and b/slides/MasterLiTL_2425_Course4_070124.pdf differ