Retour au parcoursBack to the journey
2024 – 2025projet de MasterMaster's projectétude de cascase study

Rakuten : classer 84 916 produits en 27 catégoriesRakuten: sorting 84,916 products into 27 categories

J'ai construit un pipeline texte complet, de la donnée brute à une API conteneurisée. Chaque expérience est tracée dans MLflow.I built a full text pipeline, from raw data to a containerized API. Every experiment is tracked in MLflow.

BeautifulSoup NLTK spaCy scikit-learn MLflow FastAPI pytest Docker Compose GitHub Actions Streamlit
0,806 F1 pondéré, meilleur runweighted F1, best run
0,810 benchmark RakutenRakuten benchmark
84 916 produits · 27 classesproducts · 27 classes
7 runs comparés dans MLflowruns compared in MLflow

Le problèmeThe problem

Rakuten veut prédire le code type d'un produit (prdtypecode) à partir de sa désignation et de sa description. Les 27 classes sont très déséquilibrées : la plus grande compte 10 209 produits, la plus petite 764. 35,1 % des descriptions sont vides. Le texte mêle HTML, entités encodées et plusieurs langues.Rakuten wants to predict a product's type code (prdtypecode) from its title and description. The 27 classes are heavily imbalanced: the largest has 10,209 products, the smallest 764. 35.1% of descriptions are empty. The text mixes HTML, encoded entities and several languages.

Ce que j'ai faitWhat I did

  • J'ai fusionné désignation et description, puis nettoyé le HTML, passé le texte en minuscules, retiré les mots vides et lemmatisé chaque mot.I merged title and description, then stripped HTML, lowercased the text, removed stopwords and lemmatized every word.
  • J'ai vectorisé en TF-IDF et entraîné une régression logistique, évaluée en F1 pondéré sur 20 % de test (16 984 produits).I vectorized with TF-IDF and trained a logistic regression, scored with weighted F1 on a 20% test split (16,984 products).
  • J'ai tracé 7 runs dans MLflow pour régler la taille du vocabulaire et les n-grammes.I tracked 7 runs in MLflow to tune vocabulary size and n-grams.
  • J'ai exposé le modèle derrière une API FastAPI, testée avec pytest.I served the model behind a FastAPI API, tested with pytest.
  • J'ai conteneurisé l'API et le serveur MLflow avec Docker Compose, et branché une CI GitHub Actions.I containerized the API and the MLflow server with Docker Compose, and wired up GitHub Actions CI.
  • J'ai ajouté une démo Streamlit : contexte, distribution des classes, prédiction en direct.I added a Streamlit demo: context, class distribution, live prediction.

Les runsThe runs

vocabulairevocabulary n-grammesn-grams F1 pondéréweighted F1
complet (162 589)full (162,589)10,8040
100 00010,8051
50 00010,8056
50 0001 – 20,8046
50 0001 – 30,8028

Couper le vocabulaire à 50 000 termes fait mieux que le garder entier. Les bigrammes et trigrammes font baisser le score. Écart au benchmark Rakuten : −0,004.Capping the vocabulary at 50,000 terms beats keeping all of it. Bigrams and trigrams lower the score. Gap to the Rakuten benchmark: −0.004.

Le codeThe code

# preprocessing, puis prédiction (rakuten_api.py)
text = BeautifulSoup(text, "html.parser").get_text()
text = text.lower()
text = " ".join(w for w in text.split() if w not in stop_words)
text = " ".join(t.lemma_ for t in nlp(text))
categorie = int(model.predict(tfidf.transform([text]))[0])
$ docker-compose up --build
$ curl -X POST localhost:8000/predict \
    -H "Content-Type: application/json" \
    -d '{"text": "Jeux Nintendo Switch Mario Kart console"}'
{"categorie": …}
le dépôt completthe full repository
Me contacterGet in touch Voir le code sur GitHubSee the code on GitHub