加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_泰州站长网 (http://www.0523zz.com/)- 视觉智能、AI应用、CDN、行业物联网、智能数字人!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

快来!建立你的第一个Python聊天机器人项目

发布时间:2020-03-02 12:14:24 所属栏目:Unix 来源:站长网
导读:副标题#e# 利用Python,我们可以实现很多目标,比如说建立一个你专属的聊天机器人程序。 聊天机器人程序不光满足个人需求,它对商业组织和客户都非常有帮助。大多数人喜欢直接通过聊天室交谈,而不是打电话给服务中心。 Facebook发布的数据证明了机器人的价

为了训练模型,把每个输入模式转换成数字。首先,对模式中的每个单词进行引理,并创建一个长度与单词总数相同的零列表。只将值1设置为那些在模式中包含单词的索引。同样,将1设置为模式所属的类输入,来创建输出。

# create the training data 

training= [] 

# create empty array for the output 

output_empty = [0] * len(classes) 

# training set, bag of words for everysentence 

fordoc in documents: 

# initializing bag of words 

bag= [] 

# list of tokenized words for thepattern 

word_patterns = doc[0] 

# lemmatize each word - create baseword, in attempt to represent related words 

word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns] 

# create the bag of words array with1, if word is found in current pattern 

forword in words: 

bag.append(1) if word inword_patterns else bag.append(0) 

# output is a '0' for each tag and '1'for current tag (for each pattern) 

output_row = list(output_empty) 

output_row[classes.index(doc[1])] = 1 

training.append([bag, output_row]) 

# shuffle the features and make numpyarray 

random.shuffle(training) 

training= np.array(training) 

# create training and testing lists. X- patterns, Y - intents 

train_x= list(training[:,0]) 

train_y= list(training[:,1]) 

print("Training data is created") 

第四步:训练模型

(编辑:云计算网_泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读