- The "低落" (melancholic) emotion will always be mapped to "悲伤" (sad) by QwenEmotion's text analysis. It doesn't know the difference between those emotions even if the user writes the exact words.
- Since the words and their meanings are so similar, it might not be possible to train QwenEmotion to learn the difference.
- As a workaround, we perform input text analysis and look for words that mean "melancholic", and swap the "sad" detection result, to make the melancholic/low-energy speech emotion work correctly for users via text-to-emotion.
- The new algorithm is now very fast and uses less memory, since it doesn't chain multiple `.replace()` calls or create a bunch of temporary strings and temporary dictionaries and lists anymore.
- Parses the JSON output from the QwenEmotion model directly instead of trying to manually parse it. If JSON parsing fails, it falls back to a fast and highly-accurate RegEx search which finds all key-value pairs.
- The desired emotion vector order is now stored as a static class attribute instead of being created from scratch on every call.
- The emotion dictionary creation has been completely rewritten to use a clear algorithm which takes the QwenEmotion answers, builds a new dictionary using `self.desired_vector_order`, maps each key's name to their English translations, fetches the values from QwenEmotion's answers or 0.0 if no value was given by QE, and clamps the values to the min/max ranges.
- The `backup_dict` is now removed, since it was error-prone and fragile. It could grow out of sync with the code if not carefully maintained to keep the correct order and labels.
- To handle the "fallback" dictionary creation, we now automatically scan the final emotion vectors, and if none of them are above 0.0 (meaning we didn't detect any emotions in the input text), we give the final vectors a "calm: 1.0" value. This means that we never have to worry about the fallback dictionary's correctness.
- The previous algorithm had multiple bugs. This rewrite fixes a serious vector order bug: The old algorithm built the dictionary via the found keys, and only checked if there's 8 keys in QwenEmotion's response, but it didn't check that the keys were valid. When building the final emotion dict, it skipped any values if they were not found in QE's response. Meaning that if the QE response only contained 4 of the 8 expected emotion vector labels, those would all be added at the start of the new dictionary as the "first 4 dict slots". After that, it looped through the "backup_dict" and appended any missing values at the end. This resulted in a final emotion dictionary with the wrong order for the emotion vectors. The new code always produces the correct emotion vector order.
- Discovered another bug in the text-to-emotion handling for the "melancholic" emotion, which has never worked for Chinese or English at all. It will be fixed in an upcoming patch.
- The order of the `convert_dict` now matches the desired order of the emotion vectors, for clarity.
- Internal text labels now match the updated English translations.
- This (and the previous commit) also fixes a bug: The previous, inaccurate Emotion translations meant that QwenEmotion could not understand words such as "low" at all (no emotion mapping), and it always mapped "hate" to "angry". With the fixed translations, QwenEmotion now correctly maps text-to-emotions from English inputs when users input the words that they've been taught by the user interface.
- Introduced `de_tokenized_by_CJK_char` for restoring original text from tokenized format.
- Added `TextTokenizer` class for improved tokenization, including sentence splitting and handling of special tokens.
- Enhanced `TextNormalizer` to handle names and pinyin tones with placeholder mechanisms.
- Added regression tests for new features in `regression_test.py`.
* Update Pinyin tone handling in TextNormalizer
* Enhance sentence splitting and improve tokenizer integration in inference
* Update character replacement mappings
test: "在电影《肖申克的救赎》中,安迪·杜佛兰被错误地判处终身监禁..."
* Refactor TextNormalizer and enhance testing with additional cases