当前位置: 首页>>代码示例>>Python>>正文


Python SR.get_templates_and_inputs方法代码示例

本文整理汇总了Python中SR.get_templates_and_inputs方法的典型用法代码示例。如果您正苦于以下问题:Python SR.get_templates_and_inputs方法的具体用法?Python SR.get_templates_and_inputs怎么用?Python SR.get_templates_and_inputs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SR的用法示例。


在下文中一共展示了SR.get_templates_and_inputs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_transform_relationship_FSM_table

# 需要导入模块: import SR [as 别名]
# 或者: from SR import get_templates_and_inputs [as 别名]
def get_transform_relationship_FSM_table(filename, states_in_each_word=5, using_continuous_feature=0, **kwargs):
    """
    从有限状态机中获取模板,状态转移列表,起始状态,每个nonemitting state所对应的emitting state 在模板中连续
    :param filename: 有限状态机文件名
    :param states_in_each_word: 每个单词有多少states组成
    :param kwargs:
    :return: template,states的模板
             transform_list,第i个元素为列表,代表第i个state可以从哪些states进入
             begin_list,t=0时可进入的states
             word_in_template,第i个表示template中第i个元素代表的word
    """
    start_states, terminal_states, nonemitting_transform_list = get_info_FSM_table(filename)
    number_of_nonemitting_states = len(nonemitting_transform_list)
    template = []
    digit_template = []  # 第i个值表示数字i的template
    number_of_frames_in_each_state = []  # 第i个元素代表state i的frame数
    number_of_frames_in_each_state_for_digit = []  # 第i个元素代表数字i中每个state拥有的frame数量
    covariance_matrix_in_each_state = []
    mean_in_each_state = []
    covariance_matrix_for_each_digit = []
    mean_for_each_digit = []
    word_in_template = []  # 第i个表示template中第i个元素代表的word
    if using_continuous_feature:
        digit_template = SR.get_digit_feature_from_continuous_speech()
    for digit in xrange(0, 10):
        temp = SR.get_templates_and_inputs(digit, number_of_templates=10)
        if not using_continuous_feature:
            result = kmeans.k_means(temp[0], number_of_states=5)
            digit_template.extend(result[0])
            covariance_matrix_for_each_digit.append(result[2])
            mean_for_each_digit.append(result[3])
            temp_number_of_frames_in_each_state = [0 for i in xrange(states_in_each_word)]
            for number_of_frames_in_each_state_in_each_template in result[5]:
                for i in xrange(states_in_each_word):
                    temp_number_of_frames_in_each_state[i] += number_of_frames_in_each_state_in_each_template[i]
            number_of_frames_in_each_state_for_digit.append(temp_number_of_frames_in_each_state)
    # print number_of_frames_in_each_state
    # 获取number_of_emitting_states_begin_from_nonemitting_states
    number_of_emitting_states_begin_from_nonemitting_states = []  # 第i个元素表示源于第i个nonemitting_state的edge包含的states个数
    for nonemitting_state in nonemitting_transform_list:
        # nonemitting_state形如{1: [2, 3, 4, 5, 6, 7, 8, 9], 3: []}
        temp = []
        for edge_list in nonemitting_state.values():
            temp.extend(edge_list)
        for i in temp:
            # 获取template
            covariance_matrix_in_each_state.extend(covariance_matrix_for_each_digit[i])
            mean_in_each_state.extend(mean_for_each_digit[i])
            number_of_frames_in_each_state.extend(number_of_frames_in_each_state_for_digit[i])
            template.extend(digit_template[i])
            word_in_template.append(i)
        number_of_emitting_states = len(set(temp))
        number_of_emitting_states_begin_from_nonemitting_states.append(number_of_emitting_states)
    # 获取begin_states_index_for_each_nonemitting_state
    begin_states_index_for_each_nonemitting_state = []  # 第i个元素表示源于第i个nonemitting_state的edge包含的states之前有多少states
    for i in xrange(number_of_nonemitting_states):
        begin_states_index_for_each_nonemitting_state.append(
            sum(number_of_emitting_states_begin_from_nonemitting_states[:i]))
    # 获取emitting_out_list,第i个元素为一个列表,代表第i个nonemitting state可以进入的states
    emitting_out_list = [[] for i in xrange(number_of_nonemitting_states)]
    for i, nonemitting_state in enumerate(nonemitting_transform_list):
        # nonemitting_state形如{1: [2, 3, 4, 5, 6, 7, 8, 9], 3: []}
        begin_index = begin_states_index_for_each_nonemitting_state[i]
        number_of_edges = sum(map(len, nonemitting_state.values()))
        for j in xrange(number_of_edges):
            emitting_out_list[i].append(states_in_each_word * (begin_index + j))
    changed = True
    # 考虑无条件跳转的情况
    while changed:
        new_emitting_out_list = emitting_out_list[:]
        for i, nonemitting_state in enumerate(nonemitting_transform_list):
            for key in nonemitting_state.keys():
                if nonemitting_state[key] == []:
                    new_emitting_out_list[i].extend(new_emitting_out_list[key])
        changed = (new_emitting_out_list != emitting_out_list)
    emitting_out_list = new_emitting_out_list
    # 获取emitting_in_list,第i个元素为一个列表,代表第i个nonemitting state可以由哪些states进入
    emitting_in_list = [[] for i in xrange(number_of_nonemitting_states)]
    for i, nonemitting_state in enumerate(nonemitting_transform_list):
        # nonemitting_state形如{1: [2, 3, 4, 5, 6, 7, 8, 9], 3: []}
        begin_index = begin_states_index_for_each_nonemitting_state[i]
        j = 0
        for key in nonemitting_state.keys():
            for value in nonemitting_state[key]:
                emitting_in_list[key].append(states_in_each_word * (begin_index + j))
                j += 1
    changed = True
    # 考虑无条件跳转的情况
    while changed:
        new_emitting_in_list = emitting_in_list[:]
        for i, nonemitting_state in enumerate(nonemitting_transform_list):
            for key in nonemitting_state.keys():
                if nonemitting_state[key] == []:
                    new_emitting_in_list[key].extend(new_emitting_in_list[i])
        changed = (new_emitting_in_list != emitting_in_list)
    emitting_in_list = new_emitting_in_list
    # 计算transform_list,每个元素为一个列表,表示可以进入这个state的states
    transform_list = [[] for i in
                      xrange(sum(number_of_emitting_states_begin_from_nonemitting_states) * states_in_each_word)]
    for i in xrange(number_of_nonemitting_states):
#.........这里部分代码省略.........
开发者ID:awesome-archive,项目名称:SpeechRecognitionSystem,代码行数:103,代码来源:continuous_speech_recognition_using_FSM.py


注:本文中的SR.get_templates_and_inputs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。