{
  "id": 704987,
  "title": "From Orders to Menu Items with TF-IDF and Logistic Regression",
  "content": "<h2>Overview</h2>\n<p>Our solution approached the problem as a text classification task rather than a structured JSON generation problem.</p>\n<p>Instead of directly predicting the complete expected JSON output, we observed that the first item in the target JSON often represented the primary product requested in the customer order. We therefore extracted this product name and trained a classifier to predict it directly from the natural language order text.</p>\n<p>The final pipeline consisted of:</p>\n<ul>\n<li>Label extraction from JSON targets</li>\n<li>TF-IDF text vectorization</li>\n<li>Multiclass Logistic Regression classification</li>\n</ul>\n<p>This approach was intentionally simple, computationally efficient, and easy to reproduce.</p>\n<hr>\n<h2>Data Preparation</h2>\n<p>The training dataset contained:</p>\n<ul>\n<li>500 training samples</li>\n<li>3,500 test samples</li>\n</ul>\n<p>Each training example included:</p>\n<ul>\n<li><code>order</code> (customer request in natural language)</li>\n<li><code>expected_json</code> (structured target output)</li>\n</ul>\n<p>We extracted the first item name from the JSON structure and used it as the prediction target.</p>\n<p>Example:</p>\n<pre><code>{\n  \"items\": [\n    {\n      \"name\": \"Caramel Macchiato\"\n    }\n  ]\n}\n</code></pre>\n<p>became:</p>\n<pre><code>Label = \"Caramel Macchiato\"\n</code></pre>\n<p>The extraction was implemented using a simple JSON parser.</p>\n<hr>\n<h2>Label Distribution</h2>\n<p>After extraction, the dataset contained multiple beverage and food categories such as:</p>\n<ul>\n<li>Caramel Macchiato</li>\n<li>Flat White</li>\n<li>Chai Latte</li>\n<li>Americano</li>\n<li>Drip Coffee</li>\n<li>Bagel</li>\n<li>Blueberry Muffin</li>\n</ul>\n<p>The label distribution was relatively balanced, making multiclass classification feasible without special re-weighting.</p>\n<hr>\n<h2>Feature Engineering</h2>\n<p>Order text was transformed using TF-IDF features.</p>\n<p>Configuration:</p>\n<pre><code>TfidfVectorizer(\n    ngram_range=(1, 2),\n    max_features=30000,\n    stop_words=\"english\"\n)\n</code></pre>\n<p>Key choices:</p>\n<h3>Unigrams</h3>\n<p>Capture individual menu keywords:</p>\n<pre><code>latte\namericano\nbagel\nmocha\n</code></pre>\n<h3>Bigrams</h3>\n<p>Capture menu phrases:</p>\n<pre><code>flat white\nchai latte\ncaramel macchiato\n</code></pre>\n<p>Bigrams were particularly important because many products are naturally expressed as multi-word names.</p>\n<hr>\n<h2>Model</h2>\n<p>We trained a multiclass Logistic Regression model:</p>\n<pre><code>LogisticRegression(\n    max_iter=1000,\n    n_jobs=-1\n)\n</code></pre>\n<p>Reasons for choosing Logistic Regression:</p>\n<ul>\n<li>Strong baseline for sparse TF-IDF features</li>\n<li>Fast training</li>\n<li>Good performance on small datasets</li>\n<li>Minimal hyperparameter tuning required</li>\n</ul>\n<p>The model learns associations between words in the order text and product labels.</p>\n<p>For example:</p>\n<pre><code>\"large caramel macchiato\"\n</code></pre>\n<p>is mapped toward the</p>\n<pre><code>Caramel Macchiato\n</code></pre>\n<p>class.</p>\n<hr>\n<h2>Inference Pipeline</h2>\n<p>The final prediction pipeline was:</p>\n<pre><code>Order Text\n      ↓\nTF-IDF Vectorization\n      ↓\nLogistic Regression\n      ↓\nPredicted Product\n      ↓\nSubmission File\n</code></pre>\n<p>The trained model was applied to all test orders, and predicted product names were written into the submission file.</p>\n<hr>\n<h2>Why This Worked</h2>\n<p>Several properties of the dataset favored this approach:</p>\n<ol>\n<li><p>Product names were often explicitly mentioned in customer orders.</p></li>\n<li><p>TF-IDF effectively captured discriminative menu keywords.</p></li>\n<li><p>Logistic Regression performs well on sparse text representations.</p></li>\n<li><p>The training set was relatively small, making lightweight linear models competitive.</p></li>\n</ol>\n<hr>\n<h2>Limitations</h2>\n<p>This solution has several limitations:</p>\n<ul>\n<li>Only the first item from the JSON target was modeled.</li>\n<li>Multiple-item orders were ignored.</li>\n<li>Customizations and modifiers were not captured.</li>\n<li>No attempt was made to reconstruct the complete structured JSON output.</li>\n</ul>\n<p>Future work could involve:</p>\n<ul>\n<li>Sequence-to-sequence generation models</li>\n<li>Transformer-based text encoders</li>\n<li>Structured prediction of full order JSON</li>\n<li>Ensemble methods combining classification and generation</li>\n</ul>\n<hr>\n<h2>Conclusion</h2>\n<p>We transformed the problem into a multiclass text classification task by extracting the primary item from each target JSON. Using TF-IDF features and Logistic Regression, we obtained a simple, efficient, and interpretable solution that served as a strong baseline for the competition.</p>\n<hr>",
  "comments": [],
  "comment_count": 0,
  "messages": [
    {
      "id": 3468015,
      "postDate": "2026-06-08T08:27:03.743Z",
      "content": "<h2>Overview</h2>\n<p>Our solution approached the problem as a text classification task rather than a structured JSON generation problem.</p>\n<p>Instead of directly predicting the complete expected JSON output, we observed that the first item in the target JSON often represented the primary product requested in the customer order. We therefore extracted this product name and trained a classifier to predict it directly from the natural language order text.</p>\n<p>The final pipeline consisted of:</p>\n<ul>\n<li>Label extraction from JSON targets</li>\n<li>TF-IDF text vectorization</li>\n<li>Multiclass Logistic Regression classification</li>\n</ul>\n<p>This approach was intentionally simple, computationally efficient, and easy to reproduce.</p>\n<hr>\n<h2>Data Preparation</h2>\n<p>The training dataset contained:</p>\n<ul>\n<li>500 training samples</li>\n<li>3,500 test samples</li>\n</ul>\n<p>Each training example included:</p>\n<ul>\n<li><code>order</code> (customer request in natural language)</li>\n<li><code>expected_json</code> (structured target output)</li>\n</ul>\n<p>We extracted the first item name from the JSON structure and used it as the prediction target.</p>\n<p>Example:</p>\n<pre><code>{\n  \"items\": [\n    {\n      \"name\": \"Caramel Macchiato\"\n    }\n  ]\n}\n</code></pre>\n<p>became:</p>\n<pre><code>Label = \"Caramel Macchiato\"\n</code></pre>\n<p>The extraction was implemented using a simple JSON parser.</p>\n<hr>\n<h2>Label Distribution</h2>\n<p>After extraction, the dataset contained multiple beverage and food categories such as:</p>\n<ul>\n<li>Caramel Macchiato</li>\n<li>Flat White</li>\n<li>Chai Latte</li>\n<li>Americano</li>\n<li>Drip Coffee</li>\n<li>Bagel</li>\n<li>Blueberry Muffin</li>\n</ul>\n<p>The label distribution was relatively balanced, making multiclass classification feasible without special re-weighting.</p>\n<hr>\n<h2>Feature Engineering</h2>\n<p>Order text was transformed using TF-IDF features.</p>\n<p>Configuration:</p>\n<pre><code>TfidfVectorizer(\n    ngram_range=(1, 2),\n    max_features=30000,\n    stop_words=\"english\"\n)\n</code></pre>\n<p>Key choices:</p>\n<h3>Unigrams</h3>\n<p>Capture individual menu keywords:</p>\n<pre><code>latte\namericano\nbagel\nmocha\n</code></pre>\n<h3>Bigrams</h3>\n<p>Capture menu phrases:</p>\n<pre><code>flat white\nchai latte\ncaramel macchiato\n</code></pre>\n<p>Bigrams were particularly important because many products are naturally expressed as multi-word names.</p>\n<hr>\n<h2>Model</h2>\n<p>We trained a multiclass Logistic Regression model:</p>\n<pre><code>LogisticRegression(\n    max_iter=1000,\n    n_jobs=-1\n)\n</code></pre>\n<p>Reasons for choosing Logistic Regression:</p>\n<ul>\n<li>Strong baseline for sparse TF-IDF features</li>\n<li>Fast training</li>\n<li>Good performance on small datasets</li>\n<li>Minimal hyperparameter tuning required</li>\n</ul>\n<p>The model learns associations between words in the order text and product labels.</p>\n<p>For example:</p>\n<pre><code>\"large caramel macchiato\"\n</code></pre>\n<p>is mapped toward the</p>\n<pre><code>Caramel Macchiato\n</code></pre>\n<p>class.</p>\n<hr>\n<h2>Inference Pipeline</h2>\n<p>The final prediction pipeline was:</p>\n<pre><code>Order Text\n      ↓\nTF-IDF Vectorization\n      ↓\nLogistic Regression\n      ↓\nPredicted Product\n      ↓\nSubmission File\n</code></pre>\n<p>The trained model was applied to all test orders, and predicted product names were written into the submission file.</p>\n<hr>\n<h2>Why This Worked</h2>\n<p>Several properties of the dataset favored this approach:</p>\n<ol>\n<li><p>Product names were often explicitly mentioned in customer orders.</p></li>\n<li><p>TF-IDF effectively captured discriminative menu keywords.</p></li>\n<li><p>Logistic Regression performs well on sparse text representations.</p></li>\n<li><p>The training set was relatively small, making lightweight linear models competitive.</p></li>\n</ol>\n<hr>\n<h2>Limitations</h2>\n<p>This solution has several limitations:</p>\n<ul>\n<li>Only the first item from the JSON target was modeled.</li>\n<li>Multiple-item orders were ignored.</li>\n<li>Customizations and modifiers were not captured.</li>\n<li>No attempt was made to reconstruct the complete structured JSON output.</li>\n</ul>\n<p>Future work could involve:</p>\n<ul>\n<li>Sequence-to-sequence generation models</li>\n<li>Transformer-based text encoders</li>\n<li>Structured prediction of full order JSON</li>\n<li>Ensemble methods combining classification and generation</li>\n</ul>\n<hr>\n<h2>Conclusion</h2>\n<p>We transformed the problem into a multiclass text classification task by extracting the primary item from each target JSON. Using TF-IDF features and Logistic Regression, we obtained a simple, efficient, and interpretable solution that served as a strong baseline for the competition.</p>\n<hr>",
      "rawMarkdown": "## Overview\n\nOur solution approached the problem as a text classification task rather than a structured JSON generation problem.\n\nInstead of directly predicting the complete expected JSON output, we observed that the first item in the target JSON often represented the primary product requested in the customer order. We therefore extracted this product name and trained a classifier to predict it directly from the natural language order text.\n\nThe final pipeline consisted of:\n\n* Label extraction from JSON targets\n* TF-IDF text vectorization\n* Multiclass Logistic Regression classification\n\nThis approach was intentionally simple, computationally efficient, and easy to reproduce.\n\n---\n\n## Data Preparation\n\nThe training dataset contained:\n\n* 500 training samples\n* 3,500 test samples\n\nEach training example included:\n\n* `order` (customer request in natural language)\n* `expected_json` (structured target output)\n\nWe extracted the first item name from the JSON structure and used it as the prediction target.\n\nExample:\n\n```json\n{\n  \"items\": [\n    {\n      \"name\": \"Caramel Macchiato\"\n    }\n  ]\n}\n```\n\nbecame:\n\n```text\nLabel = \"Caramel Macchiato\"\n```\n\nThe extraction was implemented using a simple JSON parser.\n\n---\n\n## Label Distribution\n\nAfter extraction, the dataset contained multiple beverage and food categories such as:\n\n* Caramel Macchiato\n* Flat White\n* Chai Latte\n* Americano\n* Drip Coffee\n* Bagel\n* Blueberry Muffin\n\nThe label distribution was relatively balanced, making multiclass classification feasible without special re-weighting.\n\n---\n\n## Feature Engineering\n\nOrder text was transformed using TF-IDF features.\n\nConfiguration:\n\n```python\nTfidfVectorizer(\n    ngram_range=(1, 2),\n    max_features=30000,\n    stop_words=\"english\"\n)\n```\n\nKey choices:\n\n### Unigrams\n\nCapture individual menu keywords:\n\n```text\nlatte\namericano\nbagel\nmocha\n```\n\n### Bigrams\n\nCapture menu phrases:\n\n```text\nflat white\nchai latte\ncaramel macchiato\n```\n\nBigrams were particularly important because many products are naturally expressed as multi-word names.\n\n---\n\n## Model\n\nWe trained a multiclass Logistic Regression model:\n\n```python\nLogisticRegression(\n    max_iter=1000,\n    n_jobs=-1\n)\n```\n\nReasons for choosing Logistic Regression:\n\n* Strong baseline for sparse TF-IDF features\n* Fast training\n* Good performance on small datasets\n* Minimal hyperparameter tuning required\n\nThe model learns associations between words in the order text and product labels.\n\nFor example:\n\n```text\n\"large caramel macchiato\"\n```\n\nis mapped toward the\n\n```text\nCaramel Macchiato\n```\n\nclass.\n\n---\n\n## Inference Pipeline\n\nThe final prediction pipeline was:\n\n```text\nOrder Text\n      ↓\nTF-IDF Vectorization\n      ↓\nLogistic Regression\n      ↓\nPredicted Product\n      ↓\nSubmission File\n```\n\nThe trained model was applied to all test orders, and predicted product names were written into the submission file.\n\n---\n\n## Why This Worked\n\nSeveral properties of the dataset favored this approach:\n\n1. Product names were often explicitly mentioned in customer orders.\n\n2. TF-IDF effectively captured discriminative menu keywords.\n\n3. Logistic Regression performs well on sparse text representations.\n\n4. The training set was relatively small, making lightweight linear models competitive.\n\n---\n\n## Limitations\n\nThis solution has several limitations:\n\n* Only the first item from the JSON target was modeled.\n* Multiple-item orders were ignored.\n* Customizations and modifiers were not captured.\n* No attempt was made to reconstruct the complete structured JSON output.\n\nFuture work could involve:\n\n* Sequence-to-sequence generation models\n* Transformer-based text encoders\n* Structured prediction of full order JSON\n* Ensemble methods combining classification and generation\n\n---\n\n## Conclusion\n\nWe transformed the problem into a multiclass text classification task by extracting the primary item from each target JSON. Using TF-IDF features and Logistic Regression, we obtained a simple, efficient, and interpretable solution that served as a strong baseline for the competition.\n\n---",
      "votes": 1
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-20T01:53:09Z",
  "competition_id": 128258,
  "competition_slug": "barista-bench",
  "team_id": 15267029,
  "solution_url": "/competitions/barista-bench/writeups/from-orders-to-menu-items-with-tf-idf-and-logistic"
}