{"id":9324,"date":"2026-08-05T11:36:11","date_gmt":"2026-08-05T02:36:11","guid":{"rendered":"https:\/\/since2020.jp\/media\/?p=9324"},"modified":"2026-08-05T11:36:12","modified_gmt":"2026-08-05T02:36:12","slug":"text-bow","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/text-bow\/","title":{"rendered":"\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5bfe\u3059\u308b\u7279\u5fb4\u91cf\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\uff08BoW\uff09"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u306f\u3058\u3081\u306b<\/h2>\n\n\n\n<p>\u5546\u54c1\u30ec\u30d3\u30e5\u30fc\u3084\u30cb\u30e5\u30fc\u30b9\u8a18\u4e8b\u3001SNS\u6295\u7a3f\u3068\u3044\u3063\u305f\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u6a5f\u68b0\u5b66\u7fd2\u30e2\u30c7\u30eb\u3067\u4f7f\u3044\u305f\u3044\u5834\u9762\u306f\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30c6\u30ad\u30b9\u30c8\u306f\u305d\u306e\u307e\u307e\u30e2\u30c7\u30eb\u306b\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u30e2\u30c7\u30eb\u304c\u6271\u3048\u308b\u306e\u306f\u6570\u5024\u3060\u3051\u306a\u306e\u3067\u3001\u6587\u7ae0\u3092\u6570\u5024\u30d9\u30af\u30c8\u30eb\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\u304c\u6700\u521d\u306e\u95a2\u9580\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30c6\u30ad\u30b9\u30c8\u306e\u30d9\u30af\u30c8\u30eb\u5316\u306b\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u4ee3\u8868\u7684\u306a\u624b\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2460\u5358\u8a9e\u306e\u51fa\u73fe\u56de\u6570\uff08BoW\uff1aBag of Words\uff09<\/li>\n\n\n\n<li>\u2461TF-IDF<\/li>\n\n\n\n<li>\u2462word2vec<\/li>\n\n\n\n<li>\u2463BERT<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u6700\u3082\u57fa\u790e\u7684\u306a\u2460BoW\u306b\u7d5e\u3063\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. BoW\uff1a\u5358\u8a9e\u306e\u51fa\u73fe\u56de\u6570\u3067\u6587\u7ae0\u3092\u6570\u5024\u5316\u3059\u308b<\/h2>\n\n\n\n<p>BoW\uff08Bag of Words\uff09\u306f\u3001\u6587\u7ae0\u3092\u300c\u3069\u306e\u5358\u8a9e\u304c\u4f55\u56de\u767b\u5834\u3057\u305f\u304b\u300d\u306b\u5909\u63db\u3059\u308b\u624b\u6cd5\u3067\u3059\u3002\u5358\u8a9e\u306e\u9806\u5e8f\u3084\u6587\u8108\u306f\u7121\u8996\u3057\u3066\u3001\u767b\u5834\u3057\u305f\u5358\u8a9e\u306e\u7a2e\u985e\u3068\u56de\u6570\u3060\u3051\u3092\u898b\u307e\u3059\u3002\u6587\u7ae0\u3092\u888b\uff08bag\uff09\u306b\u653e\u308a\u8fbc\u3093\u3067\u5358\u8a9e\u3092\u6570\u3048\u308b\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305f\u3068\u3048\u3070\u3001\u6b21\u306e3\u6587\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6587\u66f81\uff1a\u300cthe cat sat on the mat\u300d<\/li>\n\n\n\n<li>\u6587\u66f82\uff1a\u300cthe dog sat on the mat\u300d<\/li>\n\n\n\n<li>\u6587\u66f83\uff1a\u300cthe cat and the dog played\u300d<\/li>\n<\/ul>\n\n\n\n<p>BoW\u3067\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u5168\u4f53\u306b\u767b\u5834\u3059\u308b\u5168\u5358\u8a9e\u304c\u5217\u306b\u306a\u308a\u3001\u5404\u6587\u66f8\u3067\u306e\u51fa\u73fe\u56de\u6570\u304c\u884c\u306b\u4e26\u3093\u3060\u884c\u5217\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>scikit-learn\u306e <code>CountVectorizer<\/code> \u3092\u4f7f\u3046\u3068\u3001\u82f1\u8a9e\u30c6\u30ad\u30b9\u30c8\u306f\u307b\u307c\u305d\u306e\u307e\u307eBoW\u306b\u5909\u63db\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>\u30b3\u30fc\u30c9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.feature_extraction.text import CountVectorizer\nimport pandas as pd\n\ntexts = &#091;\n    \"the cat sat on the mat\",\n    \"the dog sat on the mat\",\n    \"the cat and the dog played\",\n]\n\nvectorizer = CountVectorizer()\nX = vectorizer.fit_transform(texts)\n\ndf_bow = pd.DataFrame(\n    X.toarray(),\n    columns=vectorizer.get_feature_names_out(),\n    index=&#091;\"\u6587\u66f81\", \"\u6587\u66f82\", \"\u6587\u66f83\"],\n)\n\ndf_bow.head()\n<\/code><\/pre>\n\n\n\n<p><strong>\u51fa\u529b\u7d50\u679c<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"283\" height=\"103\" src=\"https:\/\/since2020.jp\/media\/wp-content\/uploads\/2026\/08\/image.png\" alt=\"\" class=\"wp-image-9325\" \/><\/figure>\n\n\n\n<p>\u5404\u884c\u304c1\u6587\u66f8\u3092\u8868\u3057\u3001\u5024\u306f\u305d\u306e\u5358\u8a9e\u304c\u767b\u5834\u3057\u305f\u56de\u6570\u3067\u3059\u3002\u300cthe\u300d\u306f\u5168\u6587\u66f8\u306b2\u56de\u305a\u3064\u767b\u5834\u3059\u308b\u305f\u3081\u5168\u884c\u304c2\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u300ccat\u300d\u306f\u6587\u66f81\u3068\u6587\u66f83\u306b\u767b\u5834\u3057\u307e\u3059\u304c\u6587\u66f82\u306b\u306f\u767b\u5834\u3057\u306a\u3044\u305f\u3081\u3001\u6587\u66f82\u3060\u3051\u304c0\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3001\u6587\u7ae0\u306e\u9055\u3044\u304c\u6570\u5024\u306e\u5206\u5e03\u3068\u3057\u3066\u8868\u308c\u3066\u3044\u308b\u306e\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u65e5\u672c\u8a9e\u30c6\u30ad\u30b9\u30c8\u3078\u306e\u5fdc<\/h2>\n\n\n\n<p>\u82f1\u8a9e\u306f\u30b9\u30da\u30fc\u30b9\u3067\u5358\u8a9e\u304c\u533a\u5207\u3089\u308c\u3066\u3044\u308b\u305f\u3081\u3001CountVectorizer\u306b\u305d\u306e\u307e\u307e\u6e21\u305b\u307e\u3059\u3002\u4e00\u65b9\u3001\u65e5\u672c\u8a9e\u306f\u30b9\u30da\u30fc\u30b9\u304c\u306a\u3044\u306e\u3067\u3001\u4e8b\u524d\u306b\u5358\u8a9e\u306b\u5206\u89e3\u3059\u308b\u51e6\u7406\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u51e6\u7406\u3092\u300c\u5f62\u614b\u7d20\u89e3\u6790\u300d\u3068\u547c\u3073\u3001\u5206\u89e3\u3057\u305f\u5358\u8a9e\u3092\u30b9\u30da\u30fc\u30b9\u3067\u3064\u306a\u3052\u305f\u5f62\u5f0f\u3092\u300c\u5206\u304b\u3061\u66f8\u304d\u300d\u3068\u8a00\u3044\u307e\u3059\u3002\u5f62\u614b\u7d20\u89e3\u6790\u30c4\u30fc\u30eb\u3068\u3057\u3066\u5e83\u304f\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u304c <strong>MeCab<\/strong> \u3067\u3001<code>-Owakati<\/code> \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u30b9\u30da\u30fc\u30b9\u533a\u5207\u308a\u306e\u5206\u304b\u3061\u66f8\u304d\u304c\u76f4\u63a5\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001MeCab\u3067\u5f62\u614b\u7d20\u89e3\u6790\u30fb\u5206\u304b\u3061\u66f8\u304d\u3092\u884c\u3044\u3001\u305d\u306e\u7d50\u679c\u3092\u305d\u306e\u307e\u307eCountVectorizer\u306b\u6e21\u3057\u3066BoW\u306b\u5909\u63db\u3059\u308b\u307e\u3067\u3092\u4e00\u62ec\u3067\u51e6\u7406\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>\u30b3\u30fc\u30c9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!pip install mecab-python3 unidic-lite -q\n\nimport MeCab\nfrom sklearn.feature_extraction.text import CountVectorizer\nimport pandas as pd\n\nwakati = MeCab.Tagger(\"-Owakati\")\n\ntexts_ja = &#091;\n    \"\u4eca\u65e5\u306e\u5929\u6c17\u306f\u3068\u3066\u3082\u826f\u3044\",\n    \"\u660e\u65e5\u306f\u5927\u96e8\u304c\u964d\u308b\u304b\u3082\u3057\u308c\u306a\u3044\",\n    \"\u4eca\u65e5\u306f\u5098\u3092\u6301\u3063\u3066\u5916\u306b\u51fa\u304b\u3051\u305f\",\n]\n\n# \u5f62\u614b\u7d20\u89e3\u6790\u30fb\u5206\u304b\u3061\u66f8\u304d\ntokenized = &#091;wakati.parse(t).strip() for t in texts_ja]\n\n# BoW\u30d9\u30af\u30c8\u30eb\u5316\nvectorizer_ja = CountVectorizer()\nX_ja = vectorizer_ja.fit_transform(tokenized)\n\ndf_ja = pd.DataFrame(\n    X_ja.toarray(),\n    columns=vectorizer_ja.get_feature_names_out(),\n    index=&#091;\"\u6587\u66f81\", \"\u6587\u66f82\", \"\u6587\u66f83\"],\n)\n\ndf_ja.head()\n<\/code><\/pre>\n\n\n\n<p><strong>\u51fa\u529b\u7d50\u679c<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"436\" height=\"103\" src=\"https:\/\/since2020.jp\/media\/wp-content\/uploads\/2026\/08\/image-1.png\" alt=\"\" class=\"wp-image-9326\" srcset=\"https:\/\/since2020.jp\/media\/wp-content\/uploads\/2026\/08\/image-1.png 436w, https:\/\/since2020.jp\/media\/wp-content\/uploads\/2026\/08\/image-1-300x71.png 300w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/figure>\n\n\n\n<p>\uff08MeCab\u306e\u8f9e\u66f8\u3084\u5b9f\u884c\u74b0\u5883\u306b\u3088\u3063\u3066\u62bd\u51fa\u3055\u308c\u308b\u8a9e\u3084\u5217\u306e\u9806\u756a\u304c\u5909\u308f\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u306a\u304a\u3001CountVectorizer\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u8a2d\u5b9a\u3067\u306f1\u6587\u5b57\u306e\u30c8\u30fc\u30af\u30f3\u306f\u9664\u5916\u3055\u308c\u308b\u305f\u3081\u3001\u300c\u306e\u300d\u300c\u306f\u300d\u300c\u304c\u300d\u306a\u3069\u306e\u52a9\u8a5e\u306f\u81ea\u52d5\u7684\u306b\u53d6\u308a\u9664\u304b\u308c\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<p>\u300c\u4eca\u65e5\u300d\u306f\u6587\u66f81\u3068\u6587\u66f83\u306b\u767b\u5834\u3059\u308b\u305f\u3081\u3001\u3053\u306e2\u884c\u304c1\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u300c\u660e\u65e5\u300d\u306f\u6587\u66f82\u306b\u3057\u304b\u767b\u5834\u3057\u306a\u3044\u305f\u3081\u3001\u6587\u66f82\u3060\u3051\u304c1\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3001\u5f62\u614b\u7d20\u89e3\u6790\u304b\u3089BoW\u5316\u307e\u3067\u4e00\u9023\u306e\u6d41\u308c\u3067\u65e5\u672c\u8a9e\u30c6\u30ad\u30b9\u30c8\u3092\u6570\u5024\u306b\u5909\u63db\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u7279\u5fb4\u91cf\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u306e\u57fa\u672c\u3068\u3057\u3066\u3001BoW\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c6\u30ad\u30b9\u30c8\u306f\u305d\u306e\u307e\u307e\u30e2\u30c7\u30eb\u306b\u6e21\u305b\u306a\u3044\u305f\u3081\u3001\u6570\u5024\u30d9\u30af\u30c8\u30eb\u3078\u306e\u5909\u63db\u304c\u5fc5\u8981<\/li>\n\n\n\n<li>BoW\u306f\u5404\u5358\u8a9e\u306e\u51fa\u73fe\u56de\u6570\u3092\u7279\u5fb4\u91cf\u3068\u3059\u308b\u30b7\u30f3\u30d7\u30eb\u306a\u624b\u6cd5\u3067\u3001scikit-learn\u306e <code>CountVectorizer<\/code> \u3067\u5b9f\u88c5\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u65e5\u672c\u8a9e\u306e\u5834\u5408\u306fMeCab\u3067\u5f62\u614b\u7d20\u89e3\u6790\u30fb\u5206\u304b\u3061\u66f8\u304d\u3092\u884c\u3063\u3066\u304b\u3089CountVectorizer\u306b\u6e21\u3059<\/li>\n<\/ul>\n\n\n\n<p>BoW\u306f\u30b7\u30f3\u30d7\u30eb\u306a\u5206\u3001\u8a9e\u9806\u3092\u8003\u616e\u3057\u306a\u3044\u306a\u3069\u306e\u9650\u754c\u3082\u3042\u308a\u307e\u3059\u3002\u4ed6\u306e\u624b\u6cd5\u3082\u6c17\u306b\u306a\u3063\u305f\u65b9\u306f\u305c\u3072\u8abf\u3079\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u5546\u54c1\u30ec\u30d3\u30e5\u30fc\u3084\u30cb\u30e5\u30fc\u30b9\u8a18\u4e8b\u3001SNS\u6295\u7a3f\u3068\u3044\u3063\u305f\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u6a5f\u68b0\u5b66\u7fd2\u30e2\u30c7\u30eb\u3067\u4f7f\u3044\u305f\u3044\u5834\u9762\u306f\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30c6\u30ad\u30b9\u30c8\u306f\u305d\u306e\u307e\u307e\u30e2\u30c7\u30eb\u306b\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u30e2\u30c7\u30eb\u304c\u6271\u3048\u308b\u306e\u306f\u6570\u5024\u3060\u3051\u306a\u306e\u3067\u3001\u6587\u7ae0\u3092\u6570\u5024\u30d9\u30af [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":9327,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1251],"tags":[96,1384,419,355],"class_list":["post-9324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-analysis","tag-ai","tag-1384","tag-419","tag-355"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/9324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=9324"}],"version-history":[{"count":1,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/9324\/revisions"}],"predecessor-version":[{"id":9328,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/9324\/revisions\/9328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/9327"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=9324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=9324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=9324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}