本文整理汇总了Python中alex.components.slu.da.DialogueActConfusionNetwork.add方法的典型用法代码示例。如果您正苦于以下问题:Python DialogueActConfusionNetwork.add方法的具体用法?Python DialogueActConfusionNetwork.add怎么用?Python DialogueActConfusionNetwork.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alex.components.slu.da.DialogueActConfusionNetwork
的用法示例。
在下文中一共展示了DialogueActConfusionNetwork.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_merge_slu_confnets
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [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))
示例2: _resolve_user_da_in_context
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def _resolve_user_da_in_context(self, user_da, system_da):
"""Resolves and converts meaning of some user dialogue acts
given the context."""
old_user_da = deepcopy(user_da)
new_user_da = DialogueActConfusionNetwork()
if isinstance(system_da, DialogueAct):
for system_dai in system_da:
for prob, user_dai in user_da:
new_user_dai = None
if system_dai.dat == "confirm" and user_dai.dat == "affirm":
new_user_dai = DialogueActItem("inform", system_dai.name, system_dai.value)
elif system_dai.dat == "confirm" and user_dai.dat == "negate":
new_user_dai = DialogueActItem("deny", system_dai.name, system_dai.value)
elif system_dai.dat == "request" and user_dai.dat == "inform" and \
user_dai.name in self.ontology['context_resolution'] and \
system_dai.name in self.ontology['context_resolution'][user_dai.name] and \
user_dai.value == "dontcare":
new_user_dai = DialogueActItem("inform", system_dai.name, system_dai.value)
elif system_dai.dat == "request" and user_dai.dat == "inform" and \
user_dai.name in self.ontology['context_resolution'] and \
system_dai.name in self.ontology['context_resolution'][user_dai.name] and \
self.ontology.slot_has_value(system_dai.name, user_dai.value):
new_user_dai = DialogueActItem("inform", system_dai.name, user_dai.value)
elif system_dai.dat == "request" and system_dai.name != "" and \
user_dai.dat == "affirm" and self.ontology.slot_is_binary(system_dai.name):
new_user_dai = DialogueActItem("inform", system_dai.name, "true")
elif system_dai.dat == "request" and system_dai.name != "" and \
user_dai.dat == "negate" and self.ontology.slot_is_binary(system_dai.name):
new_user_dai = DialogueActItem("inform", system_dai.name, "false")
if new_user_dai:
new_user_da.add(prob, new_user_dai)
old_user_da.merge(new_user_da, combine='max')
return old_user_da
示例3: _infer_last_talked_about_slots
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def _infer_last_talked_about_slots(self, user_da, system_da):
"""This adds dialogue act items to support inference of the last slots the user talked about."""
old_user_da = deepcopy(user_da)
new_user_da = DialogueActConfusionNetwork()
colliding_slots = {}
done_slots = set()
for prob, user_dai in user_da:
new_user_dais = []
lta_tsvs = self.ontology.last_talked_about(user_dai.dat, user_dai.name, user_dai.value)
for name, value in lta_tsvs:
new_user_dais.append(DialogueActItem("inform", name, value))
if name in done_slots:
if not name in colliding_slots:
colliding_slots[name] = set()
colliding_slots[name].add(value)
else:
done_slots.add(name)
if new_user_dais:
for nudai in new_user_dais:
if not nudai in new_user_da:
new_user_da.add(prob, nudai)
# In case of collisions, prefer the current last talked about values if it is one of the colliding values.
# If there is a collision and the current last talked about value is not among the colliding values, do not
# consider the colliding DA's at all.
invalid_das = set()
for prob, da in set(new_user_da):
if da.name in colliding_slots and self[da.name].mpv() in colliding_slots[da.name]:
if not da.value == self[da.name].mpv():
invalid_das.add(da)
elif da.name in colliding_slots:
invalid_das.add(da)
for invalid_da in invalid_das:
new_user_da.remove(invalid_da)
old_user_da.merge(new_user_da, combine='max')
return old_user_da
示例4: last_talked_about
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def last_talked_about(self, user_da, system_da):
"""This adds dialogue act items to support inference of the last slots the user talked about."""
old_user_da = deepcopy(user_da)
new_user_da = DialogueActConfusionNetwork()
for prob, user_dai in user_da:
new_user_dais = []
lta_tsvs = self.ontology.last_talked_about(user_dai.dat, user_dai.name, user_dai.value)
for name, value in lta_tsvs:
new_user_dais.append(DialogueActItem("inform", name, value))
if new_user_dais:
for nudai in new_user_dais:
new_user_da.add(prob, nudai)
old_user_da.extend(new_user_da)
return old_user_da
示例5: parse_nblist
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def parse_nblist(self, obs, *args, **kwargs):
"""
Parses an observation featuring an utterance n-best list using the
parse_1_best method.
Arguments:
obs -- a dictionary of observations
:: observation type -> observed value
where observation type is one of values for `obs_type' used in
`ft_props', and observed value is the corresponding observed
value for the input
args -- further positional arguments that should be passed to the
`parse_1_best' method call
kwargs -- further keyword arguments that should be passed to the
`parse_1_best' method call
"""
nblist = obs['utt_nbl']
if len(nblist) == 0:
return DialogueActConfusionNetwork()
obs_wo_nblist = copy.deepcopy(obs)
del obs_wo_nblist['utt_nbl']
dacn_list = []
for prob, utt in nblist:
if "_other_" == utt:
dacn = DialogueActConfusionNetwork()
dacn.add(1.0, DialogueActItem("other"))
elif "_silence_" == utt:
dacn = DialogueActConfusionNetwork()
dacn.add(1.0, DialogueActItem("silence"))
else:
obs_wo_nblist['utt'] = utt
dacn = self.parse_1_best(obs_wo_nblist, *args, **kwargs)
dacn_list.append((prob, dacn))
dacn = merge_slu_confnets(dacn_list)
dacn.prune()
dacn.sort()
return dacn
示例6: test_get_prob
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_get_prob(self):
dacn = DialogueActConfusionNetwork()
dacn.add(0.2, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.1, DialogueActItem(dai='inform(food=russian)'))
self.assertAlmostEqual(dacn._get_prob([0, 1, 1]), 0.2 * 0.3 * 0.9)
self.assertAlmostEqual(dacn._get_prob([0, 0, 0]), 0.2 * 0.7 * 0.1)
示例7: test_prune
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_prune(self):
dacn = DialogueActConfusionNetwork()
dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))
# Russian food should be pruned.
self.assertEqual(len(dacn), 3)
dacn.prune()
self.assertEqual(len(dacn), 2)
self.assertTrue(not DialogueActItem(dai='inform(food=russian)') in dacn)
示例8: test_merge
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_merge(self):
dacn = DialogueActConfusionNetwork()
dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))
dacn.merge(dacn, combine='max')
# Russian food should be pruned.
dacn.sort().prune()
self.assertTrue(not DialogueActItem(dai='inform(food=russian)') in dacn)
示例9: test_sort
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_sort(self):
dacn = DialogueActConfusionNetwork()
dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(1.0, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))
dacn.sort()
cn = list(dacn)
self.assertEqual(cn[0][1], DialogueActItem(dai='inform(food=czech)'))
self.assertEqual(cn[1][1], DialogueActItem(dai='inform(food=chinese)'))
self.assertEqual(cn[2][1], DialogueActItem(dai='inform(food=russian)'))
示例10: main
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def main():
# initialize tracker and state
slots = ["food", "location"]
tr = DSTCTracker(slots)
state = DSTCState(slots)
state.pprint()
# try to update state with some information
print '---'
cn = DialogueActConfusionNetwork()
cn.add(0.3, DialogueActItem("inform", "food", "chinese"))
cn.add(0.1, DialogueActItem("inform", "food", "indian"))
tr.update_state(state, cn)
state.pprint()
# try to deny some information
print '---'
cn.add(0.9, DialogueActItem("deny", "food", "chinese"))
cn.add(0.1, DialogueActItem("deny", "food", "indian"))
tr.update_state(state, cn)
state.pprint()
示例11: test_get_platform_res_da
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_get_platform_res_da(self):
hdc_policy = self._build_policy()
state = DeterministicDiscriminativeDialogueState(self.cfg, self.ontology)
system_input = DialogueActConfusionNetwork()
res = hdc_policy.get_da(state)
user_input = DialogueActConfusionNetwork()
user_input.add(1.0, DialogueActItem(dai='info(task=find_platform)'))
user_input.add(1.0, DialogueActItem(dai='inform(from_stop=Praha)'))
user_input.add(1.0, DialogueActItem(dai='inform(to_stop=Brno)'))
state.update(user_input, system_input)
res = hdc_policy.get_da(state)
self.assert_('inform(not_supported)' in res)
示例12: _build_user_input
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def _build_user_input(self, *args):
user_input = DialogueActConfusionNetwork()
for arg in args:
user_input.add(1.0, DialogueActItem(dai=arg))
return user_input
示例13: test_get_best_nonnull_da
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_get_best_nonnull_da(self):
dacn = DialogueActConfusionNetwork()
dacn.add(0.2, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.1, DialogueActItem(dai='inform(food=russian)'))
da_nn = dacn.get_best_nonnull_da()
self.assertEqual(len(da_nn), 1)
self.assertEqual(da_nn.dais[0], DialogueActItem(dai='inform(food=czech)'))
dacn = DialogueActConfusionNetwork()
dacn.add(0.075, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='null()'))
dacn.add(0.15, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.075, DialogueActItem(dai='inform(food=russian)'))
da_nn = dacn.get_best_nonnull_da()
self.assertEqual(len(da_nn), 1)
self.assertEqual(da_nn.dais[0], DialogueActItem(dai='inform(food=czech)'))
示例14: test_get_best_da_hyp
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [as 别名]
def test_get_best_da_hyp(self):
# Test case when only one dai should be included in the hyp.
dacn = DialogueActConfusionNetwork()
dacn.add(0.2, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.1, DialogueActItem(dai='inform(food=russian)'))
best_hyp = dacn.get_best_da_hyp(use_log=False)
self.assertAlmostEqual(best_hyp.prob, 0.8 * 0.7 * 0.9)
self.assertEqual(len(best_hyp.da), 1)
# Test case when 2 dais should be included in the hyp.
dacn = DialogueActConfusionNetwork()
dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))
best_hyp = dacn.get_best_da_hyp(use_log=False)
self.assertAlmostEqual(best_hyp.prob, 0.9 * 0.7 * 0.9)
self.assertEqual(len(best_hyp.da), 2)
# Test the case with logarithms.
dacn = DialogueActConfusionNetwork()
dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))
best_hyp = dacn.get_best_da_hyp(use_log=True)
self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.7 * 0.9))
self.assertEqual(len(best_hyp.da), 2)
# Test the case with manual thresholds.
dacn = DialogueActConfusionNetwork()
dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))
best_hyp = dacn.get_best_da_hyp(
use_log=True, threshold=0.1, thresholds={
DialogueActItem(dai='inform(food=chinese)'): 0.5,
DialogueActItem(dai='inform(food=czech)'): 0.9,
DialogueActItem(dai='inform(food=russian)'): 0.5
})
# Test food=czech should NOT be included.
self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.3 * 0.9))
self.assertEqual(len(best_hyp.da), 1)
self.assertTrue(not DialogueActItem(dai='inform(food=czech)') in best_hyp.da)
dacn = DialogueActConfusionNetwork()
dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))
best_hyp = dacn.get_best_da_hyp(
use_log=True, threshold=0.1, thresholds={
DialogueActItem(dai='inform(food=chinese)'): 0.5,
DialogueActItem(dai='inform(food=czech)'): 0.5,
DialogueActItem(dai='inform(food=russian)'): 0.5
})
# Test food=czech should be included.
self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.7 * 0.9))
self.assertEqual(len(best_hyp.da), 2)
self.assertTrue(DialogueActItem(dai='inform(food=czech)') in best_hyp.da)
示例15: parse_X
# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import add [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(p[0][1], dai)
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
da_confnet.add(p[0][1], self.parsed_classifiers[clser])
da_confnet.sort().merge().prune()
return da_confnet