快来!建立你的第一个Python聊天机器人项目
为了训练模型,把每个输入模式转换成数字。首先,对模式中的每个单词进行引理,并创建一个长度与单词总数相同的零列表。只将值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") 第四步:训练模型 (编辑:站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- iphone se与iphone5s哪个好 iphone se与iphone5s区别详细介
- 街头篮球手游怎么盖帽 街头篮球手游盖帽技巧
- 腾讯优品是什么 腾讯优品怎么开店
- Flex4 DataGrid中嵌入RadioButton实现思路及代码
- Apple Pay新增支持哪三家银行 Apple Pay还会新增支持哪些银
- nice直播怎么直播 nice直播在哪里
- Nginx的这些妙用,你肯定有不知道的!
- iPhone4s可以升级iOS9.3.2吗 iPhone4s升级iOS9.3.2怎么样
- 服务商转正非一朝一夕 积累造车经验或许拥有更好站位
- iphonex廉价版和iphonex的区别 廉价版iphonex和iphonex区别