<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amal Laouaj Nozieres on Medium]]></title>
        <description><![CDATA[Stories by Amal Laouaj Nozieres on Medium]]></description>
        <link>https://medium.com/@amel-nozieres?source=rss-900ab8a4e6aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vbE5gI2xSMz8XsiGEmarfw.jpeg</url>
            <title>Stories by Amal Laouaj Nozieres on Medium</title>
            <link>https://medium.com/@amel-nozieres?source=rss-900ab8a4e6aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:24:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amel-nozieres/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Kaggle to Axiomova: Why I Built a Real AI Agent for Real-World Operations]]></title>
            <link>https://amel-nozieres.medium.com/from-kaggle-to-axiomova-why-i-built-a-real-ai-agent-for-real-world-operations-bdef9f587e45?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdef9f587e45</guid>
            <category><![CDATA[facilities-management]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[helpdesk-automation]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Sun, 13 Jul 2025 15:30:55 GMT</pubDate>
            <atom:updated>2025-07-13T15:30:55.148Z</atom:updated>
            <content:encoded><![CDATA[<p>From a GenAI prototype to a real AI product — this is how I turned my Kaggle-winning agent into <strong>Axiomova</strong>, a plug-and-play AI support agent for helpdesk operations and Facilities Management.</p><figure><img alt="Split-screen digital illustration. Left side shows a glowing neural network branching into UI elements like checklists and message boxes, symbolizing AI logic and automation. Right side features bold white text on a blue background that reads: “Winning Kaggle → Building a Real AI Agent for Helpdesk Operations.”" src="https://cdn-images-1.medium.com/max/1024/1*d-rBs_SK0wHuA08oDEz90w.png" /></figure><h3>After Winning Kaggle, I Couldn’t Let It Stay a Prototype</h3><p>Winning 1st place in the Kaggle GenAI competition with a fully working AI agent made me realize something:<br> this wasn’t just a cool demo. It was the seed of a real solution.</p><p>So I took a deep breath, rolled up my sleeves… and built it.</p><p>Not a chatbot.<br> Not a playground experiment.<br> A real product — for real workflows.</p><h3>🤯 The Problem: Most AI Support Tools Aren’t Built for Reality</h3><p>If you’ve worked in operations — especially in sectors like <strong>Facilities Management</strong> — you know how chaotic support really looks:</p><ul><li>📥 Dozens of emails a day</li><li>🔍 Lost information</li><li>🔁 Copy-pasting between systems</li><li>🧗 Chasing technicians for updates</li><li>😖 Broken SLAs, forgotten quotes, client frustration</li></ul><p>Meanwhile, most “AI support” solutions?<br> A chatbot with one canned reply and a “contact us” button.</p><h3>🎯 The Solution: Axiomova</h3><p>Meet <strong>Axiomova</strong> — a <strong>fully autonomous AI support agent</strong> that doesn’t just talk. It works.</p><p><strong>Key features at a glance:</strong></p><ul><li>🧠 Automatically classifies incoming emails</li><li>🔍 Retrieves accurate answers using RAG (retrieval-augmented generation)</li><li>🧩 Tracks every request inside a structured workflow engine</li><li>✍️ Replies or escalates just like a smart human teammate</li><li>⚙️ Integrates with OpenAI, Gemini, Anthropic — your choice</li><li>🛠 Fully customizable: prompts, tone, workflows, functions — all editable in the admin panel</li><li>🚀 Deploys in 1–2 days, with no SaaS or subscriptions</li></ul><h3>Built for FM, Ready for Any Ops-Heavy Industry</h3><p>I built Axiomova to solve the real problems I kept hearing during interviews with Facilities Management teams — <br> but it’s modular enough to plug into <strong>any helpdesk or operational support system</strong>.</p><p>This AI agent is a chameleon:<br> smart, lightweight, and built to adapt.</p><h3>❤️ Why I’m Doing This</h3><p>I’m proud (and honestly emotional) to put my AI skills to work for something tangible — <br> supporting the teams who keep our <strong>buildings</strong>, <strong>services</strong>, and <strong>workspaces</strong> running smoothly.</p><p>This is more than tech. It’s a better way to work.</p><h3>🔗 Try It. Share It.</h3><p>👉 Explore the agent at <a href="https://axiomova.com/">axiomova.com</a><br> ♻️ Know someone buried in support emails? Share this with them.</p><p>Let’s build a human chain that spreads useful AI — one share at a time.</p><h3>🚀 What’s next?</h3><p>This is just the beginning.<br>I’m already working on expanding integrations, training flows, and on-prem deployment options.</p><p>But I wanted to launch this version now — because teams are struggling now.<br>And the only way to improve it further is to get it into the hands of the people who need it.</p><h3>🙏 If this resonates…</h3><p>👉 Visit <a href="https://axiomova.com/">https://axiomova.com</a></p><p>If you know someone working in FM, logistics, or support ops — please share.<br>And if you’re one of those people who’ve been buried in email chaos for too long… I’d love to show you what Axiomova can do.</p><p>Let’s spread AI Agents that don’t just sound smart — but actually work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdef9f587e45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TensorFlow Developer Certificate: Passed!]]></title>
            <link>https://medium.com/analytics-vidhya/tensorflow-developer-certificate-passed-6db056d7371?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/6db056d7371</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 14:30:18 GMT</pubDate>
            <atom:updated>2022-02-25T16:51:11.663Z</atom:updated>
            <content:encoded><![CDATA[<p>I am today proudly a TensorFlow Developer Certificated! Here is my journey. May it inspire and help you to do it too!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*Pqynn0k-xWiGWqXcSdNNYg.png" /></figure><p>An enthusiastic reader of machine learning news, I came across this TensorFlow Developer Certificate. Google Tensorflow team developed an exam to grant you access to a certificate network. So you could find TensorFlow’s experts all over the world on google maps. Check it <a href="https://developers.google.com/certification/directory/tensorflow?hl=fr">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*wC99Ijt9cHoOQmjysHyAbw.png" /></figure><p>Are you like me? Do you get excited to get your name on the map? Yes, that is a little childish but whatever get you going is good!</p><p>If you’re asking yourself what is Tensorflow, to begin with? You’re in the right place.</p><p>Let’s get started!</p><p>What is Tensorflow?</p><p>Tensorflow is an open-source framework developed by Google for machine learning. Their site is well documented, it is easy to learn from their tutorials. TensorFlow also integrated Keras into its framework. Keras, an amazing library initially developed by the talented François Chollet in python for deep learning models.</p><p>The exam tests your TensorFlow knowledge. In my case, TensorFlow was already my favorite library, so it piqued my curiosity to see if I can make it. Can I prove to myself that I can belong to this community of TensorFlow fellows?</p><p>So first, you have to get the motivation. Whatever works for you: Recognition, fun to have your name on the google maps app, test your knowledge. If you have the motivation you got already half the challenge :)</p><p>Now, let’s get the tools to achieve it!</p><p>How did I prepare?</p><p>I read so many articles about people taking the exam. This helps me put together my to-do list. I’m gonna give you the conclusion of all my readings and how you can put together your own roadmap.</p><p><strong>Assess your starting point: your situation!</strong></p><p>Prerequisites:</p><p>So here it depends on your situation. For my part, I already had a mathematical background and got the certification on <a href="https://www.coursera.org/specializations/deep-learning">DeepLearning Specialization </a>with Andrew Ng.</p><p>If you are not there yet, you can take Coursera’s course with Andrew Ng or learn from the <a href="https://www.youtube.com/watch?v=CS4cs9xVecg&amp;list=PLkDaE6sCZn6Ec-XTbcX1uRg2_u4xOEky0">youtube playlist of Andrew Ng</a> and practice on your own.</p><p>Let’s get to it!</p><p>After getting the basics, you can take the <a href="https://www.coursera.org/professional-certificates/tensorflow-in-practice">Coursera Tensorflow Developer Certificate </a>taught by Laurence Moroney. You will see 95% of what is needed in the exam. I read about people taking the 7 days free trial of the course and watching the videos with the maximum speed. The exercises are on google Colab with their solution. Find what works for you.</p><p>Laurence Moroney is the best teacher ever …just after Andrew Ng(Sorry Laurence! Andrew Ng is the first guy that explains to me how to transform linear algebra into Neural networks, that was magical! ). I already saw many of his videos on Youtube so I knew this would be fun.</p><p>When I finished the Coursera courses, I couldn’t take the exam directly for personal reasons. So I waited many months before being able to take the exam. To refresh my knowledge I found the videos of <a href="https://www.youtube.com/channel/UClQOufBFGnnvJd-_X8TTS6A">George Zoto</a>. He created a community of people preparing for the exam. He shared slides of the courses and many tools and tips. He even created Trivia games for Tensorflow certification. That was so fun! Thank you George Zoto!</p><p>At this point you are ready!</p><p>What machine to take the exam?</p><p>If you have a GPU, that will save you so many hours of training. If not, you have to use google Colab with free GPU. Be sure to take the right versions on Colab. You can also pay for hours on the cloud. To see what your machine can do, try the TensorFlow tutorials on local and see if it is too long or not.</p><p>The exam is on Pycharm so you have to install it following the installation guide of the exam. Make sure to have the required versions. Try to play with Pycharm. For my part I tried to compile the tutorials on the Tensorflow website, I resolved any problem I had before taking the exam.</p><p>Conclusion:</p><p>This is the roadmap:</p><p>1- Get motivated</p><p>2- Watch videos, read articles, learn about deep learning</p><p>3- Take the Coursera Tensorflow developer certification or watch only the videos on Youtube or assist as a listener for free.</p><p>4- Install Pycharm and test your local machine</p><p>5- Test the Tensorflow tutorials on local</p><p>And that’s it! Hope you’re motivated to try it for yourself. Don’t hesitate to ask me your questions in the comments if you need any help.</p><p><strong>Ressources</strong></p><ul><li>Coursera</li></ul><p><a href="https://www.coursera.org/professional-certificates/tensorflow-in-practice">DeepLearning.AI TensorFlow Developer</a></p><ul><li>Playlist of Tensorflow</li></ul><p><a href="https://www.youtube.com/playlist?list=PLOU2XLYxmsII9mzQ-Xxug4l2o04JBrkLV">https://www.youtube.com/playlist?list=PLOU2XLYxmsII9mzQ-Xxug4l2o04JBrkLV</a></p><ul><li>George Zoto video</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrBwl50GAsvs%3Flist%3DPL2EBNWEnwV2dIziH1cJURyWipsoYHzN2p%26start%3D2204&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrBwl50GAsvs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrBwl50GAsvs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a2ebb32cb931663922520a1cb5b66bf/href">https://medium.com/media/2a2ebb32cb931663922520a1cb5b66bf/href</a></iframe><p>and his git hub repository:</p><p><a href="https://github.com/georgezoto/TensorFlow-in-Practice">https://github.com/georgezoto/TensorFlow-in-Practice</a></p><ul><li>Trivial game in</li></ul><p><a href="https://quizizz.com/join/quiz/5e87bdbc07fa7f001b120404/start?referrer=5d921444d0fa99001a135336">https://quizizz.com/join/quiz/5e87bdbc07fa7f001b120404/start?referrer=5d921444d0fa99001a135336</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6db056d7371" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/tensorflow-developer-certificate-passed-6db056d7371">TensorFlow Developer Certificate: Passed!</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YOLOv5, End-to-End object detector project on custom dataset]]></title>
            <link>https://medium.com/data-science/yolov5-end-to-end-object-detector-project-on-custom-dataset-5d9cc2c95921?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d9cc2c95921</guid>
            <category><![CDATA[yolov5]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Tue, 08 Jun 2021 17:49:59 GMT</pubDate>
            <atom:updated>2022-06-07T12:56:05.794Z</atom:updated>
            <content:encoded><![CDATA[<h4>YOLOv5, detect mushrooms, Please!</h4><p>This could be a command you give one of your drones walking in the forest. That would be awesome! The technology we’re gonna use here is so light, I’m sure this is far from a fantasy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MtAcOTsz3Uyl_ygLuIb-BA.png" /><figcaption>“Mushrooms in the lawn” Image from <a href="https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&amp;type=detection&amp;c=%2Fm%2F052sf&amp;id=c44d38c06d38c4e5">Open Images Dataset V6</a> Author: <a href="https://www.flickr.com/people/jamesrbowe/">James Bowe</a> (<a href="https://creativecommons.org/licenses/by/2.0/">License</a>)</figcaption></figure><p>In my <a href="https://towardsdatascience.com/computer-vision-lets-classify-mushrooms-6b3abe1561eb">previous article</a>, I walked through a first draft to classify mushrooms using CNNs with Tensorflow libraries. I used the <a href="https://www.kaggle.com/c/fungi-challenge-fgvc-2018">Fungus competition dataset</a> available on Kaggle. Many images of this dataset contain multiple objects with a rich background. I asked myself that maybe my model could be improved if trained on cropped images of a single mushroom or group of mushrooms. This also will help with my unbalanced dataset. And here comes YOLOv5 the state of the art in image detection.</p><p>If you follow the AI news, you certainly heard about YOLO. If not, you’re maybe asking yourself if this is a philosophical trick for “You Only Live Once”. So rest assured it is not. This clever acronym is for “You Only Look Once”. Please stick around we’re gonna customize this gorgeous tool to detect mushrooms.</p><p>If you’re new to all this, you can find an amazing article on object detection <a href="https://neptune.ai/blog/object-detection-algorithms-and-libraries">here</a>.</p><h4>Before we start, a little story of the YOLOv5 birth controversy</h4><p>YOLO was first created by Joseph Redmon in May 2016. That was a revolution in real-time object detection. Please notice that it was Joseph Redmon that came with this so-good name. The code has been updated with associations with Ali Farhadi for the 3 first versions. From there, the pioneers give Alexey Bochkovskiy their benediction via Twitter to take the lead of YOLO institution. Joseph Redmon’s tweet states that it isn’t his anymore. Alexey Bochkovskiy introduced YOLOv4 in April 2020.</p><p>Many days after YOLOv4, YOLOv5 was released by Glenn Jocher. There is a big controversy about the name because this new model based on Pytorch has nothing to do with the initial YOLO. It is not the new version of YOLO. This created a big controversy in the community. You can read about it from Alexey Bochkovskiy <a href="https://github.com/AlexeyAB/darknet/issues/5920">here</a> and the response <a href="https://blog.roboflow.com/yolov4-versus-yolov5/">here</a>. Anyway, the name sticks and it is a great tool. I don’t know how Alexey Bochkovskiy would name the new version of his code or if he even will make a new version. How about instead of YOLOv5, we call it YOLOP “You Only Look Once Pytorch”? I like YOLOP!</p><p>Anyway, that’s been said, let’s see how we can customize it to detect my mushrooms.</p><p>The idea here is to train the YOLOv5 on a labeled dataset of mushrooms, save the precious weights and use them on my dataset from Kaggle or on any image of mushroom for detection.</p><p>First of all, you can try the commands below on a Jupyter notebook in your python environment or directly on a terminal console window. I did both and it is simpler to do it in a terminal console window but if you want to package it and retry it again I found it easier to encapsulate the code in a function under the Jupyter notebook. If you want to give it a try without installing anything on your computer, you can try it directly on a google colab notebook. How cool is that!</p><h4><strong>Download a labeled dataset with bounding boxes</strong></h4><p><strong><em>Choose the dataset</em></strong></p><p>What we need is a dataset that gives each image the location of our favorite object: the mushroom. So the model will be able to predict/detect the locations of mushrooms on unseen images.</p><p>I tried multiple open datasets and I found the Google Open Image Dataset is the easiest to use. The <a href="https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&amp;type=detection&amp;c=%2Fm%2F052sf">website</a> allows displaying the images with the detection boxes. It is very attractive and lucky for me, they have the class Mushroom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHFUp3xPzf9TTUaTycPC5w.png" /><figcaption>Front page of <a href="https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&amp;type=detection&amp;c=%2Fm%2F052sf">Open Image Dataset V6</a>-class Mushroom</figcaption></figure><p><strong><em>Download the dataset</em></strong></p><p>I choose to use the open-source toolkit <a href="https://github.com/EscVM/OIDv4_ToolKit">OIDv4_ToolKit</a>. Feel free to use the <a href="http://fiftyone.ai/">FiftyOne</a> open-source tool recommended by OID V6 or simply download it manually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1367800d3a83c26e1006e10764384960/href">https://medium.com/media/1367800d3a83c26e1006e10764384960/href</a></iframe><p>Here I’m asking for 6000 images from the Mushroom class but the maximum number of images available on the training set is 1782.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBonFZgma3ObmLIEYqmgFw.png" /><figcaption>Image of my terminal console</figcaption></figure><p>Now, we have the images with their bounding boxes.</p><p>See what I have downloaded locally so far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*5jMKuo_2ELLB8pN6I_FwrA.png" /><figcaption>Image of my terminal console</figcaption></figure><p>The images are available now in the Mushroom folder which contains a folder of labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwSJRuAr_m67LW4zxd7jug.png" /><figcaption>Screenshot of my Mushroom folder</figcaption></figure><p>Two more steps and we’re finished with our dataset. First, we need to put all the labels on the same root as the images. Easy! Second, we need to transform the labels/bounding boxes files to the right format. The annotations stored in txt files are the coordinates (XMin, YMin, XMax, YMax). Notice that we need the coordinates scaled between 0 and 1.<br>To do this step I’m aware that you can use some labeling apps. But I like to do it myself! <br>So first we modify the OIDv4_ToolKit/classes.txt file to put only the class Mushroom. After that, I tried <a href="https://github.com/theAIGuysCode/OIDv4_ToolKit/blob/master/convert_annotations.py">convert_annotations.py</a> from the AIGuyCode. It didn’t work right away. So I put the code convert_annotations.py in my notebook and hard-coded my files paths. I don’t know why it didn’t work. But the code is good and it is open-source. <br>Check it out <a href="https://github.com/theAIGuysCode/OIDv4_ToolKit">here</a>!</p><p>Let’s see the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oeuQX_LgBN9R1J5FmI4AeQ.png" /><figcaption>Image of the Mushroom folder: The annotations are in the same root as the images</figcaption></figure><p>Let’s check the difference in the annotations</p><p>Before</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*e-fzKNwJ4gX7DTUoFgy5HQ.png" /></figure><p>After</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*lFEz2MPgvzVrt8wSZa0hSg.png" /></figure><p>Now we’re ready! We have our images dataset with the bounding boxes in the right format. Let’s get the model now!</p><h4>Install YOLOv5</h4><p>YOLOv5 is available <a href="https://github.com/ultralytics/yolov5">here</a>. Let’s clone it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80774817308487e274141c44331ddad7/href">https://medium.com/media/80774817308487e274141c44331ddad7/href</a></iframe><p>We need all the requirements that come with the package. For this, you can use the <a href="https://github.com/ultralytics/yolov5/blob/develop/requirements.txt">requirement.txt </a>file or use the pip command if you want to control more closely what you’re doing to your environment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c1c8bd07299fb07684ac9510b61314/href">https://medium.com/media/d3c1c8bd07299fb07684ac9510b61314/href</a></iframe><p>Please check my YOLOv5 folder on <a href="https://github.com/AmelNozieres/Mushrooms_YOLOv5">github</a>.</p><p>We need to add a Yaml file so YOLOv5 would be able to find the class. Here I added <a href="https://github.com/AmelNozieres/Mushrooms_YOLOv5/blob/main/data/Mushrooms.yaml"><em>Mushroom.yaml</em></a> in the data folder. Please notice that you should put here the path to the Mushroom folder we modify earlier with OIDv4_ToolKit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4490bbc3f11a3a1bde27de19eeec2a83/href">https://medium.com/media/4490bbc3f11a3a1bde27de19eeec2a83/href</a></iframe><h4>Train the model YOLOv5</h4><p>In the downloaded package of YOLOv5, we have <a href="https://github.com/AmelNozieres/Mushrooms_YOLOv5/tree/main/models">4 versions</a> of the model: YOLOv5s, YOLOv5m, YOLOv5l and, YOLOv5x. I will use the small one and it is YOLOv5s. You guessed it the letters s, m, l, and x is for the model size.</p><p>In the training command, you give the selected model these arguments:</p><ul><li><strong>img:</strong> input image size</li><li><strong>batch:</strong> batch size</li><li><strong>epochs:</strong> number of training epochs</li><li><strong>data:</strong> our yaml file created before</li><li><strong>cfg:</strong> the chosen model here I used the small one</li><li><strong>weights: </strong>a custom path to weights if empty, it will be saved in yolov5/runs/train/yolov5_results/weights</li><li><strong>name:</strong> result names</li><li><strong>device:</strong> 0 to use GPU</li><li><strong>cache:</strong> cache images for faster training</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb7c6f91e5130c347641cd2c654fde88/href">https://medium.com/media/cb7c6f91e5130c347641cd2c654fde88/href</a></iframe><p>And that’s all it takes to run it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_BXMWu4JOjlep6zcvoGNQ.png" /></figure><p>Let’s see the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hqIeRa2knxoQKBl0Mh6zw.png" /><figcaption>results.png stored on yolov5/runs/train folder</figcaption></figure><p>So in the yolov5n folder, you will get all the reportings you need.</p><p>Let’s predict!</p><p>With this command, you can detect one image giving its path or all the test images using the weights stored from the training step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/471382eb3896988bd06ae095e37806df/href">https://medium.com/media/471382eb3896988bd06ae095e37806df/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fknQeKJ_13Lpqh-NEzdrlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YEVFbzQV4xn4GOL28CJUw.png" /></figure><p>Pretty good, isn’t it?</p><p>This also works on videos and in real-time so it should be pretty awesome to code on videos of a drone.</p><p>When I started this project I couldn’t find all the information in the same place so this article is the feedback of my experience that I hope is the more complete possible. If you have any questions, let me know in the comments. I certainly find some other tricks that I forgot to put here. Hope this helps you code your own detector. If you do, please let me know about your projects.</p><p>Happy coding!</p><p>PS: I put my code here on <a href="https://github.com/AmelNozieres/Mushrooms_YOLOv5">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d9cc2c95921" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/yolov5-end-to-end-object-detector-project-on-custom-dataset-5d9cc2c95921">YOLOv5, End-to-End object detector project on custom dataset</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computer vision: Let’s classify mushrooms]]></title>
            <link>https://medium.com/data-science/computer-vision-lets-classify-mushrooms-6b3abe1561eb?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b3abe1561eb</guid>
            <category><![CDATA[convolution-neural-net]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Tue, 01 Jun 2021 15:29:52 GMT</pubDate>
            <atom:updated>2021-06-08T18:49:36.175Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsdatascience.com/tagged/hands-on-tutorials">Hands-on Tutorials</a></h4><h4><strong>Image classification with </strong>Tensorflow</h4><p>Did you ever ask yourself when walking in nature what kind of Fungus you come upon? is it safe for kids to touch it? So I’ve got the idea to train a model to recognize the mushrooms/Fungus. The idea is to take a picture with your phone and ask the model what is it. Pretty awesome isn’t it? <br>So, here is the story of my journey playing with image classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWk-OmckaZ2yyMZdvZI2Ww.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kalineri?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kalineri</a> on <a href="https://unsplash.com/s/photos/mushrooms?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>Define the problem: Image detection/ Image classification</strong></p><p>Before we start, let’s clarify some notions. Computer vision, one of the interesting branches of AI, is the art to teach a model to find information in an image and so to understand vision content. When classifying images is pretty simple for humans(cats, dogs, cars…), machines always struggled to be competitive. It is something, we humans, learn as kids. A common play game for parents/toddlers is repeating names of objects and persons. So it comes easily for everyday classes. Computer vision comes a long way and now with deep learning, it is as good as humans and even better in specific fields. For example, in medical radiology, AI could be trained to detect and classify a tumor, and often it has better results than humans.</p><p>The first step in computer vision is image detection.</p><p><em>Image detection</em> is finding in a given image a specific object in an image and return its coordinates/bounding boxes.</p><p><em>Image classification</em> is when you give an image of one object and your model returns a class with a probability and a confidence rate. So our model should first detect the objects and secondly classify them by the type of classes it has been trained on. For this, we commonly use CNN-Convolutional Neural Networks. What is a CNN?</p><p>An image is a matrix of pixels. To detect only the edges in the image you multiply with a filter matrix. This will bring the majority of the pixels to zero/black and it will show you only the edges. For more details check <a href="https://en.wikipedia.org/wiki/Kernel_%28image_processing%29">this page</a>. So CNN is a succession of nodes, each node applies a filter on the image. This helps the model learn features, mathematically saying vectors, from the image. The deeper the network is -biggest number of layers and nodes- the more it cost you on memory.</p><p><em>Image recognition</em> is when you give the model an image with multiple objects. The model, for each object in the image gives its bounding boxes(object detection) and predictions on classes with a confidence rate.</p><p>Our problem here is a multi-class categorization/ image classification.</p><p><strong>Collect the data</strong></p><p>To train a model you need good labeled data and when I say good labeled data it is like the first stone of your project. If you’ve got it wrong all the steps further would be for nothing. This is a crucial step for any machine learning project. As we say: “garbage in, garbage out”. Think about it like you’re trying to teach a kid what a mushroom is. If you show him different objects saying each time “That’s a mushroom”, you could be pretty sure, the kid will think that mushroom is a generic term for objects. So we need to be accurate. For this step, you can scrap the web or find open data available.</p><p>I tried the <a href="https://www.kaggle.com/c/fungi-challenge-fgvc-2018">Kaggle Fungus dataset</a>. It is a pretty good dataset with 1394 classes available <a href="https://github.com/visipedia/fgvcx_fungi_comp#data">here</a>. I played with it for a little while thinking, this is a classic problem of image recognition. It should be no more difficult than face recognition. Indeed I learned a while ago that face recognition is used in China in the biggest office buildings to check employees’ identities without badges. And I was so impressed I thought that with mushrooms it will be the same and I could just transfer learning from these models and let my new model do its magic with TensorFlow libraries. So guess what?</p><p>It didn’t work at all. The common features of a face are hardly usable for mushrooms. My first models didn’t learn anything. I put in so much time and even some tears to learn finally that 1394 classes with unbalanced data, didn’t work easily. In this dataset, for some classes, we have only three images. Sometimes my model was learning on the training set and doing so well like 86% of accuracy and when comes to the validation set we drop to 20%. Why? This is due to the unbalanced dataset. The model learns to guess the classes with the biggest number of images. If you show a kid 300 times a mushroom and one time a potato, he will certainly guess mushrooms more easily than a potato. For this article, I want to focus on image classification with TensorFlow. So, I choose to work with only 10 classes. The more classes we have the more the model becomes bad at distinguishing between them. So you have to collect more images to work on learning more features. For this first try, I want to keep it simple and I hope it will be efficient.</p><p>Let’s explore how to build an end-to-end project on image classification with TensorFlow.</p><p>Let’s dive in!</p><h4>Data processing</h4><p>Tensorflow provides us with this great API tf.data.dataset where you can create with one line of code an efficient dataset with multiple panels of native functions tuned to be performant. I created my dataset with the code below from the images directory downloaded locally.<br>Normally when I’m playing with a new project I prefer to make quick notebooks but here I cannot use image_dataset_from_directory to create my TensorFlow dataset so I switch to Pycharm. It is not available yet on Jupyter notebooks. So Pycharm it is!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbecc27750bd29cc3f5eca9a09decf0c/href">https://medium.com/media/dbecc27750bd29cc3f5eca9a09decf0c/href</a></iframe><p>Here are the 10 classes we will be working with:</p><blockquote>[‘11082_Xerocomellus_chrysenteron’, ‘12919_Cylindrobasidium_laeve’, ‘14064_Fomitopsis_pinicola’, ‘14160_Ganoderma_pfeifferi’, ‘17233_Mycena_galericulata’, ‘20983_Trametes_versicolor’, ‘21143_Tricholoma_scalpturatum’, ‘40392_Armillaria_lutea’, ‘40985_Byssomerulius_corium’, ‘61207_Coprinellus_micaceus’]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xqiAKBqtrLNOOmd5OHymIQ.png" /><figcaption>image from the plot produced by my code</figcaption></figure><p>Let’s set the dataset performances</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4d32f38df58c10f4be79b61f7d80f57/href">https://medium.com/media/c4d32f38df58c10f4be79b61f7d80f57/href</a></iframe><h3>Transfer learning model</h3><p>I started by creating my own CNN but it wasn’t doing so well. I’m not that patient to improve it, I choose to go for transfer learning.<br>Transfer learning is the ability to re-use models that were trained on bigger datasets, that already learned multiple features. For that, we freeze the top layers and retrain with the new classes. Many known models won the imagenet competition. The weights are available to re-use. So let’s help ourselves with these pre-trained models. I used the MobileNetV2 model because it is so light, it runs on my GPU in seconds.</p><p>The unique step I added to enhance the accuracy is the data augmentation. <br>Data augmentation is: for an input labeled image, you zoom it or flip it and add it as an input to the model. This helps the model to continue to recognize an object even if it is not always in the same position.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4094aad7270dd54fca35b9d4cd21cae5/href">https://medium.com/media/4094aad7270dd54fca35b9d4cd21cae5/href</a></iframe><p>And here are the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*R3GCB__PEtxRcixoz8smgg.png" /><figcaption>Image results of MobileNetV2 by the author</figcaption></figure><p>It is good for only 10 epochs and with only data augmentation.</p><p>Let’s predict now — my code below. I took <a href="https://www.mycodb.fr/photos/Xerocomellus_chrysenteron_2014_rp_1.jpg">an image</a> on the mycodb web dataset of Xerocomellus_chrysenteron class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ec9de69c9e91ab8226c775a4d8e2db9/href">https://medium.com/media/2ec9de69c9e91ab8226c775a4d8e2db9/href</a></iframe><p>and the model said:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*CJj4UP1voyzEDccsLDLTxg.png" /></figure><p>Pretty good, isn’t it?</p><p>The matrix above the result is the vector of predictions. <br>The end-to-end project is now finished. The next step should be to improve the accuracy and to extend to the rest of the classes.<br>This is the first step of my journey to train a model that will be able to recognize 1394 classes of fungus. It is pretty impressive that it did so good with not that much time. <br>Stay tuned for my updates!<br>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b3abe1561eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/computer-vision-lets-classify-mushrooms-6b3abe1561eb">Computer vision: Let’s classify mushrooms</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient new ways to do EDA]]></title>
            <link>https://medium.com/analytics-vidhya/efficient-new-ways-to-do-eda-aa64df1b779f?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa64df1b779f</guid>
            <category><![CDATA[pandas-profiling]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[sweetviz]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Fri, 27 Nov 2020 19:15:34 GMT</pubDate>
            <atom:updated>2020-11-28T08:06:24.603Z</atom:updated>
            <content:encoded><![CDATA[<p>Trying new ways to do Exploratory Data Analysis, I came upon some amazing open-source libraries. It is so life-changing that I wanted to share my experiments. I’m accustomed to exploring the dataframes, writing the code for visualizations with matplotlib, and seaborn libraries. Slightly the same code for every project. But here, a few lines of code using sweetviz or pandas_profiling will give you a good idea of our data.</p><p>Let’s dive in.</p><p>I’ll be working on mushrooms classification with the fungi classification challenge available on <a href="https://www.kaggle.com/c/fungi-challenge-fgvc-2018">Kaggle</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6lNg9EiyHQSetGC_Vf8rQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@campaign_creators?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Campaign Creators</a> on <a href="https://unsplash.com/s/photos/data-visualization?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>1- Reading the data</strong></p><p>Besides the images of different mushrooms, we’re provided with two JSON files for annotations. We can extract five tables: info, image, category, annotation, and license.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*O0N-XX2UNk3yAUmxisnCEQ.png" /><figcaption>image produced by the author with <a href="https://app.diagrams.net/">https://app.diagrams.net/</a></figcaption></figure><p>Here bellow the code to do it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70b311f9ecb78fe7df5153af011b8f51/href">https://medium.com/media/70b311f9ecb78fe7df5153af011b8f51/href</a></iframe><p><strong>2- Sweetviz library</strong></p><p>Now, we have our data organized on dataframes. Here comes the sweet library. It just takes to import it, analyze the dataframe, and ask to produce the visualization in an Html file. So we’re using only the analyze and show_html functions. And that’s it! isn’t it amazing?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11d832d6b635cc0139a2bb0cce0912c8/href">https://medium.com/media/11d832d6b635cc0139a2bb0cce0912c8/href</a></iframe><p>Here is the result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eMNA4xXCMv9oceDOZa071g.png" /><figcaption>image created by the <a href="https://medium.com/@amel.nozieres">author</a> and available <a href="https://www.kaggleusercontent.com/kf/46103530/eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..oGaAet5Ui3sNI-AIziiX8Q.v7ft4_qC0uOaatBy8CWRi7ZpuGK-gGy-rlfwCWM0JS4h5bvwLWNOoZ5dxaU_hiDMxCctsgyatyDcyrm89iXrXv20D43YMPoPFjdkilpnOG_romQWKYMyB6bcun9mFM5iEeIS_RqxsFZLMObEtxy1q0tS8cJF8Zrko-k5-B9bcu7OpSyHu1UHoL0PN0aqKSbhR2KGkC50YOSeouo_J4fVuhRiX4NdOE83Kv2DqA-S6ORXN-Aw2D_TbCPCC9mBrdjE_TZuSiA9ADRENUGYmPM0rtQWycooPsYTmJ5XkSF6JZ_CfrHLWJoBXphI8urQZmEBE3hAXfdF7JLHwwJCysbMvdtFfTrEVIzGAEEMUM7m_9J6voTrgpdbQT96jbyfLRcEIqlch7ZW9eXupZCYQNc9p95vYvrmPCs-HLmN5FXkxmWuoRD1I0M6uHAjHWrfjfWD5T-eWy5CBb5N9y-6gGRy3dwChVdf6xtqobk4BThUBuOhX-Pu5nKhh8gSKnMeItK1RO0uBayWXqUhcOSrQTUaaLEBWE4FMLk6oaGKDsxm0qjI0WjF78qPhl1zEOQV1-sPhAxN1Z-qpAO08D9wmbO2FW1KIL3qjqVnUgGdeExtYXX20-bVio0IlUqzIdTcgHOnvKePVlnn3LsDthdL_tbeIg.iHQ9-zqS3o9qEswrXy2aHQ/sweetviz_train_images.html">here</a></figcaption></figure><p>Please feel free to test it on Kaggle <a href="https://www.kaggleusercontent.com/kf/46103530/eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..oGaAet5Ui3sNI-AIziiX8Q.v7ft4_qC0uOaatBy8CWRi7ZpuGK-gGy-rlfwCWM0JS4h5bvwLWNOoZ5dxaU_hiDMxCctsgyatyDcyrm89iXrXv20D43YMPoPFjdkilpnOG_romQWKYMyB6bcun9mFM5iEeIS_RqxsFZLMObEtxy1q0tS8cJF8Zrko-k5-B9bcu7OpSyHu1UHoL0PN0aqKSbhR2KGkC50YOSeouo_J4fVuhRiX4NdOE83Kv2DqA-S6ORXN-Aw2D_TbCPCC9mBrdjE_TZuSiA9ADRENUGYmPM0rtQWycooPsYTmJ5XkSF6JZ_CfrHLWJoBXphI8urQZmEBE3hAXfdF7JLHwwJCysbMvdtFfTrEVIzGAEEMUM7m_9J6voTrgpdbQT96jbyfLRcEIqlch7ZW9eXupZCYQNc9p95vYvrmPCs-HLmN5FXkxmWuoRD1I0M6uHAjHWrfjfWD5T-eWy5CBb5N9y-6gGRy3dwChVdf6xtqobk4BThUBuOhX-Pu5nKhh8gSKnMeItK1RO0uBayWXqUhcOSrQTUaaLEBWE4FMLk6oaGKDsxm0qjI0WjF78qPhl1zEOQV1-sPhAxN1Z-qpAO08D9wmbO2FW1KIL3qjqVnUgGdeExtYXX20-bVio0IlUqzIdTcgHOnvKePVlnn3LsDthdL_tbeIg.iHQ9-zqS3o9qEswrXy2aHQ/sweetviz_train_images.html">here</a>.</p><p>I did the same for all the dataframes and also for the validation data. My reports are available as the output of my notebook on Kaggle <a href="https://www.kaggle.com/amelnozieres/eda-sweetviz-profiling">here</a>.</p><p><strong>3- pandas_profiling</strong>:</p><p>This library is also simple to use. We import the library and we call ProfileReport function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d8a7edca0a03973096e77e7492da656/href">https://medium.com/media/1d8a7edca0a03973096e77e7492da656/href</a></iframe><p>The result is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKe9CRaF3A1kotQB_-kjPw.png" /><figcaption>image generated by the author on kaggle <a href="https://www.kaggle.com/amelnozieres/eda-sweetviz-profiling?scriptVersionId=47926698">here</a></figcaption></figure><p>The result is organized on different tabs. Please feel free to check it out. It is available as an output of my kaggle’s notebook <a href="https://www.kaggle.com/amelnozieres/eda-sweetviz-profiling?scriptVersionId=47926698">here</a>.</p><p><strong>Conclusion</strong></p><p>The two libraries are pretty good but I have a little something for the sweetviz. I think it is the Html output. I hope this sharing will make your life easier. Please give it applause if you like it and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa64df1b779f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/efficient-new-ways-to-do-eda-aa64df1b779f">Efficient new ways to do EDA</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NLP en tensorflow: Ressusciter l’esprit de Baudelaire]]></title>
            <link>https://amel-nozieres.medium.com/nlp-en-tensorflow-ressusciter-lesprit-de-baudelaire-4de4aa829b6c?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4de4aa829b6c</guid>
            <category><![CDATA[generate]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[rnn]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Thu, 01 Oct 2020 10:00:40 GMT</pubDate>
            <atom:updated>2020-12-08T09:05:20.014Z</atom:updated>
            <content:encoded><![CDATA[<p>Avez-vous déjà essayé d’écrire un poème ou continuer une prose? C’est l’une des tâches les plus complexes de notre esprit.</p><p>Dans cet article nous allons essayer d’entraîner notre modèle sur un recueil de poèmes de Charles Baudelaire “Les fleurs du mal” et voir si le modèle peut nous donner quelque vers dans l’esprit de la plume de Baudelaire.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eg1igx4hirEBKfQyVJbvnw.png" /></figure><p>Pour les concepts de base de traitement du langage, vous pouvez consulter mon précédent article <a href="https://medium.com/@amel.nozieres/nlp-avec-tensorflow-analyse-de-sentiments-13c47984d9fb">ici</a>.</p><p>Commençons à coder!</p><p>Après avoir importé les librairies et importé le recueil de poèmes “Les fleurs du mal” qui est disponible <a href="https://raw.githubusercontent.com/AmelNozieres/NLP_Generate_poems/master/Les_fleurs_du_mal_Baudelaire">ici </a>sur mon github, nous allons procéder à la tokenisation, le séquençage puis le padding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48284311afd9e1993dbbc85f47e1e281/href">https://medium.com/media/48284311afd9e1993dbbc85f47e1e281/href</a></iframe><p>Ensuite le sequencing et le padding:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56d635a7e5d9e6ad7507384e8d0d6521/href">https://medium.com/media/56d635a7e5d9e6ad7507384e8d0d6521/href</a></iframe><p>Générer ou créer du texte est essentiellement une prédiction multi-classes. En effet, on crée notre corpus avec tous les mots existant dans le recueil de poèmes. L‘objectif’ de notre modèle est de prédire quel est le mot suivant dans la liste des mots du corpus. Une fois il a le premier mot, il recommence en alignant les mots à la suite des autres selon les probabilités qu’il a apprises du recueil. Facile non?!</p><p>Maintenant, que nous avons les mots dans un dictionnaire, nous sommes prêts à créer notre modèle(le cerveau apprenant de notre système). Nous allons partir sur un modèle assez simple pour voir comment les couches des tensorflow réagissent. Nous commençons par une première couche de neurones de Embedding. Pour rappel, la couche d’embedding permet d’associer à chaque mot un vecteur et en calculant la distance entre les vecteurs nous allons créer des paquets de vecteurs ou de mots qui ont le même sens ou employés dans le même contexte. Cette couche est assez efficace pour prédire des choses simples comme “L’herbe est …”, la réponse est “verte”. Mais des fois nous avons besoin de se rappeler d’information qui arrive en début du paragraphe ou du chapitre. Comment donc le modèle peut retenir ou garder en mémoire les choses importantes au fil du texte?</p><p>La réponse est: les Réseaux de Neurones Récurrents. Ce sont des réseaux de neurones très utiles pour toutes les données en séquence. Les séquences d’images dans une vidéo, la séquence de notes dans une partition ou la séquence de mots dans un texte.</p><p>Un neurone dans les réseaux de neurones récurrents est un neurone qui a une entrée Xt, une information cachée ht-1 et une sortie Yt, comme suit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vODZnovJafo8L_qZ-Tk1xQ.png" /><figcaption>image from<a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/"> Christopher Olah blog</a></figcaption></figure><p>Le neurone multiplie l’entrée par un poids, rajoute un vecteur, fait la même chose pour la valeur cachée, applique la fonction d’activation qui dans ce cas est tanh et nous obtenons la sortie du neurone. L’explication en détail est disponible<a href="https://fr.wikipedia.org/wiki/R%C3%A9seau_de_neurones_r%C3%A9currents"> ici</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*aO4ni-av6PIjw9Bla9e79w.png" /><figcaption>Source <a href="https://fr.wikipedia.org/wiki/R%C3%A9seau_de_neurones_r%C3%A9currents">wikipédia</a></figcaption></figure><p>Lorsqu’on obtient notre vecteur Yt qui est notre prédiction, on peut le comparer assez facilement avec la réelle valeur. En minimisant cet écart, on maximise la précision de notre modèle. Pour minimiser une fonction, on a recourt aux dérivées partielles. Donc nous allons remonter les couches de neurones de la fin au début en minimisant l’écart. Le gradient, la dérivée partielle, devient de plus en plus petite et nous sommes confrontés au problème de la disparition du gradient. Pour palier à ce problème, nous changeons chaque neurone par un neurone LSTM Long Short-Term Memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5W8FrASMi93Z81NlAui4w.png" /><figcaption>image from<a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/"> Christopher Olah blog</a></figcaption></figure><p>Le neurone LSTM va prendre en plus de l’entrée et l’état caché, une autre variable qui est la mémoire de ce qui s’est passé avant. Et c’est là toute la beauté de la chose! Dans chaque cellule LSTM c’est comme si nous avions un mini réseau de neurones qui décide à l’instant t de ce qu’il va garder comme apprentissage et ce qu’il va oublier. N’est ce pas extraordinaire?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*ecmoaRlBsufok70Q8__RuQ.png" /><figcaption>Source <a href="https://fr.wikipedia.org/wiki/R%C3%A9seau_de_neurones_r%C3%A9currents">wikipédia</a></figcaption></figure><p>Après cette petite parenthèse mathématique, revenons à notre modèle. Après la couche Embedding, nous rajoutons une couche LSTM qui parcourt dans les deux sens, ce qui a été dit et ce qui va être dit. Et on finit par une couche Dense.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16fa1aaf78038540dfad20a6b2f32f01/href">https://medium.com/media/16fa1aaf78038540dfad20a6b2f32f01/href</a></iframe><p>J’espère que vous êtes aussi impatient que moi de voir ce que ce petit modèle peut créer comme poème.</p><p>Testons! Je commence par lui donner “L’amour” comme mot du début:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/022557eeacbe7942d3c9d475528f06d9/href">https://medium.com/media/022557eeacbe7942d3c9d475528f06d9/href</a></iframe><p>et voici la suite:</p><pre>L&#39;amour après s’être lavés au fond des mers profondes<br>aurore vives<br> païens morts dans la plus <br>plus ou de l’encre taciturne » » <br>de viennent quelque toujours cimetière il <br>mystique que la pendule enrhumée en leur esprits <br>que tu vous loue rose pour une pose étrange et gorge » vipères<br> pâme de morts <br>morts dans ta crinière funèbres <br>et pleine d’escargots funèbres <br>de mots » noire et l’onde blés <br>blés mange la pâme <br>des pâme des morts » — <br>pâme du vieux t il agathe <br>il agathe de front <br>pâlissant pâme sans bords<br> le pâme amour vipères <br>pâme dans cette pourriture</pre><p>Essayons avec “La vie”</p><pre>La vie impudente et criarde <br>beauté dites beauté noir et nu <br>» chère indolente deux blés <br>chère mange de froids <br>tissus blés imparfaite <br>analyse amère se se se voila pâme chère <br>se frayer se blés se cognant de morts <br>se blés souterraine imparfaite <br>se pâme se solennelle magie vipères vipères » mea</pre><p>Même si le français n’est pas correct, dans toute cette création, il y a un trait poétique. La répétition de certains mots vient du fait que le recueil n’est pas assez conséquent. Mais dans l’ensemble, ce n’est pas trop mal pour un modèle qui s’entraîne en quelque minutes et qui fait à peine une dizaine de ligne de code. Cela pourrait même être une première version d’un poème à retravailler et à corriger pour que les vers aient plus de sens.</p><h3>Conclusion</h3><p>Tensorflow en quelque lignes nous permet de générer du texte et même garder l’esprit poétique sur-lequel il s’est entraîné. Chose que l’esprit humain peut trouver difficile à accomplir même après avoir lu toute l’œuvre poétique française. Le champ des possibles est très vaste et ceci est un bon début.</p><p>Si vous avez apprécié cet article, n’oubliez pas de l’applaudir!</p><p>N’hésitez à visiter mon code <a href="https://github.com/AmelNozieres/NLP_Generate_poems/blob/master/Generate_Baudelaire_poem_TF.ipynb">ici</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4de4aa829b6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NLP in Tensorflow: Generate an Ed sheeran song]]></title>
            <link>https://medium.com/data-science/nlp-in-tensorflow-generate-an-ed-sheeran-song-8f99fe76662d?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f99fe76662d</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[rnn]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Tue, 29 Sep 2020 15:06:00 GMT</pubDate>
            <atom:updated>2020-11-27T16:01:01.122Z</atom:updated>
            <content:encoded><![CDATA[<h3>NLP in Tensorflow</h3><h4>Generate an Ed Sheeran song</h4><p>Writing a song is one of the hardest tasks ever. In this article, I’ll walk you through my experience to code a model that will learn some Ed Sheeran songs and try to create some first sentences for a song. I’m well aware here that it should be better to make a model that creates audio and not just a poem because the work of Ed Sheeran is mainly catchy rhythms that stick in our minds. However, I didn’t want to create Shakespeare’s text. I wanted something more modern. It should be awesome to create song lyrics with its audio band but let’s focus here to create lyrics first, one step at a time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*l8RXXyEZn3TuNksChKl0TQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@photoshobby?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Photos Hobby</a> on <a href="https://unsplash.com/s/photos/robot?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Let’s dive in!</p><p>For the basics concepts of my code please take a look at my article <a href="https://medium.com/@amel.nozieres/nlp-in-tensorflow-sentiment-analysis-55e27663685b">NLP in Tensorflow: Sentiment analysis</a></p><p>So first of all, let’s import the libraries and the source file of some Ed Sheeran’s songs. I took the two last albums to start our training. You can find it on my Github <a href="https://github.com/AmelNozieres/NLP_Generate_poems/blob/master/Ed_sheeran_songs">here</a>.</p><p>After tokenization, sequencing, and padding we’re ready to predict. Generating a text is predicting for each next word which word from our corpus would it be. An almost simple multi-class prediction isn’t it?! Yeah almost!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59c0d2f68774ad47f0ca1fbdaf8ca642/href">https://medium.com/media/59c0d2f68774ad47f0ca1fbdaf8ca642/href</a></iframe><p>So let’s build a simple model. We start with an Embedding layer. Please see my previous article about <a href="https://medium.com/@amel.nozieres/nlp-in-tensorflow-sentiment-analysis-55e27663685b">embedding</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8862534ec77c29e2a7ee2db3d354de3d/href">https://medium.com/media/8862534ec77c29e2a7ee2db3d354de3d/href</a></iframe><p>With the embedding, we got for each word a vector. The vectors are sorted by distance. For example ‘The grass is …’ the next word prediction should be ‘green’. Simple! But sometimes you need information at the start of the paragraph. So how we parse our sentences and keep in memory the previous words whatever the number of sentences before.</p><p>The answer is RNN- Recurrent Neural Networks. It comes in handy for a sequence of frames in a video, text as a sequence of words, music as a sequence of notes. So sequence data in general needs RNN. Please read the fundamental article of Christopher Olah about <a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/">Understanding LSTM Networks</a> and The <a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/">Unreasonable Effectiveness of Recurrent Neural Networks</a> by Andrej Karpathy for more information.</p><p>If you’re not interested in the math or the theory behind the RNN and LSTM, feel free to skip to the end of the article but I wish you’ll find this as amazing and exciting as me to learn the magic of math behind the AI.</p><p>Briefly, an RNN is a neural network where each cell has the hidden information coming from the previous cell as one of its entries. Here three nods with a tanh activation function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vODZnovJafo8L_qZ-Tk1xQ.png" /><figcaption>image from<a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/"> Christopher Olah blog</a></figcaption></figure><p>In theory, this should get a good memory of the context but it doesn’t. This is explained by the vanishing gradient problem. Indeed to measure the quality of our prediction, we need to know the difference between the output cell- the prediction vector (calculated by the succession of activation function of weight times previous cell output adding the bias- this is the forward propagation by the way) and the actual vector. In our case, the output is the prediction of a word. So the prediction vector minus the actual vector gives us the loss value or the error value. The smaller is this difference, the closer our prediction is. Minimizing this error is maximizing the accuracy of our prediction by improving our weight values (the ability of learning). In math, to minimize a function we compute the partial derivatives and we do that from the last node to the first one. This is the back-propagation. We’re back-propagating an error gradient across every layer. Usually, the gradient is so small that the derivative gets smaller and smaller and so vanishing. So the magnitude to change the weight values is more effective in the last nodes when we start the back-propagation than the first nodes. So we cannot remember the gradient magnitude as we back-propagate. So how we remember the gradient across the nodes?<br>Here comes the LSTM, the gold star of RNN!</p><h3>LSTM</h3><p>LSTM or Long Short Term Memory. For each RNN cell, we replace it with an LSTM cell like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5W8FrASMi93Z81NlAui4w.png" /><figcaption>image from<a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/"> Christopher Olah blog</a></figcaption></figure><p>In each cell, we make a little neural network with its metrics able to learn what to remember and what to pay attention to based on the gradient descent. Isn’t it amazing?!</p><h3>The model</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8862534ec77c29e2a7ee2db3d354de3d/href">https://medium.com/media/8862534ec77c29e2a7ee2db3d354de3d/href</a></iframe><p>So, back to our Ed Sheeran AI song. Our simple model is an embedding layer, a bidirectional LSTM -<em>Please read </em><a href="https://arxiv.org/pdf/1508.01991.pdf"><em>this paper</em></a><em> for more information-</em> so we parse in the past and the future of the sentences, and a dense layer to wrap it all. Let’s create songs!</p><p>So what our Ed Sheeran AI model will create from the sentence ‘What love is’:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91e228b78e54d0ad7a80b3b608ffc282/href">https://medium.com/media/91e228b78e54d0ad7a80b3b608ffc282/href</a></iframe><p>Here is the generated text:</p><pre>I don&#39;t know about me <br>know i love someone else <br>i&#39;ve either way to dress <br>that i really wanna know<br>that i&#39;ll be creeping a long time <br>a bit too way up we found love <br>right where we are <br>oh a mystery <br>a purse a time to move home <br>that could breathe <br>still oh still time can it takes to get a long</pre><p>Let’s try with “ What love is”</p><pre>What love is a blaze time <br>that it takes to give out all <br>when you stand upon my bed <br>are changed of crisps <br>but i guess that plays never leave me <br>a stage a song that i wrote <br>that mixing fitting at my erasing <br>and a song my heart is a getting ahead of a couple of days <br>a new you take a</pre><p>Not that bad for a first simple model. It can give the inspiration to rewrite it to be more accurate but it’s somehow poetic.</p><p>I will certainly add more songs to my corpus to see how it will perform. But we cannot add that much to our corpus before running into memory saturation.</p><p>You can find my code on Github <a href="https://github.com/AmelNozieres/NLP_Generate_poems/blob/master/Generate_ed_sheeran_poem.ipynb">here</a>.</p><p>I hope you enjoyed this walk through code of Ed Sheeran generation songs with TensorFlow. Please give it applause if you like it. It’s a baseline, so feel free to duplicate my code and let me know what you make of it. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f99fe76662d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/nlp-in-tensorflow-generate-an-ed-sheeran-song-8f99fe76662d">NLP in Tensorflow: Generate an Ed sheeran song</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NLP in Tensorflow: Sentiment Analysis]]></title>
            <link>https://medium.com/swlh/nlp-in-tensorflow-sentiment-analysis-55e27663685b?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/55e27663685b</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Mon, 28 Sep 2020 08:44:55 GMT</pubDate>
            <atom:updated>2021-11-18T15:27:36.964Z</atom:updated>
            <content:encoded><![CDATA[<p>Natural Language Processing is making the machine able to understand and speak human language. With the Tensorflow libraries, it is possible to make it work in a few lines of code. Let me show you how!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0PH-FYpX5NHxAR7YBkcPQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@askkell?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andy Kelly</a> on <a href="https://unsplash.com/s/photos/human-robot?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this article, we will focus on understanding the human language step. Making an algorithm classify reviews or categorize articles is amazing. Let me walk you through this exciting field by explaining the basics.<br>You can find my code on GitHub<a href="https://github.com/AmelNozieres/NLP_CLASSIFY_IMDB_REVIEWS_TF/blob/master/NLP_TF_Sentiment_Analysis_IMDB%20.ipynb"> here</a>.</p><p>In this article we will write an algorithm that classifies movie reviews: positive or negative, we will train it on an already labeled comment dataset. Tensorflow has included databases ready to be playing with. Here we will work with the IMDB database reviews created for sentiment analysis.<br>Let’s dive into it!</p><h3><strong>Load the libraries and the database</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/574807b764988483778dc28d401d749e/href">https://medium.com/media/574807b764988483778dc28d401d749e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usmbSd4t3PpNpSAA6h8SwA.png" /></figure><p>Now we need to split our data into training and testing data. Here, it is a 50/50 split.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/604a9cdf4b53952f71045c439b472358/href">https://medium.com/media/604a9cdf4b53952f71045c439b472358/href</a></iframe><p>Let’s print an example of a training comment and its label:</p><pre>training_sentences[0]</pre><pre>&#39;b&quot;This was an absolutely terrible movie. Don\&#39;t be lured in by Christopher Walken or Michael Ironside. Both are great actors, but this must simply be their worst role in history. Even their great acting could not redeem this movie\&#39;s ridiculous storyline. This movie is an early nineties US propaganda piece. The most pathetic scenes were those when the Columbian rebels were making their cases for revolutions. Maria Conchita Alonso appeared phony, and her pseudo-love affair with Walken was nothing but a pathetic emotional plug in a movie that was devoid of any real meaning. I am disappointed that there are movies like this, ruining actor\&#39;s like Christopher Walken\&#39;s good name. I could barely sit through it.&quot;&#39;</pre><pre>training_labels[0]</pre><pre>0</pre><p>So now we have training and testing data. But we are not ready to feed it to a machine learning model yet. So how to make it process the words and even the letters? This is our first step.</p><h3><strong>Tokenization</strong></h3><p>Tokenization in general is parsing the text and storing the tokens separated by a blank(here it is adequate for English, it must be wrong for another language). In TensorFlow, tokenization is the process that attributes to each word a number. For each word, the algorithm will give an identification. This is done by sorting the words by their occurrence in our training data. For example, 1 is attributed to the word ‘the’.<br>Now we have a dictionary where the keys are the words and the values are the numbers. Each sentence is a sequence of words. We need to convert it into a sequence of numbers before feeding it to any algorithm.<br>Before the tokenization, we will put our parameters in variables so we can modify them easily to improve our model. I will go through them below. So here are the lines for tokenization in TensorFlow:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1980a8ca5b905a5913d320c5d3db52ec/href">https://medium.com/media/1980a8ca5b905a5913d320c5d3db52ec/href</a></iframe><p>We create a Tokenizer object. We call on it the fit_on_texts so it will parse our data and create the association numbers by occurrence. Now word_index stores these associations as a dictionary.</p><h3><strong>Sequencing</strong></h3><p>In a sentence, we will replace each word with its number(remember the values in our dictionary) and store it as a list. For example: ‘I love Matrix’ will be stored as [3,5,9].<br>And we build a dictionary or a corpus with all the words encountered in the training data. When we see a new word, we replace it with ‘OOV’ — Out Of Vocabulary or ‘UNK’ — Unknown.<br>After fit_on_texts, we call the texts_to_sequences on our training and testing data to store the sequences of word indexes. In mathematical words, we store little vectors of each word in a big matrix. How wonderful is that!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/738316c5d5e982ce1e6dbf0c06c4f3be/href">https://medium.com/media/738316c5d5e982ce1e6dbf0c06c4f3be/href</a></iframe><h3><strong>Padding</strong></h3><p>Our sentences don’t have the same length, So our matrix (list of lists of words indexes) will not have the same shape. Models don’t like that. So we need to normalize their length. And here comes the padding. We add zeroes at the end or at the beginning of our sequence to make it the same length as the longest sentence in our data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d09186432bea345b14656dd1395db83/href">https://medium.com/media/3d09186432bea345b14656dd1395db83/href</a></iframe><p>So now our training and testing texts are stored in the right format but how to make the model understand the meaning of words?</p><h3><strong>Embedding</strong></h3><p>This is the core of teaching the machine our language. The idea is to give each word of our corpus a vector. By sorting the distance between these vectors- using the euclidean distance to make it simple. We can create clusters of meaning. For example ‘Apple’ and ‘Orange’ should be in the same cluster of fruits.<br>So the more our corpus is big, the more the interpretation will be accurate. The backward of this processing is the machine will learn from the human language tendency to sexism or racism. For example, woman is associated with a nurse and man with doctors. It isn’t our dilemma here. This will be for another article. The second side effect is memory utilization. Parsing and memorizing big corpus need powerful machines.</p><p>But let’s focus now on the process. When scanning the sentences, the algorithm will be able to create associations by making pools of vectors that are near each other.<br>In TensorFlow, the embedding is available as a layer on a machine learning model. It will dynamically scan the text.</p><h3><strong>The model</strong></h3><p>Let’s make it simple. Our model is a sequential model starting with an embedding layer. Followed by a Flatten layer, and two Dense layers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bc54b0dda84db77064aa99142568752/href">https://medium.com/media/3bc54b0dda84db77064aa99142568752/href</a></iframe><p>Let’s look to the summary of our model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*u4QklxRgozy7aWgwgwLlRA.png" /><figcaption>Summary model</figcaption></figure><h3>Training our model</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/214011ad1bd867a604b2414ea5a7f593/href">https://medium.com/media/214011ad1bd867a604b2414ea5a7f593/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGWNEOwKY7cbEPWTG2gzzg.png" /><figcaption>model training</figcaption></figure><p>Here we can see the model is over-fitting but let’s try to predict for new comments anyway.</p><h3>Let’s predict!</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73fb82bc7b72f128808c79c5d11e6575/href">https://medium.com/media/73fb82bc7b72f128808c79c5d11e6575/href</a></iframe><p>Here are the predictions:</p><pre>Review:I loved this movie. sentiment:[0.7176274]<br><br>Review:This film is so boring. sentiment:[0.52462786]<br><br>Review:This movie is so hilarious. I had a really great time! sentiment:[0.83763087]<br><br>Review:Very linear scenario, no surprises at all sentiment:[0.8178184]<br><br>Review:Another amazing addition to the franchise with good story arcs and standalone episodes. sentiment:[0.6473206]<br><br>Review:Not for the hardened not even the casual fans. sentiment:[0.96109796]</pre><p>Here we can see that our model is doing pretty well but it is a basic model. So for the last comments, it isn’t predicting correctly. But in a few lines with TensorFlow, we’re able to have a baseline model that certainly we’ll inspire you.<br>Happy coding!</p><h3>Conclusion</h3><p>In this article, we covered some basic themes of NLP and we wrote a simple code to predict sentiment from a text. This is the first step in making the machine understands our language. I hope you can feel how exciting this is.<br>Thank you for reading!</p><p><a href="https://github.com/AmelNozieres/NLP_CLASSIFY_IMDB_REVIEWS_TF/blob/master/NLP_TF_Sentiment_Analysis_IMDB%20.ipynb">Here</a> is my code on Github.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55e27663685b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/nlp-in-tensorflow-sentiment-analysis-55e27663685b">NLP in Tensorflow: Sentiment Analysis</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NLP avec Tensorflow: Analyse de sentiments]]></title>
            <link>https://amel-nozieres.medium.com/nlp-avec-tensorflow-analyse-de-sentiments-13c47984d9fb?source=rss-900ab8a4e6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/13c47984d9fb</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Amal Laouaj Nozieres]]></dc:creator>
            <pubDate>Wed, 05 Aug 2020 16:27:51 GMT</pubDate>
            <atom:updated>2020-11-27T19:21:19.482Z</atom:updated>
            <content:encoded><![CDATA[<p>Natural Language Processing ou traitement automatique du langage est le domaine de l’intelligence artificielle qui permet à la machine de comprendre notre langage humain et même de répondre à nos requêtes en langage humain. Nos commentaires sur Twitter ou Facebook peuvent avoir des nuances de sarcasmes et d’ironie et ce qui est formidable c’est que nous pouvons entraîner notre algorithme à les reconnaître. Avec les librairies Tensorflow de google, ceci devient possible en quelque lignes de code et gratuitement. N’est ce pas extraordinaire?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0PH-FYpX5NHxAR7YBkcPQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@askkell?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andy Kelly</a> on <a href="https://unsplash.com/s/photos/human-robot?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Dans cet article, nous allons voir l’une des premières étapes de la compréhension du langage. Nous allons classifier des avis de films de la base de données IMDB. Tensorflow intègre une base de données de commentaires qui proviennent du site IMDB. Les commentaires sont déjà nettoyés et pré-traités et donc prêts à être utilisés. Ils ont été labellisés c-à-d qu’à chaque commentaire de la base de données nous avons un booléen associé : 0 ou 1 qui correspondent à avis négatif ou positif respectivement.</p><p>Commençons le code:</p><h3><strong>Charger les librairies et la base de données</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/574807b764988483778dc28d401d749e/href">https://medium.com/media/574807b764988483778dc28d401d749e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usmbSd4t3PpNpSAA6h8SwA.png" /></figure><p>Maintenant on sépare les données en une partie pour entraîner l’algorithme et une partie pour le tester. Donc l’algorithme ne verra que ce qu’il y a dans la partie pour l’entraînement. Toutefois il ne faudra pas oublier d’appliquer les mêmes modifications et traitements aux deux parties de la base de données pour que les prédictions de notre algorithme restent cohérentes.</p><p>Ici nous divisons en moitiés égales.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/604a9cdf4b53952f71045c439b472358/href">https://medium.com/media/604a9cdf4b53952f71045c439b472358/href</a></iframe><p>Voici un exemple d’avis et de sa labellisation</p><pre>training_sentences[0]<br>&#39;b&quot;This was an absolutely terrible movie. Don\&#39;t be lured in by Christopher Walken or Michael Ironside. Both are great actors, but this must simply be their worst role in history. Even their great acting could not redeem this movie\&#39;s ridiculous storyline. This movie is an early nineties US propaganda piece. The most pathetic scenes were those when the Columbian rebels were making their cases for revolutions. Maria Conchita Alonso appeared phony, and her pseudo-love affair with Walken was nothing but a pathetic emotional plug in a movie that was devoid of any real meaning. I am disappointed that there are movies like this, ruining actor\&#39;s like Christopher Walken\&#39;s good name. I could barely sit through it.&quot;&#39;</pre><pre>training_labels[0]<br>0</pre><p>Maintenant que nos sets de données sont prêts, nous pouvons traiter les mots puis les phrases pour que ce soit dans un format d’entrée à un réseau de neurones.</p><p>Comment décomposer les mots et les phrases?</p><h3>Tokenisation</h3><p>La tokenisation est la découpe du texte en unité élémentaire — des tokens. Dans notre cas, vu que les données sont en anglais. Nous allons parcourir le texte et les séparer suivant les espaces en petites unités, ici ce sera les mots. Dans Tensorflow, lors de la tokenisation, chaque mot est attribué à un nombre, suivant la récurrence de ce mots dans notre texte et non dans le langage en général. Donc, les mots que la machine va rencontrer le plus souvent seront attribués aux premiers nombres. A la fin de la tokenisation nous obtenons un dictionnaire de tous les mots de notre texte avec leur association nombre.</p><p>Avant d’écrire le code de la tokenisation, nous allons stocker tous les paramètres qui nous permettront par la suite d’ajuster notre réseaux de neurones. Je les présenterai au fur et à mesure du code.</p><p>Voici le code pour faire la tokenisation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1980a8ca5b905a5913d320c5d3db52ec/href">https://medium.com/media/1980a8ca5b905a5913d320c5d3db52ec/href</a></iframe><p>Nous initions un objet de la classe Tokenizer puis nous appliquons la fonction fit_on_texts qui parcourt le texte et associe à chaque token-mot un nombre selon sa récurrence dans le texte. Donc à la fin word_index est notre index de mots et leurs identifiants nombres.</p><h3>Séquençage</h3><p>Le séquençage est l’étape suivante. Nous parcourons le texte et nous remplaçons chaque mots par son identifiant nombre et nous stockons le tout dans l’ordre de la phrase dans des vecteurs ou liste de nombre. Si le mot rencontré n’est pas connu, nous le remplaçons par ‘OOV’ Out Of Vocabulary — en dehors du vocabulaire ou ‘UNK’ Unknown — inconnu.</p><p>Dans Tensorflow nous appelons la fonctions texts_to_sequences sur nos deux sets de données et stockons la séquence de nombres</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/738316c5d5e982ce1e6dbf0c06c4f3be/href">https://medium.com/media/738316c5d5e982ce1e6dbf0c06c4f3be/href</a></iframe><h3>Padding ou le remplissage</h3><p>Nous disposons maintenant de séquence qui sont donc des matrices de différentes tailles. Le réseau de neuronnes n’acceptent pas cette différence de taille et donc nous devons procéder à une normalisation des tailles; ceci simplement en rajoutons des zéros au début ou à la fin du vecteurs. Selon le paramètre cité au-dessus trunc-type = ‘post’ nous allons rajouter ou remplir les vecteurs en rajoutant les zéros à la fin des vecteurs de manière à avoir tous les vecteurs qui font la longueur de la phrase ou séquence la plus longue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d09186432bea345b14656dd1395db83/href">https://medium.com/media/3d09186432bea345b14656dd1395db83/href</a></iframe><p>Maintenant que nous avons traduits les mots en nombres et stockées dans des matrices de même taille comment saisir le contexte dans lequel sont utilisés les mots et donc comment comprendre la signification du mot et surtout de la phrase?</p><h3>Plongements de mots ou Word Embedding</h3><p>La solution est le cœur de ce merveilleux domaine. Elle consiste à donner à chaque mot un vecteur. Nous regroupons les vecteurs par distance entre eux. Nous pouvons utiliser la distance euclidienne. Par la suite nous regroupons les vecteurs par distance et créons des groupes de sens. Ainsi ‘pomme” et ‘poire’ doivent être dans le même groupe de mots ‘fruits’. Aussi les contraires sont représentés par des vecteurs opposés -angle 180 de même taille.</p><p>L’un des inconvénients de cette méthode est la qualité du texte. Si par exemple nous entraînons notre algorithme sur des données récoltées dans le web, nous pouvons apprendre à la machine du sexisme ou du racisme. Par exemple pour un nom commun qui va apparaître plusieurs fois comme étant un méchant ou un mauvais caractère va être stocké comme tel. Ainsi un algorithme, sans intervention humaine, à la phrase</p><p>“ L’homme est docteur et la femme est …”</p><p>la machine répond “infirmière”.</p><p>L’intervention de celui qui code est primordial dans ce cas. Mais ce n’est pas le sujet de cet article.</p><p>Dans tensorflow le embedding ou le plongement de mot est disponible de façon dynamique comme première couche de traitement.</p><h3>Notre modèle -réseau de neurones</h3><p>Écrivons un modèle très simple qui pourrait servir comme modèle de référence à améliorer. Nous commençons par une couche de Embedding, suivi d’un Flatten pour aplatir et mettre tous les neurones sur une seule lignes et enfin deux couches de Dense de neurones interconnectés. Nous appliquons la fonction sigmoid (1/1+e-x) au dernier nœud pour calculer la probabilités que l’avis soit négatif ou positif. Plus la probabilité se rapproche de 1, plus l’avis est positif. Nous pouvons définir un seuil, ici j’ai choisi au dessus 0.7 pour déterminer les avis positifs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bc54b0dda84db77064aa99142568752/href">https://medium.com/media/3bc54b0dda84db77064aa99142568752/href</a></iframe><p>voici le sommaire de notre réseau de neurone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*u4QklxRgozy7aWgwgwLlRA.png" /></figure><h3>Entrainement du modèle</h3><p>Notre réseau de neurones ou modèle est prêt à recevoir nos données.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*bUwEbv_ms-YaFTgIUlqN5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGWNEOwKY7cbEPWTG2gzzg.png" /></figure><p>A la fin de l’entraînement nous avons une précision de 80% sur les données de test jamais vues par le modèle. Ce qui n’est pas trop mal mais vu que la précision est de 1 sur les données d’entraînement, c’est que notre modèle est en sur-apprentissage c-à-d qu’il colle trop parfaitement à la distribution des données de l’entraînement pour être flexible pour les nouvelles données mais qu’importe le but de cet article était de développer un réseau de neurones rapidement. Testons le avec nos propres commentaires en anglais forcément.</p><h3>Prédictions</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73fb82bc7b72f128808c79c5d11e6575/href">https://medium.com/media/73fb82bc7b72f128808c79c5d11e6575/href</a></iframe><p>et voici les résultats</p><pre>Review:I loved this movie. sentiment:[0.7176274]<br><br>Review:This film is so boring. sentiment:[0.52462786]<br><br>Review:This movie is so hilarious. I had a really great time! sentiment:[0.83763087]<br><br>Review:Very linear scenario, no surprises at all sentiment:[0.8178184]<br><br>Review:Another amazing addition to the franchise with good story arcs and standalone episodes. sentiment:[0.6473206]<br><br>Review:Not for the hardened not even the casual fans. sentiment:[0.96109796]</pre><p>J’ai rentré 6 phrases et à la fin nous remarquons que 2 phrases n’ont pas été classées correctement. Après plusieurs tests, on voit que le modèle arrive assez bien pour les phrases claires mais se trompe dans les tournures de style comme ‘Very linear scenario’ . Le programme ne détecte pas qu’un scénario linéaire est mauvais mais globalement il a des résultats corrects pour un jet de quelques lignes de code.</p><h3>Conclusion</h3><p>Dans cet article nous avons vu les bases du traitement automatique du langage et grâce à Tensorflow avons écrit un simple code en quelque lignes pour prédire la classification des avis.</p><p>Si cet article vous a inspiré, n’oubliez pas de l’applaudir.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13c47984d9fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>