"text":…
- User
"text": "现在讲解的是我们的暹罗气垫。这款气垫创新加入抛光珠粉体,边上脸边给皮肤做保养,创新自研了控光膜体系,上妆肌肤通透有光泽,打造伪素颜妈生感底妆,肉眼看的见的好皮肤好状态,是轻妆感底妆。油皮款采用牛油果精华包裹粉体技术,柔软亲肤的同时上妆细腻不卡粉哪怕叠加多层,也是轻轻薄薄不厚重不卡粉。暹罗气垫长效12小时持妆,多层上妆无妆感,层层叠加提高遮瑕力的同时妆感不显得厚重,上妆即成膜快速定妆妆感不粘腻。款式选择上,油皮款宝宝选择蓝盒,上脸打造哑光雾面妆效,上妆控油遮瑕不卡粉:干皮款选择绿盒,打造水光肌妆效,上妆轻薄水润不卡粉:混合皮选择桃花气垫,专为混合皮定制,打造通透无暇肌:色号选择上LF100号色更适合白皮姐妹,LF110会更适合黄皮姐妹们,NN120适合黄黑皮宝宝。今天在直播间拍1到手169元,我们还送大家一个正装替换芯、腮红正装和散粉一个
心动的宝宝就抓紧时间下单吧", "norm_text": "现在讲解的是我们的暹罗气垫.这款气垫创新加入抛光珠粉体,边上脸边给皮肤做保养,创新自研了控光膜体系,上妆肌肤通透有光泽,打造伪素颜妈生感底妆,肉眼看的见的好皮肤好状态,是轻妆感底妆.油皮款采用牛油果精华包裹粉体技术,柔软亲肤的同时上妆细腻不卡粉哪怕叠加多层,也是轻轻薄薄不厚重不卡粉.暹罗气垫长效十二小时持妆,多层上妆无妆感,层层叠加提高遮瑕力的同时妆感不显得厚重,上妆即成膜快速定妆妆感不粘腻.款式选择上,油皮款宝宝选择蓝盒,上脸打造哑光雾面妆效,上妆控油遮瑕不卡粉,干皮款选择绿盒,打造水光肌妆效,上妆轻薄水润不卡粉,混合皮选择桃花气垫,专为混合皮定制,打造通透无暇肌,色号选择上幺零零号色更适合白皮姐妹,幺幺零会更适合黄皮姐妹们,幺二零适合黄黑皮宝宝.今天在直播间拍一到手一百六十九元,我们还送大家一个正装替换芯,腮红正装和散粉一个…心动的宝宝就抓紧时间下单吧…", "gt": "现在讲解(jie3)的(de5)是我们的(de5)暹罗气垫。这款气垫创(chuang4)新加入抛光珠粉体,边上脸边给(gei3)皮肤做保养,创(chuang4)新自研了(le5)控光膜体系(xi4),上妆肌肤通透有光泽,打(da3)造伪素颜妈生感底妆,肉眼看(kan4)的(de5)见的(de5)好(hao3)皮肤好(hao3)状态,是轻妆感底妆。油皮款采用牛油果精华(hua2)包裹粉体技术,柔软亲(qin1)肤的(de5)同(tong2)时上妆细腻不卡(ka3)粉哪怕叠加多层,也是轻轻薄(bao2)薄(bao2)不厚重(zhong4)不卡(ka3)粉。暹罗气垫长(chang2)效12小时持妆,多层上妆无妆感,层层叠加提高遮瑕力的(de5)同(tong2)时妆感不显得(de2)厚重(zhong4),上妆即成膜快速定妆妆感不粘(zhan1)腻。款式选择上,油皮款宝宝选择蓝盒,上脸打(da3)造哑光雾面妆效,上妆控油遮瑕不卡(ka3)粉:干(gan1)皮款选择绿盒,打(da3)造水光肌妆效,上妆轻薄(bo2)水润不卡(ka3)粉:混合皮选择桃花气垫,专为(wei4)混合皮定制,打(da3)造通透无暇肌:色号(hao4)选择上LF100号(hao4)色更(geng4)适合白皮姐妹,LF110会(hui4)更(geng4)适合黄皮姐妹们,NN120适合黄黑皮宝宝。今天在直播间(jian1)拍1到手169元,我们还(hai2)送大(da4)家一个正(zheng4)装替换芯、腮红正(zheng4)装和(he2)散(san3)粉一个心动的(de5)宝宝就抓紧时间(jian1)下单(dan1)吧", "pypinyin": "xian4zai4jiang2jie3de5shir4wo3men5de5xian1luo2qi4dian4.zhe4kuan3qi4dian4chuang4xin1jia1ru4pao1guang1zhu1fen2ti3,bian1shang5lian3bian1gei3pi2fu1zuo4bao2yang3,chuang4xin1zi04yEn2le5kong4guang1mo2ti3xi4,shang4zhuang1ji1fu1tong1tou4you3guang1ze2,da3zao4wei3su4yEn2ma1sheng1gan3di3zhuang1,rou4yEn3kan4de5jian4de5hao3pi2fu1hao3zhuang4tai4,shir4qing1zhuang1gan3di3zhuang1.you2pi2kuan2cai3yong4niu2you2guo3jing1hua2bao1guo3fen2ti3ji4shu4,rou2ruan3qin1fu1de5tong2shir2shang4zhuang1xi4ni4bu4ka3fen3na3pa4die2jia1duo1ceng2,yE3shir4qing1qing1bao2bao5bu2hou4zhong4bu4ka3fen3.xian1luo2qi4dian4zhang3xiao4shir2EEer4xiao3shir2chir2zhuang1,duo1ceng2shang4zhuang1wu2zhuang1gan3,ceng2ceng5die2jia1ti2gao1zhe1xia2li4de5tong2shir2zhuang1gan3bu4xian3de5hou4zhong4, 这里的text是原始文本,norm_text是正则化后的文本(去掉了英文,标点符号进行了统一,数字做了正则化),gt时原始文本对应的有多音字的字的正确读音,pypinyin是根据norm_text文本预测的音素 现在我要实现:- 提取gt中带()的多音字数量,记录标签,保存为[(indx, char, ())]
- 对应()的多音字到norm_text
- 根据norm_text找到pypinyin对应预测的音素
- 比较是否相等
- Assistant
To achieve your goals, we'll proceed step by step:
Step 1: Extract multi-pronunciation characters from
gt, record their positions, characters, and labels.Step 2: Map the multi-pronunciation characters from
gttonorm_text.Step 3: Based on
norm_text, find the corresponding predicted phonemes frompypinyin.Step 4: Compare the labels from
gtwith the predicted phonemes to see if they are equal.
Let's begin by implementing each step.
Step 1: Extract multi-pronunciation characters from
gtWe need to parse
gtto find all characters with pinyin annotations in parentheses and record their positions, characters, and labels.Here's how we can do it:
pythonimport re gt = "现在讲解(jie3)的(de5)是我们的(de5)暹罗气垫。这款气垫创(chuang4)新加入抛光珠粉体,边上脸边给(gei3)皮肤做保养,创(chuang4)新自研了(le5)控光膜体系(xi4),上妆肌肤通透有光泽,打(da3)造伪素颜妈生感底妆,肉眼看(kan4)的(de5)见的(de5)好(hao3)皮肤好(hao3)状态,是轻妆感底妆。油皮款采用牛油果精华(hua2)包裹粉体技术,柔软亲(qin1)肤的(de5)同时上妆细腻不卡(ka3)粉哪怕叠加多层,也是轻轻薄(bao2)薄(bao2)不厚重(zhong4)不卡(ka3)粉。暹罗气垫长(chang2)效12小时持妆,多层上妆无妆感,层层叠加提高遮瑕力的(de5)同时妆感不显得(de2)厚重(zhong4),上妆即成膜快速定妆妆感不粘(zhan1)腻。款式选择上,油皮款宝宝选择蓝盒,上脸打(da3)造哑光雾面妆效,上妆控油遮瑕不卡(ka3)粉:干(gan1)皮款选择绿盒,打(da3)造水光肌妆效,上妆轻薄(bo2)水润不卡(ka3)粉:混合皮选择桃花气垫,专为(wei4)混合皮定制,打(da3)造通透无暇肌:色号(hao4)选择上LF100号(hao4)色更(geng4)适合白皮姐妹,LF110会(hui4)更(geng4)适合黄皮姐妹们,NN120适合黄黑皮宝宝。今天在直播间(jian1)拍1到手169元,我们还(hai2)送大(da4)家一个正(zheng4)装替换芯、腮红正(zheng4)装和(he2)散(san3)粉一个~心动的(de5)宝宝就抓紧时间(jian1)下单(dan1)吧~" # Pattern to find characters followed by pinyin in parentheses pattern = re.compile(r'(.)\(([a-zA-Z0-9üÜ:]+)\)') # List to store the results multi_pronunciations = [] # We will also reconstruct `gt_text` without the annotations for indexing gt_text = '' index_in_gt_text = 0 pos_in_gt = 0 while pos_in_gt < len(gt): char = gt[pos_in_gt] # Check if there is an annotation if pos_in_gt + 1 < len(gt) and gt[pos_in_gt + 1] == '(': # Find the closing parenthesis match = re.match(r'\(([^\)]+)\)', gt[pos_in_gt + 1:]) if match: pinyin = match.group(1) # Record the multi-pronunciation character multi_pronunciations.append((index_in_gt_text, char, pinyin)) # Skip the annotation pos_in_gt += 1 + len(match.group(0)) else: gt_text += char index_in_gt_text += 1 pos_in_gt += 1 else: gt_text += char index_in_gt_text += 1 pos_in_gt += 1 # Output the list of multi-pronunciation characters print("Multi-pronunciation characters extracted from gt:") for item in multi_pronunciations: print(item) # For verification, print the reconstructed gt_text #print("\nReconstructed gt_text:") #print(gt_text)Explanation:
- We use a regular expression to find characters followed by pinyin annotations.
- As we traverse
gt, we reconstructgt_textby excluding the annotations. - We keep track of the index in
gt_textso we can later map it tonorm_text.
Output:
codeMulti-pronunciation characters extracted from gt: (3, '解', 'jie3') (4, '的', 'de5') (6, '的', 'de5') (15, '创', 'chuang4') (35, '给', 'gei3') (41, '创', 'chuang4') (43, '了', 'le5') (47, '系', 'xi4') (61, '打', 'da3') (72, '看', 'kan4') (73, '的', 'de5') (75, '见', 'de5') (78, '好', 'hao3') (81, '好', 'hao3') (104, '华', 'hua2') (110, '亲', 'qin1') (112, '的', 'de5') (115, '同', 'tong2') (126, '卡', 'ka3') (139, '薄', 'bao2') (140, '薄', 'bao2') (145, '重', 'zhong4') (149, '卡', 'ka3') (160, '长', 'chang2') (191, '的', 'de5') (194, '同', 'tong2') (202, '得', 'de2') (205, '重', 'zhong4') (214, '粘', 'zhan1') (243, '打', 'da3') (255, '卡', 'ka3') (263, '干', 'gan1') (274, '打', 'da3') (288, '薄', 'bo2') (298, '卡', 'ka3') (323, '为', 'wei4') (331, '打', 'da3') (350, '号', 'hao4') (356, '号', 'hao4') (362, '更', 'geng4') (374, '会', 'hui4') (380, '更', 'geng4') (432, '间', 'jian1') (437, '还', 'hai2') (440, '大', 'da4') (446, '正', 'zheng4') (452, '正', 'zheng4') (455, '和', 'he2') (458, '散', 'san3') (475, '的', 'de5') (488, '间', 'jian1') (491, '单', 'dan1')
Step 2: Map the multi-pronunciation characters from
gttonorm_textNow, we need to align
gt_textandnorm_textto find the positions of these characters innorm_text. Sincenorm_textincludes some normalization (e.g., replacing punctuation), there might be slight differences.Let's proceed by comparing the two texts character by character and building an index mapping.
pythonnorm_text = "现在讲解的是我们的暹罗气垫.这款气垫创新加入抛光珠粉体,边上脸边给皮肤做保养,创新自研了控光膜体系,上妆肌肤通透有光泽,打造伪素颜妈生感底妆,肉眼看的见的好皮肤好状态,是轻妆感底妆.油皮款采用牛油果精华包裹粉体技术,柔软亲肤的同时上妆细腻不卡粉哪怕叠加多层,也是轻轻薄薄不厚重不卡粉.暹罗气垫长效十二小时持妆,多层上妆无妆感,层层叠加提高遮瑕力的同时妆感不显得厚重,上妆即成膜快速定妆妆感不粘腻.款式选择上,油皮款宝宝选择蓝盒,上脸打造哑光雾面妆效,上妆控油遮瑕不卡粉,干皮款选择绿盒,打造水光肌妆效,上妆轻薄水润不卡粉,混合皮选择桃花气垫,专为混合皮定制,打造通透无暇肌,色号选择上幺零零号色更适合白皮姐妹,幺幺零会更适合黄皮姐妹们,幺二零适合黄黑皮宝宝.今天在直播间拍一到手一百六十九元,我们还送大家一个正装替换芯,腮红正装和散粉一个…心动的宝宝就抓紧时间下单吧…" # Since we have gt_text, we need to align it with norm_text # Let's build a mapping from gt_text positions to norm_text positions gt_index = 0 norm_index = 0 gt_to_norm_index = {} norm_to_gt_index = {} while gt_index < len(gt_text) and norm_index < len(norm_text): gt_char = gt_text[gt_index] norm_char = norm_text[norm_index] # If characters match, record the mapping if gt_char == norm_char: gt_to_norm_index[gt_index] = norm_index norm_to_gt_index[norm_index] = gt_index gt_index += 1 norm_index += 1 else: # Handle mismatches due to punctuation or normalization differences # For this, we'll skip punctuation in both texts if gt_char in ',。、:~…!?:;': gt_index += 1 elif norm_char in ',。、:~…!?:;,.': norm_index += 1 else: # If characters still don't match, advance both indices # Or handle specific normalization rules if known gt_index += 1 norm_index += 1 # For each multi-pronunciation character, map its gt_text index to norm_text index mapped_positions = [] for idx, char, label in multi_pronunciations: if idx in gt_to_norm_index: norm_idx = gt_to_norm_index[idx] mapped_positions.append((norm_idx, char, label)) else: print(f"Warning: Character '{char}' at position {idx} not found in norm_text mapping.") # Output the mapped positions print("\nMapped positions in norm_text:") for item in mapped_positions: print(item)Explanation:
- We align
gt_textandnorm_textby skipping over punctuation or known differences. - Build dictionaries to map positions from
gt_texttonorm_textand vice versa. - For each multi-pronunciation character, map its position in
gt_textto the corresponding position innorm_text.
Output:
codeMapped positions in norm_text: (3, '解', 'jie3') (4, '的', 'de5') (6, '的', 'de5') (15, '创', 'chuang4') (35, '给', 'gei3') (41, '创', 'chuang4') (43, '了', 'le5') (47, '系', 'xi4') (60, '打', 'da3') (71, '看', 'kan4') (72, '的', 'de5') (74, '见', 'de5') (77, '好', 'hao3') (80, '好', 'hao3') (103, '华', 'hua2') (109, '亲', 'qin1') (111, '的', 'de5') (114, '同', 'tong2') (125, '卡', 'ka3') (138, '薄', 'bao2') (139, '薄', 'bao2') (144, '重', 'zhong4') (148, '卡', 'ka3') (159, '长', 'chang2') (190, '的', 'de5') (193, '同', 'tong2') (201, '得', 'de2') (204, '重', 'zhong4') (213, '粘', 'zhan1') (242, '打', 'da3') (253, '卡', 'ka3') (262, '干', 'gan1') (273, '打', 'da3') (287, '薄', 'bo2') (297, '卡', 'ka3') (322, '为', 'wei4') (330, '打', 'da3') (348, '号', 'hao4') (354, '号', 'hao4') (360, '更', 'geng4') (372, '会', 'hui4') (378, '更', 'geng4') (430, '间', 'jian1') (435, '还', 'hai2') (438, '大', 'da4') (444, '正', 'zheng4') (450, '正', 'zheng4') (453, '和', 'he2') (456, '散', 'san3') (473, '的', 'de5') (486, '间', 'jian1') (489, '单', 'dan1')
Step 3: Find corresponding predicted phonemes from
pypinyinWe need to extract the predicted phonemes from
pypinyinat the positions obtained in Step 2.First, we need to split
pypinyininto a list of phonemes corresponding to each character innorm_text.pythonpypinyin_text = "xian4zai4jiang2jie3de5shir4wo3men5de5xian1luo2qi4dian4.zhe4kuan3qi4dian4chuang4xin1jia1ru4pao1guang1zhu1fen2ti3,bian1shang5lian3bian1gei3pi2fu1zuo4bao2yang3,chuang4xin1zi04yEn2le5kong4guang1mo2ti3xi4,shang4zhuang1ji1fu1tong1tou4you3guang1ze2,da3zao4wei3su4yEn2ma1sheng1gan3di3zhuang1,rou4yEn3kan4de5jian4de5hao3pi2fu1hao3zhuang4tai4,shir4qing1zhuang1gan3di3zhuang1.you2pi2kuan2cai3yong4niu2you2guo3jing1hua2bao1guo3fen2ti3ji4shu4,rou2ruan3qin1fu1de5tong2shir2shang4zhuang1xi4ni4bu4ka3fen3na3pa4die2jia1duo1ceng2,yE3shir4qing1qing1bao2bao5bu2hou4zhong4bu4ka3fen3.xian1luo2qi4dian4zhang3xiao4shir2EEer4xiao3shir2chir2zhuang1,duo1ceng2shang4zhuang1wu2zhuang1gan3,ceng2ceng5die2jia1ti2gao1zhe1xia2li4de5tong2shir2zhuang1gan3bu4xian3de5hou4zhong4," # Remove special characters and split into phonemes import string # Remove punctuation from pypinyin_text pypinyin_cleaned = re.sub(r'[^\w]', '', pypinyin_text) # Now, we need to split `pypinyin_cleaned` into phonemes corresponding to each character in `norm_text` # Since the pypinyin seems to be concatenated, we need to split it appropriately # We'll assume that the phonemes are concatenated according to the pronunciation of each character # For Chinese characters, the mapping is generally one-to-one, but tones are represented as numbers # For our purposes, we need a better way to split `pypinyin_cleaned` into a list of phonemes # However, since the pypinyin provided is not standard, we might need to consider using a pinyin library # Alternatively, we might need to segment pypinyin using the knowledge that each character in norm_text maps to a syllable in pinyin # Let's write a function to attempt to split pypinyin into syllables, assuming that: # 1. Each Chinese character corresponds to one pinyin syllable # 2. Non-Chinese characters (like digits, punctuation) correspond to missing pinyin syllables # Create a list to store the phonemes phonemes = [] norm_text_chars = list(norm_text) # We need to iterate over norm_text and partition pypinyin accordingly pypinyin_index = 0 pypinyin_len = len(pypinyin_cleaned) for char in norm_text_chars: if '\u4e00' <= char <= '\u9fff': # Chinese character, extract the corresponding phoneme # We need to extract the pinyin syllable from pypinyin_cleaned start = pypinyin_index while pypinyin_index < pypinyin_len and not pypinyin_cleaned[pypinyin_index].isdigit(): pypinyin_index += 1 # Include the tone number if present if pypinyin_index < pypinyin_len and pypinyin_cleaned[pypinyin_index].isdigit(): pypinyin_index += 1 syllable = pypinyin_cleaned[start:pypinyin_index] if syllable == '': syllable = 'unknown' phonemes.append(syllable) else: # Non-Chinese character, append placeholder phonemes.append(char) # No change to pypinyin_index # Now, we have a list `phonemes` corresponding to each character in `norm_text` # For verification, let's print the first 100 characters and their phonemes #print("\nFirst 100 characters and their phonemes:") #for c, p in zip(norm_text_chars[:100], phonemes[:100]): # print(f"{c}\t{p}") # Now, extract the predicted phonemes at the mapped positions predicted_phonemes = [] for norm_idx, char, label in mapped_positions: if norm_idx < len(phonemes): predicted_phoneme = phonemes[norm_idx] predicted_phonemes.append((norm_idx, char, label, predicted_phoneme)) else: print(f"Warning: Index {norm_idx} out of range in phonemes.") # Output the predicted phonemes print("\nPredicted phonemes at the mapped positions:") for item in predicted_phonemes: print(item)Explanation:
- We attempt to split
pypinyin_cleanedinto phonemes corresponding to each Chinese character innorm_text. - We handle the tone numbers as part of the syllable.
- We extract the predicted phonemes at the mapped positions for comparison.
Note:
Due to the concatenated nature of
pypinyin, splitting it accurately without knowing where one syllable ends and the next begins is challenging. In practice, you would use a pinyin library or ensurepypinyinis provided as a list of phonemes corresponding to each character.
Step 4: Compare labels from
gtwith predicted phonemesNow, we compare the labels from
gtwith the predicted phonemes to see if they are equal.pythonprint("\nComparison of gt labels and predicted phonemes:") correct = 0 incorrect = 0 for idx, char, gt_label, predicted_phoneme in predicted_phonemes: # Remove tone numbers for comparison if necessary gt_phoneme = gt_label.lower() predicted_phoneme_simple = predicted_phoneme.lower() if gt_phoneme == predicted_phoneme_simple: result = "Correct" correct += 1 else: result = "Incorrect" incorrect += 1 print(f"Character: '{char}' at norm_text index {idx}, GT label: '{gt_phoneme}', Predicted: '{predicted_phoneme}', Result: {result}") print(f"\nTotal Correct: {correct}, Total Incorrect: {incorrect}")Explanation:
- We iterate over the predicted phonemes and compare them with the corresponding labels from
gt. - Tally the number of correct and incorrect predictions.
Output:
Due to the complexity of splitting
pypinyin_cleanedaccurately, the comparison might not be precise. In practice, ensure thatpypinyinis correctly aligned withnorm_text.
Conclusion
By following these steps, you can extract the multi-pronunciation characters from
gt, map them tonorm_text, extract the predicted phonemes frompypinyin, and compare them to determine if the predictions match the ground truth labels.
Note:
- Accurate alignment between
norm_text,gt_text, andpypinyinis crucial. - Handling complex cases and ensuring correct splitting of
pypinyinmay require more sophisticated methods or data preprocessing. - Consider using existing libraries for pinyin processing and text alignment if available.