alicemillour
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # idl_16 Système de recommandation de films Pour ce TP, le fichier `fims.json` est fourni. Il contient des entrées de la forme suivante : ```jsonld { "Title": "The Shawshank Redemption", "Plot": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency." }, { "Title": "The Godfather", "Plot": "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son." }, ``` Comme vous pouvez le constater les `plots` (résumés) sont très courts, mais nous allons voir dans ce TP ce qu'on peut déjà développer sur cette base. ## I. Préparation du dataset ### Étape 1 : lecture du jeu de données Implémentez une fonction `json_to_dic()` qui prend en argument le nom d'un fichier `json` de la forme ci-dessus, et renvoie un dictionnaire dont les `clés` sont les titres de films, et les `valeurs` les résumés. ```python! {'The Shawshank Redemption': 'Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.', 'The Godfather': 'The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.', [...]} ``` ### Étape 2 : chaîne de traitement en TAL Nous devons effectuer un certain nombre de pré-traitements sur nos résumés :question: quelles sont les étapes à réaliser ? Implémentez une fonction `nlp` qui prend en argument une phrase et renvoie la liste des tokens pertinents pour la recommandation. ```python! sentence = "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency" print(nlp(sentence)) ['Two', 'imprison', 'man', 'bind', 'number', 'year', 'find', 'solace', 'eventual', 'redemption', 'act', 'common', 'decency'] ``` Vous vous appuierez pour cela sur des librairies existantes. Il est possible que vous ayez besoin de télécharger les modules suivants **dans python** 1. lancez un interpréteur python (en ligne de commande) ```python= >>> import nltk >>> nltk.download('stopwords') >>> nltk.download('punkt_tab') >>> nltk.download('wordnet') ``` ### Étape 3 : application de la chaîne de traitement au dictionnaire Implémentez une fonction `nlp_dico` qui prend en argument un dictionnaire et renvoie un dictionnaire où le traitement ci-dessus a été appliqué à chacune des valeurs. ## II. Calcul de la similarité de Jaccard Implémentez une fonction `jaccard_similarity` qui prend en argument deux listes de tokens et renvoie la valeur flottante correspondant au coefficient de similarité entre ces deux listes. Implémentez une fonction `jaccard_similarity_from_title` qui prend en argument deux titres de films et qui renvoie le coefficient de similarité entre les deux résumés correspondants, et affiche le résultat sous la forme : ```python! le Score de simiarité de Jaccard des films `The Godfather` et `The Godfather: Part II` est 0.1111111111111111 ``` ## III. Calcul de la représentation vectorielle Nous allons ici construire une représentation vectorielle de notre corpus basée sur le calcul des coefficients dits `TD-IDF`. :question: quelle doit-être la taille des vecteurs représentant chaque document de notre corpus ? Cette valeur peut-elle être obtenue en aditionnant toutes les longueurs des valeurs du dictionnaire obtenu à l'étape 3 du I ? ### Etape 1 : Calcul de TF et d'IDF - Implémentez une fonction `TF` qui calcule, pour un terme donné, la fréquence de ce terme dans un résumé de film donné. $$ TF(token, document) = { Nb\_occurrences\_token \over Nb\_total\_tokens} $$ - Implémentez une fonction `IDF` qui prend en argument un dictionnaire (clé : titre, valeur : résumé) et qui renvoie un dictionnaire dont les clés sont les tokens du vocabulaire de l'ensemble du corpus, et les valeurs sont le score idf pour chacun de ces tokens. Vous pourrez utiliser la fonction `log10` de la librairie `maths`. $$ IDF(token, corpus) = log10({ Nb\_docs\_du\_corpus \over Nb\_docs\_contenant\_token} ) $$ Exemple de résultat : ```csv {'Two': 1.6989700043360187, 'imprison': 2.0969100130080562, 'man': 1.7958800173440752, 'bind': 2.0969100130080562, 'number': 2.0969100130080562, etc. } ``` ### Étape 2 : Calcul des vecteurs Implémentez une fonction `TFIDF` qui prend en argument le dictionnaire des films et qui renvoie un dictionnaire dont les clés sont le titre des films et les valeurs sont le vecteur de coefficients TF-IDF correspondants à ce film. $$ TFIDF(token, document, corpus) = TF(token, document, corpus) * IDF(token, corpus) $$ Exemple de résultat (les valeurs que vous obtiendrez ne sont pas forcément les mêmes en raison de différences entre versions des librairies): ```csv {'The Shawshank Redemption': [ 0.07079041684733411, // token Two 0.08737125054200234, // token imprison 0.07482833405600313, // token man 0.08737125054200234, // token bind etc. ], etc. } ``` ## IV. Recommandation Dans cette dernière section, on considère que le profil d'un.e utilisateurice se résume à un titre de film qu'il/elle dit avoir aimé. Implémentez-donc deux fonctions `recommend_Jaccard` et `recommend_TFIDF` qui, pour un titre de film donné, recommandent 3 films. On utilisera pour calculer la similarité entre deux films (dans le cadre de la représentation vectorielle) la fonction `cosine_similarity` ci-dessous. Cette fonction requiert l'import suivant `import numpy as np`. ```python def cosine_similarity(list1, list2): dot = np.dot(list1, list2) norm1 = np.linalg.norm(list1) norm2 = np.linalg.norm(list2) cos = dot / (norm1 * norm2) return(cos) ``` Exemple de résultat : ```python! Les recommandations basées sur la mesure de similarité de Jaccard pour le film "The Nightmare Before Christmas" sont : [('Finding Nemo', 0.07692307692307693), ('A Christmas Story', 0.06451612903225806), ("Hachi: A Dog's Tale", 0.047619047619047616)] Les recommandations basées sur la distance cosinus et sur TF-IDF pour le film "The Nightmare Before Christmas" sont : [('A Christmas Story', 0.10757874998175111), ('Life of Brian', 0.09473294779049923), ('Finding Nemo', 0.09460119447812901)] ``` ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully