本文整理汇总了Python中alex.components.slu.da.DialogueActConfusionNetwork.add_merge方法的典型用法代码示例。如果您正苦于以下问题:Python DialogueActConfusionNetwork.add_merge方法的具体用法?Python DialogueActConfusionNetwork.add_merge怎么用?Python DialogueActConfusionNetwork.add_merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alex.components.slu.da.DialogueActConfusionNetwork
的用法示例。
在下文中一共展示了DialogueActConfusionNetwork.add_merge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_confusion_network
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add_merge [as 别名]
def _build_confusion_network(self, sampled_da_items):
confusion_net = DialogueActConfusionNetwork()
for da_items, probs in sampled_da_items:
for dai, prob in zip(da_items, probs):
confusion_net.add_merge(prob, dai)
return confusion_net
示例2: _build_confusion_network
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add_merge [as 别名]
def _build_confusion_network(self, sampled_da_items):
'''Build confusion network from a list containing DialgoueActItem and their observation probability.'''
confusion_net = DialogueActConfusionNetwork()
for da_items, probs in sampled_da_items:
for dai, prob in zip(da_items, probs):
confusion_net.add_merge(prob, dai)
return confusion_net
示例3: test_add_merge
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add_merge [as 别名]
def test_add_merge(self):
dai = DialogueActItem(dai='inform(food=chinese)')
dacn = DialogueActConfusionNetwork()
dacn.add_merge(0.5, dai, combine='add')
self.assertEqual(dacn._get_prob([0]), 0.5)
dacn.add_merge(0.5, dai, combine='add')
self.assertEqual(dacn._get_prob([0]), 1.0)
示例4: test_merge_slu_confnets
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add_merge [as 别名]
def test_merge_slu_confnets(self):
confnet1 = DialogueActConfusionNetwork()
confnet1.add(0.7, DialogueActItem('hello'))
confnet1.add(0.2, DialogueActItem('bye'))
confnet2 = DialogueActConfusionNetwork()
confnet2.add(0.6, DialogueActItem('hello'))
confnet2.add(0.3, DialogueActItem('restart'))
confnets = [[0.7, confnet1], [0.3, confnet2]]
merged_confnets = merge_slu_confnets(confnets)
correct_merged_confnet = DialogueActConfusionNetwork()
correct_merged_confnet.add_merge(0.7 * 0.7, DialogueActItem('hello'),
combine='add')
correct_merged_confnet.add_merge(0.7 * 0.2, DialogueActItem('bye'),
combine='add')
correct_merged_confnet.add_merge(0.3 * 0.6, DialogueActItem('hello'),
combine='add')
correct_merged_confnet.add_merge(0.3 * 0.3, DialogueActItem('restart'),
combine='add')
s = []
s.append("")
s.append("Merged confnets:")
s.append(unicode(merged_confnets))
s.append("")
s.append("Correct merged results:")
s.append(unicode(correct_merged_confnet))
s.append("")
self.assertEqual(unicode(merged_confnets), unicode(correct_merged_confnet))
示例5: parse_X
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add_merge [as 别名]
def parse_X(self, utterance, verbose=False):
if verbose:
print '='*120
print 'Parsing X'
print '-'*120
print unicode(utterance)
if self.preprocessing:
utterance = self.preprocessing.normalise(utterance)
utterance_fvcs = self.get_fvc(utterance)
if verbose:
print unicode(utterance)
print unicode(utterance_fvcs)
da_confnet = DialogueActConfusionNetwork()
for clser in self.trained_classifiers:
if verbose:
print "Using classifier: ", unicode(clser)
if self.parsed_classifiers[clser].value and self.parsed_classifiers[clser].value.startswith('CL_'):
# process abstracted classifiers
for f, v, c in utterance_fvcs:
cc = "CL_" + c.upper()
if self.parsed_classifiers[clser].value == cc:
#print clser, f, v, c
classifiers_features = self.get_features(utterance, (f, v, cc), utterance_fvcs)
classifiers_inputs = np.zeros((1, len(self.classifiers_features_mapping[clser])))
classifiers_inputs[0] = classifiers_features.get_feature_vector(self.classifiers_features_mapping[clser])
#if verbose:
# print classifiers_features
# print self.classifiers_features_mapping[clser]
p = self.trained_classifiers[clser].predict_proba(classifiers_inputs)
if verbose:
print ' Probability:', p
dai = DialogueActItem(self.parsed_classifiers[clser].dat, self.parsed_classifiers[clser].name, v)
da_confnet.add_merge(p[0][1], dai, combine='max')
else:
# process concrete classifiers
classifiers_features = self.get_features(utterance, (None, None, None), utterance_fvcs)
classifiers_inputs = np.zeros((1, len(self.classifiers_features_mapping[clser])))
classifiers_inputs[0] = classifiers_features.get_feature_vector(self.classifiers_features_mapping[clser])
#if verbose:
# print classifiers_features
# print self.classifiers_features_mapping[clser]
p = self.trained_classifiers[clser].predict_proba(classifiers_inputs)
if verbose:
print ' Probability:', p
dai = self.parsed_classifiers[clser]
da_confnet.add_merge(p[0][1], dai, combine='max')
da_confnet.sort().prune()
return da_confnet