 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
		<id>http://wiki.sseuu.com/index.php?action=history&amp;feed=atom&amp;title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA%28%E4%BD%BF%E7%94%A8NLTK%29_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91</id>
		<title>从零开始用Python写一个聊天机器人(使用NLTK) - 【知乎】 - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.sseuu.com/index.php?action=history&amp;feed=atom&amp;title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA%28%E4%BD%BF%E7%94%A8NLTK%29_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91"/>
		<link rel="alternate" type="text/html" href="http://wiki.sseuu.com/index.php?title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA(%E4%BD%BF%E7%94%A8NLTK)_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91&amp;action=history"/>
		<updated>2026-05-08T01:10:13Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://wiki.sseuu.com/index.php?title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA(%E4%BD%BF%E7%94%A8NLTK)_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91&amp;diff=121364&amp;oldid=prev</id>
		<title>2023年9月1日 (五) 06:53 江南仁</title>
		<link rel="alternate" type="text/html" href="http://wiki.sseuu.com/index.php?title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA(%E4%BD%BF%E7%94%A8NLTK)_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91&amp;diff=121364&amp;oldid=prev"/>
				<updated>2023-09-01T06:53:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;zh-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;2023年9月1日 (五) 06:53的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l16&quot; &gt;第16行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第16行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Gartner 估计到2020年聊天机器人将处理85%的客户服务交互；它们现在已经处理了大约30%。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Gartner 估计到2020年聊天机器人将处理85%的客户服务交互；它们现在已经处理了大约30%。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;我肯定你听说过 Duolingo ：一款流行的语言学习应用，可以通过游戏来练习一门新语言。它因其新颖的外语教学方式而广受欢迎。其概念很简单：每天五到十分钟的互动训练就足以学习一门语言。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;我肯定你听说过&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[https://www.duolingo.cn/ &lt;/ins&gt;Duolingo&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;] &lt;/ins&gt;：一款流行的语言学习应用，可以通过游戏来练习一门新语言。它因其新颖的外语教学方式而广受欢迎。其概念很简单：每天五到十分钟的互动训练就足以学习一门语言。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;然而，尽管Duolingo 正在帮助人们学习一门新的语言，但它的实践者们却有一个担忧。人们觉得自己没有学习到有价值的会话技巧，因为他们是在自学。由于害怕尴尬，人们也害怕与其他语言学习者配对。这成了Duolingo &lt;/del&gt;规划中的一大瓶颈。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;然而，尽管[[Duolingo]] 正在帮助人们学习一门新的语言，但它的实践者们却有一个担忧。人们觉得自己没有学习到有价值的会话技巧，因为他们是在自学。由于害怕尴尬，人们也害怕与其他语言学习者配对。这成了[[Duolingo]] &lt;/ins&gt;规划中的一大瓶颈。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;因此他们的团队通过在自己的应用程序中构建一个本地聊天机器人来解决这个问题，帮助用户学习会话技能并实践他们所学的知识。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;因此他们的团队通过在自己的应用程序中构建一个本地聊天机器人来解决这个问题，帮助用户学习会话技能并实践他们所学的知识。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;http://bots.duolingo.com/&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;http://bots.duolingo.com/&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;由于这些机器人被设计成会话型和友好型的，Duolingo &lt;/del&gt;学习者可以在一天中的任何时间与他们选择的角色机器人练习会话，直到他们有足够的勇气与其他说新语言的人一起练习为止。这解决了消费者的一个主要痛点，让通过应用学习变得更加有趣。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;由于这些机器人被设计成会话型和友好型的，[[Duolingo]] &lt;/ins&gt;学习者可以在一天中的任何时间与他们选择的角色机器人练习会话，直到他们有足够的勇气与其他说新语言的人一起练习为止。这解决了消费者的一个主要痛点，让通过应用学习变得更加有趣。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;所以什么是聊天机器人?&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;所以什么是聊天机器人?&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l49&quot; &gt;第49行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第49行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;先决条件&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;先决条件&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;具有scikit库和NLTK的实际操作知识。但是你如果是NLP新手，仍然可以阅读本文，然后参照参考资料。&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;具有[[scikit]]库和NLTK的实际操作知识。但是你如果是NLP新手，仍然可以阅读本文，然后参照参考资料。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''[[NLP]]'''&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''[[NLP]]'''&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l119&quot; &gt;第119行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第119行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;考虑一个包含100个单词的文档，其中单词“phone”出现了5次。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;考虑一个包含100个单词的文档，其中单词“phone”出现了5次。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;“phone”的检索词频率就是(5 / 100) = 0.05。现在，假设我们有1000万份文档，其中1000份文档中出现了“电话”这个词。那么逆文档频率就是log(10,000,000 / 1,000) = 4。TF-IDF权重就是这两者的乘积：0.05 * 4 = 0.20。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;“phone”的检索词频率就是(5 / 100) = 0.05。现在，假设我们有1000万份文档，其中1000份文档中出现了“电话”这个词。那么逆文档频率就是log(10,000,000 / 1,000) = 4。TF-IDF权重就是这两者的乘积：0.05 * 4 = 0.20。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Tf-IDF &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;可以在scikit learn中调用&lt;/del&gt;:&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Tf-IDF &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;可以在[[scikit learn]]中调用&lt;/ins&gt;:&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.feature_extraction.text import TfidfVectorizer&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.feature_extraction.text import TfidfVectorizer&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l197&quot; &gt;第197行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第197行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;为了让我们的机器人为输入问题生成回复，这里将使用文档相似性的概念。因此，我们首先需要导入必要的模块。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;为了让我们的机器人为输入问题生成回复，这里将使用文档相似性的概念。因此，我们首先需要导入必要的模块。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;从scikit learn库中，导入TFidf矢量化器，将一组原始文档转换为TF&lt;/del&gt;-IDF特征矩阵。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;从[[scikit learn]]库中，导入TFidf矢量化器，将一组原始文档转换为TF&lt;/ins&gt;-IDF特征矩阵。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.feature_extraction.text import TfidfVectorizer&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.feature_extraction.text import TfidfVectorizer&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;同时, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;从scikit learn库中导入cosine &lt;/del&gt;similarity模块&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;同时, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;从[[scikit learn]]库中导入cosine &lt;/ins&gt;similarity模块&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.metrics.pairwise import cosine_similarity&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sklearn.metrics.pairwise import cosine_similarity&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;这将用于查找用户输入的单词与语料库中的单词之间的相似性。这是聊天机器人最简单的实现。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;这将用于查找用户输入的单词与语料库中的单词之间的相似性。这是聊天机器人最简单的实现。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>江南仁</name></author>	</entry>

	<entry>
		<id>http://wiki.sseuu.com/index.php?title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA(%E4%BD%BF%E7%94%A8NLTK)_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91&amp;diff=120191&amp;oldid=prev</id>
		<title>江南仁：创建页面，内容为“{{4}} 本文为 AI 研习社编译的技术博客，原标题 ：&lt;br&gt; Building a Simple Chatbot from Scratch in Python (using NLTK)&lt;br&gt; 作者 | Parul Pandey&lt;br&gt;...”</title>
		<link rel="alternate" type="text/html" href="http://wiki.sseuu.com/index.php?title=%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%94%A8Python%E5%86%99%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA(%E4%BD%BF%E7%94%A8NLTK)_-_%E3%80%90%E7%9F%A5%E4%B9%8E%E3%80%91&amp;diff=120191&amp;oldid=prev"/>
				<updated>2023-04-22T12:40:06Z</updated>
		
		<summary type="html">&lt;p&gt;创建页面，内容为“{{4}} 本文为 AI 研习社编译的技术博客，原标题 ：&amp;lt;br&amp;gt; Building a Simple Chatbot from Scratch in Python (using NLTK)&amp;lt;br&amp;gt; 作者 | Parul Pandey&amp;lt;br&amp;gt;...”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{4}}&lt;br /&gt;
