UNPKG

@mhg/blog

Version:
1 lines 270 kB
<!DOCTYPE html><html lang="zh-CN"><head hexo-theme="https://github.com/volantis-x/hexo-theme-volantis/#6.0.0-alpha.0"><meta name="generator" content="Hexo 6.3.0"><meta name="Volantis" content="6.0.0-alpha.0"><meta charset="utf-8"><meta name="robots" content="index,follow"><link rel="canonical" href="https://blog.mhuig.top/p/175a1706/"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://static.mhuig.top"><link rel="preconnect" href="https://static.mhuig.top" crossorigin><meta name="renderer" content="webkit"><meta name="force-rendering" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"><meta name="HandheldFriendly" content="True"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5"><meta content="black-translucent" name="apple-mobile-web-app-status-bar-style"><meta content="telephone=no" name="format-detection"><script>function registerServiceWorker(e){"localhost"!=window.location.hostname&&"serviceWorker"in navigator&&navigator.serviceWorker.register(`${e}`).then((function(e){"localhost"==window.location.hostname&&(e.onupdatefound=function(){var r=e.installing;r.onstatechange=function(){switch(r.state){case"installed":navigator.serviceWorker.controller?console.log("Updated Service Worker."):console.log("Service Worker Sucess!");break;case"redundant":console.log("The installing service worker became redundant.")}}})})).catch((function(e){console.error("Error during service worker registration:",e),"undefined"==typeof swinstallretry&&(swinstallretry=1,registerServiceWorker("/jquery.js?v=0258ff4f79"))}))}registerServiceWorker("/jquery.js?v=0258ff4f79")</script><link rel="apple-touch-icon" sizes="180x180" href="/lib/favicon/apple-touch-icon.png?v=e035908f18"><link rel="icon" type="image/png" sizes="32x32" href="/lib/favicon/favicon-32x32.png?v=b9d9ae54cc"><link rel="icon" type="image/png" sizes="192x192" href="/lib/favicon/android-chrome-192x192.png?v=8bf02188e3"><link rel="icon" type="image/png" sizes="144x144" href="/lib/favicon/android-chrome-144x144.png?v=5c8eadcbb7"><link rel="icon" type="image/png" sizes="16x16" href="/lib/favicon/favicon-16x16.png?v=f896f2f634"><link rel="manifest" href="/lib/favicon/site.webmanifest?v=f138de5899"><link rel="mask-icon" href="/lib/favicon/safari-pinned-tab.svg?v=87d61e51a5" color="#5bbad5"><meta name="apple-mobile-web-app-title" content="MHuiG's Blog"><meta name="application-name" content="MHuiG's Blog"><meta name="msapplication-TileColor" content="#87ceeb"><meta name="msapplication-TileImage" content="/lib/favicon/mstile-144x144.png"><meta name="theme-color" content="#87ceeb" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#21232f" media="(prefers-color-scheme: dark)"><link href="/opensearch.xml?v=2f4fd4e7e0" rel="search" title="MHuiG's Blog" type="application/opensearchdescription+xml"><link rel="preload" href="/css/style.css?v=2d24f6fe3e" as="style"><link rel="preload" href="https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/fonts/VarelaRound/VarelaRound-Regular.ttf" as="font" type="font/ttf" crossorigin="anonymous"><link rel="alternate" href="/atom.xml?v=fe8205151a" title="MHuiG" type="application/atom+xml"><link rel="alternate" href="/rss2.xml?v=6b8706d024" title="MHuiG" type="application/rss+xml"><title>尝试在博客中添加简易文章推荐功能 - MHuiG</title><meta name="keywords" content="Data mining,推荐系统,Blog, IT, BigData, MHuiG, @MHuiG, iMHuiG, 博客, 梦幻岛, Neverland, 技术博客"><meta desc name="description" content="如何在博客中添加简易文章推荐功能 - MHuiG - MHuiG"><meta property="og:type" content="article"><meta property="og:title" content="尝试在博客中添加简易文章推荐功能"><meta property="og:url" content="https://blog.mhuig.top/p/175a1706/"><meta property="og:site_name" content="MHuiG"><meta property="og:description" content="如何在博客中添加简易文章推荐功能"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://blog.mhuig.top/lib/favicon/android-chrome-192x192.png"><meta property="article:published_time" content="2022-09-15T11:13:00.000Z"><meta property="article:modified_time" content="2022-09-16T02:48:00.000Z"><meta property="article:author" content="MHuiG"><meta property="article:tag" content="Data mining"><meta property="article:tag" content="推荐系统"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://blog.mhuig.top/lib/favicon/android-chrome-192x192.png"><meta name="twitter:creator" content="@iMHuiG"><meta name="twitter:site" content="@iMHuiG"><style>#safearea{display:none}.post-story+.post-story{content-visibility:auto;contain-intrinsic-size:10px 500px}:root{--color-site-body:#87ceeb;--color-site-bg:#87ceeb;--color-site-inner:#555;--color-site-footer:#666;--color-card:#fff;--color-text:#444;--color-block:#f6f6f6;--color-inlinecode:#d56d28;--color-codeblock:#fff7ea;--color-h1:#3a3a3a;--color-h2:#3a3a3a;--color-h3:#333;--color-h4:#444;--color-h5:#555;--color-h6:#666;--color-p:#444;--color-list:#666;--color-list-hl:#1a78c2;--color-meta:#888;--color-read-bkg:#e0d8c8;--color-read-post:#f8f1e2;--color-copyright-bkg:#f5f5f5}*{box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;outline:0;margin:0;padding:0}::-webkit-scrollbar{height:4px;width:4px}::-webkit-scrollbar-track-piece{background:0 0}::-webkit-scrollbar-thumb{background:#2196f3;cursor:pointer;border-radius:2px;-webkit-border-radius:2px}::-webkit-scrollbar-thumb:hover{background:#ff5722}html{color:var(--color-text);width:100%;height:100%;font-family:"Varela Round","PingFang SC","Microsoft YaHei",Helvetica,Arial,Menlo,Monaco,monospace,sans-serif;font-size:16px}html>::-webkit-scrollbar{height:4px;width:4px}html>::-webkit-scrollbar-track-piece{background:0 0}html>::-webkit-scrollbar-thumb{background:#2196f3;cursor:pointer;border-radius:2px;-webkit-border-radius:2px}html>::-webkit-scrollbar-thumb:hover{background:#ff5722}body{background-color:var(--color-site-body);text-rendering:optimizelegibility;-webkit-tap-highlight-color:transparent;line-height:1.6;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body.modal-active{overflow:hidden}@media screen and (max-width:680px){body.modal-active{position:fixed;top:0;right:0;bottom:0;left:0}}a{color:#2196f3;cursor:pointer;text-decoration:none;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}a:hover{color:#ff5722}a:active,a:hover{outline:0}ol,ul{padding-left:0}ol li,ul li{list-style:none}header{display:-webkit-box;display:-moz-box;display:block}img{border:0;background:0 0;max-width:100%}svg:not(:root){overflow:hidden}hr{-moz-box-sizing:content-box;box-sizing:content-box;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;height:0;border:0;border-radius:1px;-webkit-border-radius:1px;border-bottom:1px solid rgba(68,68,68,.1)}button,input{color:inherit;font:inherit;margin:0}button{overflow:visible;text-transform:none;-webkit-appearance:button;cursor:pointer}@supports (backdrop-filter:blur(20px)){.blur{background:rgba(255,255,255,.9)!important;backdrop-filter:saturate(200%) blur(20px)}}.shadow{box-shadow:0 1px 2px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 1px 2px 0 rgba(0,0,0,.1)}.shadow.floatable{transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}.shadow.floatable:hover{box-shadow:0 2px 4px 0 rgba(0,0,0,.1),0 4px 8px 0 rgba(0,0,0,.1),0 8px 16px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 2px 4px 0 rgba(0,0,0,.1),0 4px 8px 0 rgba(0,0,0,.1),0 8px 16px 0 rgba(0,0,0,.1)}#l_cover{min-height:64px}.cover-wrapper{top:0;left:0;max-width:100%;height:100vh;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;flex-wrap:nowrap;-webkit-flex-wrap:nowrap;-khtml-flex-wrap:nowrap;-moz-flex-wrap:nowrap;-o-flex-wrap:nowrap;-ms-flex-wrap:nowrap;-webkit-box-direction:normal;-moz-box-direction:normal;-webkit-box-orient:vertical;-moz-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;align-items:center;align-self:center;align-content:center;color:var(--color-site-inner);padding:0 16px;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;position:relative;overflow:hidden;margin-bottom:-100px}.cover-wrapper .cover-bg{position:absolute;width:100%;height:100%;background-position:center;background-size:cover;-webkit-background-size:cover;-moz-background-size:cover}.cover-wrapper .cover-bg.lazyload:not(.loaded){opacity:0;-webkit-opacity:0;-moz-opacity:0}.cover-wrapper .cover-bg.lazyload.loaded{animation-delay:0s;animation-duration:.5s;animation-fill-mode:forwards;animation-timing-function:ease-out;animation-name:fadeIn}@-moz-keyframes fadeIn{0%{opacity:0;-webkit-opacity:0;-moz-opacity:0;filter:blur(12px);transform:scale(1.02);-webkit-transform:scale(1.02);-khtml-transform:scale(1.02);-moz-transform:scale(1.02);-o-transform:scale(1.02);-ms-transform:scale(1.02)}100%{opacity:1;-webkit-opacity:1;-moz-opacity:1}}@-webkit-keyframes fadeIn{0%{opacity:0;-webkit-opacity:0;-moz-opacity:0;filter:blur(12px);transform:scale(1.02);-webkit-transform:scale(1.02);-khtml-transform:scale(1.02);-moz-transform:scale(1.02);-o-transform:scale(1.02);-ms-transform:scale(1.02)}100%{opacity:1;-webkit-opacity:1;-moz-opacity:1}}@-o-keyframes fadeIn{0%{opacity:0;-webkit-opacity:0;-moz-opacity:0;filter:blur(12px);transform:scale(1.02);-webkit-transform:scale(1.02);-khtml-transform:scale(1.02);-moz-transform:scale(1.02);-o-transform:scale(1.02);-ms-transform:scale(1.02)}100%{opacity:1;-webkit-opacity:1;-moz-opacity:1}}@keyframes fadeIn{0%{opacity:0;-webkit-opacity:0;-moz-opacity:0;filter:blur(12px);transform:scale(1.02);-webkit-transform:scale(1.02);-khtml-transform:scale(1.02);-moz-transform:scale(1.02);-o-transform:scale(1.02);-ms-transform:scale(1.02)}100%{opacity:1;-webkit-opacity:1;-moz-opacity:1}}.cover-wrapper .cover-body{z-index:1;position:relative;width:100%;height:100%}.cover-wrapper#full{height:calc(100vh + 100px);padding-bottom:100px}.cover-wrapper#half{max-height:640px;min-height:400px;height:calc(36vh - 64px + 200px)}.cover-wrapper #scroll-down{width:100%;height:64px;position:absolute;bottom:100px;text-align:center;cursor:pointer}.cover-wrapper #scroll-down .scroll-down-effects{color:#fff;font-size:24px;line-height:64px;position:absolute;width:24px;left:calc(50% - 12px);text-shadow:0 1px 2px rgba(0,0,0,.1);animation:scroll-down-effect 1.5s infinite;-webkit-animation:scroll-down-effect 1.5s infinite;-khtml-animation:scroll-down-effect 1.5s infinite;-moz-animation:scroll-down-effect 1.5s infinite;-o-animation:scroll-down-effect 1.5s infinite;-ms-animation:scroll-down-effect 1.5s infinite}@-moz-keyframes scroll-down-effect{0%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}50%{top:-16px;opacity:.4;-webkit-opacity:0.4;-moz-opacity:0.4}100%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}}@-webkit-keyframes scroll-down-effect{0%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}50%{top:-16px;opacity:.4;-webkit-opacity:0.4;-moz-opacity:0.4}100%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}}@-o-keyframes scroll-down-effect{0%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}50%{top:-16px;opacity:.4;-webkit-opacity:0.4;-moz-opacity:0.4}100%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}}@keyframes scroll-down-effect{0%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}50%{top:-16px;opacity:.4;-webkit-opacity:0.4;-moz-opacity:0.4}100%{top:0;opacity:1;-webkit-opacity:1;-moz-opacity:1}}.cover-wrapper .cover-body{margin-top:64px;margin-bottom:100px}.cover-wrapper .cover-body,.cover-wrapper .cover-body .bottom,.cover-wrapper .cover-body .top{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;-webkit-box-direction:normal;-moz-box-direction:normal;-webkit-box-orient:vertical;-moz-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;align-items:center;justify-content:center;-webkit-justify-content:center;-khtml-justify-content:center;-moz-justify-content:center;-o-justify-content:center;-ms-justify-content:center;max-width:100%}.cover-wrapper .cover-body .bottom{margin-top:32px}.cover-wrapper .cover-body .title{font-family:"Varela Round","PingFang SC","Microsoft YaHei",Helvetica,Arial,Helvetica,monospace;font-size:3.125rem;line-height:1.2;text-shadow:0 1px 2px rgba(0,0,0,.1)}.cover-wrapper .cover-body .subtitle{font-size:20px}.cover-wrapper .cover-body .logo{max-height:120px;max-width:calc(100% - 4 * 16px)}@media screen and (min-height:1024px){.cover-wrapper .cover-body .title{font-size:3rem}.cover-wrapper .cover-body .subtitle{font-size:1.05rem}.cover-wrapper .cover-body .logo{max-height:150px}}.cover-wrapper .cover-body .m_search{position:relative;max-width:calc(100% - 16px);width:320px;vertical-align:middle}.cover-wrapper .cover-body .m_search .form{position:relative;display:-webkit-box;display:-moz-box;display:block;width:100%}.cover-wrapper .cover-body .m_search .icon,.cover-wrapper .cover-body .m_search .input{transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}.cover-wrapper .cover-body .m_search .icon{position:absolute;display:-webkit-box;display:-moz-box;display:block;line-height:2.5rem;width:32px;top:0;left:5px;color:rgba(68,68,68,.75)}.cover-wrapper .cover-body .m_search .input{display:-webkit-box;display:-moz-box;display:block;height:2.5rem;width:100%;box-shadow:none;-webkit-box-shadow:none;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;font-size:.875rem;-webkit-appearance:none;padding-left:36px;border-radius:1.4rem;-webkit-border-radius:1.4rem;background:rgba(255,255,255,.6);backdrop-filter:blur(10px);border:none;color:var(--color-text)}@media screen and (max-width:500px){.cover-wrapper .cover-body .m_search .input{padding-left:36px}}.cover-wrapper .cover-body .m_search .input:hover{background:rgba(255,255,255,.8)}.cover-wrapper .cover-body .m_search .input:focus{background:#fff}.cover-wrapper .list-h{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;-webkit-box-direction:normal;-moz-box-direction:normal;-webkit-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;flex-wrap:wrap;-webkit-flex-wrap:wrap;-khtml-flex-wrap:wrap;-moz-flex-wrap:wrap;-o-flex-wrap:wrap;-ms-flex-wrap:wrap;align-items:stretch;border-radius:4px;-webkit-border-radius:4px;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}.cover-wrapper .list-h a{-webkit-box-flex:1;-moz-box-flex:1;-webkit-flex:1 0;-ms-flex:1 0;flex:1 0;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;font-weight:600}.cover-wrapper .list-h a img{display:-webkit-box;display:-moz-box;display:block;border-radius:2px;-webkit-border-radius:2px;margin:4px;min-width:40px;max-width:44px}@media screen and (max-width:768px){.cover-wrapper .list-h a img{min-width:36px;max-width:40px}}@media screen and (max-width:500px){.cover-wrapper .list-h a img{margin:2px 4px;min-width:32px;max-width:36px}}@media screen and (max-width:375px){.cover-wrapper .list-h a img{min-width:28px;max-width:32px}}.cover-wrapper{max-width:100%}.cover-wrapper.search .bottom .menu{margin-top:16px}.cover-wrapper.search .bottom .menu .list-h a{white-space:nowrap;-webkit-box-direction:normal;-moz-box-direction:normal;-webkit-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;align-items:baseline;padding:2px;margin:4px;color:var(--color-site-inner);opacity:.75;-webkit-opacity:0.75;-moz-opacity:0.75;text-shadow:0 1px 2px rgba(0,0,0,.05);border-bottom:2px solid transparent}.cover-wrapper.search .bottom .menu .list-h a i{margin-right:4px}.cover-wrapper.search .bottom .menu .list-h a p{font-size:.9375rem}.cover-wrapper.search .bottom .menu .list-h a.active,.cover-wrapper.search .bottom .menu .list-h a:active,.cover-wrapper.search .bottom .menu .list-h a:hover{opacity:1;-webkit-opacity:1;-moz-opacity:1;border-bottom:2px solid var(--color-site-inner)}.cover-wrapper.dock .menu,.cover-wrapper.featured .menu,.cover-wrapper.focus .menu{border-radius:6px;-webkit-border-radius:6px}.cover-wrapper.dock .menu .list-h a,.cover-wrapper.featured .menu .list-h a,.cover-wrapper.focus .menu .list-h a{-webkit-box-direction:normal;-moz-box-direction:normal;-webkit-box-orient:vertical;-moz-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;align-items:center;padding:12px;line-height:24px;border-radius:4px;-webkit-border-radius:4px;border-bottom:none;text-align:center;align-content:flex-end;color:rgba(68,68,68,.7);font-size:1.5rem}@media screen and (max-width:500px){.cover-wrapper.dock .menu .list-h a,.cover-wrapper.featured .menu .list-h a,.cover-wrapper.focus .menu .list-h a{padding:12px 8px}}.cover-wrapper.dock .menu .list-h a i,.cover-wrapper.featured .menu .list-h a i,.cover-wrapper.focus .menu .list-h a i{margin:8px}.cover-wrapper.dock .menu .list-h a p,.cover-wrapper.featured .menu .list-h a p,.cover-wrapper.focus .menu .list-h a p{font-size:.875rem}.cover-wrapper.dock .menu .list-h a.active,.cover-wrapper.featured .menu .list-h a.active,.cover-wrapper.focus .menu .list-h a.active{background:var(--color-card);backdrop-filter:none}.cover-wrapper.dock .menu .list-h a.active i,.cover-wrapper.dock .menu .list-h a.active i+p,.cover-wrapper.featured .menu .list-h a.active i,.cover-wrapper.featured .menu .list-h a.active i+p,.cover-wrapper.focus .menu .list-h a.active i,.cover-wrapper.focus .menu .list-h a.active i+p{color:#2196f3}.cover-wrapper.dock .menu .list-h a.active img+p,.cover-wrapper.featured .menu .list-h a.active img+p,.cover-wrapper.focus .menu .list-h a.active img+p{color:var(--color-text)}.cover-wrapper.dock .menu .list-h a:hover,.cover-wrapper.featured .menu .list-h a:hover,.cover-wrapper.focus .menu .list-h a:hover{background:var(--color-card)}.cover-wrapper.featured .menu .list-h{margin:-2px}.cover-wrapper.featured .menu .list-h a{margin:2px;background:rgba(255,255,255,.5)}@supports (backdrop-filter:blur(20px)){.cover-wrapper.featured .menu .list-h a{background:rgba(255,255,255,.5);backdrop-filter:saturate(200%) blur(20px)}}@media (prefers-color-scheme:dark){:root{--color-mode:'dark'}:root:not([color-scheme]){--color-site-body:#121212;--color-read-bkg:#21232f;--color-read-post:#252d38;--color-site-bg:#21232f;--color-site-inner:#efefef;--color-site-footer:#666;--color-card:#252d38;--color-text:rgba(238,238,238,0.871);--color-block:rgba(68,68,68,0.65);--color-codeblock:rgba(68,68,68,0.65);--color-inlinecode:#d56d28;--color-h1:rgba(255,255,255,0.871);--color-h2:rgba(255,255,255,0.871);--color-h3:rgba(255,255,255,0.6);--color-h4:rgba(255,255,255,0.6);--color-h5:rgba(255,255,255,0.6);--color-h6:rgba(255,255,255,0.6);--color-p:rgba(217,217,217,0.871);--color-list:rgba(217,217,217,0.871);--color-list-hl:#4dabf5;--color-meta:rgba(191,191,191,0.871);--color-link:rgba(191,191,191,0.871);--color-copyright-bkg:#21252b}:root:not([color-scheme]) img{filter:brightness(70%)!important}:root:not([color-scheme]) .blur{background:rgba(33,35,47,.9)!important}:root:not([color-scheme]) .white-box.blur{background:rgba(37,45,56,.9)!important}:root:not([color-scheme]) .nav-main .u-search-input{background:var(--color-card)!important}:root:not([color-scheme]) #l_main .article .prev-next>a{background:var(--color-block)!important}:root:not([color-scheme]) #l_main .article .prev-next>a:hover{background:var(--color-site-bg)!important}:root:not([color-scheme]) .article blockquote{background:var(--color-block)!important}:root:not([color-scheme]) .article-title a{color:var(--color-h1)!important}:root:not([color-scheme]) details>summary{color:var(--color-p)!important;background:var(--color-site-bg)!important}:root:not([color-scheme]) details{border:1px solid var(--color-site-bg)!important;background:var(--color-site-bg)!important}:root:not([color-scheme]) #u-search .modal,:root:not([color-scheme]) #u-search .modal-body,:root:not([color-scheme]) #u-search .modal-header{background:var(--color-card)!important}:root:not([color-scheme]) #u-search .modal-body .modal-results .result:hover{background:var(--color-block)!important}:root:not([color-scheme]) .u-search-input:hover{background:var(--color-block)!important}:root:not([color-scheme]) .u-search-input:focus{background:var(--color-site-body)!important}}[color-scheme=dark]{--color-site-body:#121212;--color-read-bkg:#21232f;--color-read-post:#252d38;--color-site-bg:#21232f;--color-site-inner:#efefef;--color-site-footer:#666;--color-card:#252d38;--color-text:rgba(238,238,238,0.871);--color-block:rgba(68,68,68,0.65);--color-codeblock:rgba(68,68,68,0.65);--color-inlinecode:#d56d28;--color-h1:rgba(255,255,255,0.871);--color-h2:rgba(255,255,255,0.871);--color-h3:rgba(255,255,255,0.6);--color-h4:rgba(255,255,255,0.6);--color-h5:rgba(255,255,255,0.6);--color-h6:rgba(255,255,255,0.6);--color-p:rgba(217,217,217,0.871);--color-list:rgba(217,217,217,0.871);--color-list-hl:#4dabf5;--color-meta:rgba(191,191,191,0.871);--color-link:rgba(191,191,191,0.871);--color-copyright-bkg:#21252b}[color-scheme=dark] img{filter:brightness(70%)!important}[color-scheme=dark] .blur{background:rgba(33,35,47,.9)!important}[color-scheme=dark] .white-box.blur{background:rgba(37,45,56,.9)!important}[color-scheme=dark] .nav-main .u-search-input{background:var(--color-card)!important}[color-scheme=dark] #l_main .article .prev-next>a{background:var(--color-block)!important}[color-scheme=dark] #l_main .article .prev-next>a:hover{background:var(--color-site-bg)!important}[color-scheme=dark] .article blockquote{background:var(--color-block)!important}[color-scheme=dark] .article-title a{color:var(--color-h1)!important}[color-scheme=dark] details>summary{color:var(--color-p)!important;background:var(--color-site-bg)!important}[color-scheme=dark] details{border:1px solid var(--color-site-bg)!important;background:var(--color-site-bg)!important}[color-scheme=dark] #u-search .modal,[color-scheme=dark] #u-search .modal-body,[color-scheme=dark] #u-search .modal-header{background:var(--color-card)!important}[color-scheme=dark] #u-search .modal-body .modal-results .result:hover{background:var(--color-block)!important}[color-scheme=dark] .u-search-input:hover{background:var(--color-block)!important}[color-scheme=dark] .u-search-input:focus{background:var(--color-site-body)!important}@media screen and (max-width:500px){[color-scheme=dark] .l_header .m_search{background:var(--color-site-bg)!important}}@font-face{font-family:'Varela Round';src:url("");font-weight:'normal';font-style:'normal';font-display:swap}@font-face{font-family:'Varela Round';src:url("https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/fonts/VarelaRound/VarelaRound-Regular.ttf");font-weight:'normal';font-style:'normal';font-display:swap}.l_header{position:fixed;z-index:1000;top:0;width:100%;height:64px;background:var(--color-card);box-shadow:0 1px 2px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 1px 2px 0 rgba(0,0,0,.1)}.l_header.auto{transition:opacity .4s ease;-webkit-transition:opacity .4s ease;-khtml-transition:opacity 0.4s ease;-moz-transition:opacity .4s ease;-o-transition:opacity .4s ease;-ms-transition:opacity .4s ease;visibility:hidden}.l_header.auto.show{opacity:1!important;-webkit-opacity:1!important;-moz-opacity:1!important;visibility:visible}.l_header .container{margin-left:16px;margin-right:16px}.l_header #wrapper{height:100%;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}.l_header #wrapper .nav-main,.l_header #wrapper .nav-sub{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;flex-wrap:nowrap;-webkit-flex-wrap:nowrap;-khtml-flex-wrap:nowrap;-moz-flex-wrap:nowrap;-o-flex-wrap:nowrap;-ms-flex-wrap:nowrap;justify-content:space-between;-webkit-justify-content:space-between;-khtml-justify-content:space-between;-moz-justify-content:space-between;-o-justify-content:space-between;-ms-justify-content:space-between;align-items:center}.l_header #wrapper .nav-main{transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}.l_header #wrapper.sub .nav-main{transform:translateY(-64px);-webkit-transform:translateY(-64px);-khtml-transform:translateY(-64px);-moz-transform:translateY(-64px);-o-transform:translateY(-64px);-ms-transform:translateY(-64px)}.l_header #wrapper .nav-sub{transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease;opacity:0;-webkit-opacity:0;-moz-opacity:0;height:64px;width:calc(100% - 2 * 16px);position:absolute}.l_header #wrapper .nav-sub ::-webkit-scrollbar{display:-webkit-box;display:-moz-box;display:none}@media screen and (min-width:2048px){.l_header #wrapper .nav-sub{max-width:55vw;margin:auto}}.l_header #wrapper.sub .nav-sub{opacity:1;-webkit-opacity:1;-moz-opacity:1}.l_header #wrapper .title{position:relative;color:var(--color-text);padding-left:24px;max-height:64px}.l_header #wrapper .nav-main .title{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:0;line-height:64px;padding:0 24px;font-size:1.25rem;font-family:"Varela Round","PingFang SC","Microsoft YaHei",Helvetica,Arial,Helvetica,monospace}.l_header #wrapper .nav-main .title img{height:64px}.l_header .nav-sub{max-width:1080px;margin:auto}.l_header .nav-sub .title{font-weight:700;font-family:"Varela Round","PingFang SC","Microsoft YaHei",Helvetica,Arial,Menlo,Monaco,monospace,sans-serif;line-height:1.2;max-height:64px;white-space:normal;flex-shrink:1}.l_header .switcher{display:-webkit-box;display:-moz-box;display:none;line-height:64px;align-items:center}.l_header .switcher .s-toc{display:-webkit-box;display:-moz-box;display:none}@media screen and (max-width:768px){.l_header .switcher .s-toc{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex}}.l_header .switcher>li{height:48px;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease;margin:2px}@media screen and (max-width:500px){.l_header .switcher>li{margin:0 1px;height:48px}}.l_header .switcher>li>a{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;justify-content:center;-webkit-justify-content:center;-khtml-justify-content:center;-moz-justify-content:center;-o-justify-content:center;-ms-justify-content:center;align-items:center;width:48px;height:48px;padding:.85em 1.1em;border-radius:100px;-webkit-border-radius:100px;border:none;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease;color:#2196f3}.l_header .switcher>li>a:hover{border:none}.l_header .switcher>li>a.active,.l_header .switcher>li>a:active{border:none;background:var(--color-site-bg)}@media screen and (max-width:500px){.l_header .switcher>li>a{width:36px;height:48px}}.l_header .nav-sub .switcher{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex}.l_header .m_search{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;height:64px;width:240px;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}@media screen and (max-width:1024px){.l_header .m_search{width:44px;min-width:44px}.l_header .m_search input::placeholder{opacity:0;-webkit-opacity:0;-moz-opacity:0}.l_header .m_search:hover{width:240px}.l_header .m_search:hover input::placeholder{opacity:1;-webkit-opacity:1;-moz-opacity:1}}@media screen and (min-width:500px){.l_header .m_search:hover .input{width:100%}.l_header .m_search:hover .input::placeholder{opacity:1;-webkit-opacity:1;-moz-opacity:1}}@media screen and (max-width:500px){.l_header .m_search{min-width:0}.l_header .m_search input::placeholder{opacity:1;-webkit-opacity:1;-moz-opacity:1}}.l_header .m_search .form{position:relative;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;width:100%;align-items:center}.l_header .m_search .icon{position:absolute;width:36px;left:5px;color:var(--color-meta)}@media screen and (max-width:500px){.l_header .m_search .icon{display:-webkit-box;display:-moz-box;display:none}}.l_header .m_search .input{display:-webkit-box;display:-moz-box;display:block;padding-top:8px;padding-bottom:8px;line-height:1.3;width:100%;color:var(--color-text);background:#fafafa;box-shadow:none;-webkit-box-shadow:none;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;padding-left:40px;font-size:.875rem;border-radius:8px;-webkit-border-radius:8px;border:none;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}@media screen and (min-width:500px){.l_header .m_search .input:focus{box-shadow:0 4px 8px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 4px 8px 0 rgba(0,0,0,.1)}}@media screen and (max-width:500px){.l_header .m_search .input{background:var(--color-block);padding-left:8px;border:none}.l_header .m_search .input:focus,.l_header .m_search .input:hover{border:none}}@media (max-width:500px){.l_header .m_search{left:0;width:0;overflow:hidden;position:absolute;background:#fff;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}.l_header .m_search .input{border-radius:32px;-webkit-border-radius:32px;margin-left:16px;padding-left:16px}.l_header.z_search-open .m_search{width:100%}.l_header.z_search-open .m_search .input{width:calc(100% - 120px)}}ul.m-pc>li>a{color:inherit;border-bottom:2px solid transparent}ul.m-pc>li>a.active,ul.m-pc>li>a:active{border-bottom:2px solid #2196f3}ul.list-v li:hover>ul.list-v,ul.m-pc li:hover>ul.list-v{display:-webkit-box;display:-moz-box;display:block}ul.nav-list-h{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;align-items:stretch}ul.nav-list-h>li{position:relative;justify-content:center;-webkit-justify-content:center;-khtml-justify-content:center;-moz-justify-content:center;-o-justify-content:center;-ms-justify-content:center;height:100%;line-height:2.4;border-radius:4px;-webkit-border-radius:4px}ul.nav-list-h>li>a{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-weight:600}ul.list-v{z-index:1;display:-webkit-box;display:-moz-box;display:none;position:absolute;background:var(--color-card);box-shadow:0 2px 4px 0 rgba(0,0,0,.08),0 4px 8px 0 rgba(0,0,0,.08),0 8px 16px 0 rgba(0,0,0,.08);-webkit-box-shadow:0 2px 4px 0 rgba(0,0,0,.08),0 4px 8px 0 rgba(0,0,0,.08),0 8px 16px 0 rgba(0,0,0,.08);margin-top:-6px;border-radius:4px;-webkit-border-radius:4px;padding:8px 0}ul.list-v.show{display:-webkit-box;display:-moz-box;display:block}ul.list-v hr{margin-top:8px;margin-bottom:8px}ul.list-v>li{white-space:nowrap;word-break:keep-all}ul.list-v>li.header{font-size:.78125rem;font-weight:700;line-height:2em;color:var(--color-meta);margin:8px 16px 4px}ul.list-v>li.header i{margin-right:8px}ul.list-v>li ul{margin-left:0;display:-webkit-box;display:-moz-box;display:none;margin-top:-40px}ul.list-v .aplayer-container{min-height:64px;padding:6px 16px}ul.list-v>li>a{transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease;display:-webkit-box;display:-moz-box;display:block;color:var(--color-list);font-size:.875rem;font-weight:700;line-height:36px;padding:0 20px 0 16px;text-overflow:ellipsis;margin:0 4px;border-radius:4px;-webkit-border-radius:4px}@media screen and (max-width:1024px){ul.list-v>li>a{line-height:40px}}ul.list-v>li>a>i{margin-right:8px}ul.list-v>li>a.active,ul.list-v>li>a:active{color:var(--color-list-hl)}ul.list-v>li>a:hover{color:var(--color-list-hl);background:var(--color-site-bg)}.l_header .menu>ul>li>a{display:-webkit-box;display:-moz-box;display:block;padding:0 8px}.l_header .menu>ul>li>a>i{margin-right:4px}.l_header ul.nav-list-h>li{color:var(--color-list);line-height:64px}.l_header ul.nav-list-h>li>a{max-height:64px;overflow:hidden;color:inherit}.l_header ul.nav-list-h>li>a.active,.l_header ul.nav-list-h>li>a:active{color:#2196f3}.l_header ul.nav-list-h>li:hover>a{color:var(--color-list-hl)}.l_header ul.nav-list-h>li i.music{animation:rotate-effect 1.5s linear infinite;-webkit-animation:rotate-effect 1.5s linear infinite;-khtml-animation:rotate-effect 1.5s linear infinite;-moz-animation:rotate-effect 1.5s linear infinite;-o-animation:rotate-effect 1.5s linear infinite;-ms-animation:rotate-effect 1.5s linear infinite}@-moz-keyframes rotate-effect{0%{transform:rotate(0);-webkit-transform:rotate(0);-khtml-transform:rotate(0);-moz-transform:rotate(0);-o-transform:rotate(0);-ms-transform:rotate(0)}25%{transform:rotate(90deg);-webkit-transform:rotate(90deg);-khtml-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg)}50%{transform:rotate(180deg);-webkit-transform:rotate(180deg);-khtml-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg)}75%{transform:rotate(270deg);-webkit-transform:rotate(270deg);-khtml-transform:rotate(270deg);-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-ms-transform:rotate(270deg)}100%{transform:rotate(360deg);-webkit-transform:rotate(360deg);-khtml-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);-ms-transform:rotate(360deg)}}@-webkit-keyframes rotate-effect{0%{transform:rotate(0);-webkit-transform:rotate(0);-khtml-transform:rotate(0);-moz-transform:rotate(0);-o-transform:rotate(0);-ms-transform:rotate(0)}25%{transform:rotate(90deg);-webkit-transform:rotate(90deg);-khtml-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg)}50%{transform:rotate(180deg);-webkit-transform:rotate(180deg);-khtml-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg)}75%{transform:rotate(270deg);-webkit-transform:rotate(270deg);-khtml-transform:rotate(270deg);-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-ms-transform:rotate(270deg)}100%{transform:rotate(360deg);-webkit-transform:rotate(360deg);-khtml-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);-ms-transform:rotate(360deg)}}@-o-keyframes rotate-effect{0%{transform:rotate(0);-webkit-transform:rotate(0);-khtml-transform:rotate(0);-moz-transform:rotate(0);-o-transform:rotate(0);-ms-transform:rotate(0)}25%{transform:rotate(90deg);-webkit-transform:rotate(90deg);-khtml-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg)}50%{transform:rotate(180deg);-webkit-transform:rotate(180deg);-khtml-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg)}75%{transform:rotate(270deg);-webkit-transform:rotate(270deg);-khtml-transform:rotate(270deg);-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-ms-transform:rotate(270deg)}100%{transform:rotate(360deg);-webkit-transform:rotate(360deg);-khtml-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);-ms-transform:rotate(360deg)}}@keyframes rotate-effect{0%{transform:rotate(0);-webkit-transform:rotate(0);-khtml-transform:rotate(0);-moz-transform:rotate(0);-o-transform:rotate(0);-ms-transform:rotate(0)}25%{transform:rotate(90deg);-webkit-transform:rotate(90deg);-khtml-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg)}50%{transform:rotate(180deg);-webkit-transform:rotate(180deg);-khtml-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg)}75%{transform:rotate(270deg);-webkit-transform:rotate(270deg);-khtml-transform:rotate(270deg);-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-ms-transform:rotate(270deg)}100%{transform:rotate(360deg);-webkit-transform:rotate(360deg);-khtml-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);-ms-transform:rotate(360deg)}}.menu-phone li ul.list-v{right:calc(100% - .5 * 16px)}.menu-phone li ul.list-v ul{right:calc(100% - .5 * 16px)}#wrapper{max-width:1080px;margin:auto}@media screen and (min-width:2048px){#wrapper{max-width:55vw}}#wrapper .menu{-webkit-box-flex:1;-moz-box-flex:1;-webkit-flex:1 1;-ms-flex:1 1;flex:1 1;margin:0 16px 0 0}#wrapper .menu .list-v ul{left:calc(100% - .5 * 16px)}.menu-phone{display:-webkit-box;display:-moz-box;display:none;margin-top:16px;right:8px;transition:all .28s ease;-webkit-transition:all .28s ease;-khtml-transition:all 0.28s ease;-moz-transition:all .28s ease;-o-transition:all .28s ease;-ms-transition:all .28s ease}.menu-phone ul{right:calc(100% - .5 * 16px)}@media screen and (max-width:500px){.menu-phone{display:-webkit-box;display:-moz-box;display:block}}.l_header{max-width:65vw;left:calc((100% - 65vw) * .5);border-bottom-left-radius:8px;border-bottom-right-radius:8px}@media screen and (max-width:2048px){.l_header{max-width:1112px;left:calc((100% - 1112px) * .5)}}@media screen and (max-width:1112px){.l_header{left:0;border-radius:0;-webkit-border-radius:0;max-width:100%}}@media screen and (max-width:500px){.l_header .container{margin-left:0;margin-right:0}.l_header #wrapper .nav-main .title{padding-left:16px;padding-right:16px}.l_header #wrapper .nav-sub{width:100%}.l_header #wrapper .nav-sub .title{overflow-y:scroll;margin-top:2px;padding:8px 16px}.l_header #wrapper .switcher{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;display:flex;margin-right:8px}.l_header .menu{display:-webkit-box;display:-moz-box;display:none}}@media screen and (max-width:500px){.list-v li{max-width:270px}}#u-search{display:-webkit-box;display:-moz-box;display:none;position:fixed;top:0;left:0;width:100%;height:100%;padding:60px 20px;z-index:1001}@media screen and (max-width:680px){#u-search{padding:0}}@media screen and (prefers-color-scheme:dark) and (max-width:500px){.l_header .m_search{background:var(--color-site-bg)!important}}.cover-wrapper .cover-body .subtitle{font-size:.875rem}.fa-brands.color-github,.fa-duotone.color-github,.fa-light.color-github,.fa-regular.color-github,.fa-solid.color-github,.fa-thin.color-github,.fa.color-github,.fad.color-github,.fal.color-github,.far.color-github,.fas.color-github,.iziToast>.iziToast-body .iziToast-icon.color-github{color:#000}.fa-brands.color-friends,.fa-duotone.color-friends,.fa-light.color-friends,.fa-regular.color-friends,.fa-solid.color-friends,.fa-thin.color-friends,.fa.color-friends,.fad.color-friends,.fal.color-friends,.far.color-friends,.fas.color-friends,.iziToast>.iziToast-body .iziToast-icon.color-friends{color:#d31ee9}.fa-brands.color-about,.fa-duotone.color-about,.fa-light.color-about,.fa-regular.color-about,.fa-solid.color-about,.fa-thin.color-about,.fa.color-about,.fad.color-about,.fal.color-about,.far.color-about,.fas.color-about,.iziToast>.iziToast-body .iziToast-icon.color-about{color:#0095ff}.fa-brands.color-travellings,.fa-duotone.color-travellings,.fa-light.color-travellings,.fa-regular.color-travellings,.fa-solid.color-travellings,.fa-thin.color-travellings,.fa.color-travellings,.fad.color-travellings,.fal.color-travellings,.far.color-travellings,.fas.color-travellings,.iziToast>.iziToast-body .iziToast-icon.color-travellings{color:#734ae6}</style><link rel="stylesheet" href="/css/style.css?v=2d24f6fe3e" media="print" onload="this.media=&quot;all&quot;,this.onload=null"><noscript><link rel="stylesheet" href="/css/style.css?v=2d24f6fe3e"></noscript><script>let userColorScheme=localStorage.getItem("color-scheme");userColorScheme&&document.documentElement.setAttribute("color-scheme",userColorScheme)</script><script>window.MSInputMethodContext&&document.documentMode&&document.write('<style>html{overflow-x: hidden !important;overflow-y: hidden !important;}.kill-ie{text-align:center;height: 100%;margin-top: 15%;margin-bottom: 5500%;}.kill-t{font-size: 2rem;}.kill-c{font-size: 1.2rem;}#l_header,#l_body{display: none;}</style><div class="kill-ie"><span class="kill-t"><b>抱歉,您的浏览器无法访问本站</b></span><br/><span class="kill-c">微软已经于2016年终止了对 Internet Explorer (IE) 10 及更早版本的支持,<br/>继续使用存在极大的安全隐患,请使用当代主流的浏览器进行访问。</span><br/><a target="_blank" rel="noopener" href="https://blogs.windows.com/windowsexperience/2021/05/19/the-future-of-internet-explorer-on-windows-10-is-in-microsoft-edge/"><strong>了解详情 ></strong></a></div>')</script><noscript><style>html{overflow-x:hidden!important;overflow-y:hidden!important}.kill-noscript{text-align:center;height:100%;margin-top:15%;margin-bottom:5500%}.kill-t{font-size:2rem}.kill-c{font-size:1.2rem}#l_body,#l_header{display:none}</style><div class="kill-noscript"> <span class="kill-t"><b>抱歉,您的浏览器无法访问本站</b></span><br> <span class="kill-c">本页面需要浏览器支持(启用)JavaScript</span><br> <a target="_blank" rel="external nofollow noopener noreferrer" href="https://www.baidu.com/s?wd=启用JavaScript"><strong>了解详情 &gt;</strong></a></div></noscript><script>function volantisEventListener(e,t,o){this.type=e,this.f=t,this.ele=o}function volantisDom(e){return e||(e=document.createElement("div")),this.ele=e,this.ele.find=e=>{let t=this.ele.querySelector(e);if(t)return new volantisDom(t)},this.ele.hasClass=e=>this.ele.className.match(new RegExp("(\\s|^)"+e+"(\\s|$)")),this.ele.addClass=e=>(this.ele.classList.add(e),this.ele),this.ele.removeClass=e=>(this.ele.classList.remove(e),this.ele),this.ele.toggleClass=e=>(this.ele.hasClass(e)?this.ele.removeClass(e):this.ele.addClass(e),this.ele),this.ele.on=(e,t,o=1)=>(this.ele.addEventListener(e,t,!1),o&&volantis.EventListener.list.push(new volantisEventListener(e,t,this.ele)),this.ele),this.ele.click=(e,t)=>(this.ele.on("click",e,t),this.ele),this.ele.scroll=(e,t)=>(this.ele.on("scroll",e,t),this.ele),this.ele.html=e=>(this.ele.innerHTML=e,this.ele),this.ele.hide=e=>(this.ele.style.display="none",this.ele),this.ele.show=e=>(this.ele.style.display="block",this.ele),this.ele}function RunItem(){function e(e,t){this.name=t||e.name,this.run=()=>{try{e()}catch(e){console.log(e)}}}this.list=[],this.start=()=>{for(var e=0;e<this.list.length;e++)this.list[e].run()},this.push=(t,o,n=!0)=>{let l=t;n&&(l=()=>{volantis.requestAnimationFrame(t)});var s=new e(l,o);this.list.push(s)},this.remove=e=>{for(let t=0;t<this.list.length;t++){this.list[t].name==e&&this.list.splice(t,1)}}}function errorImgAvatar(e){e.src="https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/avatar/round/3442075.svg",e.onerror=null}function errorImgCover(e){e.src="https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/cover/76b86c0226ffd.svg",e.onerror=null}window.volantis={},volantis.debug="false",volantis.dom={},volantis.EventListener={},volantis.EventListener.list=[],volantis.EventListener.remove=()=>{volantis.EventListener.list.forEach((function(e){e.ele.removeEventListener(e.type,e.f,!1)})),volantis.EventListener.list=[]},volantis.dom.$=e=>e?new volantisDom(e):null,volantis.pjax={},volantis.pjax.method={complete:new RunItem,error:new RunItem,send:new RunItem},volantis.pjax=Object.assign(volantis.pjax,{push:volantis.pjax.method.complete.push,error:volantis.pjax.method.error.push,send:volantis.pjax.method.send.push}),volantis.rightmenu={},volantis.rightmenu.method={handle:new RunItem},volantis.rightmenu=Object.assign(volantis.rightmenu,{handle:volantis.rightmenu.method.handle.push}),volantis.dark={},volantis.dark.method={toggle:new RunItem},volantis.dark=Object.assign(volantis.dark,{push:volantis.dark.method.toggle.push}),volantis.js=(e,t)=>new Promise((o=>{setTimeout((function(){var n=document.getElementsByTagName("head")[0]||document.documentElement,l=document.createElement("script");if(l.setAttribute("type","text/javascript"),t)if(JSON.stringify(t))for(let e in t)"onload"==e?l[e]=()=>{t[e](),o()}:(l[e]=t[e],l.onload=o);else l.onload=()=>{t(),o()};else l.onload=o;l.setAttribute("src",e),n.appendChild(l)}))})),volantis.css=e=>new Promise((t=>{setTimeout((function(){var o=document.createElement("link");o.rel="stylesheet",o.href=e,o.onload=t,document.getElementsByTagName("head")[0].appendChild(o)}))})),volantis.import={jQuery:()=>"undefined"==typeof jQuery?volantis.js("https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"):new Promise((e=>{e()}))},volantis.requestAnimationFrame=e=>{window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame),window.requestAnimationFrame(e)},volantis.layoutHelper=(e,t,o)=>{function n(e,t,o){volantis.tempDiv=document.createElement("div"),volantis.tempDiv.innerHTML=t;let n=document.querySelector("#layoutHelper-"+e);n&&(o&&(n.innerHTML=""),n.append(volantis.tempDiv))}o=Object.assign({clean:!1,pjax:!0},o),n(e,t,o.clean),o.pjax&&volantis.pjax.push((()=>{n(e,t,o.clean)}),"layoutHelper-"+e)},volantis.scroll={engine:new RunItem,unengine:new RunItem},volantis.scroll=Object.assign(volantis.scroll,{push:volantis.scroll.engine.push}),volantis.scroll.getScrollTop=()=>{let e;return window.pageYOffset?e=window.pageYOffset:document.compatMode&&"BackCompat"!=document.compatMode?e=document.documentElement.scrollTop:document.body&&(e=document.body.scrollTop),e},volantis.scroll.scrollHeight=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)},volantis.scroll.offsetHeight=function(){return Math.max(document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},volantis.scroll.progress=function(){return volantis.scroll.getScrollTop()/(volantis.scroll.scrollHeight()-volantis.scroll.offsetHeight())},volantis.scroll.handleScrollEvents=()=>{volantis.scroll.lastScrollTop=volantis.scroll.getScrollTop(),volantis.requestAnimationFrame((function e(){const t=volantis.scroll.getScrollTop();volantis.scroll.lastScrollTop!==t?(volantis.scroll.del=t-volantis.scroll.lastScrollTop,volantis.scroll.lastScrollTop=t,volantis.scroll.unengine.list=[],volantis.scroll.engine.start()):volantis.scroll.unengine.start(),volantis.requestAnimationFrame(e)}))},volantis.scroll.handleScrollEvents(),volantis.scroll.ele=null,volantis.scroll.to=(e,t={})=>{e&&(volantis.scroll.ele=e,opt={top:e.getBoundingClientRect().top+document.documentElement.scrollTop,behavior:"smooth"},"top"in t&&(opt.top=t.top),"behavior"in t&&(opt.behavior=t.behavior),"addTop"in t&&(opt.top+=t.addTop),"observerDic"in t||(t.observerDic=100),window.scrollTo(opt),t.observer&&setTimeout((()=>{volantis.scroll.ele==e&&volantis.scroll.unengine.push((()=>{let o=e.getBoundingClientRect().top;o>=-t.observerDic&&o<=t.observerDic||volantis.scroll.to(e,t),volantis.scroll.unengine.remove("unengineObserver")}),"unengineObserver")}),1e3))},volantis.cleanContentVisibility=()=>{document.querySelector(".post-story")&&(console.log("cleanContentVisibility"),document.querySelectorAll(".post-story").forEach((e=>{e.classList.remove("post-story")})))}</script><script>volantis.GLOBAL_CONFIG={root:"/",debug:!1,default:{avatar:"https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/avatar/round/3442075.svg",link:"https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/link/8f277b4ee0ecd.svg",cover:"https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/cover/76b86c0226ffd.svg",image:"https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/media/placeholder/image/2659360.svg"},lastupdate:new Date(1739832285375),cdn:{izitoast_css:"https://cdn.bootcdn.net/ajax/libs/izitoast/1.4.0/css/iziToast.min.css",izitoast_js:"https://cdn.bootcdn.net/ajax/libs/izitoast/1.4.0/js/iziToast.min.js",fancybox_css:"https://cdn.bootcdn.net/ajax/libs/fancyapps-ui/4.0.31/fancybox.min.css",fancybox_js:"https://cdn.bootcdn.net/ajax/libs/fancyapps-ui/4.0.31/fancybox.umd.min.js"},sidebar:{for_page:["blogger","navigation","webinfo"],for_post:["toc"],webinfo:{lastupd:{enable:!1,friendlyShow:!0},runtime:{data:"2019/08/19",unit:"天"}}},plugins:{message:{enable:!1,icon:{default:"fa-solid fa-info-circle light-blue",quection:"fa-solid fa-question-circle light-blue"},time:{default:5e3,quection:2e4},position:"topRight",transitionIn:"bounceInLeft",transitionOut:"fadeOutRight",titleColor:"var(--color-text)",messageColor:"var(--color-text)",backgroundColor:"var(--color-card)",zindex:2147483647,copyright:{enable:!0,title:"知识共享许可协议",message:"请遵守 CC BY-NC-SA 4.0 协议。",icon:"far fa-copyright light-blue"},aplayer:{enable:!0,play:"fa-solid fa-play",pause:"fa-solid fa-pause"},rightmenu:{enable:!0,notice:!0}},aplayer:{id:1480000098,enable:!0}},search:{dataPath:("/".endsWith("/")?"/":"//")+"content.json"},languages:{search:{hits_empty:"找不到您查询的内容:${query}",hits_stats:"找到 ${hits} 条结果,用时 ${time} 毫秒"}}}</script></head><body itemscope itemtype="http://schema.org/WebPage"><header itemscope itemtype="http://schema.org/WPHeader" id="l_header" class="l_header auto shadow floatable blur show" style="opacity:0"><div class="container"><div id="wrapper"><div class="nav-sub"><p class="title"></p><ul class="switcher nav-list-h m-phone" id="pjax-header-nav-list"><li><a id="s-comment" class="fa-solid fa-comments fa-fw" target="_self" title="comment"></a></li><li><a id="s-toc" class="s-toc fa-solid fa-list fa-fw" target="_self" title="toc"></a></li></ul></div><div class="nav-main"> <a class="title flat-box" target="_self" href="/">MHuiG's Blog</a><div class="menu navigation"><ul class="nav-list-h m-pc"><li><a class="menuitem flat-box faa-parent animated-hover" title="索引"><i class="fa-duotone fa-list-alt fa-fw"></i> 索引</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="/notes/" title="便签" active-action="action-notes"><i class="fa-duotone fa-books fa-fw"></i> 便签</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/categories/" title="分类" active-action="action-categories"><i class="fa-duotone fa-folder-open fa-fw"></i> 分类</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/tags/" title="标签" active-action="action-tags"><i class="fa-duotone fa-tags fa-fw"></i> 标签</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/archives/" title="归档" active-action="action-archives"><i class="fa-duotone fa-archive fa-fw"></i> 归档</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/friends/" title="友链" active-action="action-pagesfriends"><i class="fa-duotone fa-link fa-fw"></i> 友链</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="https://www.travellings.cn/go-by-clouds.html" title="Travelling" target="_blank" active-action="action-https:wwwtravellingscngo-by-cloudshtml" rel="external nofollow noopener noreferrer"><i class="fa-duotone fa-subway fa-fw"></i> Travelling</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/about/" title="关于" active-action="action-pagesabout"><i class="fa-duotone fa-user-tie fa-fw"></i> 关于</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="noopener" href="https://mhuig.top/privacy-policy/" title="隐私政策" active-action="action-https:mhuigtopprivacy-policy"><i class="fa-duotone fa-user-secret fa-fw"></i> 隐私政策</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" title="更多"><i class="fa-duotone fa-fan fa-spin fa-fw"></i> 更多</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/beer/" title="Sponsor" active-action="action-pagesbeer"><i class="fa-duotone fa-heart-square fa-fw"></i> Sponsor</a></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" title="博客管理"><i class="fa-duotone fa-user-shield fa-fw"></i> 博客管理</a><ul class="list-v"><li><a class="menuitem flat-box header toggle-mode-btn"><i class="fa-duotone fa-bat fa-fw"></i> 暗黑模式</a></li><li></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/rss/" title="RSS订阅" active-action="action-pagesrss"><i class="fa-duotone fa-rss fa-fw"></i> RSS订阅</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/sitemap.xml" title="站点地图" active-action="action-sitemapxml"><i class="fa-duotone fa-sitemap fa-fw"></i> 站点地图</a></li><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://mhuig.instatus.com/" title="Monitors" active-action="action-https:mhuiginstatuscom"><i class="fa-duotone fa-telescope fa-fw"></i> Monitors</a></li><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://ssl.mhuig.top/" title="SSL Status" active-action="action-https:sslmhuigtop"><i class="fa-brands fa-expeditedssl fa-fw"></i> SSL Status</a></li></ul></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" title="工具箱"><i class="fa-duotone fa-tools fa-fw"></i> 工具箱</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://rssbox.mhuig.top/" title="RSS Box" active-action="action-https:rssboxmhuigtop"><i class="fa-duotone fa-conveyor-belt-boxes fa-fw"></i> RSS Box</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/havefun/Coco/" title="My Cat" active-action="action-havefunCoco"><i class="fa-duotone fa-cat fa-fw"></i> My Cat</a></li><li><a class="menuitem flat-box"><i class="fa-duotone fa-compact-disc fa-spin fa-fw music"></i> Music</a><ul class="list-v"><li><div class="aplayer-container"><div class="aplayer-local"></div></div></li></ul></li><li></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/talk/" title="碎言碎语" active-action="action-pagestalk"><i class="fa-duotone fa-comments fa-fw"></i> 碎言碎语</a></li></ul></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://github.com/MHuiG" title="GitHub" active-action="action-https:githubcomMHuiG"><i class="fa-brands fa-github fa-fw"></i> GitHub</a></li></ul></li></ul></div><div class="m_search"><form name="searchform" class="form u-search-form"><i class="icon fa-solid fa-search fa-fw"></i> <input type="text" class="input u-search-input" placeholder="Search..."></form></div><ul class="switcher nav-list-h m-phone"><li><a class="s-search fa-solid fa-search fa-fw" target="_self" title="search"></a></li><li><a class="s-menu fa-solid fa-bars fa-fw" target="_self" title="menu"></a><ul class="menu-phone list-v navigation white-box"><li><a class="menuitem flat-box faa-parent animated-hover" title="索引"><i class="fa-duotone fa-list-alt fa-fw"></i> 索引</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="/notes/" title="便签" active-action="action-notes"><i class="fa-duotone fa-books fa-fw"></i> 便签</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/categories/" title="分类" active-action="action-categories"><i class="fa-duotone fa-folder-open fa-fw"></i> 分类</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/tags/" title="标签" active-action="action-tags"><i class="fa-duotone fa-tags fa-fw"></i> 标签</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/archives/" title="归档" active-action="action-archives"><i class="fa-duotone fa-archive fa-fw"></i> 归档</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/friends/" title="友链" active-action="action-pagesfriends"><i class="fa-duotone fa-link fa-fw"></i> 友链</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="https://www.travellings.cn/go-by-clouds.html" title="Travelling" target="_blank" active-action="action-https:wwwtravellingscngo-by-cloudshtml" rel="external nofollow noopener noreferrer"><i class="fa-duotone fa-subway fa-fw"></i> Travelling</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/about/" title="关于" active-action="action-pagesabout"><i class="fa-duotone fa-user-tie fa-fw"></i> 关于</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="noopener" href="https://mhuig.top/privacy-policy/" title="隐私政策" active-action="action-https:mhuigtopprivacy-policy"><i class="fa-duotone fa-user-secret fa-fw"></i> 隐私政策</a></li></ul></li><li><a class="menuitem flat-box faa-parent animated-hover" title="更多"><i class="fa-duotone fa-fan fa-spin fa-fw"></i> 更多</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/beer/" title="Sponsor" active-action="action-pagesbeer"><i class="fa-duotone fa-heart-square fa-fw"></i> Sponsor</a></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" title="博客管理"><i class="fa-duotone fa-user-shield fa-fw"></i> 博客管理</a><ul class="list-v"><li><a class="menuitem flat-box header toggle-mode-btn"><i class="fa-duotone fa-bat fa-fw"></i> 暗黑模式</a></li><li></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/rss/" title="RSS订阅" active-action="action-pagesrss"><i class="fa-duotone fa-rss fa-fw"></i> RSS订阅</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/sitemap.xml" title="站点地图" active-action="action-sitemapxml"><i class="fa-duotone fa-sitemap fa-fw"></i> 站点地图</a></li><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://mhuig.instatus.com/" title="Monitors" active-action="action-https:mhuiginstatuscom"><i class="fa-duotone fa-telescope fa-fw"></i> Monitors</a></li><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://ssl.mhuig.top/" title="SSL Status" active-action="action-https:sslmhuigtop"><i class="fa-brands fa-expeditedssl fa-fw"></i> SSL Status</a></li></ul></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" title="工具箱"><i class="fa-duotone fa-tools fa-fw"></i> 工具箱</a><ul class="list-v"><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://rssbox.mhuig.top/" title="RSS Box" active-action="action-https:rssboxmhuigtop"><i class="fa-duotone fa-conveyor-belt-boxes fa-fw"></i> RSS Box</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/havefun/Coco/" title="My Cat" active-action="action-havefunCoco"><i class="fa-duotone fa-cat fa-fw"></i> My Cat</a></li><li><a class="menuitem flat-box faa-parent animated-hover" href="/pages/talk/" title="碎言碎语" active-action="action-pagestalk"><i class="fa-duotone fa-comments fa-fw"></i> 碎言碎语</a></li></ul></li><hr><li><a class="menuitem flat-box faa-parent animated-hover" target="_blank" rel="external nofollow noopener noreferrer" href="https://github.com/MHuiG" title="GitHub" active-action="action-https:githubcomMHuiG"><i class="fa-brands fa-github fa-fw"></i> GitHub</a></li></ul></li></ul></li></ul></div></div></div></header><div id="l_body"><div id="l_cover"><div id="none" class="cover-wrapper post featured" style="display:none"><div class="cover-bg lazyload placeholder" data-bg></div><div class="cover-body"><div class="top"><p class="title">MHuiG</p><p class="subtitle">「看庭前花开花落,望天上云卷云舒」</p></div><div class="bottom"><div class="menu navigation"><div class="list-h"><a target="_blank" rel="external nofollow noopener noreferrer" href="https://github.com/MHuiG" active-action="action-https:githubcomMHuiG"><i class="fa-brands fa-github color-github fa-fw"></i><p>Github</p></a><a href="/pages/friends/" active-action="action-pagesfriends"><i class="fa-duotone fa-link color-friends fa-fw"></i><p>友链</p></a><a href="/pages/about/" active-action="action-pagesabout"><i class="fa-duotone fa-user-tie color-about fa-fw"></i><p>关于</p></a><a href="https://www.travellings.cn/go-by-clouds.html" target="_blank" active-action="action-https:wwwtravellingscngo-by-cloudshtml" rel="external nofollow noopener noreferrer"><i class="fa-duotone fa-subway color-travellings fa-fw"></i><p>Travelling</p></a></div></div></div></div><div id="scroll-down" style="display:none"><i class="fa fa-chevron-down scroll-down-effects"></i></div></div></div><div id="safearea"><div class="body-wrapper"><div id="l_main" class><article itemscope itemtype="http://schema.org/Article" class="article post white-box reveal md shadow floatable blur article-type-post" id="post" itemprop="blogPost"><link itemprop="mainEntityOfPage" href="https://blog.mhuig.top/p/175a1706/"><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="MHuiG"></span><span hidden itemprop="post" itemscope itemtype="http://schema.org/Post"><meta itemprop="name" content="MHuiG"><meta itemprop="description" content="MHuiG&amp;#39;s Blog (MHuiG的博客) MHuiG&amp;#39;s Neverland(MHuiG的梦幻岛) —— MHuiG(@MHuiG) 随便写写画画的地方 - 技术博客"></span><div class="headimg-div"> <a class="headimg-a"><img itemprop="image" class="headimg lazyload" src="https://static.mhuig.top/npm/mhgoos@0.0.1663317354137/tf-idf.png" data-srcset="https://static.mhuig.top/npm/mhgoos@0.0.1663317354137/tf-idf.png" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="></a></div><div class="article-meta" id="top"><h1 class="title" itemprop="name headline"> 尝试在博客中添加简易文章推荐功能</h1><div class="new-meta-box"><div class="new-meta-item author" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" class="author" target="_blank" href="https://mhuig.top/" rel="nofollow noopener"><img itemprop="image" src="/lib/avatar/avatar-16.webp?v=2199236952" class="lazyload" data-srcset="/lib/avatar/avatar-16.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="><p itemprop="name">MHuiG</p></a></div><div class="new-meta-item wordcount"><a class="notlink"><i class="fa-duotone fa-keyboard fa-fw" aria-hidden="true"></i><p>字数:2.7k 字</p></a></div><div class="new-meta-item readtime"><a class="notlink"><i class="fa-duotone fa-hourglass-half fa-fw" aria-hidden="true"></i><p>时长:10 分钟</p></a></div></div></div><div id="layoutHelper-page-plugins"></div><div id="post-body" itemprop="articleBody"><p>把文档转换成 “向量”,并且尝试用线性代数等数学工具来解决信息检索这类问题,至少可以追溯到 20 世纪 70 年代。想到在 Hexo 这种静态博客系统,特别是 GitHub Page 这种 Serverless 服务中使用 Word2Vec 等深度学习方法似乎并不现实,所以这里使用的是一个非常简单经典的 TF-IDF 算法.</p><p>TF-IDF 算法原来是搜索引擎中的核心部分,谷歌百度已经使用 TF-IDF 作为内容排名因素很长一段时间.</p><p>现在的搜索引擎一般用如下的算法计算网站页面得分:score (页面得分) = TFIDF 分 * x + 链接分 * y + 用户体验分 * z(其中 x+y+z=100%),TFIDF 分值百度大约占 40% 左右的权重,谷歌更是达到了 50%.</p><p>这是百度的计算方法: score (页面得分) = 40% 的内容质量相关性(TFIDF)+ 40% 的用户体验分 + 20% 的链接分(域名 + 外链).</p><p>搜索引擎使用 TF-IDF 来计算内容质量相关性,我们这边也可以用它来计算文章内容相关性,然后实现简易文章推荐功能。</p><p>当然也可以使用文章的 tags 标签最为推荐依据,但是这样过于依赖人工标注数据,顺便最近发现在 Hexo 中分类和标签只能在 <code>source/_posts</code> 文件夹中使用才能渲染出来。</p><div class="story post-story"><h2 id="构建向量空间模型"><a href="#构建向量空间模型" class="headerlink" title="构建向量空间模型"></a>构建向量空间模型</h2><p>将文档转化为向量来表示,这样文档与文档之间就可以定量的去度量他们之间的关系,挖掘文档之间的联系。上面提到的 Word2Vec 是把单词转化为向量来表示,这样词与词之间就可以定量的去度量他们之间的关系,挖掘词之间的联系.</p><p>比如将词的维度降维到 2 维,用下图的词向量表示词:</p><p><img src="https://static.mhuig.top/npm/mhgoos@0.0.1663246894190/1.png" class="lazyload" data-srcset="https://static.mhuig.top/npm/mhgoos@0.0.1663246894190/1.png" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="单词转化为向量"></p><p><img src="https://static.mhuig.top/npm/mhgoos@0.0.1663284804787/2.png" class="lazyload" data-srcset="https://static.mhuig.top/npm/mhgoos@0.0.1663284804787/2.png" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="向量运算"></p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:42.671ex"><svg style="vertical-align:-1.498ex;min-width:42.671ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="4.127ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1162)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1162) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="7352.2 -1162 1 1824"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-412)"><g data-mml-node="mtd"><g data-mml-node="mover"><g data-mml-node="mrow"><g data-mml-node="mi"><path data-c="1D43E" d="M285 628Q285 635 228 637 205 637 198 638T191 647Q191 649 193 661 199 681 203 682 205 683 214 683H219Q260 681 355 681 389 681 418 681T463 682 483 682Q500 682 500 674 500 669 497 660 496 658 496 654T495 648 493 644 490 641 486 639 479 638 470 637 456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620 692 635 667 637 651 637 651 648 651 650 654 662T659 677Q662 682 676 682 680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672 889 650 881 642 878 637 862 637 787 632 726 586 710 576 656 534T556 455L509 418 518 396Q527 374 546 329T581 244Q656 67 661 61 663 59 666 57 680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3 503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71 544 75 517 141T485 216L427 354 359 301 291 248 268 155Q245 63 245 58 245 51 253 49T303 46H334Q340 37 340 35 340 19 333 5 328 0 317 0 314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 147 65 216 339T285 628Z"/></g><g data-mml-node="mi" transform="translate(889,0)"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mi" transform="translate(1234,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mi" transform="translate(1834,0)"><path data-c="1D454" d="M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412 431 419 447 422Q461 422 470 413T480 394Q480 379 423 152T363-80Q345-134 286-169T151-205Q10-205 10-137 10-111 28-91T74-71Q89-71 102-80T116-111Q116-121 114-130T107-144 99-154 92-162L90-164H91Q101-167 151-167 189-167 211-155 234-144 254-122T282-75Q288-56 298-13 311 35 311 43ZM384 328 380 339Q377 350 375 354T369 368 359 382 346 393 328 402 306 405Q262 405 221 352 191 313 171 233T151 117Q151 38 213 38 269 38 323 108L331 118 384 328Z"/></g></g><g data-mml-node="mo" transform="translate(0,870)"><path data-c="2192" d="M56 237T56 250 70 270H835Q719 357 692 493 692 494 692 496T691 499Q691 511 708 511H711Q720 511 723 510T729 506 732 497 735 481 743 456Q765 389 816 336T935 261Q944 258 944 250 944 244 939 241T915 231 877 212Q836 186 806 152T761 85 740 35 732 4Q730-6 727-8T711-11Q691-11 691 0 691 7 696 25 728 151 835 230H70Q56 237 56 250Z" transform="translate(1311,0)"/><svg width="1411" height="865" x="0" y="-182" viewBox="352.7 -182 1411 865"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z" transform="scale(2.72,1)"/></svg></g></g><g data-mml-node="mo" transform="translate(2533.2,0)"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"/></g><g data-mml-node="mover" transform="translate(3533.4,0)"><g data-mml-node="mrow"><g data-mml-node="mi"><path data-c="1D440" d="M289 629Q289 635 232 637 208 637 201 638T194 648Q194 649 196 659 197 662 198 666T199 671 201 676 203 679 207 681 212 683 220 683 232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117 510 154Q534 190 574 254T662 394Q837 673 839 675 840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673 1051 668 1048 656T1045 643Q1041 637 1008 637 968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50 822 48 855 46H886Q892 37 892 35 892 19 885 5 880 0 869 0 864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11 592 13 594 25 598 41 602 43T625 46Q652 46 685 49 699 52 704 61 706 65 742 207T813 490 848 631L654 322Q458 10 453 5 451 4 449 3 444 0 433 0 418 0 415 7 413 11 374 317L335 624 267 354Q200 88 200 79 206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1 274 0 267 0 265 0 255 0T221 1 157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46 135 46 154 86 158 92 223 354T289 629Z"/></g><g data-mml-node="mi" transform="translate(1051,0)"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mi" transform="translate(1580,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="mo" transform="translate(0,870)"><path data-c="2192" d="M56 237T56 250 70 270H835Q719 357 692 493 692 494 692 496T691 499Q691 511 708 511H711Q720 511 723 510T729 506 732 497 735 481 743 456Q765 389 816 336T935 261Q944 258 944 250 944 244 939 241T915 231 877 212Q836 186 806 152T761 85 740 35 732 4Q730-6 727-8T711-11Q691-11 691 0 691 7 696 25 728 151 835 230H70Q56 237 56 250Z" transform="translate(1180,0)"/><svg width="1280" height="865" x="0" y="-182" viewBox="320 -182 1280 865"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z" transform="scale(2.468,1)"/></svg></g></g><g data-mml-node="mo" transform="translate(5935.7,0)"><path data-c="2B" d="M56 237T56 250 70 270H369V420L370 570Q380 583 389 583 402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401-82 391-82H389 387Q375-82 369-68V230H70Q56 237 56 250Z"/></g><g data-mml-node="mover" transform="translate(6935.9,0)"><g data-mml-node="mrow"><g data-mml-node="mi"><path data-c="1D44A" d="M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674 695 670 692 659 687 641 683 639T661 637Q636 636 621 632T600 624 597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170 666 200 690 241 720 295 759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647 817 650 819 660 823 676 825 679T839 682Q842 682 856 682T895 682 949 681Q1015 681 1034 683 1048 683 1048 672 1048 666 1045 655T1038 640 1028 637Q1006 637 988 631T958 617 939 600 927 584L923 578 754 282Q586-14 585-15 579-22 561-22 546-22 542-17 539-14 523 229T506 480L494 462Q472 425 366 239 222-13 220-15T215-19Q210-22 197-22 178-22 176-15 176-12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648 52 671 64 683H76Q118 680 176 680 301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620 262 160 266 136L501 550 499 587Q496 629 489 632 483 636 447 637 428 637 422 639T416 648Q416 650 418 660 419 664 420 669T421 676 424 680 428 682 436 683Z"/></g><g data-mml-node="mi" transform="translate(1048,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(1533,0)"><path data-c="1D45A" d="M21 287Q22 293 24 303T36 341 56 388 88 425 132 442 175 435 205 417 221 395 229 376L231 369Q231 367 232 367L243 378Q303 442 384 442 401 442 415 440T441 433 460 423 475 411 485 398 493 385 497 373 500 364 502 357L510 367Q573 442 659 442 713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145 857 144 853 130 845 101 831 73T785 17 716-10Q669-10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291 466 157Q433 26 428 16 415-11 385-11 372-11 364-4T353 8 350 18Q350 29 384 161L420 307Q423 322 423 345 423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 181 151 335 151 342 154 357 154 369 154 405 129 405 107 405 92 377T69 316 57 280Q55 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mi" transform="translate(2411,0)"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mi" transform="translate(2940,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="mo" transform="translate(0,870)"><path data-c="2192" d="M56 237T56 250 70 270H835Q719 357 692 493 692 494 692 496T691 499Q691 511 708 511H711Q720 511 723 510T729 506 732 497 735 481 743 456Q765 389 816 336T935 261Q944 258 944 250 944 244 939 241T915 231 877 212Q836 186 806 152T761 85 740 35 732 4Q730-6 727-8T711-11Q691-11 691 0 691 7 696 25 728 151 835 230H70Q56 237 56 250Z" transform="translate(2540,0)"/><svg width="2640" height="865" x="0" y="-182" viewBox="660 -182 2640 865"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z" transform="scale(5.09,1)"/></svg></g></g><g data-mml-node="mo" transform="translate(10753.7,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mover" transform="translate(11809.4,0)"><g data-mml-node="mrow"><g data-mml-node="mi"><path data-c="1D444" d="M399-80Q399-47 400-30T402-11V-7L387-11Q341-22 303-22 208-22 138 35T51 201Q50 209 50 244 50 346 98 438T227 601Q351 704 476 704 514 704 524 703 621 689 680 617T740 435Q740 255 592 107 529 47 461 16L444 8V3Q444 2 449-24T470-66 516-82Q551-82 583-60T625-3Q631 11 638 11 647 11 649 2 649-6 639-34T611-100 557-165 481-194Q399-194 399-87V-80ZM636 468Q636 523 621 564T580 625 530 655 477 665Q429 665 379 640 277 591 215 464T153 216Q153 110 207 59 231 38 236 38V46Q236 86 269 120T347 155Q372 155 390 144T417 114 429 82 435 55L448 64Q512 108 557 185T619 334 636 468ZM314 18Q362 18 404 39L403 49Q399 104 366 115 354 117 347 117 344 117 341 117T337 118Q317 118 296 98T274 52Q274 18 314 18Z"/></g><g data-mml-node="mi" transform="translate(791,0)"><path data-c="1D462" d="M21 287Q21 295 30 318T55 370 99 420 158 442Q204 442 227 417T250 358Q250 340 216 246T182 105Q182 62 196 45T238 27 291 44 328 78L339 95Q341 99 377 247 407 367 413 387T427 416Q444 431 463 431 480 431 488 421T496 402L420 84Q419 79 419 68 419 43 426 35T447 26Q469 29 482 57T512 145Q514 153 532 153 551 153 551 144 550 139 549 130T540 98 523 55 498 17 462-8Q454-10 438-10 372-10 347 46 345 45 336 36T318 21 296 6 267-6 233-11Q189-11 155 7 103 38 103 113 103 170 138 262T173 379Q173 380 173 381 173 390 173 393T169 400 158 404H154Q131 404 112 385T82 344 65 302 57 280Q55 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mi" transform="translate(1363,0)"><path data-c="1D452" d="M39 168Q39 225 58 272T107 350 174 402 244 433 307 442H310Q355 442 388 420T421 355Q421 265 310 237 261 224 176 223 139 223 138 221 138 219 132 186T125 128Q125 81 146 54T209 26 302 45 394 111Q403 121 406 121 410 121 419 112T429 98 420 82 390 55 344 24 281-1 205-11Q126-11 83 42T39 168ZM373 353Q367 405 305 405 272 405 244 391T199 357 170 316 154 280 149 261Q149 260 169 260 282 260 327 284T373 353Z"/></g><g data-mml-node="mi" transform="translate(1829,0)"><path data-c="1D452" d="M39 168Q39 225 58 272T107 350 174 402 244 433 307 442H310Q355 442 388 420T421 355Q421 265 310 237 261 224 176 223 139 223 138 221 138 219 132 186T125 128Q125 81 146 54T209 26 302 45 394 111Q403 121 406 121 410 121 419 112T429 98 420 82 390 55 344 24 281-1 205-11Q126-11 83 42T39 168ZM373 353Q367 405 305 405 272 405 244 391T199 357 170 316 154 280 149 261Q149 260 169 260 282 260 327 284T373 353Z"/></g><g data-mml-node="mi" transform="translate(2295,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="mo" transform="translate(0,891)"><path data-c="2192" d="M56 237T56 250 70 270H835Q719 357 692 493 692 494 692 496T691 499Q691 511 708 511H711Q720 511 723 510T729 506 732 497 735 481 743 456Q765 389 816 336T935 261Q944 258 944 250 944 244 939 241T915 231 877 212Q836 186 806 152T761 85 740 35 732 4Q730-6 727-8T711-11Q691-11 691 0 691 7 696 25 728 151 835 230H70Q56 237 56 250Z" transform="translate(1895,0)"/><svg width="1995" height="865" x="0" y="-182" viewBox="498.8 -182 1995 865"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z" transform="scale(3.846,1)"/></svg></g></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1162 1 1824"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:1" transform="translate(0,338)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>似乎发现了什么不得了的事情。</p><p>对于自然语言书写的文本这种非结构化信息,从文本中抽取出的特征来量化来表示文本信息,构建向量空间模型,并基于数学模型的处理,将文本转换为机器可以理解的语言的方式是很重要的。</p></div><div class="story post-story"><h2 id="举个栗子"><a href="#举个栗子" class="headerlink" title="举个栗子"></a>举个栗子</h2><p>要实现文章推荐,就需要从一堆文章中找出一些内容相似的文章。基本思路就是,如果文章的关键词越相似,那么他们的内容就会越相似。</p><p>我们先从几个简单的句子着手。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:我这里有苹果和西瓜。</span><br><span class="line"></span><br><span class="line">句子B:我喜欢吃西瓜,不喜欢吃苹果。</span><br><span class="line"></span><br><span class="line">句子C:我喜欢吃蔬菜。</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第一步:数据清洗"><a href="#第一步:数据清洗" class="headerlink" title="第一步:数据清洗"></a>第一步:数据清洗</h2><p>简单去除标点符号等干扰信息。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A: 我这里有苹果和西瓜</span><br><span class="line"></span><br><span class="line">句子B: 我喜欢吃西瓜 不喜欢吃苹果</span><br><span class="line"></span><br><span class="line">句子C: 我喜欢吃蔬菜</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第二步:分词"><a href="#第二步:分词" class="headerlink" title="第二步:分词"></a>第二步:分词</h2><p>使用分词工具进行分词。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">[ <span class="string">'我'</span>, <span class="string">'这里'</span>, <span class="string">'有'</span>, <span class="string">'苹果'</span>, <span class="string">'和'</span>, <span class="string">'西瓜'</span> ]</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line">[</span><br><span class="line">  <span class="string">'我'</span>, <span class="string">'喜欢'</span>,</span><br><span class="line">  <span class="string">'吃'</span>, <span class="string">'西瓜'</span>,</span><br><span class="line">  <span class="string">'不'</span>, <span class="string">'喜欢'</span>,</span><br><span class="line">  <span class="string">'吃'</span>, <span class="string">'苹果'</span></span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">[ <span class="string">'我'</span>, <span class="string">'喜欢'</span>, <span class="string">'吃'</span>, <span class="string">'蔬菜'</span> ]</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第三步:去重收集所有句子中所有的词"><a href="#第三步:去重收集所有句子中所有的词" class="headerlink" title="第三步:去重收集所有句子中所有的词"></a>第三步:去重收集所有句子中所有的词</h2><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">[</span><br><span class="line">  <span class="string">'我'</span>,   <span class="string">'这里'</span>, <span class="string">'有'</span>,</span><br><span class="line">  <span class="string">'苹果'</span>, <span class="string">'和'</span>,   <span class="string">'西瓜'</span>,</span><br><span class="line">  <span class="string">'喜欢'</span>, <span class="string">'吃'</span>,   <span class="string">'不'</span>,</span><br><span class="line">  <span class="string">'蔬菜'</span></span><br><span class="line">]</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第四步:计算词频"><a href="#第四步:计算词频" class="headerlink" title="第四步:计算词频"></a>第四步:计算词频</h2><p>词频背后的假设是文章的重要程度即文章的相关度与单词在文档中出现的次数成正比。文章的关键词应当比文章中的其他词出现的次数多。</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:49.142ex"><svg style="vertical-align:-.566ex;min-width:49.142ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="2.262ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -750)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 750) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="8782.3 -750 1 1000"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr"><g data-mml-node="mtd"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mo" transform="translate(2000,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(2389,0)"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(3093,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(3842,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g><g data-mml-node="mo" transform="translate(4508.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mi" transform="translate(5564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x67d0;</text></g><g data-mml-node="mi" transform="translate(6564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2a;</text></g><g data-mml-node="mi" transform="translate(7564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(8564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x5728;</text></g><g data-mml-node="mi" transform="translate(9564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(10564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7ae0;</text></g><g data-mml-node="mi" transform="translate(11564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2d;</text></g><g data-mml-node="mi" transform="translate(12564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x51fa;</text></g><g data-mml-node="mi" transform="translate(13564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x73b0;</text></g><g data-mml-node="mi" transform="translate(14564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(15564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6b21;</text></g><g data-mml-node="mi" transform="translate(16564.6,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -750 1 1000"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:2"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></svg></g></g></g></g></svg></mjx-container></p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 1,</span><br><span class="line">  <span class="string">'这里'</span>: 1,</span><br><span class="line">  <span class="string">'有'</span>: 1,</span><br><span class="line">  <span class="string">'苹果'</span>: 1,</span><br><span class="line">  <span class="string">'和'</span>: 1,</span><br><span class="line">  <span class="string">'西瓜'</span>: 1,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 1,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 1,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 1,</span><br><span class="line">  <span class="string">'喜欢'</span>: 2,</span><br><span class="line">  <span class="string">'吃'</span>: 2,</span><br><span class="line">  <span class="string">'不'</span>: 1,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 1,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 1,</span><br><span class="line">  <span class="string">'吃'</span>: 1,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 1</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第四步:词频标准化"><a href="#第四步:词频标准化" class="headerlink" title="第四步:词频标准化"></a>第四步:词频标准化</h2><p>文章的篇幅有长有短,为了便于不同文章的比较,进行” 词频” 标准化。词频标准化的目的是把所有的词频在同一维度上分析。</p><p>词频标准化有两种方案:</p><p>方案一:</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:50.137ex"><svg style="vertical-align:-2.077ex;min-width:50.137ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="5.285ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1418)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1418) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="9002.3 -1418 1 2336"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-8)"><g data-mml-node="mtd"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mo" transform="translate(2000,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(2389,0)"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(3093,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(3842,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g><g data-mml-node="mo" transform="translate(4508.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mfrac" transform="translate(5564.6,0)"><g data-mml-node="mrow" transform="translate(220,676)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x67d0;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2a;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x5728;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7ae0;</text></g><g data-mml-node="mi" transform="translate(6000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2d;</text></g><g data-mml-node="mi" transform="translate(7000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x51fa;</text></g><g data-mml-node="mi" transform="translate(8000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x73b0;</text></g><g data-mml-node="mi" transform="translate(9000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(10000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6b21;</text></g><g data-mml-node="mi" transform="translate(11000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g><g data-mml-node="mrow" transform="translate(3220,-710)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7ae0;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x603b;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g><rect width="12200" height="60" x="120" y="220"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1418 1 2336"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:3" transform="translate(0,742)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664 351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336 375 315Q457 262 457 175 457 96 395 37T238-22Q158-22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94 148 82 136 74 126 70 118 67L114 66Q165 21 238 21 293 21 321 74 338 107 338 175V195Q338 290 274 322 259 328 213 329L171 330 168 332Q166 335 166 348 166 366 174 366 202 366 232 371 266 376 294 413T322 525V533Q322 590 287 612 265 626 240 626 208 626 181 615T143 592 132 580H135Q138 579 143 578T153 573 165 566 175 555 183 540 186 520Q186 498 172 481T127 463Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>方案二:</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:52.399ex"><svg style="vertical-align:-2.077ex;min-width:52.399ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="5.285ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1418)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1418) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="9502.3 -1418 1 2336"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-8)"><g data-mml-node="mtd"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mo" transform="translate(2000,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(2389,0)"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(3093,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(3842,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g><g data-mml-node="mo" transform="translate(4508.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mfrac" transform="translate(5564.6,0)"><g data-mml-node="mrow" transform="translate(720,676)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x67d0;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2a;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x5728;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7ae0;</text></g><g data-mml-node="mi" transform="translate(6000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x4e2d;</text></g><g data-mml-node="mi" transform="translate(7000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x51fa;</text></g><g data-mml-node="mi" transform="translate(8000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x73b0;</text></g><g data-mml-node="mi" transform="translate(9000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(10000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6b21;</text></g><g data-mml-node="mi" transform="translate(11000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g><g data-mml-node="mrow" transform="translate(220,-710)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8be5;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x51fa;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x73b0;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6700;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x591a;</text></g><g data-mml-node="mi" transform="translate(6000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(7000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(8000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x51fa;</text></g><g data-mml-node="mi" transform="translate(9000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x73b0;</text></g><g data-mml-node="mi" transform="translate(10000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(11000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6b21;</text></g><g data-mml-node="mi" transform="translate(12000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g><rect width="13200" height="60" x="120" y="220"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1418 1 2336"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:4" transform="translate(0,742)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="34" d="M462 0Q444 3 333 3 217 3 199 0H190V46H221Q241 46 248 46T265 48 279 53 286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675 336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212 183 211H293Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>一般情况下,第二个标准化方案更适用,因为能够使词频的值相对大点,便于分析。</p><p>有时候常常用<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.566ex" xmlns="http://www.w3.org/2000/svg" width="12.662ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 5596.4 1000"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g><g data-mml-node="mo" transform="translate(722.2,0)"><path data-c="2B" d="M56 237T56 250 70 270H369V420L370 570Q380 583 389 583 402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401-82 391-82H389 387Q375-82 369-68V230H70Q56 237 56 250Z"/></g><g data-mml-node="mi" transform="translate(1722.4,0)"><path data-c="1D43F" d="M228 637Q194 637 192 641 191 643 191 649 191 673 202 682 204 683 217 683 271 680 344 680 485 680 506 683H518Q524 677 524 674T522 656Q517 641 513 637H475Q406 636 394 628 387 624 380 600T313 336Q297 271 279 198T252 88L243 52Q243 48 252 48T311 46H328Q360 46 379 47T428 54 478 72 522 106 564 161Q580 191 594 228T611 270Q616 273 628 273H641Q647 264 647 262T627 203 583 83 557 9Q555 4 553 3T537 0 494-1Q483-1 418-1T294 0H116Q32 0 32 10 32 17 34 24 39 43 44 45 48 46 59 46H65Q92 46 125 49 139 52 144 61 147 65 216 339T285 628Q285 635 228 637Z"/></g><g data-mml-node="mi" transform="translate(2403.4,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(2888.4,0)"><path data-c="1D454" d="M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412 431 419 447 422Q461 422 470 413T480 394Q480 379 423 152T363-80Q345-134 286-169T151-205Q10-205 10-137 10-111 28-91T74-71Q89-71 102-80T116-111Q116-121 114-130T107-144 99-154 92-162L90-164H91Q101-167 151-167 189-167 211-155 234-144 254-122T282-75Q288-56 298-13 311 35 311 43ZM384 328 380 339Q377 350 375 354T369 368 359 382 346 393 328 402 306 405Q262 405 221 352 191 313 171 233T151 117Q151 38 213 38 269 38 323 108L331 118 384 328Z"/></g><g data-mml-node="mo" transform="translate(3365.4,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(3754.4,0)"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(4458.4,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(5207.4,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g></g></g></svg></mjx-container> 这个值来代替原来的 TF 取值。这样的计算保持了一个平衡,既有区分度,但也不至于完全线性增长。</p><p>这里使用比较简单的方案一作为栗子:</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'这里'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'有'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'苹果'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'和'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0.16666666666666666,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 0.125,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 0.125,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0.125,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0.25,</span><br><span class="line">  <span class="string">'吃'</span>: 0.25,</span><br><span class="line">  <span class="string">'不'</span>: 0.125,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: 0.25,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0.25,</span><br><span class="line">  <span class="string">'吃'</span>: 0.25,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0.25</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第五步:计算逆文档频率"><a href="#第五步:计算逆文档频率" class="headerlink" title="第五步:计算逆文档频率"></a>第五步:计算逆文档频率</h2><p>仅有词频 (TF) 不能比较完整地描述文档的相关度。因为语言的因素,有一些单词可能会比较自然地在很多文档中反复出现,比如这里中的 “我”、“和” 等等。这些词大多起到了链接语句的作用,是保持语言连贯不可或缺的部分。</p><p>很明显,如果有太多文档都涵盖了某个单词,这个单词也就越不重要,或者说是这个单词就越没有信息量。因此,我们需要对词频 (TF) 的值进行修正,而 逆文档频率 (IDF) 的想法是用文档频率 (DF) 的倒数来进行修正。</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:57.803ex"><svg style="vertical-align:-2.077ex;min-width:57.803ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="5.285ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1418)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1418) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="10696.5 -1418 1 2336"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-8)"><g data-mml-node="mtd"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9006;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6863;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7387;</text></g><g data-mml-node="mo" transform="translate(5000,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(5389,0)"><path data-c="1D43C" d="M43 1Q26 1 26 10 26 12 29 24 34 43 39 45 42 46 54 46H60Q120 46 136 53 137 53 138 54 143 56 149 77T198 273Q210 318 216 344 286 624 286 626 284 630 284 631 274 637 213 637H193Q184 643 189 662 193 677 195 680T209 683H213Q285 681 359 681 481 681 487 683H497Q504 676 504 672T501 655 494 639Q491 637 471 637 440 637 407 634 393 631 388 623 381 609 337 432 326 385 315 341 245 65 245 59 245 52 255 50T307 46H339Q345 38 345 37T342 19Q338 6 332 0H316Q279 2 179 2 143 2 113 2T65 2 43 1Z"/></g><g data-mml-node="mi" transform="translate(5893,0)"><path data-c="1D437" d="M287 628Q287 635 230 637 207 637 200 638T193 647Q193 655 197 667T204 682Q206 683 403 683 570 682 590 682T630 676Q702 659 752 597T803 431Q803 275 696 151T444 3L430 1 236 0H125 72Q48 0 41 2T33 11Q33 13 36 25 40 41 44 43T67 46Q94 46 127 49 141 52 146 61 149 65 218 339T287 628ZM703 469Q703 507 692 537T666 584 629 613 590 629 555 636Q553 636 541 636T512 636 479 637H436Q392 637 386 627 384 623 313 339T242 52Q242 48 253 48T330 47Q335 47 349 47T373 46Q499 46 581 128 617 164 640 212T683 339 703 469Z"/></g><g data-mml-node="mi" transform="translate(6721,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(7470,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g><g data-mml-node="mo" transform="translate(8136.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mi" transform="translate(9192.6,0)"><path data-c="1D459" d="M117 59Q117 26 142 26 179 26 205 131 211 151 215 152 217 153 225 153H229Q238 153 241 153T246 151 248 144Q247 138 245 128T234 90 214 43 183 6 137-11Q101-11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623 167 626 166 628T162 632 157 634 149 635 141 636 132 637 122 637Q112 637 109 637T101 638 95 641 94 647Q94 649 96 661 101 680 107 682T179 688Q194 689 213 690T243 693 254 694Q266 694 266 686 266 675 193 386T118 83Q118 81 118 75T117 65V59Z"/></g><g data-mml-node="mi" transform="translate(9490.6,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(9975.6,0)"><path data-c="1D454" d="M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412 431 419 447 422Q461 422 470 413T480 394Q480 379 423 152T363-80Q345-134 286-169T151-205Q10-205 10-137 10-111 28-91T74-71Q89-71 102-80T116-111Q116-121 114-130T107-144 99-154 92-162L90-164H91Q101-167 151-167 189-167 211-155 234-144 254-122T282-75Q288-56 298-13 311 35 311 43ZM384 328 380 339Q377 350 375 354T369 368 359 382 346 393 328 402 306 405Q262 405 221 352 191 313 171 233T151 117Q151 38 213 38 269 38 323 108L331 118 384 328Z"/></g><g data-mml-node="mo" transform="translate(10452.6,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mfrac" transform="translate(10841.6,0)"><g data-mml-node="mrow" transform="translate(1081.2,676)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bed;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6599;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x5e93;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6863;</text></g><g data-mml-node="mi" transform="translate(6000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x603b;</text></g><g data-mml-node="mi" transform="translate(7000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g></g><g data-mml-node="mrow" transform="translate(220,-710)"><g data-mml-node="mi"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x5305;</text></g><g data-mml-node="mi" transform="translate(1000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x542b;</text></g><g data-mml-node="mi" transform="translate(2000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8be5;</text></g><g data-mml-node="mi" transform="translate(3000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(4000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7684;</text></g><g data-mml-node="mi" transform="translate(5000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(6000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6863;</text></g><g data-mml-node="mi" transform="translate(7000,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6570;</text></g><g data-mml-node="mo" transform="translate(8222.2,0)"><path data-c="2B" d="M56 237T56 250 70 270H369V420L370 570Q380 583 389 583 402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401-82 391-82H389 387Q375-82 369-68V230H70Q56 237 56 250Z"/></g><g data-mml-node="mn" transform="translate(9222.4,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g><rect width="9922.4" height="60" x="120" y="220"/></g><g data-mml-node="mo" transform="translate(21004,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1418 1 2336"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:5" transform="translate(0,742)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22 294 22 326 82 345 115 345 210 345 313 318 349 292 382 260 382H254Q176 382 136 314 132 307 129 306T114 304Q97 304 95 310 93 314 93 485V614Q93 664 98 664 100 666 102 666 103 666 123 658T178 642 253 634Q324 634 389 662 397 666 402 666 410 666 410 648V635Q328 538 205 538 174 538 149 544L139 546V374Q158 388 169 396T205 412 256 420Q337 420 393 355T449 201Q449 109 385 44T229-22Q148-22 99 32T50 154Q50 178 61 192T84 210 107 214Q132 214 148 197T164 157Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>如果一个词越常见,那么分母就越大,逆文档频率就越小越接近 0。分母之所以要加 1,是为了避免分母为 0(即所有文档都不包含该词)。log 表示对得到的值取对数。为什么要用 log 函数?log 函数是单调递增,求 log 是为了归一化,保证逆文档频率不会过大。用 Log 进行变换,也是一个非线性增长的技巧,这样的计算保持了一个平衡,既有区分度,但也不至于完全线性增长。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.2876820724517809,</span><br><span class="line">  <span class="string">'这里'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'有'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0.4054651081081644</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.2876820724517809,</span><br><span class="line">  <span class="string">'这里'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'有'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0.4054651081081644</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.2876820724517809,</span><br><span class="line">  <span class="string">'这里'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'有'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0.4054651081081644,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0.4054651081081644</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第六步:计算TF-IDF"><a href="#第六步:计算TF-IDF" class="headerlink" title="第六步:计算TF-IDF"></a>第六步:计算 TF-IDF</h2><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:53.3ex"><svg style="vertical-align:-.566ex;min-width:53.3ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="2.262ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -750)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 750) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="9701.2 -750 1 1000"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr"><g data-mml-node="mtd"><g data-mml-node="mi"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(704,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(1675.2,0)"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"/></g><g data-mml-node="mi" transform="translate(2675.4,0)"><path data-c="1D43C" d="M43 1Q26 1 26 10 26 12 29 24 34 43 39 45 42 46 54 46H60Q120 46 136 53 137 53 138 54 143 56 149 77T198 273Q210 318 216 344 286 624 286 626 284 630 284 631 274 637 213 637H193Q184 643 189 662 193 677 195 680T209 683H213Q285 681 359 681 481 681 487 683H497Q504 676 504 672T501 655 494 639Q491 637 471 637 440 637 407 634 393 631 388 623 381 609 337 432 326 385 315 341 245 65 245 59 245 52 255 50T307 46H339Q345 38 345 37T342 19Q338 6 332 0H316Q279 2 179 2 143 2 113 2T65 2 43 1Z"/></g><g data-mml-node="mi" transform="translate(3179.4,0)"><path data-c="1D437" d="M287 628Q287 635 230 637 207 637 200 638T193 647Q193 655 197 667T204 682Q206 683 403 683 570 682 590 682T630 676Q702 659 752 597T803 431Q803 275 696 151T444 3L430 1 236 0H125 72Q48 0 41 2T33 11Q33 13 36 25 40 41 44 43T67 46Q94 46 127 49 141 52 146 61 149 65 218 339T287 628ZM703 469Q703 507 692 537T666 584 629 613 590 629 555 636Q553 636 541 636T512 636 479 637H436Q392 637 386 627 384 623 313 339T242 52Q242 48 253 48T330 47Q335 47 349 47T373 46Q499 46 581 128 617 164 640 212T683 339 703 469Z"/></g><g data-mml-node="mi" transform="translate(4007.4,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(5034.2,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mi" transform="translate(6090,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x8bcd;</text></g><g data-mml-node="mi" transform="translate(7090,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mo" transform="translate(8090,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(8479,0)"><path data-c="1D447" d="M40 437Q21 437 21 445 21 450 37 501T71 602L88 651Q93 669 101 677H569 659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437 640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631 469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46 418 46 427 45T436 36Q436 31 433 22 429 4 424 1L422 0Q419 0 415 0 410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83 94Q174 46 189 55 190 56 191 56 196 59 201 76T241 233Q258 301 269 344 339 619 339 625 339 630 310 630H279Q212 630 191 624 146 614 121 583T67 467Q60 445 57 441T43 437H40Z"/></g><g data-mml-node="mi" transform="translate(9183,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(9932,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g><g data-mml-node="mo" transform="translate(10543.2,0)"><path data-c="D7" d="M630 29Q630 9 609 9 604 9 587 25T493 118L389 222 284 117Q178 13 175 11 171 9 168 9 160 9 154 15T147 29Q147 36 161 51T255 146L359 250 255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489 178 487 284 383L389 278 493 382Q570 459 587 475T609 491Q630 491 630 471 630 464 620 453T522 355L418 250 522 145Q606 61 618 48T630 29Z"/></g><g data-mml-node="mi" transform="translate(11543.4,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9006;</text></g><g data-mml-node="mi" transform="translate(12543.4,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6587;</text></g><g data-mml-node="mi" transform="translate(13543.4,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x6863;</text></g><g data-mml-node="mi" transform="translate(14543.4,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x9891;</text></g><g data-mml-node="mi" transform="translate(15543.4,0)"><text data-variant="normal" transform="scale(1,-1)" font-size="884px" font-family="serif">&#x7387;</text></g><g data-mml-node="mo" transform="translate(16543.4,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="mi" transform="translate(16932.4,0)"><path data-c="1D43C" d="M43 1Q26 1 26 10 26 12 29 24 34 43 39 45 42 46 54 46H60Q120 46 136 53 137 53 138 54 143 56 149 77T198 273Q210 318 216 344 286 624 286 626 284 630 284 631 274 637 213 637H193Q184 643 189 662 193 677 195 680T209 683H213Q285 681 359 681 481 681 487 683H497Q504 676 504 672T501 655 494 639Q491 637 471 637 440 637 407 634 393 631 388 623 381 609 337 432 326 385 315 341 245 65 245 59 245 52 255 50T307 46H339Q345 38 345 37T342 19Q338 6 332 0H316Q279 2 179 2 143 2 113 2T65 2 43 1Z"/></g><g data-mml-node="mi" transform="translate(17436.4,0)"><path data-c="1D437" d="M287 628Q287 635 230 637 207 637 200 638T193 647Q193 655 197 667T204 682Q206 683 403 683 570 682 590 682T630 676Q702 659 752 597T803 431Q803 275 696 151T444 3L430 1 236 0H125 72Q48 0 41 2T33 11Q33 13 36 25 40 41 44 43T67 46Q94 46 127 49 141 52 146 61 149 65 218 339T287 628ZM703 469Q703 507 692 537T666 584 629 613 590 629 555 636Q553 636 541 636T512 636 479 637H436Q392 637 386 627 384 623 313 339T242 52Q242 48 253 48T330 47Q335 47 349 47T373 46Q499 46 581 128 617 164 640 212T683 339 703 469Z"/></g><g data-mml-node="mi" transform="translate(18264.4,0)"><path data-c="1D439" d="M48 1Q31 1 31 11 31 13 34 25 38 41 42 43T65 46Q92 46 125 49 139 52 144 61 146 66 215 342T285 622Q285 629 281 629 273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H742Q749 676 749 669 749 664 736 557T722 447Q720 440 702 440H690Q683 445 683 453 683 454 686 477T689 530Q689 560 682 579T663 610 626 626 575 633 503 634H480Q398 633 393 631 388 629 386 623 385 622 352 492L320 363H375Q378 363 398 363T426 364 448 367 472 374 489 386Q502 398 511 419T524 457 529 475Q532 480 548 480H560Q567 475 567 470 567 467 536 339T502 207Q500 200 482 200H470Q463 206 463 212 463 215 468 234T473 274Q473 303 453 310T364 317H309L277 190Q245 66 245 60 245 46 334 46H359Q365 40 365 39T363 19Q359 6 353 0H336Q295 2 185 2 120 2 86 2T48 1Z"/></g><g data-mml-node="mo" transform="translate(19013.4,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -750 1 1000"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:6"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601 351 623 311 626 240 626 194 566 147 500 147 364L148 360Q153 366 156 373 197 433 263 433H267Q313 433 348 414 372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149 440 90 387 34T253-22Q225-22 199-14T143 16 92 75 56 172 42 313ZM257 397Q227 397 205 380T171 335 154 278 148 216Q148 133 160 97T198 39Q222 21 251 21 302 21 329 59 342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>可以看到,TF-IDF 与一个词在文档中的出现次数成正比,与该词在整个文档库中的出现次数成反比。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.047947012075296815,</span><br><span class="line">  <span class="string">'这里'</span>: 0.06757751801802739,</span><br><span class="line">  <span class="string">'有'</span>: 0.06757751801802739,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0.06757751801802739,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.03596025905647261,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0.05068313851352055,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line">  <span class="string">'我'</span>: -0.07192051811294523,</span><br><span class="line">  <span class="string">'这里'</span>: 0,</span><br><span class="line">  <span class="string">'有'</span>: 0,</span><br><span class="line">  <span class="string">'苹果'</span>: 0,</span><br><span class="line">  <span class="string">'和'</span>: 0,</span><br><span class="line">  <span class="string">'西瓜'</span>: 0,</span><br><span class="line">  <span class="string">'喜欢'</span>: 0,</span><br><span class="line">  <span class="string">'吃'</span>: 0,</span><br><span class="line">  <span class="string">'不'</span>: 0,</span><br><span class="line">  <span class="string">'蔬菜'</span>: 0.1013662770270411</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第七步:列出文档向量"><a href="#第七步:列出文档向量" class="headerlink" title="第七步:列出文档向量"></a>第七步:列出文档向量</h2><p>这里准确来说应该是 TF-IDF 特征向量,这是一个稀疏矩阵。下面把它作为描述文章特征的向量。</p><p>说明一点,这里的文章的特征不是由某几个关键词的 TF-IDF 值决定的,而是由所有的词的 TF-IDF 值共同决定的。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">句子A:</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">  -0.047947012075296815,</span><br><span class="line">  0.06757751801802739,</span><br><span class="line">  0.06757751801802739,</span><br><span class="line">  0,</span><br><span class="line">  0.06757751801802739,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">句子B:</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">  -0.03596025905647261,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0.05068313851352055,</span><br><span class="line">  0</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">句子C:</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">  -0.07192051811294523,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0,</span><br><span class="line">  0.1013662770270411</span><br><span class="line">]</span><br></pre></td></tr></tbody></table></figure><p>可以对文档向量进行标准化,使得这些向量能够不受向量里有效元素多少的影响,也就是不同的文档可能有不同的长度。把向量都标准化为一个单位向量的长度。这个时候再进行点积运算,就相当于在原来的向量上进行余弦相似度的运算。</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:32.32ex"><svg style="vertical-align:-.958ex;min-width:32.32ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="3.048ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -923.5)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 923.5) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="5064.8 -923.5 1 1347"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-173.5)"><g data-mml-node="mtd"><g data-mml-node="TeXAtom" data-mjx-texclass="ORD"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mo" transform="translate(264.5,31) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g><g data-mml-node="mo" transform="translate(751.2,0)"><path data-c="22C5" d="M78 250Q78 274 95 292T138 310Q162 310 180 294T199 251Q199 226 182 208T139 190 96 207 78 250Z"/></g><g data-mml-node="TeXAtom" data-mjx-texclass="ORD" transform="translate(1251.4,0)"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402 231 442 283 442 345 442 383 396T422 280Q422 169 343 79T173-11Q123-11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640 73 647ZM336 325V331Q336 405 275 405 258 405 240 397T207 376 181 352 163 330L157 322 136 236Q114 150 114 114 114 66 138 42 154 26 178 26 211 26 245 58 270 81 285 114T318 219Q336 291 336 325Z"/></g><g data-mml-node="mo" transform="translate(214.5,283) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g><g data-mml-node="mo" transform="translate(1958.2,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mo" transform="translate(3014,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="TeXAtom" data-mjx-texclass="ORD" transform="translate(3292,0)"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mo" transform="translate(264.5,31) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g><g data-mml-node="mo" transform="translate(3821,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="mo" transform="translate(4099,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="TeXAtom" data-mjx-texclass="ORD" transform="translate(4377,0)"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402 231 442 283 442 345 442 383 396T422 280Q422 169 343 79T173-11Q123-11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640 73 647ZM336 325V331Q336 405 275 405 258 405 240 397T207 376 181 352 163 330L157 322 136 236Q114 150 114 114 114 66 138 42 154 26 178 26 211 26 245 58 270 81 285 114T318 219Q336 291 336 325Z"/></g><g data-mml-node="mo" transform="translate(214.5,283) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g><g data-mml-node="mo" transform="translate(4806,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="mi" transform="translate(5084,0)"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mi" transform="translate(5517,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(6002,0)"><path data-c="1D460" d="M131 289Q131 321 147 354T203 415 300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372 367 378Q368 378 368 379 368 382 361 388T336 399 297 405Q249 405 227 379T204 326Q204 301 223 291T278 274 330 259Q396 230 396 163 396 135 385 107T352 51 289 7 195-10Q118-10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34 201 27Q237 27 263 38T301 66 318 97 323 122Q323 150 302 164T254 181 195 196 148 231Q131 256 131 289Z"/></g><g data-mml-node="mi" transform="translate(6471,0)"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g><g data-mml-node="mo" transform="translate(7217.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mi" transform="translate(8273.6,0)"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mi" transform="translate(8706.6,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(9191.6,0)"><path data-c="1D460" d="M131 289Q131 321 147 354T203 415 300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372 367 378Q368 378 368 379 368 382 361 388T336 399 297 405Q249 405 227 379T204 326Q204 301 223 291T278 274 330 259Q396 230 396 163 396 135 385 107T352 51 289 7 195-10Q118-10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34 201 27Q237 27 263 38T301 66 318 97 323 122Q323 150 302 164T254 181 195 196 148 231Q131 256 131 289Z"/></g><g data-mml-node="mi" transform="translate(9660.6,0)"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -923.5 1 1347"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:7" transform="translate(0,576.5)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="37" d="M55 458Q56 460 72 567L88 674Q88 676 108 676H128V672Q128 662 143 655T195 646 364 644H485V605L417 512Q408 500 387 472T360 435 339 403 319 367 305 330 292 284 284 230 278 162 275 80Q275 66 275 52T274 28V19Q270 2 255-10T221-22Q210-22 200-19T179 0 168 40Q168 198 265 368 285 400 349 489L395 552H302Q128 552 119 546 113 543 108 522T98 479L95 458V455H55V458Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p></div><div class="story post-story"><h2 id="第八步:计算余弦相似度"><a href="#第八步:计算余弦相似度" class="headerlink" title="第八步:计算余弦相似度"></a>第八步:计算余弦相似度</h2><p>到这里,如何寻找两篇相似文章的问题转变成了如何计算这两个向量的相似程度的问题。</p><p>什么叫做向量相似?</p><p>一般地,如果两个向量平行或重合,我们认为这两个向量相似度为<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.131ex" height="1.507ex" role="img" focusable="false" viewBox="0 -666 500 666"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g></svg></mjx-container>。如果这两个向量垂直,或者说正交,我们认为这两个向量的相似度为<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.05ex" xmlns="http://www.w3.org/2000/svg" width="1.131ex" height="1.557ex" role="img" focusable="false" viewBox="0 -666 500 688"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="30" d="M96 585Q152 666 249 666 297 666 345 640T423 548Q460 465 460 320 460 165 417 83 397 41 362 16T301-15 250-22Q224-22 198-16T137 16 82 83Q39 165 39 320 39 494 96 585ZM321 597Q291 629 250 629 208 629 178 597 153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16 290 16 318 46 347 76 354 130T362 333Q362 478 354 524T321 597Z"/></g></g></g></svg></mjx-container>。</p><p>以二维空间为例,<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.023ex" xmlns="http://www.w3.org/2000/svg" width="1.197ex" height="1.934ex" role="img" focusable="false" viewBox="0 -845 529 855"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="TeXAtom" data-mjx-texclass="ORD"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mo" transform="translate(264.5,31) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g></g></g></svg></mjx-container> 和<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.025ex" xmlns="http://www.w3.org/2000/svg" width="0.971ex" height="2.507ex" role="img" focusable="false" viewBox="0 -1097 429 1108"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="TeXAtom" data-mjx-texclass="ORD"><g data-mml-node="mover"><g data-mml-node="mi"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402 231 442 283 442 345 442 383 396T422 280Q422 169 343 79T173-11Q123-11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640 73 647ZM336 325V331Q336 405 275 405 258 405 240 397T207 376 181 352 163 330L157 322 136 236Q114 150 114 114 114 66 138 42 154 26 178 26 211 26 245 58 270 81 285 114T318 219Q336 291 336 325Z"/></g><g data-mml-node="mo" transform="translate(214.5,283) translate(-250 0)"><path data-c="20D7" d="M377 694Q377 702 382 708T397 714Q404 714 409 709 414 705 419 690 429 653 460 633 471 626 471 615 471 606 468 603T454 594Q411 572 379 531 377 529 374 525T369 519 364 517 357 516Q350 516 344 521T337 536Q337 555 384 595H213L42 596Q29 605 29 615 29 622 42 635H401Q377 673 377 694Z"/></g></g></g></g></g></svg></mjx-container> 是两个向量,我们要计算它们的夹角<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.023ex" xmlns="http://www.w3.org/2000/svg" width="1.061ex" height="1.618ex" role="img" focusable="false" viewBox="0 -705 469 715"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g></g></g></svg></mjx-container> 。余弦定理告诉我们,可以用下面的公式求得:</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:29.256ex"><svg style="vertical-align:-1.931ex;min-width:29.256ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="4.993ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1353.5)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1353.5) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="4387.6 -1353.5 1 2206.9"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,-156.5)"><g data-mml-node="mtd"><g data-mml-node="mi"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mi" transform="translate(433,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(918,0)"><path data-c="1D460" d="M131 289Q131 321 147 354T203 415 300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372 367 378Q368 378 368 379 368 382 361 388T336 399 297 405Q249 405 227 379T204 326Q204 301 223 291T278 274 330 259Q396 230 396 163 396 135 385 107T352 51 289 7 195-10Q118-10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34 201 27Q237 27 263 38T301 66 318 97 323 122Q323 150 302 164T254 181 195 196 148 231Q131 256 131 289Z"/></g><g data-mml-node="mi" transform="translate(1387,0)"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g><g data-mml-node="mo" transform="translate(2133.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mfrac" transform="translate(3189.6,0)"><g data-mml-node="mrow" transform="translate(220,676)"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mn" transform="translate(562,363) scale(0.707)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g></g><g data-mml-node="mo" transform="translate(1187.8,0)"><path data-c="2B" d="M56 237T56 250 70 270H369V420L370 570Q380 583 389 583 402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401-82 391-82H389 387Q375-82 369-68V230H70Q56 237 56 250Z"/></g><g data-mml-node="msup" transform="translate(2188,0)"><g data-mml-node="mi"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402 231 442 283 442 345 442 383 396T422 280Q422 169 343 79T173-11Q123-11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640 73 647ZM336 325V331Q336 405 275 405 258 405 240 397T207 376 181 352 163 330L157 322 136 236Q114 150 114 114 114 66 138 42 154 26 178 26 211 26 245 58 270 81 285 114T318 219Q336 291 336 325Z"/></g><g data-mml-node="mn" transform="translate(462,363) scale(0.707)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g></g><g data-mml-node="mo" transform="translate(3275.8,0)"><path data-c="2212" d="M84 237T84 250 98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"/></g><g data-mml-node="msup" transform="translate(4276,0)"><g data-mml-node="mi"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mn" transform="translate(466,363) scale(0.707)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g></g></g><g data-mml-node="mrow" transform="translate(2063.8,-686)"><g data-mml-node="mn"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mi" transform="translate(500,0)"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392 386 422 416 422 429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35 443 55 463 131 469 151 473 152 475 153 483 153H487Q506 153 506 144 506 138 501 117T481 63 449 13Q436 0 417-8 409-10 393-10 359-10 336 5T306 36L300 51Q299 52 296 50 294 48 292 46 233-10 172-10 117-10 75 30T33 157ZM351 328Q351 334 346 350T323 385 277 405Q242 405 210 374T160 293Q131 214 119 129 119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"/></g><g data-mml-node="mi" transform="translate(1029,0)"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402 231 442 283 442 345 442 383 396T422 280Q422 169 343 79T173-11Q123-11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640 73 647ZM336 325V331Q336 405 275 405 258 405 240 397T207 376 181 352 163 330L157 322 136 236Q114 150 114 114 114 66 138 42 154 26 178 26 211 26 245 58 270 81 285 114T318 219Q336 291 336 325Z"/></g></g><rect width="5345.5" height="60" x="120" y="220"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1353.5 1 2206.9"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:8" transform="translate(0,593.5)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="38" d="M70 417T70 494 124 618 248 666Q319 666 374 624T429 515Q429 485 418 459T392 417 361 389 335 371 324 363L338 354Q352 344 366 334T382 323Q457 264 457 174 457 95 399 37T249-22Q159-22 101 29T43 155Q43 263 172 335L154 348Q133 361 127 368 70 417 70 494ZM286 386 292 390Q298 394 301 396T311 403 323 413 334 425 345 438 355 454 364 471 369 491 371 513Q371 556 342 586T275 624Q268 625 242 625 201 625 165 599T128 534Q128 511 141 492T167 463 217 431Q224 426 228 424L286 386ZM250 21Q308 21 350 55T392 137Q392 154 387 169T375 194 353 216 330 234 301 253 274 270Q260 279 244 289T218 306L210 311Q204 311 181 294T133 239 107 157Q107 98 150 60T250 21Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>假定<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.697ex" height="1.62ex" role="img" focusable="false" viewBox="0 -716 750 716"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g></g></g></svg></mjx-container>和<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.717ex" height="1.545ex" role="img" focusable="false" viewBox="0 -683 759 683"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g></g></g></svg></mjx-container>是两个<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.025ex" xmlns="http://www.w3.org/2000/svg" width="1.357ex" height="1.025ex" role="img" focusable="false" viewBox="0 -442 600 453"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g></g></svg></mjx-container>维向量,我们把这些向量放到<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.025ex" xmlns="http://www.w3.org/2000/svg" width="1.357ex" height="1.025ex" role="img" focusable="false" viewBox="0 -442 600 453"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g></g></svg></mjx-container>维欧几里得空间中讨论,向量之间的距离使用欧几里得距离。</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:26.31ex"><svg style="vertical-align:-2.094ex;min-width:26.31ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="5.319ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1425.5)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2078,0) translate(-2078,0)"><g transform="translate(0 1425.5) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="3736.5 -1425.5 1 2351"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,33.5)"><g data-mml-node="mtd"><g data-mml-node="mi"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mi" transform="translate(433,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(918,0)"><path data-c="1D460" d="M131 289Q131 321 147 354T203 415 300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372 367 378Q368 378 368 379 368 382 361 388T336 399 297 405Q249 405 227 379T204 326Q204 301 223 291T278 274 330 259Q396 230 396 163 396 135 385 107T352 51 289 7 195-10Q118-10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34 201 27Q237 27 263 38T301 66 318 97 323 122Q323 150 302 164T254 181 195 196 148 231Q131 256 131 289Z"/></g><g data-mml-node="mi" transform="translate(1387,0)"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g><g data-mml-node="mo" transform="translate(2133.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mfrac" transform="translate(3189.6,0)"><g data-mml-node="mrow" transform="translate(1026,676)"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mo" transform="translate(972.2,0)"><path data-c="22C5" d="M78 250Q78 274 95 292T138 310Q162 310 180 294T199 251Q199 226 182 208T139 190 96 207 78 250Z"/></g><g data-mml-node="mi" transform="translate(1472.4,0)"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g></g><g data-mml-node="mrow" transform="translate(220,-709.5)"><g data-mml-node="mo" transform="translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="mi" transform="translate(278,0)"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mo" transform="translate(1028,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="mo" transform="translate(1528.2,0)"><path data-c="D7" d="M630 29Q630 9 609 9 604 9 587 25T493 118L389 222 284 117Q178 13 175 11 171 9 168 9 160 9 154 15T147 29Q147 36 161 51T255 146L359 250 255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489 178 487 284 383L389 278 493 382Q570 459 587 475T609 491Q630 491 630 471 630 464 620 453T522 355L418 250 522 145Q606 61 618 48T630 29Z"/></g><g data-mml-node="mo" transform="translate(2528.4,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g><g data-mml-node="mi" transform="translate(2806.4,0)"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mo" transform="translate(3565.4,0) translate(0 -0.5)"><path data-c="7C" d="M139-249H137Q125-249 119-235V251L120 737Q130 750 139 750 152 750 159 735V-235Q151-249 141-249H139Z"/></g></g><rect width="4043.4" height="60" x="120" y="220"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1278 -1425.5 1 2351"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:9" transform="translate(0,783.5)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="39" d="M352 287Q304 211 232 211 154 211 104 270T44 396Q42 412 42 436V444Q42 537 111 606 171 666 243 666 245 666 249 666T257 665H261Q273 665 286 663T323 651 370 619 413 560Q456 472 456 334 456 194 396 97 361 41 312 10T208-22Q147-22 108 7T68 93 121 149Q143 149 158 135T173 96Q173 78 164 65T148 49 135 44L131 43Q131 41 138 37T164 27 206 22H212Q272 22 313 86 352 142 352 280V287ZM244 248Q292 248 321 297T351 430Q351 508 343 542 341 552 337 562T323 588 293 615 246 625Q208 625 181 598 160 576 154 546T147 441Q147 358 152 329T172 282Q197 248 244 248Z" transform="translate(389,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(889,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><p>假定<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.697ex" height="1.62ex" role="img" focusable="false" viewBox="0 -716 750 716"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g></g></g></svg></mjx-container>是<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.566ex" xmlns="http://www.w3.org/2000/svg" width="16.015ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 7078.7 1000"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mo"><path data-c="5B" d="M118-250V750H255V710H158V-210H255V-250H118Z"/></g><g data-mml-node="mi" transform="translate(278,0)"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mn" transform="translate(1028,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g><g data-mml-node="mo" transform="translate(1528,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mi" transform="translate(1972.7,0)"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mn" transform="translate(2722.7,0)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mo" transform="translate(3222.7,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mo" transform="translate(3667.3,0)"><path data-c="2026" d="M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0 96 17 78 60ZM525 60Q525 84 542 102T585 120Q609 120 627 104T646 61Q646 36 629 18T586 0 543 17 525 60ZM972 60Q972 84 989 102T1032 120Q1056 120 1074 104T1093 61Q1093 36 1076 18T1033 0 990 17 972 60Z"/></g><g data-mml-node="mo" transform="translate(5006,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mi" transform="translate(5450.7,0)"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mi" transform="translate(6200.7,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mo" transform="translate(6800.7,0)"><path data-c="5D" d="M22 710V750H159V-250H22V-210H119V710H22Z"/></g></g></g></svg></mjx-container> ,<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.717ex" height="1.545ex" role="img" focusable="false" viewBox="0 -683 759 683"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g></g></g></svg></mjx-container>是<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.566ex" xmlns="http://www.w3.org/2000/svg" width="16.076ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 7105.7 1000"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mo"><path data-c="5B" d="M118-250V750H255V710H158V-210H255V-250H118Z"/></g><g data-mml-node="mi" transform="translate(278,0)"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mn" transform="translate(1037,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g><g data-mml-node="mo" transform="translate(1537,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mi" transform="translate(1981.7,0)"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mn" transform="translate(2740.7,0)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mo" transform="translate(3240.7,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mo" transform="translate(3685.3,0)"><path data-c="2026" d="M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0 96 17 78 60ZM525 60Q525 84 542 102T585 120Q609 120 627 104T646 61Q646 36 629 18T586 0 543 17 525 60ZM972 60Q972 84 989 102T1032 120Q1056 120 1074 104T1093 61Q1093 36 1076 18T1033 0 990 17 972 60Z"/></g><g data-mml-node="mo" transform="translate(5024,0)"><path data-c="2C" d="M78 35T78 60 94 103 137 121Q165 121 187 96T210 8Q210-27 201-60T180-117 154-158 130-185 117-194Q113-194 104-185T95-172Q95-168 106-156T131-126 157-76 173-3V9L172 8Q170 7 167 6T161 3 152 1 140 0Q113 0 96 17Z"/></g><g data-mml-node="mi" transform="translate(5468.7,0)"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mi" transform="translate(6227.7,0)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mo" transform="translate(6827.7,0)"><path data-c="5D" d="M22 710V750H159V-250H22V-210H119V710H22Z"/></g></g></g></svg></mjx-container> ,则<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.697ex" height="1.62ex" role="img" focusable="false" viewBox="0 -716 750 716"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g></g></g></svg></mjx-container>与<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.717ex" height="1.545ex" role="img" focusable="false" viewBox="0 -683 759 683"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g></g></g></svg></mjx-container>的夹角<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.023ex" xmlns="http://www.w3.org/2000/svg" width="1.061ex" height="1.618ex" role="img" focusable="false" viewBox="0 -705 469 715"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g></g></g></svg></mjx-container>的余弦等于:</p><p><mjx-container class="MathJax" jax="SVG" display="true" width="full" style="min-width:43.748ex"><svg style="vertical-align:-3.295ex;min-width:43.748ex" xmlns="http://www.w3.org/2000/svg" width="100%" height="7.722ex" role="img" focusable="false"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(0.0181,-0.0181) translate(0, -1956.5)"><g data-mml-node="math"><g data-mml-node="mtable" transform="translate(2578,0) translate(-2578,0)"><g transform="translate(0 1956.5) matrix(1 0 0 -1 0 0) scale(55.25)"><svg data-table="true" preserveAspectRatio="xMidYMid" viewBox="7090.4 -1956.5 1 3412.9"><g transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mlabeledtr" transform="translate(0,363.5)"><g data-mml-node="mtd"><g data-mml-node="mi"><path data-c="1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325 330 359 352 380 366 386H367Q367 388 361 392T340 400 306 404Q276 404 249 390 228 381 206 359 162 315 142 235T121 119Q121 73 147 50 169 26 205 26H209Q321 26 394 111 403 121 406 121 410 121 419 112T429 98 420 83 391 55 346 25 282 0 202-11Q127-11 81 37T34 159Z"/></g><g data-mml-node="mi" transform="translate(433,0)"><path data-c="1D45C" d="M201-11Q126-11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441 333 441 341 440 354 437 367 433T402 417 438 387 464 338 476 268Q476 161 390 75T201-11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375 346 405 306 405 243 405 195 347 158 303 140 230T121 120Z"/></g><g data-mml-node="mi" transform="translate(918,0)"><path data-c="1D460" d="M131 289Q131 321 147 354T203 415 300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372 367 378Q368 378 368 379 368 382 361 388T336 399 297 405Q249 405 227 379T204 326Q204 301 223 291T278 274 330 259Q396 230 396 163 396 135 385 107T352 51 289 7 195-10Q118-10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34 201 27Q237 27 263 38T301 66 318 97 323 122Q323 150 302 164T254 181 195 196 148 231Q131 256 131 289Z"/></g><g data-mml-node="mi" transform="translate(1387,0)"><path data-c="1D703" d="M35 200Q35 302 74 415T180 610 319 704Q320 704 327 704T339 705Q393 701 423 656 462 596 462 495 462 380 417 261T302 66 168-10H161Q125-10 99 10T60 63 41 130 35 200ZM383 566Q383 668 330 668 294 668 260 623T204 521 170 421 157 371Q206 370 254 370L351 371Q352 372 359 404T375 484 383 566ZM113 132Q113 26 166 26 181 26 198 36T239 74 287 161 335 307L340 324H145Q145 321 136 286T120 208 113 132Z"/></g><g data-mml-node="mo" transform="translate(2133.8,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mfrac" transform="translate(3189.6,0)"><g data-mml-node="mrow" transform="translate(2270.6,803.3)"><g data-mml-node="munderover"><g data-mml-node="mo"><path data-c="2211" d="M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533 999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709 186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149-187Q149-188 362-188 388-188 436-188T506-189Q679-189 778-162T936-43Q946-27 959 6H999L913-249 489-250Q65-250 62-248 56-246 56-239 56-234 118-161 186-81 245-11L428 206Q428 207 242 462L57 717 56 728Q56 744 61 748Z"/></g><g data-mml-node="TeXAtom" transform="translate(1089,477.1) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="TeXAtom" transform="translate(1089,-285.4) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mo" transform="translate(345,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mn" transform="translate(1123,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g><g data-mml-node="mo" transform="translate(2286.6,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/></g><g data-mml-node="msub" transform="translate(2675.6,0)"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mi" transform="translate(783,-150) scale(0.707)"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="mo" transform="translate(3974.8,0)"><path data-c="D7" d="M630 29Q630 9 609 9 604 9 587 25T493 118L389 222 284 117Q178 13 175 11 171 9 168 9 160 9 154 15T147 29Q147 36 161 51T255 146L359 250 255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489 178 487 284 383L389 278 493 382Q570 459 587 475T609 491Q630 491 630 471 630 464 620 453T522 355L418 250 522 145Q606 61 618 48T630 29Z"/></g><g data-mml-node="msub" transform="translate(4975,0)"><g data-mml-node="mi"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mi" transform="translate(792,-150) scale(0.707)"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="mo" transform="translate(6061,0)"><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z"/></g></g><g data-mml-node="mrow" transform="translate(220,-1228.1)"><g data-mml-node="msqrt"><g transform="translate(1020,0)"><g data-mml-node="munderover"><g data-mml-node="mo"><path data-c="2211" d="M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533 999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709 186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149-187Q149-188 362-188 388-188 436-188T506-189Q679-189 778-162T936-43Q946-27 959 6H999L913-249 489-250Q65-250 62-248 56-246 56-239 56-234 118-161 186-81 245-11L428 206Q428 207 242 462L57 717 56 728Q56 744 61 748Z"/></g><g data-mml-node="TeXAtom" transform="translate(1089,477.1) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="TeXAtom" transform="translate(1089,-285.4) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mo" transform="translate(345,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mn" transform="translate(1123,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g><g data-mml-node="msubsup" transform="translate(2453.3,0)"><g data-mml-node="mi"><path data-c="1D434" d="M208 74Q208 50 254 46 272 46 272 35 272 34 270 22 267 8 264 4T251 0Q249 0 239 0T205 1 141 2Q70 2 50 0H42Q35 7 35 11 37 38 48 46H62Q132 49 164 96 170 102 345 401T523 704Q530 716 547 716H555 572Q578 707 578 706L606 383Q634 60 636 57 641 46 701 46 726 46 726 36 726 34 723 22 720 7 718 4T704 0Q701 0 690 0T651 1 578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260 413 259Q516 259 516 260Z"/></g><g data-mml-node="mn" transform="translate(783,353.6) scale(0.707)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mi" transform="translate(783,-293.8) scale(0.707)"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g></g></g><g data-mml-node="mo" transform="translate(0,58.1)"><path data-c="221A" d="M1001 1150Q1017 1150 1020 1132 1020 1127 741 244L460-643Q453-650 436-650H424Q423-647 423-645T421-640 419-631 415-617 408-594 399-560 385-512 367-448 343-364 312-259L203 119 138 41 111 67 212 188 264 248 472-474 983 1140Q988 1150 1001 1150Z"/></g><rect width="3639.9" height="60" x="1020" y="1148.1"/></g><g data-mml-node="mo" transform="translate(4882.1,0)"><path data-c="D7" d="M630 29Q630 9 609 9 604 9 587 25T493 118L389 222 284 117Q178 13 175 11 171 9 168 9 160 9 154 15T147 29Q147 36 161 51T255 146L359 250 255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489 178 487 284 383L389 278 493 382Q570 459 587 475T609 491Q630 491 630 471 630 464 620 453T522 355L418 250 522 145Q606 61 618 48T630 29Z"/></g><g data-mml-node="msqrt" transform="translate(5882.3,0)"><g transform="translate(1020,0)"><g data-mml-node="munderover"><g data-mml-node="mo"><path data-c="2211" d="M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533 999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709 186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149-187Q149-188 362-188 388-188 436-188T506-189Q679-189 778-162T936-43Q946-27 959 6H999L913-249 489-250Q65-250 62-248 56-246 56-239 56-234 118-161 186-81 245-11L428 206Q428 207 242 462L57 717 56 728Q56 744 61 748Z"/></g><g data-mml-node="TeXAtom" transform="translate(1089,477.1) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341 56 388 89 425 135 442Q171 442 195 424T225 390 231 369Q231 367 232 367L243 378Q304 442 382 442 436 442 469 415T503 336 465 179 427 52Q427 26 444 26 450 26 453 27 482 32 505 65T540 145Q542 153 560 153 580 153 580 145 580 144 576 130 568 101 554 73T508 17 439-10Q392-10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291 189 157Q156 26 151 16 138-11 108-11 95-11 87-5T76 7 74 17Q74 30 112 180T152 343Q153 348 153 366 153 405 129 405 91 405 66 305 60 285 60 284 58 278 41 278H27Q21 284 21 287Z"/></g></g><g data-mml-node="TeXAtom" transform="translate(1089,-285.4) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g><g data-mml-node="mo" transform="translate(345,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347 722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153 722 140 707 133H70Q56 140 56 153Z"/></g><g data-mml-node="mn" transform="translate(1123,0)"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g><g data-mml-node="msubsup" transform="translate(2453.3,0)"><g data-mml-node="mi"><path data-c="1D435" d="M231 637Q204 637 199 638T194 649Q194 676 205 682 206 683 335 683 594 683 608 681 671 671 713 636T756 544Q756 480 698 429T565 360L555 357Q619 348 660 311T702 219Q702 146 630 78T453 1Q446 0 242 0 42 0 39 2 35 5 35 10 35 17 37 24 42 43 47 45 51 46 62 46H68Q95 46 128 49 142 52 147 61 150 65 219 339T288 628Q288 635 231 637ZM649 544Q649 574 634 600T585 634Q578 636 493 637 473 637 451 637T416 636H403Q388 635 384 626 382 622 352 506 352 503 351 500L320 374H401Q482 374 494 376 554 386 601 434T649 544ZM595 229Q595 273 572 302T512 336Q506 337 429 337 311 337 310 336 310 334 293 263T258 122L240 52Q240 48 252 48T333 46Q422 46 429 47 491 54 543 105T595 229Z"/></g><g data-mml-node="mn" transform="translate(792,353.6) scale(0.707)"><path data-c="32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315 301 241Q265 210 201 149L142 93 218 92Q375 92 385 97 392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19 31Q50 38 56 46T86 81Q115 113 136 137 145 147 170 174T204 211 233 244 261 278 284 308 305 340 320 369 333 401 340 431 343 464Q343 527 309 573T212 619Q179 619 154 602T119 569 109 550Q109 549 114 549 132 549 151 535T170 489Q170 464 154 447T109 429Z"/></g><g data-mml-node="mi" transform="translate(792,-293.8) scale(0.707)"><path data-c="1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369 98 420 158 442Q197 442 223 419T250 357Q250 340 236 301T196 196 154 83Q149 61 149 51 149 26 166 26 175 26 185 29T208 43 235 78 260 137Q263 149 265 151T282 153Q302 153 302 143 302 135 293 112T268 61 223 11 161-11Q129-11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281 56 279 53 278 49 278 41 278H27Q21 284 21 287Z"/></g></g></g><g data-mml-node="mo" transform="translate(0,58.1)"><path data-c="221A" d="M1001 1150Q1017 1150 1020 1132 1020 1127 741 244L460-643Q453-650 436-650H424Q423-647 423-645T421-640 419-631 415-617 408-594 399-560 385-512 367-448 343-364 312-259L203 119 138 41 111 67 212 188 264 248 472-474 983 1140Q988 1150 1001 1150Z"/></g><rect width="3648.9" height="60" x="1020" y="1148.1"/></g></g><rect width="10751.2" height="60" x="120" y="220"/></g></g></g></g></svg><svg data-labels="true" preserveAspectRatio="xMaxYMid" viewBox="1778 -1956.5 1 3412.9"><g data-labels="true" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="mtd" id="mjx-eqn:10" transform="translate(0,1113.5)"><text data-id-align="true"/><g data-idbox="true" transform="translate(0,-750)"><g data-mml-node="mtext"><path data-c="28" d="M94 250Q94 319 104 381T127 488 164 576 202 643 244 695 277 729 302 750H315 319Q333 750 333 741 333 738 316 720T275 667 226 581 184 443 167 250 184 58 225-81 274-167 316-220 333-241Q333-250 318-250H315 302L274-226Q180-141 137-14T94 250Z"/><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z" transform="translate(389,0)"/><path data-c="30" d="M96 585Q152 666 249 666 297 666 345 640T423 548Q460 465 460 320 460 165 417 83 397 41 362 16T301-15 250-22Q224-22 198-16T137 16 82 83Q39 165 39 320 39 494 96 585ZM321 597Q291 629 250 629 208 629 178 597 153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16 290 16 318 46 347 76 354 130T362 333Q362 478 354 524T321 597Z" transform="translate(889,0)"/><path data-c="29" d="M60 749 64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12 224-76 186-143 145-194 113-227 90-246Q87-249 86-250H74Q66-250 63-250T58-247 55-238Q56-237 66-225 221-64 221 250T66 725Q56 737 55 738 55 746 60 749Z" transform="translate(1389,0)"/></g></g></g></g></svg></g></g></g></g></svg></mjx-container></p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">{</span><br><span class="line">  <span class="string">'句子A'</span>: {</span><br><span class="line">    <span class="string">'句子A'</span>: 1.0000000000000002,</span><br><span class="line">    <span class="string">'句子B'</span>: 0.21934876427664535,</span><br><span class="line">    <span class="string">'句子C'</span>: 0.21934876427664535</span><br><span class="line">  },</span><br><span class="line">  <span class="string">'句子B'</span>: {</span><br><span class="line">    <span class="string">'句子A'</span>: 0.21934876427664535,</span><br><span class="line">    <span class="string">'句子B'</span>: 1,</span><br><span class="line">    <span class="string">'句子C'</span>: 0.33484380220099325</span><br><span class="line">  },</span><br><span class="line">  <span class="string">'句子C'</span>: {</span><br><span class="line">    <span class="string">'句子A'</span>: 0.21934876427664535,</span><br><span class="line">    <span class="string">'句子B'</span>: 0.33484380220099325,</span><br><span class="line">    <span class="string">'句子C'</span>: 1</span><br><span class="line">  }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div><div class="story post-story"><h2 id="第九步:余弦相似度按照降序排序"><a href="#第九步:余弦相似度按照降序排序" class="headerlink" title="第九步:余弦相似度按照降序排序"></a>第九步:余弦相似度按照降序排序</h2><p>两两计算向量夹角的余弦值,然后按降序排列,取排在最前面的几个文章,就是相似度较高的文章,作为推荐结果。</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">{</span><br><span class="line">  <span class="string">'句子A'</span>: {</span><br><span class="line">    <span class="string">'句子A'</span>: 1.0000000000000002,</span><br><span class="line">    <span class="string">'句子B'</span>: 0.21934876427664535,</span><br><span class="line">    <span class="string">'句子C'</span>: 0.21934876427664535</span><br><span class="line">  },</span><br><span class="line">  <span class="string">'句子B'</span>: {</span><br><span class="line">    <span class="string">'句子B'</span>: 1,</span><br><span class="line">    <span class="string">'句子C'</span>: 0.33484380220099325,</span><br><span class="line">    <span class="string">'句子A'</span>: 0.21934876427664535</span><br><span class="line">  },</span><br><span class="line">  <span class="string">'句子C'</span>: {</span><br><span class="line">    <span class="string">'句子C'</span>: 1,</span><br><span class="line">    <span class="string">'句子B'</span>: 0.33484380220099325,</span><br><span class="line">    <span class="string">'句子A'</span>: 0.21934876427664535,</span><br><span class="line">  }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>相同句子的余弦值是<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.131ex" height="1.507ex" role="img" focusable="false" viewBox="0 -666 500 666"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g></svg></mjx-container>. 余弦值越接近<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:0" xmlns="http://www.w3.org/2000/svg" width="1.131ex" height="1.507ex" role="img" focusable="false" viewBox="0 -666 500 666"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="31" d="M213 578 200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641 273 663Q275 666 285 666 294 666 302 660V361L303 61Q310 54 315 52T339 48 401 46H427V0H416Q395 3 257 3 121 3 100 0H88V46H114Q136 46 152 46T177 47 193 50 201 52 207 57 213 61V578Z"/></g></g></g></svg></mjx-container>,就表明夹角越接近<mjx-container class="MathJax" jax="SVG"><svg style="vertical-align:-.05ex" xmlns="http://www.w3.org/2000/svg" width="1.131ex" height="1.557ex" role="img" focusable="false" viewBox="0 -666 500 688"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mn"><path data-c="30" d="M96 585Q152 666 249 666 297 666 345 640T423 548Q460 465 460 320 460 165 417 83 397 41 362 16T301-15 250-22Q224-22 198-16T137 16 82 83Q39 165 39 320 39 494 96 585ZM321 597Q291 629 250 629 208 629 178 597 153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16 290 16 318 46 347 76 354 130T362 333Q362 478 354 524T321 597Z"/></g></g></g></svg></mjx-container>度,也就是两个向量越相似.</p></div><div class="story post-story"><h2 id="第十步:收集推荐结果"><a href="#第十步:收集推荐结果" class="headerlink" title="第十步:收集推荐结果"></a>第十步:收集推荐结果</h2><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">{</span><br><span class="line">  <span class="string">'句子A'</span>: [ <span class="string">'句子B'</span>, <span class="string">'句子C'</span> ],</span><br><span class="line">  <span class="string">'句子B'</span>: [ <span class="string">'句子C'</span>, <span class="string">'句子A'</span> ],</span><br><span class="line">  <span class="string">'句子C'</span>: [ <span class="string">'句子B'</span>, <span class="string">'句子A'</span> ]</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>即:</p><figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">A-B</span><br><span class="line">B-C</span><br><span class="line">C-B</span><br></pre></td></tr></tbody></table></figure><p>A 和 C 之间没什么关系。</p></div><div class="story post-story"><h2 id="源码实现"><a href="#源码实现" class="headerlink" title="源码实现"></a>源码实现</h2><div class="tag link"><a class="link-card" title="Volantis主题实现文章推荐" target="_blank" rel="external nofollow noopener noreferrer" href="https://github.com/volantis-x/hexo-theme-volantis/blob/684c40333b16b5d1df1a9e4a7f1da90216e5a17a/scripts/helpers/文章推荐.js"><div class="left"><img src="https://static.mhuig.top/npm/volantis-static@0.0.1649552113628/media/twemoji/assets/svg/1f433.svg" class="lazyload" data-srcset="https://static.mhuig.top/npm/volantis-static@0.0.1649552113628/media/twemoji/assets/svg/1f433.svg" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="></div><div class="right"><p class="text">Volantis 主题实现文章推荐</p><p class="url">https://github.com/volantis-x/hexo-theme-volantis/blob/684c40333b16b5d1df1a9e4a7f1da90216e5a17a/scripts/helpers/ 文章推荐.js</p></div></a></div><p><del>UI 界面是随手写的,又不是不能用(</del></p><p>代码变量是中文写的,方便易读。<psw>其实是中间出 Bug 了,然后调试 Debug 时顺便整的活</psw></p></div></div><div class="footer"><div class="copyright license"><div class="license-title">尝试在博客中添加简易文章推荐功能</div><div class="license-link"><a href="https://blog.mhuig.top/p/175a1706/">https://blog.mhuig.top/p/175a1706/</a></div><div class="license-meta"><div class="license-meta-item"><div class="license-meta-title">本文作者</div><div class="license-meta-text">MHuiG</div></div><div class="license-meta-item"><div class="license-meta-title">发布于</div><div class="license-meta-text">2022年9月15日</div></div><div class="license-meta-item"><div class="license-meta-title">更新于</div><div class="license-meta-text">2022年9月16日</div></div><div class="license-meta-item"><div class="license-meta-title">许可协议</div><div class="license-meta-text"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh#" target="_blank" rel="external nofollow noopener noreferrer">CC BY-NC-SA 4.0</a></div></div></div><div class="license-statement">署名-非商业性使用-相同方式共享 4.0 国际。</div></div></div><div class="article-meta" id="bottom"><div class="new-meta-box"><div class="new-meta-item category"><i class="fa-duotone fa-folder-open fa-fw" aria-hidden="true"></i> <a class="category-link" href="/categories/Data-mining/">Data mining</a> <span hidden itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Data-mining/" itemprop="url"><span itemprop="name">Data mining</span></a></span></div><div class="new-meta-item meta-tags"><a class="tag" href="/tags/Data-mining/" rel="nofollow"><i class="fa-duotone fa-hashtag fa-fw" aria-hidden="true"></i><p>Data mining</p></a></div><div class="new-meta-item meta-tags"><a class="tag" href="/tags/%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/" rel="nofollow"><i class="fa-duotone fa-hashtag fa-fw" aria-hidden="true"></i><p>推荐系统</p></a></div> <span hidden itemprop="keywords">Data mining 推荐系统</span><div class="new-meta-item date" itemprop="dateCreated datePublished" datetime="2022-09-15T19:13:00+08:00"><a class="notlink"><i class="fa-duotone fa-calendar-alt fa-fw" aria-hidden="true"></i><p>发布于:2022年9月15日</p></a></div><div class="new-meta-item date" itemprop="dateModified" datetime="2022-09-16T10:48:00+08:00"><a class="notlink"><i class="fa-duotone fa-edit fa-fw" aria-hidden="true"></i><p>更新于:2022年9月16日</p></a></div></div></div><div class="prev-next"><a class="prev" href="/p/2f345bb/"><p class="title"><i class="fa-solid fa-chevron-left" aria-hidden="true"></i>辛普森悖论 | 你还相信数据吗</p><p class="content"> 数据是一个有力的武器,它既能被用来澄清现实,也能被用来混淆是非 你知不知道,数据也会说谎? 一个栗子假设您患有肾结石并去看医生。医生告诉你有两种治疗方法,治疗 A(开放手术 open sur...</p></a><a class="next" href="/p/de4b9576/"><p class="title">记一次重装系统 (Win11)<i class="fa-solid fa-chevron-right" aria-hidden="true"></i></p><p class="content">电脑开机后要先卡顿 30 min,然后才能正常工作,还有不明程序一直在读写磁盘,噪声太大了,没救了重装系统吧。 重装系统之后操作瞬间就流畅很多~ 意料之外:重装系统之后,win11 自带的杀软...</p></a></div><div class="recommended-article"><div class="recommended-article-header"><i class="fa-solid fa-bookmark fa-fw" aria-hidden="true"></i> <span>推荐阅读</span></div><div class="recommended-article-group"> <a class="recommended-article-item" href="/p/48f700eb/" title="BERT 预训练模型及其应用案例" rel="bookmark"><img src="https://static.mhuig.top/npm/mhgoos@0.0.1651974150318/2020116102430.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/mhgoos@0.0.1651974150318/2020116102430.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="BERT 预训练模型及其应用案例"> <span class="title">BERT 预训练模型及其应用案例</span></a> <a class="recommended-article-item" href="/p/2f345bb/" title="辛普森悖论 | 你还相信数据吗" rel="bookmark"><img src="https://static.mhuig.top/npm/imbox@0.0.15/c/108.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/imbox@0.0.15/c/108.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="辛普森悖论 | 你还相信数据吗"> <span class="title">辛普森悖论 | 你还相信数据吗</span></a> <a class="recommended-article-item" href="/notes/LaTeX/index.html" title="LaTeX数学符号语法速查表" rel="bookmark"><img src="https://static.mhuig.top/npm/imbox@0.0.15/c/112.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/imbox@0.0.15/c/112.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="LaTeX数学符号语法速查表"> <span class="title">LaTeX数学符号语法速查表</span></a> <a class="recommended-article-item" href="/p/f0765214/" title="特征向量和特征值的几何本质" rel="bookmark"><img src="https://static.mhuig.top/npm/imbox@0.0.15/c/111.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/imbox@0.0.15/c/111.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="特征向量和特征值的几何本质"> <span class="title">特征向量和特征值的几何本质</span></a> <a class="recommended-article-item" href="/p/dad4292a/" title="我们从哪里来?" rel="bookmark"><img src="https://static.mhuig.top/npm/mhgoos@0.0.1651884877591/1622901746000.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/mhgoos@0.0.1651884877591/1622901746000.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="我们从哪里来?"> <span class="title">我们从哪里来?</span></a> <a class="recommended-article-item" href="/p/f8d2d5ec/" title="hexo 命令及 Markdown 语法" rel="bookmark"><img src="https://static.mhuig.top/npm/imbox@0.0.15/c/105.webp" class="lazyload" data-srcset="https://static.mhuig.top/npm/imbox@0.0.15/c/105.webp" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="hexo 命令及 Markdown 语法"> <span class="title">hexo 命令及 Markdown 语法</span></a></div></div></article><article class="post white-box shadow floatable blur" id="comments"><span hidden><meta itemprop="discussionUrl" content="/p/175a1706/#comments"></span><p ct><i class="fa-duotone fa-comments"></i> 留言区</p><div id="layoutHelper-comments"></div></article></div><aside id="l_side" itemscope itemtype="http://schema.org/WPSideBar"><div class="widget-sticky pjax"><section class="widget toc-wrapper desktop mobile" id="toc-div"><header><i class="fa-duotone fa-list fa-fw" aria-hidden="true"></i> <span class="name">本文目录</span></header><div class="content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9E%84%E5%BB%BA%E5%90%91%E9%87%8F%E7%A9%BA%E9%97%B4%E6%A8%A1%E5%9E%8B"><span class="toc-text">构建向量空间模型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BE%E4%B8%AA%E6%A0%97%E5%AD%90"><span class="toc-text">举个栗子</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%9A%E6%95%B0%E6%8D%AE%E6%B8%85%E6%B4%97"><span class="toc-text">第一步:数据清洗</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%BA%8C%E6%AD%A5%EF%BC%9A%E5%88%86%E8%AF%8D"><span class="toc-text">第二步:分词</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%89%E6%AD%A5%EF%BC%9A%E5%8E%BB%E9%87%8D%E6%94%B6%E9%9B%86%E6%89%80%E6%9C%89%E5%8F%A5%E5%AD%90%E4%B8%AD%E6%89%80%E6%9C%89%E7%9A%84%E8%AF%8D"><span class="toc-text">第三步:去重收集所有句子中所有的词</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%9B%9B%E6%AD%A5%EF%BC%9A%E8%AE%A1%E7%AE%97%E8%AF%8D%E9%A2%91"><span class="toc-text">第四步:计算词频</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%9B%9B%E6%AD%A5%EF%BC%9A%E8%AF%8D%E9%A2%91%E6%A0%87%E5%87%86%E5%8C%96"><span class="toc-text">第四步:词频标准化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%BA%94%E6%AD%A5%EF%BC%9A%E8%AE%A1%E7%AE%97%E9%80%86%E6%96%87%E6%A1%A3%E9%A2%91%E7%8E%87"><span class="toc-text">第五步:计算逆文档频率</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%85%AD%E6%AD%A5%EF%BC%9A%E8%AE%A1%E7%AE%97TF-IDF"><span class="toc-text">第六步:计算 TF-IDF</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%83%E6%AD%A5%EF%BC%9A%E5%88%97%E5%87%BA%E6%96%87%E6%A1%A3%E5%90%91%E9%87%8F"><span class="toc-text">第七步:列出文档向量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%85%AB%E6%AD%A5%EF%BC%9A%E8%AE%A1%E7%AE%97%E4%BD%99%E5%BC%A6%E7%9B%B8%E4%BC%BC%E5%BA%A6"><span class="toc-text">第八步:计算余弦相似度</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B9%9D%E6%AD%A5%EF%BC%9A%E4%BD%99%E5%BC%A6%E7%9B%B8%E4%BC%BC%E5%BA%A6%E6%8C%89%E7%85%A7%E9%99%8D%E5%BA%8F%E6%8E%92%E5%BA%8F"><span class="toc-text">第九步:余弦相似度按照降序排序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%8D%81%E6%AD%A5%EF%BC%9A%E6%94%B6%E9%9B%86%E6%8E%A8%E8%8D%90%E7%BB%93%E6%9E%9C"><span class="toc-text">第十步:收集推荐结果</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BA%90%E7%A0%81%E5%AE%9E%E7%8E%B0"><span class="toc-text">源码实现</span></a></li></ol></div></section></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div><div class="pjax"></div></aside><pjax><script>window.pdata={},pdata.ispage=!0,pdata.commentPath="",pdata.commentPlaceholder="",pdata.commentConfig={};var l_header=document.getElementById("l_header");l_header.classList.add("show");var cover_wrapper=document.querySelector("#l_cover .cover-wrapper"),scroll_down=document.getElementById("scroll-down");cover_wrapper.id="none",cover_wrapper.style.display="none",scroll_down.style.display="none"</script></pjax></div><footer class="footer clearfix" itemscope itemtype="http://schema.org/WPFooter"><br><br><div class="aplayer-container"><div class="aplayer-local"></div></div><br><div class="social-wrapper" itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/atom.xml" class="social fa-duotone fa-rss flat-btn" target="_blank" rel="external nofollow noopener noreferrer" itemprop="url"></a><a href="https://mhuig.top/contact/" class="social fa-duotone fa-envelope flat-btn" target="_blank" rel="external nofollow noopener noreferrer" itemprop="url"></a><a href="https://github.com/MHuiG" class="social fa-brands fa-github flat-btn" target="_blank" rel="external nofollow noopener noreferrer" itemprop="url"></a><a href="https://t.me/MHuiG" class="social fa-brands fa-telegram flat-btn" target="_blank" rel="external nofollow noopener noreferrer" itemprop="url"></a></div><div><p>博客内容遵循 <a target="_blank" rel="external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议</a></p></div><div class="copyright"><p><a href="https://icp.gov.moe" target="_blank" rel="external nofollow noopener noreferrer">萌ICP备</a> <a href="https://icp.gov.moe/?keyword=2020012138" target="_blank" rel="external nofollow noopener noreferrer">2020012138号</a><br><a target="_blank" rel="noopener" href="https://mhuig.top/">Copyright © Since 2018 MHuiG</a></p></div></footer><a id="s-top" class="fa-solid fa-arrow-up fa-fw" title="top"></a></div></div><div><script>volantis.dom.bodyAnchor=volantis.dom.$(document.getElementById("safearea")),volantis.dom.topBtn=volantis.dom.$(document.getElementById("s-top")),volantis.dom.wrapper=volantis.dom.$(document.getElementById("wrapper")),volantis.dom.coverAnchor=volantis.dom.$(document.querySelector("#l_cover .cover-wrapper")),volantis.dom.switcher=volantis.dom.$(document.querySelector("#l_header .switcher .s-search")),volantis.dom.header=volantis.dom.$(document.getElementById("l_header")),volantis.dom.search=volantis.dom.$(document.querySelector("#l_header .m_search")),volantis.dom.mPhoneList=volantis.dom.$(document.querySelectorAll("#l_header .m-phone .list-v"))</script><script>volantis.css("https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/libs/@fortawesome/fontawesome-pro/css/all.min.css")</script><script src="/js/app.js?v=196690b6a0"></script><script>const rootElement=document.documentElement,darkModeStorageKey="color-scheme",rootElementDarkModeAttributeName="color-scheme",setLS=(e,t)=>{localStorage.setItem(e,t)},removeLS=e=>{localStorage.removeItem(e)},getLS=e=>localStorage.getItem(e),getModeFromCSSMediaQuery=()=>window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",resetRootDarkModeAttributeAndLS=()=>{rootElement.removeAttribute("color-scheme"),removeLS("color-scheme")},validColorModeKeys={dark:!0,light:!0},applyCustomDarkModeSettings=e=>{const t=e||getLS("color-scheme");getCustomDarkMode(),t===getModeFromCSSMediaQuery()?resetRootDarkModeAttributeAndLS():validColorModeKeys[t]?rootElement.setAttribute("color-scheme",t):resetRootDarkModeAttributeAndLS()},invertDarkModeObj={dark:"light",light:"dark"},getCustomDarkMode=()=>{let e=getLS("color-scheme");if(validColorModeKeys[e])e=invertDarkModeObj[e];else{if(null!==e)return;e=invertDarkModeObj[getModeFromCSSMediaQuery()]}volantis.dark.mode="dark"==e?"light":"dark"},toggleCustomDarkMode=()=>{let e=getLS("color-scheme");if(validColorModeKeys[e])e=invertDarkModeObj[e];else{if(null!==e)return;e=invertDarkModeObj[getModeFromCSSMediaQuery()]}return setLS("color-scheme",e),e};function bindToggleButton(){document.querySelectorAll("#wrapper .toggle-mode-btn,#rightmenu-wrapper .toggle-mode-btn").forEach((function(e){volantis.dom.$(e).on("click",volantis.dark.toggle)}))}volantis.dark.toggle=()=>{const e=toggleCustomDarkMode();applyCustomDarkModeSettings(e),volantis.dark.method.toggle.start()},applyCustomDarkModeSettings(),document.addEventListener("DOMContentLoaded",(()=>{volantis.requestAnimationFrame(bindToggleButton)})),volantis.pjax.push(bindToggleButton);const darkModelListeners={dark:e=>{e.matches&&(volantis.dark.mode="dark"),volantis.dark.method.toggle.start()},light:e=>{e.matches&&(volantis.dark.mode="light"),volantis.dark.method.toggle.start()}};window.matchMedia("(prefers-color-scheme: dark)").addListener(darkModelListeners.dark),window.matchMedia("(prefers-color-scheme: light)").addListener(darkModelListeners.light)</script><script>function loadIssuesJS(){null!=document.getElementById("sites-api")&&"undefined"==typeof SitesJS&&volantis.js("/js/plugins/tags/sites.js?v=a7e55dacdf");null!=document.getElementById("friends-api")&&"undefined"==typeof FriendsJS&&volantis.js("/js/plugins/tags/friends.js?v=187f37f894");null!=document.getElementById("contributors-api")&&"undefined"==typeof ContributorsJS&&volantis.js("/js/plugins/tags/contributors.js?v=16e248333a")}loadIssuesJS(),volantis.pjax.push((()=>{loadIssuesJS()}))</script><script defer="defer" src="https://cdn.bootcdn.net/ajax/libs/vanilla-lazyload/17.1.0/lazyload.min.js"></script><script>window.lazyLoadOptions={elements_selector:".lazyload",threshold:0},window.addEventListener("LazyLoad::Initialized",(function(n){window.lazyLoadInstance=n.detail.instance}),!1),document.addEventListener("DOMContentLoaded",(function(){lazyLoadInstance.update()})),document.addEventListener("pjax:complete",(function(){lazyLoadInstance.update()}))</script><script>window.FPConfig={delay:0,ignoreKeywords:["#"],maxRPS:6,hoverDelay:0}</script><script defer="defer" src="https://static.mhuig.top/npm/volantis-static@0.0.1660614606622/libs/flying-pages/flying-pages.min.js"></script><script type="text/javascript">function pjax_scrollrebeal(){ScrollReveal().reveal("#l_main .reveal",{distance:"32px",duration:"800",interval:"20",scale:"1",easing:"ease-out"})}function init_scrollrebeal(){"undefined"==typeof ScrollReveal?volantis.requestAnimationFrame(init_scrollrebeal):pjax_scrollrebeal()}volantis.js("https://cdn.bootcdn.net/ajax/libs/scrollReveal.js/4.0.9/scrollreveal.min.js"),document.addEventListener("DOMContentLoaded",init_scrollrebeal),volantis.pjax.push(pjax_scrollrebeal,"pjax_scrollrebeal",setRequestAnimationFrame=!1)</script><script>volantis.css("https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.css"),volantis.js("https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.js").then((()=>{document.querySelectorAll(".aplayer-local").forEach((e=>{new APlayer({container:e,fixed:!1,order:"list",volume:"0.7",autoplay:!1,loop:"all",theme:"#1BCDFC",listMaxHeight:"320px",listFolded:"true",preload:"auto",lrcType:3,audio:[{name:"虹之间",artist:"钢琴版伴奏",url:"https://blog.mhuig.top/music-Archive/BetweenTheRainbow.mp3",lrc:"https://blog.mhuig.top/music-Archive/BetweenTheRainbow.lrc",cover:"https://blog.mhuig.top/music-Archive/BetweenTheRainbow.jpg"},{name:"Avem",artist:"Alan Walker",url:"https://blog.mhuig.top/music-Archive/Avem.mp3",lrc:"https://blog.mhuig.top/music-Archive/Avem.lrc",cover:"https://blog.mhuig.top/music-Archive/Avem.jpg"},{name:"Fly",artist:"Marshmello / Leau Culver",url:"https://blog.mhuig.top/music-Archive/fly.mp3",lrc:"https://blog.mhuig.top/music-Archive/fly.lrc",cover:"https://blog.mhuig.top/music-Archive/fly.jpg"},{name:"Alone",artist:"Marshmello",url:"https://blog.mhuig.top/music-Archive/alone.mp3",lrc:"https://blog.mhuig.top/music-Archive/alone.lrc",cover:"https://blog.mhuig.top/music-Archive/alone.jpg"}]})}))}))</script><script>function check_giscus(){return"dark"===volantis.dark.mode?volantis.giscus.Theme="dark":volantis.giscus.Theme="light",document.getElementById("giscus_container")}function pjax_giscus(){const t=check_giscus();if(!t)return;let s=Object.assign({theme:{light:"light",dark:"dark"},repo:"MHuiG/talk","repo-id":"MDEwOlJlcG9zaXRvcnkyODQ4NDg1NTg=",category:"Giscus","category-id":"DIC_kwDOEPpxrs4B_X67",mapping:"pathname","reactions-enabled":"1","emit-metadata":"1",lang:"zh-CN","input-position":"top"},pdata.commentConfig);const e=document.createElement("script");e.setAttribute("src","https://giscus.app/client.js"),Object.keys(s).forEach((t=>{"theme"!=t&&e.setAttribute("data-"+t,s[t])})),e.setAttribute("data-theme",volantis.giscus.Theme),e.setAttribute("crossorigin","anonymous"),t.appendChild(e)}function dark_giscus(){if(!check_giscus())return;const t={setConfig:{theme:volantis.giscus.Theme}};document.querySelector("iframe.giscus-frame").contentWindow.postMessage({giscus:t},"https://giscus.app")}volantis.layoutHelper("comments",'<div id="giscus_container"></div>'),volantis.giscus={},pjax_giscus(),volantis.pjax.push(pjax_giscus),volantis.dark.push(dark_giscus)</script><script>async function loadSearchScript(){return volantis.js("/js/search/hexo.js?v=e2a1e6a8d9");}function loadSearchService(){loadSearchScript(),document.querySelectorAll(".input.u-search-input").forEach((e=>{e.removeEventListener("focus",loadSearchService,!1)})),document.querySelectorAll(".u-search-form").forEach((e=>{e.addEventListener("submit",(e=>{e.preventDefault()}),!1)}))}function OpenSearch(e){"undefined"==typeof SearchService?loadSearchScript().then((()=>{SearchService.setQueryText(e),SearchService.search()})):(SearchService.setQueryText(e),SearchService.search())}if(window.location.search&&/^\?s=/g.test(window.location.search)){OpenSearch(decodeURI(window.location.search).replace(/\ /g,"-").replace(/^\?s=/g,""))}document.querySelectorAll(".input.u-search-input").forEach((e=>{e.addEventListener("focus",loadSearchService,!1)}))</script><script>function pjax_highlightjs_copyCode(){(document.querySelector(".highlight .code pre")||document.querySelector(".article pre code"))&&VolantisApp.utilCopyCode(".highlight .code pre, .article pre code")}volantis.requestAnimationFrame(pjax_highlightjs_copyCode),volantis.pjax.push(pjax_highlightjs_copyCode)</script><script>function load_swiper(){document.querySelectorAll(".swiper-container")[0]&&(volantis.css("https://cdn.bootcdn.net/ajax/libs/Swiper/8.3.2/swiper-bundle.min.css"),volantis.js("https://cdn.bootcdn.net/ajax/libs/Swiper/8.3.2/swiper-bundle.min.js").then((()=>{pjax_swiper()})))}function pjax_swiper(){volantis.swiper=new Swiper(".swiper-container",{slidesPerView:"auto",spaceBetween:8,centeredSlides:!0,loop:!0,pagination:{el:".swiper-pagination",clickable:!0},navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev"}})}load_swiper(),volantis.pjax.push((()=>{document.querySelectorAll(".swiper-container")[0]&&(void 0===volantis.swiper?load_swiper():pjax_swiper())}))</script><script>volantis.css("https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/themes/blue/pace-theme-minimal.min.css"),volantis.js("https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/pace.min.js").then((()=>{Pace.options.restartOnPushState=!1,volantis.pjax.send(Pace.restart),volantis.scroll.push((()=>{Pace.stop(),Pace.trigger("start"),Pace.bar.update(100*volantis.scroll.progress()),document.body.className=document.body.className.replaceAll("pace-running ","")}),"阅读进度")}))</script><pjax><style>#post-body p{text-indent:2em}#post-body .new-meta-box p,#post-body .note p,#post-body .prev-next p,#post-body .tab-pane .checkbox #post-body section p,#post-body .tag p,#post-body blockquote p,#post-body details p,#post-body p.p{text-indent:initial}</style></pjax><script>function listenSidebarTOC(){const t=document.querySelectorAll(".toc li");if(!t.length)return;const e=[];Array.from(t).forEach((t=>{const n=t.querySelector(".toc-link"),i=document.getElementById(n.getAttribute("href")?decodeURI(n.getAttribute("href")).replace("#",""):n.getAttribute("toc-action").split("toc-")[1]);return e.push(i),n.getAttribute("href")&&(n.setAttribute("toc-action","toc-"+decodeURI(n.getAttribute("href")).replace("#","")),n.removeAttribute("href")),i&&i.id&&n.addEventListener("click",(t=>{t.preventDefault(),volantis.scroll.to(i,{addTop:5,observer:!0}),history.pushState(null,document.title,"#"+i.id)})),i}));function n(t){if(t.classList.contains("active-current"))return;document.querySelectorAll(".toc .active").forEach((t=>{t.classList.remove("active","active-current")})),t.classList.add("active","active-current");let e=t.parentNode;for(;!e.matches(".toc");)e.matches("li")&&e.classList.add("active"),e=e.parentNode}volantis.activateNavIndex=0,n(t[volantis.activateNavIndex]),e[0]&&volantis.scroll.push((()=>{if(e[0].getBoundingClientRect().top>=0)volantis.activateNavIndex=0;else if(e[e.length-1].getBoundingClientRect().top<0)volantis.activateNavIndex=e.length-1;else for(let t=0;t<e.length;t++){const n=e[t],i=e[(t+1)%e.length];if(n.getBoundingClientRect().top<0&&i.getBoundingClientRect().top>=0){volantis.activateNavIndex=t;break}}n(t[volantis.activateNavIndex])}))}document.addEventListener("DOMContentLoaded",(()=>{volantis.requestAnimationFrame(listenSidebarTOC)})),volantis.pjax.push(listenSidebarTOC)</script><script>try{let e=(e,t,n=2)=>Math.abs(e-t)<=n,t=(t,n)=>!e(t.width,n.width)||!e(t.height,n.height),n=new WeakMap,i=(e,i=e.getClientBoundingRect())=>{let o=n.get(e);o&&!t(o,i)||(n.set(e,i),e.style["contain-intrinsic-size"]=`${i.width}px ${i.height}px`)},o=new IntersectionObserver(((e,t)=>{e.forEach((e=>{i(e.target,e.boundingClientRect)}))}),{rootMargin:"500px 0px 500px 0px"}),r=new ResizeObserver(((e,t)=>{e.forEach((e=>{i(e.target,e.contentRect)}))})),s=e=>{let t=document.querySelectorAll(e);t.length&&(t.forEach((e=>{o.observe(e),r.observe(e)})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{t[0].style["content-visibility"]="auto"}))})))},a=()=>{"content-visibility"in document.documentElement.style&&s(".post-story")};a(),volantis.pjax.push(a)}catch(e){console.log(e)}</script><script>document.onreadystatechange=function(){if("complete"==document.readyState){const{saveData:e,effectiveType:t}=navigator.connection||navigator.mozConnection||navigator.webkitConnection||{};("none"==getComputedStyle(document.querySelector("#safearea"),null).display||e||/2g/.test(t))&&(document.querySelectorAll(".reveal").forEach((function(e){e.style.opacity="1"})),document.querySelector("#safearea").style.display="block")}}</script><script type="application/ld+json">[{"@context":"http://schema.org","@type":"Organization","name":"MHuiG's Blog","url":"https://blog.mhuig.top/","logo":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3","width":192,"height":192}},{"@context":"http://schema.org","@type":"Person","name":"MHuiG","image":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3"},"url":"https://blog.mhuig.top/","sameAs":["https://github.com/MHuiG","https://twitter.com/iMHuiG","https://t.me/MHuiG","https://keybase.io/MHuiG"],"description":"「Be Yourself, Make a Difference.」"},{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https://blog.mhuig.top/","name":"MHuiG"}},{"@type":"ListItem","position":2,"item":{"@id":"https://blog.mhuig.top/categories/Data-mining/","name":"Data mining"}},{"@type":"ListItem","position":3,"item":{"@id":"https://blog.mhuig.top/p/175a1706/","name":"尝试在博客中添加简易文章推荐功能"}}]},{"@context":"http://schema.org","@type":"WebSite","name":"MHuiG's Blog","url":"https://blog.mhuig.top/","keywords":"Blog, IT, BigData, MHuiG, @MHuiG, iMHuiG, 博客, 梦幻岛, Neverland, 技术博客","description":"MHuiG&amp;#39;s Blog (MHuiG的博客) MHuiG&amp;#39;s Neverland(MHuiG的梦幻岛) —— MHuiG(@MHuiG) 随便写写画画的地方 - 技术博客","author":{"@type":"Person","name":"MHuiG","image":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3"},"url":"https://blog.mhuig.top/","description":"「Be Yourself, Make a Difference.」"},"publisher":{"@type":"Organization","name":"MHuiG's Blog","url":"https://blog.mhuig.top/","logo":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3","width":192,"height":192}},"potentialAction":{"@type":"SearchAction","name":"Coco | The Cat of MHuiG","target":{"@type":"EntryPoint","urlTemplate":"https://blog.mhuig.top/havefun/Coco/?s={search_term_string}"},"query-input":"required name=search_term_string"}},{"@context":"http://schema.org","@type":"BlogPosting","headline":"尝试在博客中添加简易文章推荐功能","description":"如何在博客中添加简易文章推荐功能","inLanguage":"zh-CN","mainEntityOfPage":{"@type":"WebPage","@id":"https://blog.mhuig.top/p/175a1706/"},"author":{"@type":"Person","name":"MHuiG","image":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3"},"url":"https://blog.mhuig.top/"},"publisher":{"@type":"Organization","name":"MHuiG's Blog","logo":{"@type":"ImageObject","url":"/lib/favicon/android-chrome-192x192.png?v=8bf02188e3","width":192,"height":192}},"url":"https://blog.mhuig.top/p/175a1706/","wordCount":0,"datePublished":"2022-09-15T11:13:00.000Z","dateModified":"2022-09-16T02:48:00.000Z","articleSection":"Data mining","keywords":"Data mining,推荐系统","image":{"@type":"ImageObject","url":"https://static.mhuig.top/npm/mhgoos@0.0.1663317354137/tf-idf.png","width":1024,"height":768}}]</script><script src="https://cdn.bootcdn.net/ajax/libs/pjax/0.2.8/pjax.min.js"></script><script>var pjax;document.addEventListener("DOMContentLoaded",(function(){pjax=new Pjax({elements:'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([pjax-fancybox]):not([onclick="return false;"]):not([onclick="return!1"]):not([target="_blank"]):not([target="view_window"]):not([href$=".xml"])',selectors:["head title","head meta[name=keywords]","head meta[name=description]","#l_main","#pjax-header-nav-list",".pjax","pjax"],cacheBust:!1,timeout:5e3})})),document.addEventListener("pjax:send",(function(e){try{var t=window.location.pathname,n=e.triggerElement.href,a=[""];""!=a[0]&&a.forEach((e=>{-1==t.indexOf(e)&&-1==n.indexOf(e)||(window.location.href=n)}))}catch(e){}volantis.pjax.method.send.start()})),document.addEventListener("pjax:complete",(function(){document.querySelectorAll("script[data-pjax], .pjax-reload script").forEach((e=>{const t=e.text||e.textContent||e.innerHTML||"",n=document.createElement("script");Object.keys(e.attributes).forEach((t=>{n.setAttribute(e.attributes[t].nodeName,e.attributes[t].nodeValue)})),t&&n.appendChild(document.createTextNode(t)),e.parentNode.replaceChild(n,e)})),volantis.pjax.method.complete.start()})),document.addEventListener("pjax:error",(function(e){"pjax"===volantis.debug?(console.error(e),console.log("pjax error: \n"+JSON.stringify(e))):(volantis.pjax.method.error.start(),window.location.href=e.triggerElement.href)}))</script></div><pjax> <a style="display:none" target="_blank" rel="external nofollow noopener noreferrer" href="https://bot-trap.mhuig.top/">Are You A Robot?</a></pjax><script>top.location!=self.location&&(top.location=self.location),"mhuig.github.io"==window.location.host||"localhost:4000"==window.location.host||/mhuig\.top$/.test(window.location.host)||/kix\.moe$/.test(window.location.host)||/mhuig/.test(window.location.host)||/ipfs/.test(window.location.host)||(window.location.href="https://blog.mhuig.top/")</script></body></html>