{
  "source_file": "0930",
  "source_platform": "Dev.to",
  "author": "zeromathai",
  "title_listed": "Discriminative vs Generative Models: What Are You Actually Learning?",
  "keywords": "",
  "domain": "文本处理",
  "content_type": "技术教程",
  "is_paid_flag": "否",
  "url": "https://dev.to/zeromathai/discriminative-vs-generative-models-what-are-you-actually-learning-g0e",
  "publish_date": "2026-09-02",
  "corpus_stage": "",
  "notes": "",
  "id": "21b83c4b33c0",
  "collected_at": "2026-10-02T13:50:35",
  "title": "Discriminative vs Generative Models: What Are You Actually Learning? - DEV Community",
  "body_markdown": "When a supervised model maps an input to an output, it is easy to assume that every model is learning essentially the same relationship. In practice, two models can solve the same prediction problem while modeling very different probability relationships.\nA\nDiscriminative Model\nlearns the relationship needed to predict the output directly. A\nGenerative Model\ninstead models how the input is distributed for each possible output and uses that probability structure to infer the prediction.\nThe most useful question is therefore not simply, \"\"What does the model predict?\"\" but\n\"\"What probability relationship does it learn directly?\"\"\nStart with the supervised learning objective\nAt a high level, supervised learning asks us to learn a mapping from an observed input\nx\nx\nx\nto a target output\ny\ny\ny\n:\nf\n:\nx\n↦\ny\nf:x\\mapsto y\nf\n:\nx\n↦\ny\nBoth discriminative and generative approaches aim to solve this mapping problem. The difference is the probability relationship they model in order to reach the prediction.\nA compact mental model is:\nDiscriminative\nx\n│\n├── learn p(y | x)\n│\n└── choose y directly\n\nGenerative\ny\n│\n├── learn p(x | y)\n├── combine with p(y)\n│\n└── infer the best y for x\nEnter fullscreen mode\nExit fullscreen mode\nThe prediction target is the same, but the learned structure is different.\nDiscriminative Models: learn the conditional relationship directly\nA Discriminative Model focuses on the conditional probability of an output given an input:\np\n(\ny\n∣\nx\n)\np(y\\mid x)\np\n(\ny\n∣\nx\n)\nFor classification, prediction can be written as:\nf\n(\nx\n)\n=\narg\n⁡\nmax\n⁡\ny\np\n(\ny\n∣\nx\n)\nf(x)=\\arg\\max_y p(y\\mid x)\nf\n(\nx\n)\n=\nar\ng\ny\nmax\n​\np\n(\ny\n∣\nx\n)\nThe calculation flow is direct:\ninput x\n   ↓\nestimate p(y | x)\n   ↓\ncompare candidate outputs\n   ↓\nselect the most probable y\nEnter fullscreen mode\nExit fullscreen mode\nThe model focuses on the relationship needed to distinguish possible outputs from the observed input. In the input space, this leads naturally to the idea of a\ndecision boundary\n: regions of the space are associated with different outputs according to the learned predictive relationship.\nSupport Vector Machine is a representative discriminative example in this comparison. Its role here is best understood through the decision structure it learns between outputs rather than as a model of the overall probability distribution of the data.\nGenerative Models: model the input distribution for each output\nA Generative Model approaches the same supervised problem from the opposite conditional direction. Instead of directly modeling\np\n(\ny\n∣\nx\n)\np(y\\mid x)\np\n(\ny\n∣\nx\n)\n, it models:\np\n(\nx\n∣\ny\n)\np(x\\mid y)\np\n(\nx\n∣\ny\n)\nThis tells us how likely an input\nx\nx\nx\nis under a particular output\ny\ny\ny\n. The model then combines this conditional probability with the prior probability of the output,\np\n(\ny\n)\np(y)\np\n(\ny\n)\n.\nPrediction can therefore be written as:\nf\n(\nx\n)\n=\narg\n⁡\nmax\n⁡\ny\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\nf(x)=\\arg\\max_y p(x\\mid y)p(y)\nf\n(\nx\n)\n=\nar\ng\ny\nmax\n​\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\nThe calculation flow becomes:\ncandidate y\n   ↓\nevaluate p(x | y)\n   ↓\ncombine with p(y)\n   ↓\ncompare p(x | y)p(y)\n   ↓\nselect the best y\nEnter fullscreen mode\nExit fullscreen mode\nBayes rule shows how this connects back to the conditional probability used by the discriminative view:\np\n(\ny\n∣\nx\n)\n=\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\np\n(\nx\n)\np(y\\mid x)=\\frac{p(x\\mid y)p(y)}{p(x)}\np\n(\ny\n∣\nx\n)\n=\np\n(\nx\n)\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\n​\nFor a fixed input\nx\nx\nx\n, the denominator\np\n(\nx\n)\np(x)\np\n(\nx\n)\nis shared across all candidate outputs. When the goal is only to determine which output has the highest posterior probability, that common denominator does not affect the comparison.\nThis is why a Generative Model can use\np\n(\nx\n∣\ny\n)\np(x\\mid y)\np\n(\nx\n∣\ny\n)\ntogether with\np\n(\ny\n)\np(y)\np\n(\ny\n)\nto choose the appropriate output without directly modeling\np\n(\ny\n∣\nx\n)\np(y\\mid x)\np\n(\ny\n∣\nx\n)\n.\nGaussian Mixture and Bayes Nets are representative generative examples in this comparison. The important distinction is that this approach models the\nprobability distribution\ndescribing how inputs relate to possible outputs.\nThe comparison that matters\nIt is tempting to reduce the distinction to \"\"classification versus generation,\"\" but that misses the central point. In this supervised-learning setting, both approaches can predict\ny\ny\ny\nfrom\nx\nx\nx\n.\nWhat differs is what they learn directly.\nDiscriminative Model\nGenerative Model\nPrediction goal\nPredict\ny\ny\ny\nfrom\nx\nx\nx\nPredict\ny\ny\ny\nfrom\nx\nx\nx\nDirectly modeled relationship\np\n(\ny\n∣\nx\n)\np(y\\mid x)\np\n(\ny\n∣\nx\n)\np\n(\nx\n∣\ny\n)\np(x\\mid y)\np\n(\nx\n∣\ny\n)\nAdditional probability used\n—\np\n(\ny\n)\np(y)\np\n(\ny\n)\nPrediction rule\narg\n⁡\nmax\n⁡\ny\np\n(\ny\n∣\nx\n)\n\\arg\\max_y p(y\\mid x)\nar\ng\nmax\ny\n​\np\n(\ny\n∣\nx\n)\narg\n⁡\nmax\n⁡\ny\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\n\\arg\\max_y p(x\\mid y)p(y)\nar\ng\nmax\ny\n​\np\n(\nx\n∣\ny\n)\np\n(\ny\n)\nUseful structural view\nDecision boundary\nProbability distribution\nRepresentative example\nSupport Vector Machine\nGaussian Mixture, Bayes Nets\nFor developers, this distinction is useful when reading a model definition or implementation. If the model directly represents the relationship from\nx\nx\nx\nto\ny\ny\ny\n, the focus is discriminative. If it models how\nx\nx\nx\nbehaves under each\ny\ny\ny\nand combines that with\np\n(\ny\n)\np(y)\np\n(\ny\n)\n, the focus is generative.\nTakeaway\nDiscriminative and generative models can solve the same supervised prediction problem through different probabilistic views.\nA Discriminative Model directly models:\np\n(\ny\n∣\nx\n)\np(y\\mid x)\np\n(\ny\n∣\nx\n)\nA Generative Model models:\np\n(\nx\n∣\ny\n)\np(x\\mid y)\np\n(\nx\n∣\ny\n)\nand combines it with\np\n(\ny\n)\np(y)\np\n(\ny\n)\nto infer the appropriate output.\nThe key distinction is not simply\nclassification vs generation\n. It is\nwhich probability relationship the model learns directly and uses for prediction\n.\nOriginally published at zeromathai.com.\nOriginal article:\nhttps://zeromathai.com/en/discriminative-vs-generative-models-course-en/",
  "metadata": {
    "title": "Discriminative vs Generative Models: What Are You Actually Learning? - DEV Community",
    "description": "When a supervised model maps an input to an output, it is easy to assume that every model is learning... Tagged with machinelearning, generativemodels, supervisedlearning, probability.",
    "keywords": "machinelearning, generativemodels, supervisedlearning, probability, software, coding, development, engineering, inclusive, community",
    "author": null,
    "og:type": "article",
    "og:url": "https://dev.to/zeromathai/discriminative-vs-generative-models-what-are-you-actually-learning-g0e",
    "og:title": "Discriminative vs Generative Models: What Are You Actually Learning?",
    "og:description": "When a supervised model maps an input to an output, it is easy to assume that every model is learning...",
    "og:site_name": "DEV Community",
    "og:image": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa7o55dknzqnk56zzl9td.png",
    "twitter:site": "@thepracticaldev",
    "twitter:creator": "@",
    "twitter:title": "Discriminative vs Generative Models: What Are You Actually Learning?",
    "twitter:description": "When a supervised model maps an input to an output, it is easy to assume that every model is learning...",
    "twitter:card": "summary_large_image",
    "twitter:widgets:new-embed-design": "on",
    "twitter:image:src": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa7o55dknzqnk56zzl9td.png"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/21b83c4b33c0/code/body-000.txt",
      "chars": 148,
      "language": "text"
    },
    {
      "file": "attachments/21b83c4b33c0/code/body-001.txt",
      "chars": 94,
      "language": "text"
    },
    {
      "file": "attachments/21b83c4b33c0/code/body-002.txt",
      "chars": 107,
      "language": "text"
    }
  ],
  "images": [],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://zeromathai.com/en/discriminative-vs-generative-models-course-en/",
      "label": "https://zeromathai.com/en/discriminative-vs-generative-models-course-en/",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:48:15Z",
  "source_url": "https://dev.to/zeromathai/discriminative-vs-generative-models-what-are-you-actually-learning-g0e",
  "papers": [],
  "actual_video_files": [],
  "body_chars": 5857,
  "expected_body_images": 0,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/21b83c4b33c0/pages/source.html",
  "local_html": "attachments/21b83c4b33c0/pages/article.html",
  "body_base_path": "attachments/21b83c4b33c0/pages/",
  "body_markdown_path": "attachments/21b83c4b33c0/pages/article.md"
}