本文为 AI 研习社编译的技术博客，原标题 ：&amp;lt;br&amp;gt;&lt;br /&gt;
Building a Simple Chatbot from Scratch in Python (using NLTK)&amp;lt;br&amp;gt;&lt;br /&gt;
作者 | Parul Pandey&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
翻译 | Disillusion&amp;lt;br&amp;gt;&lt;br /&gt;
校对 | 酱番梨 整理 | 菠萝妹&amp;lt;br&amp;gt;&lt;br /&gt;
原文链接：&amp;lt;br&amp;gt;&lt;br /&gt;
https://medium.com/analytics-vidhya/building-a-simple-chatbot-in-python-using-nltk-7c8c8215ac6e&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
从零开始用Python写一个聊天机器人（使用NLTK）&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
来源: eWeek&amp;lt;br&amp;gt;&lt;br /&gt;
Gartner 估计到2020年聊天机器人将处理85%的客户服务交互；它们现在已经处理了大约30%。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
我肯定你听说过 Duolingo ：一款流行的语言学习应用，可以通过游戏来练习一门新语言。它因其新颖的外语教学方式而广受欢迎。其概念很简单：每天五到十分钟的互动训练就足以学习一门语言。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
然而，尽管Duolingo 正在帮助人们学习一门新的语言，但它的实践者们却有一个担忧。人们觉得自己没有学习到有价值的会话技巧，因为他们是在自学。由于害怕尴尬，人们也害怕与其他语言学习者配对。这成了Duolingo 规划中的一大瓶颈。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
因此他们的团队通过在自己的应用程序中构建一个本地聊天机器人来解决这个问题，帮助用户学习会话技能并实践他们所学的知识。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
http://bots.duolingo.com/&amp;lt;br&amp;gt;&lt;br /&gt;
由于这些机器人被设计成会话型和友好型的，Duolingo 学习者可以在一天中的任何时间与他们选择的角色机器人练习会话，直到他们有足够的勇气与其他说新语言的人一起练习为止。这解决了消费者的一个主要痛点，让通过应用学习变得更加有趣。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
所以什么是聊天机器人?&amp;lt;br&amp;gt;&lt;br /&gt;
聊天机器人是人造的以智慧为动力的软件(比如Siri，Alexa，谷歌助理等)，它们存在于设备中，应用程序，网站或其他网络，试图衡量消费者的需要，然后帮助他们执行一个特定任务，如商业交易，酒店预订，表单提交等等。今天几乎每个公司都 部署聊天机器人与用户交流。公司使用聊天机器人的一些方式是：&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
提供航班信息&amp;lt;br&amp;gt;&lt;br /&gt;
连接客户和他们的财务&amp;lt;br&amp;gt;&lt;br /&gt;
作为客户支持&amp;lt;br&amp;gt;&lt;br /&gt;
可能性(几乎)是无限的。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
聊天机器人的历史可以追溯到1966年，当时韦森鲍姆发明了一种名为“伊丽莎”(ELIZA)的电脑程序。它仅仅从200行代码中模仿一个心理治疗师的言语。你现在仍然可以和它交谈:伊丽莎。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Source: Cognizant&amp;lt;br&amp;gt;&lt;br /&gt;
聊天机器人如何工作?&amp;lt;br&amp;gt;&lt;br /&gt;
聊天机器人大致有两种变体：基于规则的和自学习的。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
基于规则的聊天机器人将根据它所训练的一些规则回答问题。定义的规则可以非常简单，也可以非常复杂。机器人可以处理简单的查询，但无法管理复杂的查询。&amp;lt;br&amp;gt;&lt;br /&gt;
自学习机器人使用一些基于机器学习的方法，他们往往比基于规则的机器人更有效。这些机器人进一步分为以下两种类型：基于检索或生成型&amp;lt;br&amp;gt;&lt;br /&gt;
在基于检索的模型中，聊天机器人使用一些启发式方法从预定义的响应库中选择响应。聊天机器人使用消息和对话上下文从预定义的聊天机器人消息列表中选择最佳响应。上下文可以包括对话树中的当前位置、对话中的所有先前消息、先前保存的变量(例如用户名)。选择响应的启发式方法可以采用许多不同的方式进行设计，从基于规则的if-else条件逻辑到机器学习分类器等。&amp;lt;br&amp;gt;&lt;br /&gt;
生成型机器人可以生成回答，但并不总是用一组答案中的一个来回答。这使他们更聪明，因为他们从查询中逐字提取并生成答案。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
在本文中，我们将在python中基于NLTK库构建一个简单的基于检索的聊天机器人。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
开始构建机器人&amp;lt;br&amp;gt;&lt;br /&gt;
先决条件&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
具有scikit库和NLTK的实际操作知识。但是你如果是NLP新手，仍然可以阅读本文，然后参照参考资料。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''[[NLP]]'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
研究人类语言和计算机交互的领域称为自然语言处理，简称NLP。它位于计算机科学、人工智能和计算语言学的交汇处(维基百科)。NLP是计算机分析、理解和从人类语言中获取意义的一种聪明且有用的方法。利用NLP，开发人员可以组织和结构化知识来执行诸如自动摘要、翻译、命名实体识别、关系提取、情感分析、语音识别和主题分割等任务。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''[[NLTK]]''': 简要介绍&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
NLTK(自然语言工具包)是构建Python程序来处理人类语言数据的领先平台。它为超过50个语料库和词汇资源(如WordNet)提供了易于使用的接口，同时提供了一套用于分类、词语切分、词干、标记、解析和语义推理的文本处理库，这些都是工业强度NLP库的封装器。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
NLTK被称为“使用Python进行计算语言学教学和工作的一个极好工具”，以及“一个与自然语言打交道的绝佳库”。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Python的自然语言处理提供了语言处理编程的实用介绍。我强烈推荐这本书给使用Python的NLP初学者。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
下载及安装NLTK&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
安装NLTK: 运行 pip install nltk&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
测试安装: 运行 python 接着输入 import nltk&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
对特定平台的指令,点这。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
安装NLTK包&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
导入NLTK 然后运行 nltk.download().这将打开NLTK的下载程序，你可以从其中选择要下载的语料库和模型。也可以一次下载所有包。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''用NLTK对文本进行预处理'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
文本数据的主要问题是它都是文本格式(字符串)。然而，机器学习算法需要某种数值特征向量来完成任务。因此，在我们开始任何NLP项目之前，我们都需对其进行预处理。基本文本预处理包括：&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
将整个文本转换为大写或小写，这样算法就不会将大小写的相同单词视为不同的单词&amp;lt;br&amp;gt;&lt;br /&gt;
词语切分：指将普通文本字符串转换为符号列表的过程。也就是我们真正想要的词。句子分词器可用于查找句子列表，单词分词器可用于查找字符串形式的单词列表。&amp;lt;br&amp;gt;&lt;br /&gt;
NLTK数据包包括一个用于英语的预训练Punkt分词器。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
去除噪声，即所有不是标准数字或字母的东西。&amp;lt;br&amp;gt;&lt;br /&gt;
删除停止词。有时，一些在帮助选择符合用户需要的文档方面似乎没有什么价值的常见单词被完全排除在词汇表之外。这些单词叫做停止词。&amp;lt;br&amp;gt;&lt;br /&gt;
词干提取：词干提取是将词尾变化词(有时是派生词)还原为词干、词根或词根形式(通常是书面形式)的过程。例如，如果我们要提取下列词：“Stems”, “Stemming”, “Stemmed”, “and Stemtization”，结果将是一个词“stem”。&amp;lt;br&amp;gt;&lt;br /&gt;
词形还原：词干提取的一个细微变体是词形还原 。它们之间的主要区别在于，词干提取可以创建不存在的词，而词元是实际的词。所以你的词根，也就是你最终得到的词，在字典里通常是查不到的，但词元你是可以查到的。词形还原的例子如：“run”是“running”或“ran”等词的基本形式，或者“better”和“good”是同一个词元，因此它们被认为是相同的。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[单词袋]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
在初始预处理阶段之后，我们需要将文本转换为有意义的数字向量(或数组)。单词袋是描述文档中单词出现情况的文本表示。它包括两个东西:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
•一个已知词汇表。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
•一个对已知词存在的量度。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
为什么它被称为一个单词袋？这是因为关于文档中单词的顺序或结构的任何信息都会被丢弃，模型只关心已知单词是否出现在文档中，而不关心它们在文档中的位置。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
单词袋的直观感受是，如果文档的内容相似，那么文档就相似。此外，我们还可以从文档的内容中了解一些文档的含义。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
例如，如果我们的字典包含单词{Learning, is, the, not, great}，并且我们想向量化文本“Learning is great”，我们将有以下向量:(1,1,0,0,1)。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[TF-IDF]] 方法&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
单词袋方法的一个问题是，频繁出现的单词开始在文档中占据主导地位(例如，得分更高)，但可能并没有包含太多的“有信息内容”。此外，它将给予较长的文档更多的权重。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
一种方法是根据单词在所有文档中出现的频率重新调整单词的频率，以便对“the”等在所有文档中也经常出现的单词适当降低权重。这种评分方法称为检索词频率-逆文档频率，简称TF-IDF，其中:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
检索词频率: 是当前文档中单词出现频率的得分。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
TF = (Number of times term t appears in a document)/(Number of terms in the document)&amp;lt;br&amp;gt;&lt;br /&gt;
逆文档频率：是这个词在文档中罕见度的得分。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
IDF = 1+log(N/n), where, N is the number of documents and n is the number of documents a term t has appeared in.&amp;lt;br&amp;gt;&lt;br /&gt;
Tf-idf 权重是信息检索和文本挖掘中常用的一种权重。该权重是一种统计度量，用于评估单词对集合或语料库中的文档有多重要&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''例子:'''&lt;br /&gt;
考虑一个包含100个单词的文档，其中单词“phone”出现了5次。&amp;lt;br&amp;gt;&lt;br /&gt;
“phone”的检索词频率就是(5 / 100) = 0.05。现在，假设我们有1000万份文档，其中1000份文档中出现了“电话”这个词。那么逆文档频率就是log(10,000,000 / 1,000) = 4。TF-IDF权重就是这两者的乘积：0.05 * 4 = 0.20。&amp;lt;br&amp;gt;&lt;br /&gt;
Tf-IDF 可以在scikit learn中调用:&amp;lt;br&amp;gt;&lt;br /&gt;
from sklearn.feature_extraction.text import TfidfVectorizer&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''余弦相似度'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
TF-IDF是一种在向量空间中得到两个实值向量的文本变换。然后我们可以通过取点积然后除以它们的范数乘积来得到任意一对向量的余弦相似度。接着以此得到向量夹角的余弦值。余弦相似度是两个非零向量之间相似度的度量。利用这个公式，我们可以求出任意两个文档d1和d2之间的相似性。&lt;br /&gt;
&lt;br /&gt;
Cosine Similarity (d1, d2) =  Dot product(d1, d2) / ||d1|| * ||d2||&amp;lt;br&amp;gt;&lt;br /&gt;
其中d1，d2是非零向量。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
TF-IDF和余弦相似度的详细说明和实际例子参见下面的文档。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Tf-Idf and Cosine similarity&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the year 1998 Google handled 9800 average search queries every day. In 2012 this number shot up to 5.13 billion…http://janav.wordpress.com&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
现在我们对NLP过程有了一个基本概念。是我们开始真正工作的时候了。我们在这里将聊天机器人命名为“ROBO ”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''导入必备库'''&lt;br /&gt;
import nltk&amp;lt;br&amp;gt;&lt;br /&gt;
import numpy as np&amp;lt;br&amp;gt;&lt;br /&gt;
import random&amp;lt;br&amp;gt;&lt;br /&gt;
import string # to process standard python strings&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''语料库'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
在我们的示例中，我们将使用聊天机器人的Wikipedia页面作为我们的语料库。从页面复制内容并将其放入名为“chatbot.txt”的文本文件中。然而，你可以使用你选择的任何语料库。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''读入数据'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
我们将阅读corpus.txt文件，并将整个语料库转换为句子列表和单词列表，以便进行进一步的预处理。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
f=open('chatbot.txt','r',errors = 'ignore')&amp;lt;br&amp;gt;&lt;br /&gt;
raw=f.read()&amp;lt;br&amp;gt;&lt;br /&gt;
raw=raw.lower()# converts to lowercase&amp;lt;br&amp;gt;&lt;br /&gt;
nltk.download('punkt') # first-time use only&amp;lt;br&amp;gt;&lt;br /&gt;
nltk.download('wordnet') # first-time use only&amp;lt;br&amp;gt;&lt;br /&gt;
sent_tokens = nltk.sent_tokenize(raw)# converts to list of sentences &amp;lt;br&amp;gt;&lt;br /&gt;
word_tokens = nltk.word_tokenize(raw)# converts to list of words&amp;lt;br&amp;gt;&lt;br /&gt;
让我们看看sent_tokens 和 the word_tokens的例子&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
['a chatbot (also known as a talkbot, chatterbot, bot, im bot, interactive agent, or artificial conversational entity) is a computer program or an artificial intelligence which conducts a conversation via auditory or textual methods.',&lt;br /&gt;
['a', 'chatbot', '(', 'also', 'known']&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''预处理原始文本'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
现在我们将定义一个名为LemTokens 的函数，它将接受符号作为输入并返回规范化符号。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
lemmer = nltk.stem.WordNetLemmatizer()&lt;br /&gt;
#&lt;br /&gt;
def LemTokens(tokens):&lt;br /&gt;
   return [lemmer.lemmatize(token) for token in tokens]&lt;br /&gt;
remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)&lt;br /&gt;
def LemNormalize(text):&lt;br /&gt;
   return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''关键字匹配'''&lt;br /&gt;
&lt;br /&gt;
接下来，我们将通过机器人定义一个问候函数，即如果用户的输入是问候语，机器人将返回相应的回复。ELIZA使用一个简单的关键字匹配问候。我们将在这里使用相同的概念。&lt;br /&gt;
&lt;br /&gt;
GREETING_INPUTS = (&amp;quot;hello&amp;quot;, &amp;quot;hi&amp;quot;, &amp;quot;greetings&amp;quot;, &amp;quot;sup&amp;quot;, &amp;quot;what's up&amp;quot;,&amp;quot;hey&amp;quot;,)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GREETING_RESPONSES = [&amp;quot;hi&amp;quot;, &amp;quot;hey&amp;quot;, &amp;quot;*nods*&amp;quot;, &amp;quot;hi there&amp;quot;, &amp;quot;hello&amp;quot;, &amp;quot;I am glad! You are talking to me&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def greeting(sentence):&lt;br /&gt;
&lt;br /&gt;
   for word in sentence.split():&lt;br /&gt;
       if word.lower() in GREETING_INPUTS:&lt;br /&gt;
           return random.choice(GREETING_RESPONSES)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
生成回复&lt;br /&gt;
&lt;br /&gt;
为了让我们的机器人为输入问题生成回复，这里将使用文档相似性的概念。因此，我们首先需要导入必要的模块。&lt;br /&gt;
&lt;br /&gt;
从scikit learn库中，导入TFidf矢量化器，将一组原始文档转换为TF-IDF特征矩阵。&lt;br /&gt;
from sklearn.feature_extraction.text import TfidfVectorizer&lt;br /&gt;
同时, 从scikit learn库中导入cosine similarity模块&lt;br /&gt;
from sklearn.metrics.pairwise import cosine_similarity&lt;br /&gt;
这将用于查找用户输入的单词与语料库中的单词之间的相似性。这是聊天机器人最简单的实现。&lt;br /&gt;
&lt;br /&gt;
我们定义了一个回复函数，该函数搜索用户的表达，搜索一个或多个已知的关键字，并返回几个可能的回复之一。如果没有找到与任何关键字匹配的输入，它将返回一个响应:“对不起!”我不明白你的意思&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def response(user_response):&lt;br /&gt;
   robo_response=''&lt;br /&gt;
TfidfVec = TfidfVectorizer(tokenizer=LemNormalize, stop_words='english')&lt;br /&gt;
   tfidf = TfidfVec.fit_transform(sent_tokens)&lt;br /&gt;
   vals = cosine_similarity(tfidf[-1], tfidf)&lt;br /&gt;
   idx=vals.argsort()[0][-2]&lt;br /&gt;
   flat = vals.flatten()&lt;br /&gt;
   flat.sort()&lt;br /&gt;
   req_tfidf = flat[-2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if(req_tfidf==0):&lt;br /&gt;
       robo_response=robo_response+&amp;quot;I am sorry! I don't understand you&amp;quot;&lt;br /&gt;
       return robo_response&lt;br /&gt;
   else:&lt;br /&gt;
       robo_response = robo_response+sent_tokens[idx]&lt;br /&gt;
       return robo_response&lt;br /&gt;
最后，我们将根据用户的输入来决定机器人在开始和结束对话时说的话。&lt;br /&gt;
&lt;br /&gt;
flag=True&lt;br /&gt;
print(&amp;quot;ROBO: My name is Robo. I will answer your queries about Chatbots. If you want to exit, type Bye!&amp;quot;)&lt;br /&gt;
while(flag==True):&lt;br /&gt;
   user_response = input()&lt;br /&gt;
   user_response=user_response.lower()&lt;br /&gt;
   if(user_response!='bye'):&lt;br /&gt;
       if(user_response=='thanks' or user_response=='thank you' ):&lt;br /&gt;
           flag=False&lt;br /&gt;
           print(&amp;quot;ROBO: You are welcome..&amp;quot;)&lt;br /&gt;
       else:&lt;br /&gt;
           if(greeting(user_response)!=None):&lt;br /&gt;
               print(&amp;quot;ROBO: &amp;quot;+greeting(user_response))&lt;br /&gt;
           else:&lt;br /&gt;
               sent_tokens.append(user_response)&lt;br /&gt;
               word_tokens=word_tokens+nltk.word_tokenize(user_response)&lt;br /&gt;
               final_words=list(set(word_tokens))&lt;br /&gt;
               print(&amp;quot;ROBO: &amp;quot;,end=&amp;quot;&amp;quot;)&lt;br /&gt;
               print(response(user_response))&lt;br /&gt;
               sent_tokens.remove(user_response)&lt;br /&gt;
   else:&lt;br /&gt;
       flag=False&lt;br /&gt;
       print(&amp;quot;ROBO: Bye! take care..&amp;quot;)&lt;br /&gt;
差不多就是这样。我们用NLTK中编写了第一个聊天机器人的代码。你可以在这里找到带有语料库的完整代码。现在，让我们看看它是如何与人类互动的:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
尽管聊天机器人在某些问题上不能给出令人满意的答案，但在另一些问题上却表现得很好。&lt;br /&gt;
&lt;br /&gt;
结论&lt;br /&gt;
虽然它是一个非常简单的机器人，几乎没有任何认知技能，但它是一个很好的方法来了解NLP和聊天机器人。虽然“ROBO”会对用户输入做出响应。但它愚弄不了你的朋友，对于一个生产系统，你可能希望考虑现有的机器人平台或框架之一，但是这个示例应该能够帮助你思考设计和创建聊天机器人的挑战。互联网充斥着大量的资源，在阅读了这篇文章之后，我相信你会想要创建一个自己的聊天机器人。快乐编程! !&lt;/div&gt;</summary>
		<author><name>江南仁</name></author>	</entry>

	</feed>