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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
repo_id = "humanify/ARAG_embedding_pretrain"
|
| 5 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
|
| 8 |
+
model = AutoModel.from_pretrained(
|
| 9 |
+
repo_id,
|
| 10 |
+
trust_remote_code=True,
|
| 11 |
+
torch_dtype=torch.float32,
|
| 12 |
+
).to(device).eval()
|
| 13 |
+
model.set_tokenizer(tokenizer)
|
| 14 |
+
|
| 15 |
+
QUERY_INSTRUCTION = "Based on the question asked in the text query and context in the audio query, retrieve the relevant text document associated with that question."
|
| 16 |
+
DOC_INSTRUCTION = "Represent the user's input."
|
| 17 |
+
|
| 18 |
+
# case 1
|
| 19 |
+
# expect [0-1match, 2-3match]
|
| 20 |
+
# 模型正确区分出性别
|
| 21 |
+
# tensor([[0.5530, 0.4304],
|
| 22 |
+
# [0.6178, 0.4669],
|
| 23 |
+
# [0.3870, 0.6268],
|
| 24 |
+
# [0.4139, 0.6821]], device='cuda:0')
|
| 25 |
+
# tensor([[1.0000, 0.8968, 0.7887, 0.7221],
|
| 26 |
+
# [0.8968, 1.0000, 0.7567, 0.7600],
|
| 27 |
+
# [0.7887, 0.7567, 1.0000, 0.9216],
|
| 28 |
+
# [0.7221, 0.7600, 0.9216, 1.0000]], device='cuda:0')
|
| 29 |
+
# query_text = [
|
| 30 |
+
# "What is the gender of speaker in this audio?",
|
| 31 |
+
# "What is the gender of speaker in this audio?",
|
| 32 |
+
# "What is the gender of speaker in this audio?",
|
| 33 |
+
# "What is the gender of speaker in this audio?",
|
| 34 |
+
# ]
|
| 35 |
+
# query_audio = ["./samples/en_male_music.wav", "./samples/en_male.wav",
|
| 36 |
+
# "./samples/en_female_music.wav", "./samples/en_female.wav"]
|
| 37 |
+
|
| 38 |
+
# case 2
|
| 39 |
+
# expect [0-2match, 1-3match]
|
| 40 |
+
# 测试显示模型是可以区分出是否有背景音乐的
|
| 41 |
+
# tensor([[0.4247, 0.1398],
|
| 42 |
+
# [0.2891, 0.1501],
|
| 43 |
+
# [0.2446, 0.3100],
|
| 44 |
+
# [0.2502, 0.3032]], device='cuda:0')
|
| 45 |
+
# tensor([[1.0000, 0.7550, 0.6976, 0.6746],
|
| 46 |
+
# [0.7550, 1.0000, 0.7014, 0.6887],
|
| 47 |
+
# [0.6976, 0.7014, 1.0000, 0.8886],
|
| 48 |
+
# [0.6746, 0.6887, 0.8886, 1.0000]], device='cuda:0')
|
| 49 |
+
# query_text = [
|
| 50 |
+
# "Describe the background noise of this audio?",
|
| 51 |
+
# "Describe the background noise of this audio?",
|
| 52 |
+
# "Describe the background noise of this audio?",
|
| 53 |
+
# "Describe the background noise of this audio?",
|
| 54 |
+
# ]
|
| 55 |
+
# query_audio = ["./samples/en_male_music.wav", "./samples/en_female_music.wav",
|
| 56 |
+
# "./samples/en_male.wav", "./samples/en_female.wav"]
|
| 57 |
+
|
| 58 |
+
# case 3
|
| 59 |
+
# expect [0-2match, 1-3match]
|
| 60 |
+
# 模型具有quality分辨能力
|
| 61 |
+
# tensor([[0.4325, 0.3912],
|
| 62 |
+
# [0.4801, 0.4459],
|
| 63 |
+
# [0.4836, 0.4986],
|
| 64 |
+
# [0.4723, 0.4741]], device='cuda:0')
|
| 65 |
+
# tensor([[1.0000, 0.9511, 0.9240, 0.8633],
|
| 66 |
+
# [0.9511, 1.0000, 0.9416, 0.8835],
|
| 67 |
+
# [0.9240, 0.9416, 1.0000, 0.9293],
|
| 68 |
+
# [0.8633, 0.8835, 0.9293, 1.0000]], device='cuda:0')
|
| 69 |
+
# query_text = [
|
| 70 |
+
# "Describe the quality of the audio.",
|
| 71 |
+
# "Describe the quality of the audio.",
|
| 72 |
+
# "Describe the quality of the audio.",
|
| 73 |
+
# "Describe the quality of the audio.",
|
| 74 |
+
# ]
|
| 75 |
+
# query_audio = ["./samples/en_male_music.wav", "./samples/en_male.wav",
|
| 76 |
+
# "./samples/en_female_music.wav", "./samples/en_female.wav"]
|
| 77 |
+
|
| 78 |
+
# case 4-1
|
| 79 |
+
# expect [1-3match]
|
| 80 |
+
# query_text = [
|
| 81 |
+
# "Describe the speech content and topic.",
|
| 82 |
+
# "Describe the speech content and topic.",
|
| 83 |
+
# "Describe the speech content and topic.",
|
| 84 |
+
# "Describe the speech content and topic.",
|
| 85 |
+
# ]
|
| 86 |
+
|
| 87 |
+
# query_audio = ["./samples/en_male_sunny.wav", "./samples/en_male.wav",
|
| 88 |
+
# "./samples/en_female_sunny.wav", "./samples/en_female.wav"]
|
| 89 |
+
|
| 90 |
+
# case 4-2
|
| 91 |
+
# expect [1-3match]
|
| 92 |
+
# 模型可以正确区分出来音频中是否包含某个单词
|
| 93 |
+
# tensor([[0.7353, 0.4429],
|
| 94 |
+
# [0.7130, 0.4250],
|
| 95 |
+
# [0.5905, 0.6196],
|
| 96 |
+
# [0.5303, 0.7002]], device='cuda:0')
|
| 97 |
+
# tensor([[1.0000, 0.9781, 0.8920, 0.7941],
|
| 98 |
+
# [0.9781, 1.0000, 0.9070, 0.8146],
|
| 99 |
+
# [0.8920, 0.9070, 1.0000, 0.9668],
|
| 100 |
+
# [0.7941, 0.8146, 0.9668, 1.0000]], device='cuda:0')
|
| 101 |
+
# query_text = [
|
| 102 |
+
# "Does the speaker mention the word 'sunny' in the audio?",
|
| 103 |
+
# "Does the speaker mention the word 'sunny' in the audio?",
|
| 104 |
+
# "Does the speaker mention the word 'sunny' in the audio?",
|
| 105 |
+
# "Does the speaker mention the word 'sunny' in the audio?",
|
| 106 |
+
# ]
|
| 107 |
+
|
| 108 |
+
# query_audio = ["./samples/en_male_sunny.wav", "./samples/en_female_sunny.wav",
|
| 109 |
+
# "./samples/en_male.wav", "./samples/en_female.wav"]
|
| 110 |
+
|
| 111 |
+
# case 5
|
| 112 |
+
# expect [0-1 match]
|
| 113 |
+
# 模型具备区分动物叫声的能力,结果显示如下:
|
| 114 |
+
# tensor([[0.7022, 0.4406, 0.4651],
|
| 115 |
+
# [0.7497, 0.3858, 0.4209],
|
| 116 |
+
# [0.3636, 0.4995, 0.3304],
|
| 117 |
+
# [0.4793, 0.2937, 0.7720]], device='cuda:0')
|
| 118 |
+
# tensor([[1.0000, 0.9535, 0.6508, 0.7476],
|
| 119 |
+
# [0.9535, 1.0000, 0.5688, 0.6673],
|
| 120 |
+
# [0.6508, 0.5688, 1.0000, 0.5568],
|
| 121 |
+
# [0.7476, 0.6673, 0.5568, 1.0000]], device='cuda:0')
|
| 122 |
+
# query_text = [
|
| 123 |
+
# "What type of animal is this?",
|
| 124 |
+
# "What type of animal is this?",
|
| 125 |
+
# "What type of animal is this?",
|
| 126 |
+
# "What type of animal is this?",
|
| 127 |
+
# ]
|
| 128 |
+
# query_audio = ["./samples/animal_cow_1moo.wav", "./samples/animal_cow_5moo.wav",
|
| 129 |
+
# "./samples/animal_lion.wav", "./samples/animal_rooster.wav"]
|
| 130 |
+
|
| 131 |
+
# case 6
|
| 132 |
+
# expect [0-2 match, 1-3 match]
|
| 133 |
+
# 模型能区分出中文和英文
|
| 134 |
+
# 汉语和英语
|
| 135 |
+
# 第一个矩阵结果正确,第二个矩阵有点问题
|
| 136 |
+
# tensor([[0.4100, 0.2334],
|
| 137 |
+
# [0.4451, 0.2417],
|
| 138 |
+
# [0.3379, 0.3609],
|
| 139 |
+
# [0.3997, 0.4074]], device='cuda:0')
|
| 140 |
+
# tensor([[1.0000, 0.9034, 0.8573, 0.7466],
|
| 141 |
+
# [0.9034, 1.0000, 0.7729, 0.7808],
|
| 142 |
+
# [0.8573, 0.7729, 1.0000, 0.8199],
|
| 143 |
+
# [0.7466, 0.7808, 0.8199, 1.0000]], device='cuda:0')
|
| 144 |
+
# 法语和英语,完全没有问题
|
| 145 |
+
# tensor([[0.4100, 0.3098],
|
| 146 |
+
# [0.4411, 0.3229],
|
| 147 |
+
# [0.3494, 0.4212],
|
| 148 |
+
# [0.3523, 0.4130]], device='cuda:0')
|
| 149 |
+
# tensor([[1.0000, 0.9030, 0.8696, 0.8591],
|
| 150 |
+
# [0.9030, 1.0000, 0.7874, 0.8468],
|
| 151 |
+
# [0.8696, 0.7874, 1.0000, 0.9654],
|
| 152 |
+
# [0.8591, 0.8468, 0.9654, 1.0000]], device='cuda:0')
|
| 153 |
+
# 英语和西班牙语,完全没有问题
|
| 154 |
+
# tensor([[0.4100, 0.3012],
|
| 155 |
+
# [0.4411, 0.3069],
|
| 156 |
+
# [0.3274, 0.3698],
|
| 157 |
+
# [0.3249, 0.3558]], device='cuda:0')
|
| 158 |
+
# tensor([[1.0000, 0.9030, 0.8591, 0.8590],
|
| 159 |
+
# [0.9030, 1.0000, 0.7775, 0.8208],
|
| 160 |
+
# [0.8591, 0.7775, 1.0000, 0.9739],
|
| 161 |
+
# [0.8590, 0.8208, 0.9739, 1.0000]], device='cuda:0')
|
| 162 |
+
# 法语和西班牙语,完全没有问题
|
| 163 |
+
# tensor([[0.4212, 0.2785],
|
| 164 |
+
# [0.4170, 0.2737],
|
| 165 |
+
# [0.2793, 0.3698],
|
| 166 |
+
# [0.2721, 0.3558]], device='cuda:0')
|
| 167 |
+
# tensor([[1.0000, 0.9661, 0.8730, 0.8688],
|
| 168 |
+
# [0.9661, 1.0000, 0.8493, 0.8726],
|
| 169 |
+
# [0.8730, 0.8493, 1.0000, 0.9739],
|
| 170 |
+
# [0.8688, 0.8726, 0.9739, 1.0000]], device='cuda:0')
|
| 171 |
+
# 法语和汉语,完全没问题
|
| 172 |
+
# tensor([[0.4212, 0.2278],
|
| 173 |
+
# [0.4130, 0.2353],
|
| 174 |
+
# [0.2986, 0.3609],
|
| 175 |
+
# [0.3602, 0.4074]], device='cuda:0')
|
| 176 |
+
# tensor([[1.0000, 0.9654, 0.7965, 0.6456],
|
| 177 |
+
# [0.9654, 1.0000, 0.7990, 0.7011],
|
| 178 |
+
# [0.7965, 0.7990, 1.0000, 0.8199],
|
| 179 |
+
# [0.6456, 0.7011, 0.8199, 1.0000]], device='cuda:0')
|
| 180 |
+
# 西班牙语和汉语,完全没问题
|
| 181 |
+
# tensor([[0.3698, 0.1813],
|
| 182 |
+
# [0.3558, 0.1784],
|
| 183 |
+
# [0.2814, 0.3609],
|
| 184 |
+
# [0.3257, 0.4074]], device='cuda:0')
|
| 185 |
+
# tensor([[1.0000, 0.9739, 0.7871, 0.6249],
|
| 186 |
+
# [0.9739, 1.0000, 0.7837, 0.6546],
|
| 187 |
+
# [0.7871, 0.7837, 1.0000, 0.8199],
|
| 188 |
+
# [0.6249, 0.6546, 0.8199, 1.0000]], device='cuda:0')
|
| 189 |
+
query_text = [
|
| 190 |
+
"Describe the language of the speaker.",
|
| 191 |
+
"Describe the language of the speaker.",
|
| 192 |
+
"Describe the language of the speaker.",
|
| 193 |
+
"Describe the language of the speaker."
|
| 194 |
+
]
|
| 195 |
+
query_audio = ["./samples/spanish_male.wav", "./samples/spanish_female.wav",
|
| 196 |
+
"./samples/chinese_male.wav", "./samples/zh_female.wav"]
|
| 197 |
+
|
| 198 |
+
# case 7
|
| 199 |
+
# expect [0-1 match] + [2-3 match]
|
| 200 |
+
# 测试结果显示模型不具备区分出说话者语速快慢的能力
|
| 201 |
+
# query_text = [
|
| 202 |
+
# "Describe the speaking rate of the speaker.",
|
| 203 |
+
# "Describe the speaking rate of the speaker.",
|
| 204 |
+
# "Describe the speaking rate of the speaker.",
|
| 205 |
+
# "Describe the speaking rate of the speaker."
|
| 206 |
+
# ]
|
| 207 |
+
# query_audio = ["./samples/female_fast_4.wav", "./samples/female_fast.wav",
|
| 208 |
+
# "./samples/male_slow.wav", "./samples/female_slow.wav"]
|
| 209 |
+
|
| 210 |
+
# case 8
|
| 211 |
+
# expect [0->one, 1->two]
|
| 212 |
+
# 测试结果显示模型无法区分出声音不同类别的能力
|
| 213 |
+
# query_text = [
|
| 214 |
+
# "How many distinct sound types are present in this audio?",
|
| 215 |
+
# "How many distinct sound types are present in this audio?",
|
| 216 |
+
# "How many distinct sound types are present in this audio?",
|
| 217 |
+
# "How many distinct sound types are present in this audio?"
|
| 218 |
+
# ]
|
| 219 |
+
# query_audio = [
|
| 220 |
+
# "./samples/one_type_sound.flac", "./samples/one_type_sound_2.flac",
|
| 221 |
+
# "./samples/two_type_sound.flac", "./samples/two_type_sound_2.flac",
|
| 222 |
+
# ]
|
| 223 |
+
|
| 224 |
+
# case 9
|
| 225 |
+
# expect [0-1 match] + [2-3 match]
|
| 226 |
+
# 测试结果显示模型具备对话语类型/语义的判断,结果如下所示。
|
| 227 |
+
# tensor([[0.3587, 0.2188],
|
| 228 |
+
# [0.3793, 0.2482],
|
| 229 |
+
# [0.2806, 0.3153],
|
| 230 |
+
# [0.2676, 0.3588]], device='cuda:0')
|
| 231 |
+
# tensor([[1.0000, 0.9275, 0.6241, 0.5684],
|
| 232 |
+
# [0.9275, 1.0000, 0.7433, 0.6704],
|
| 233 |
+
# [0.6241, 0.7433, 1.0000, 0.7269],
|
| 234 |
+
# [0.5684, 0.6704, 0.7269, 1.0000]], device='cuda:0')
|
| 235 |
+
# query_text = [
|
| 236 |
+
# "Identify the utterance type of this speech.",
|
| 237 |
+
# "Identify the utterance type of this speech.",
|
| 238 |
+
# "Identify the utterance type of this speech.",
|
| 239 |
+
# "Identify the utterance type of this speech."
|
| 240 |
+
# ]
|
| 241 |
+
# query_audio = ["./samples/male_statement.wav", "./samples/female_statement.wav",
|
| 242 |
+
# "./samples/male_question.wav", "./samples/female_question.wav"]
|
| 243 |
+
|
| 244 |
+
# # case 10
|
| 245 |
+
# # expect
|
| 246 |
+
# # 测试结果显示模型可以区分出音频是one-speaker还是two-speaker,结果如下所示。
|
| 247 |
+
# # tensor([[0.7003, 0.6864],
|
| 248 |
+
# # [0.7050, 0.6986],
|
| 249 |
+
# # [0.3909, 0.7932],
|
| 250 |
+
# # [0.4326, 0.8110]], device='cuda:0')
|
| 251 |
+
# # tensor([[1.0000, 0.9369, 0.7105, 0.7634],
|
| 252 |
+
# # [0.9369, 1.0000, 0.7473, 0.7579],
|
| 253 |
+
# # [0.7105, 0.7473, 1.0000, 0.8984],
|
| 254 |
+
# # [0.7634, 0.7579, 0.8984, 1.0000]], device='cuda:0')
|
| 255 |
+
# query_text = [
|
| 256 |
+
# "How many speakers in this audio?",
|
| 257 |
+
# "How many speakers in this audio?",
|
| 258 |
+
# "How many speakers in this audio?",
|
| 259 |
+
# "How many speakers in this audio?",
|
| 260 |
+
# ]
|
| 261 |
+
# query_audio = [
|
| 262 |
+
# "./samples/en_male.wav", "./samples/en_female.wav",
|
| 263 |
+
# "./samples/two_speaker.flac", "./samples/two_speaker_2.flac",
|
| 264 |
+
# ]
|
| 265 |
+
|
| 266 |
+
# case 11-1(说话)
|
| 267 |
+
# expect
|
| 268 |
+
# 测试结果如下所示。低音全都是用的male,可能有点不够solid。query-doc矩阵没问题,但是query-query矩阵有问题。
|
| 269 |
+
# tensor([[0.4330, 0.4321],
|
| 270 |
+
# [0.4118, 0.3743],
|
| 271 |
+
# [0.3756, 0.3932],
|
| 272 |
+
# [0.4046, 0.4489]], device='cuda:0')
|
| 273 |
+
# tensor([[1.0000, 0.9168, 0.9511, 0.9505],
|
| 274 |
+
# [0.9168, 1.0000, 0.9212, 0.9323],
|
| 275 |
+
# [0.9511, 0.9212, 1.0000, 0.9565],
|
| 276 |
+
# [0.9505, 0.9323, 0.9565, 1.0000]], device='cuda:0')
|
| 277 |
+
# query_text = [
|
| 278 |
+
# "Is the speaker's tone high or low?",
|
| 279 |
+
# "Is the speaker's tone high or low?",
|
| 280 |
+
# "Is the speaker's tone high or low?",
|
| 281 |
+
# "Is the speaker's tone high or low?"
|
| 282 |
+
# ]
|
| 283 |
+
# query_audio = [
|
| 284 |
+
# "./samples/female_speech_high_1.wav", "./samples/male_speech_high_1.wav",
|
| 285 |
+
# "./samples/male_speech_low_1.wav", "./samples/male_speech_low_2.wav"
|
| 286 |
+
# ]
|
| 287 |
+
|
| 288 |
+
# case 11-2(唱歌)
|
| 289 |
+
# expect
|
| 290 |
+
# 测试结果如下所示。低音全都是用的male,可能有点不够solid。
|
| 291 |
+
# tensor([[0.4901, 0.3206],
|
| 292 |
+
# [0.4875, 0.3638],
|
| 293 |
+
# [0.4354, 0.4760],
|
| 294 |
+
# [0.4144, 0.4296]], device='cuda:0')
|
| 295 |
+
# tensor([[1.0000, 0.9399, 0.8666, 0.8854],
|
| 296 |
+
# [0.9399, 1.0000, 0.9261, 0.9368],
|
| 297 |
+
# [0.8666, 0.9261, 1.0000, 0.9752],
|
| 298 |
+
# [0.8854, 0.9368, 0.9752, 1.0000]], device='cuda:0')
|
| 299 |
+
# query_text = [
|
| 300 |
+
# "Is the speaker's tone high or low?",
|
| 301 |
+
# "Is the speaker's tone high or low?",
|
| 302 |
+
# "Is the speaker's tone high or low?",
|
| 303 |
+
# "Is the speaker's tone high or low?"
|
| 304 |
+
# ]
|
| 305 |
+
# query_audio = [
|
| 306 |
+
# "./samples/female_sing_high_1.wav", "./samples/male_sing_high_1.wav",
|
| 307 |
+
# "./samples/male_sing_low_1.wav", "./samples/male_sing_low_2.wav"
|
| 308 |
+
# ]
|
| 309 |
+
|
| 310 |
+
# case 12
|
| 311 |
+
# expect [0-1 -> outdoor, 2-3 -> indoor]
|
| 312 |
+
# 测试结果显示模型无法区分出模型是在室内还是室外发生
|
| 313 |
+
# query_text = [
|
| 314 |
+
# "Where is this audio most likely recorded?",
|
| 315 |
+
# "Where is this audio most likely recorded?",
|
| 316 |
+
# "Where is this audio most likely recorded?",
|
| 317 |
+
# "Where is this audio most likely recorded?"
|
| 318 |
+
# ]
|
| 319 |
+
# query_audio = ["./samples/male_outdoor.wav", "./samples/female_outdoor.wav",
|
| 320 |
+
# "./samples/indoor.flac", "./samples/indoor2.flac"]
|
| 321 |
+
|
| 322 |
+
# # case 13
|
| 323 |
+
# # expect
|
| 324 |
+
# 测试结果显示模型能够区分出情感差异,结果如下所示。
|
| 325 |
+
# tensor([[0.3226, 0.1865],
|
| 326 |
+
# [0.4463, 0.2482],
|
| 327 |
+
# [0.4102, 0.4539],
|
| 328 |
+
# [0.3474, 0.4925]], device='cuda:0')
|
| 329 |
+
# tensor([[1.0000, 0.7824, 0.5576, 0.5138],
|
| 330 |
+
# [0.7824, 1.0000, 0.6224, 0.5177],
|
| 331 |
+
# [0.5576, 0.6224, 1.0000, 0.8121],
|
| 332 |
+
# [0.5138, 0.5177, 0.8121, 1.0000]], device='cuda:0')
|
| 333 |
+
# query_text = [
|
| 334 |
+
# "What is the emotion of the speaker?",
|
| 335 |
+
# "What is the emotion of the speaker?",
|
| 336 |
+
# "What is the emotion of the speaker?",
|
| 337 |
+
# "What is the emotion of the speaker?"
|
| 338 |
+
# ]
|
| 339 |
+
# query_audio = [
|
| 340 |
+
# "./samples/people_happy_1.flac", "./samples/people_happy_2.flac",
|
| 341 |
+
# "./samples/people_cry_1.flac", "./samples/female_sad_1.wav"
|
| 342 |
+
# ]
|
| 343 |
+
|
| 344 |
+
# # case 14
|
| 345 |
+
# # expect [0->child, 1->adult]
|
| 346 |
+
# # 测试结果如下所示,显示模型具备能力区分说话者的大致年龄。但是两个young都是用的boy;
|
| 347 |
+
# # 如果用young_girl.wav的话, 第一个矩阵没问题,第二个矩阵有问题。
|
| 348 |
+
# # tensor([[0.5183, 0.5019],
|
| 349 |
+
# # [0.5069, 0.4590],
|
| 350 |
+
# # [0.2864, 0.5422],
|
| 351 |
+
# # [0.3039, 0.5131]], device='cuda:0')
|
| 352 |
+
# # tensor([[1.0000, 0.9227, 0.7293, 0.7653],
|
| 353 |
+
# # [0.9227, 1.0000, 0.6910, 0.7291],
|
| 354 |
+
# # [0.7293, 0.6910, 1.0000, 0.8695],
|
| 355 |
+
# # [0.7653, 0.7291, 0.8695, 1.0000]], device='cuda:0')
|
| 356 |
+
# query_text = [
|
| 357 |
+
# "Estimate the age of the speaker.",
|
| 358 |
+
# "Estimate the age of the speaker.",
|
| 359 |
+
# "Estimate the age of the speaker.",
|
| 360 |
+
# "Estimate the age of the speaker."
|
| 361 |
+
# ]
|
| 362 |
+
# query_audio = [
|
| 363 |
+
# "./samples/young_boy_1.flac", "./samples/young_boy_2.wav",
|
| 364 |
+
# "./samples/adult_man.flac", "./samples/adult_woman.flac"
|
| 365 |
+
# ]
|
| 366 |
+
|
| 367 |
+
# case 15
|
| 368 |
+
# 测试结果显示模型可以区分出不同的英语口音,结果如下所示。其中第二个矩阵中有点不够solid
|
| 369 |
+
# tensor([[0.7703, 0.7582],
|
| 370 |
+
# [0.7267, 0.7185],
|
| 371 |
+
# [0.7237, 0.7307],
|
| 372 |
+
# [0.7646, 0.7759]], device='cuda:0')
|
| 373 |
+
# tensor([[1.0000, 0.9324, 0.9442, 0.9598],
|
| 374 |
+
# [0.9324, 1.0000, 0.9827, 0.9704],
|
| 375 |
+
# [0.9442, 0.9827, 1.0000, 0.9857],
|
| 376 |
+
# [0.9598, 0.9704, 0.9857, 1.0000]], device='cuda:0')
|
| 377 |
+
# query_text = [
|
| 378 |
+
# "Identify the English accent of the speaker.",
|
| 379 |
+
# "Identify the English accent of the speaker.",
|
| 380 |
+
# "Identify the English accent of the speaker.",
|
| 381 |
+
# "Identify the English accent of the speaker."
|
| 382 |
+
# ]
|
| 383 |
+
# query_audio = ["./samples/male_america_english.wav", "./samples/female_america_english.wav",
|
| 384 |
+
# "./samples/male_british_english.wav", "./samples/female_british_english.wav"]
|
| 385 |
+
|
| 386 |
+
# # case 16
|
| 387 |
+
# # expect
|
| 388 |
+
# # 测试结果显示模型可以区分出飞机引擎声和大巴引擎声,结果如下所示
|
| 389 |
+
# # tensor([[0.4200, 0.2822],
|
| 390 |
+
# # [0.5744, 0.2713],
|
| 391 |
+
# # [0.2183, 0.3696],
|
| 392 |
+
# # [0.2527, 0.3816]], device='cuda:0')
|
| 393 |
+
# # tensor([[1.0000, 0.8755, 0.7497, 0.7796# [0.6261, 0.5706, 1.0000, 0.7327],
|
| 394 |
+
# [0.4892, 0.5031, 0.7327, 1.0000]], device='cuda:0')
|
| 395 |
+
# query_text = [
|
| 396 |
+
# "What is the source of this sound?",
|
| 397 |
+
# "What is the source of this sound?",
|
| 398 |
+
# "What is the source of this sound?",
|
| 399 |
+
# "What is the source of this sound?"
|
| 400 |
+
# ]
|
| 401 |
+
# query_audio = ["./samples/rainy.wav", "./samples/rainy_2.flac",
|
| 402 |
+
# "./samples/wind_2.flac", "./samples/wind.flac"]
|
| 403 |
+
|
| 404 |
+
# case 18
|
| 405 |
+
# expect
|
| 406 |
+
# 测试结果显示模型具备对说话者的计数能力;
|
| 407 |
+
# 3-speaker/4-speaker测试结果如下, query-doc矩阵没问题,query-query矩阵有点小问题
|
| 408 |
+
# tensor([[0.4325, 0.3912],
|
| 409 |
+
# [0.4801, 0.4459],
|
| 410 |
+
# [0.4836, 0.4986],
|
| 411 |
+
# [0.4723, 0.4741]], device='cuda:0')
|
| 412 |
+
# tensor([[1.0000, 0.9511, 0.9240, 0.8633],
|
| 413 |
+
# [0.9511, 1.0000, 0.9416, 0.8835],
|
| 414 |
+
# [0.9240, 0.9416, 1.0000, 0.9293],
|
| 415 |
+
# [0.8633, 0.8835, 0.9293, 1.0000]], device='cuda:0')
|
| 416 |
+
# query_text = [
|
| 417 |
+
# "What's the number of participants in the current conversation?",
|
| 418 |
+
# "What's the number of participants in the current conversation?",
|
| 419 |
+
# "What's the number of participants in the current conversation?",
|
| 420 |
+
# "What's the number of participants in the current conversation?"
|
| 421 |
+
# ]
|
| 422 |
+
# query_audio = [
|
| 423 |
+
# "./samples/three_speaker_2.wav", "./samples/three_speaker.wav",
|
| 424 |
+
# "./samples/four_speaker.wav", "./samples/four_speaker_3.wav",
|
| 425 |
+
# ]
|
| 426 |
+
|
| 427 |
+
# case 19
|
| 428 |
+
# 测试结果显示不具备音乐风格识别能力
|
| 429 |
+
# query_text = [
|
| 430 |
+
# "What is the music style in the audio?",
|
| 431 |
+
# "What is the music style in the audio?",
|
| 432 |
+
# "What is the music style in the audio?",
|
| 433 |
+
# "What is the music style in the audio?"
|
| 434 |
+
# ]
|
| 435 |
+
# query_audio = [
|
| 436 |
+
# "./samples/hiphop_1.flac", "./samples/hiphop_2.flac",
|
| 437 |
+
# "./samples/classical_1.flac", "./samples/classical_2.flac",
|
| 438 |
+
# ]
|
| 439 |
+
|
| 440 |
+
# case 20
|
| 441 |
+
# 测试结果显示模型具备识别乐器声音的能力
|
| 442 |
+
# tensor([[0.4882, 0.3500],
|
| 443 |
+
# [0.4124, 0.3477],
|
| 444 |
+
# [0.3047, 0.6171],
|
| 445 |
+
# [0.4425, 0.5910]], device='cuda:0')
|
| 446 |
+
# tensor([[1.0000, 0.8528, 0.7110, 0.8001],
|
| 447 |
+
# [0.8528, 1.0000, 0.7338, 0.7728],
|
| 448 |
+
# [0.7110, 0.7338, 1.0000, 0.9112],
|
| 449 |
+
# [0.8001, 0.7728, 0.9112, 1.0000]], device='cuda:0')
|
| 450 |
+
# query_text = [
|
| 451 |
+
# "What musical instrument is producing the sound?",
|
| 452 |
+
# "What musical instrument is producing the sound?",
|
| 453 |
+
# "What musical instrument is producing the sound?",
|
| 454 |
+
# "What musical instrument is producing the sound?"
|
| 455 |
+
# ]
|
| 456 |
+
# query_audio = [
|
| 457 |
+
# "./samples/piano_3.flac", "./samples/piano_2.flac",
|
| 458 |
+
# "./samples/guitar_1.flac", "./samples/guitar_2.flac",
|
| 459 |
+
# ]
|
| 460 |
+
|
| 461 |
+
# case 21
|
| 462 |
+
# 测试显示模型无法计数说话中单词的数量
|
| 463 |
+
# query_text = [
|
| 464 |
+
# "How many times does the word 'said' appear in the audio?",
|
| 465 |
+
# "How many times does the word 'beautiful' appear in the audio?",
|
| 466 |
+
# "How many times does the word 'fate' appear in the audio?",
|
| 467 |
+
# "How many times does the word 'ninty' appear in the audio?"
|
| 468 |
+
# ]
|
| 469 |
+
# query_audio = [
|
| 470 |
+
# "./samples/1_said.wav", "./samples/1_beautiful.wav",
|
| 471 |
+
# "./samples/1_fate.wav", "./samples/3_ninty_nine.wav",
|
| 472 |
+
# ]
|
| 473 |
+
|
| 474 |
+
# case 22
|
| 475 |
+
# 测试显示模型是否具备计数铃声和鼓声的能力
|
| 476 |
+
# query_text = [
|
| 477 |
+
# "How many times does the sound appear in the audio?",
|
| 478 |
+
# "How many times does the sound appear in the audio?",
|
| 479 |
+
# "How many times does the sound appear in the audio?",
|
| 480 |
+
# "How many times does the sound appear in the audio?"
|
| 481 |
+
# ]
|
| 482 |
+
# query_audio = [
|
| 483 |
+
# "./samples/2_drumbeat.wav", "./samples/2_ringtone.wav",
|
| 484 |
+
# "./samples/6_drumbeat.wav", "./samples/6_ringtone.wav"
|
| 485 |
+
# ]
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
# ----
|
| 489 |
+
|
| 490 |
+
# doc_text = [
|
| 491 |
+
# "male",
|
| 492 |
+
# "female",
|
| 493 |
+
# ]
|
| 494 |
+
|
| 495 |
+
# doc_text = [
|
| 496 |
+
# "music",
|
| 497 |
+
# "nothing",
|
| 498 |
+
# ]
|
| 499 |
+
|
| 500 |
+
# doc_text = [
|
| 501 |
+
# "High-quality",
|
| 502 |
+
# "Low-quality",
|
| 503 |
+
# ]
|
| 504 |
+
|
| 505 |
+
# doc_text = [
|
| 506 |
+
# "yes",
|
| 507 |
+
# "no",
|
| 508 |
+
# ]
|
| 509 |
+
|
| 510 |
+
# doc_text = [
|
| 511 |
+
# "cow",
|
| 512 |
+
# "lion",
|
| 513 |
+
# "rooster",
|
| 514 |
+
# ]
|
| 515 |
+
|
| 516 |
+
doc_text = [
|
| 517 |
+
"spanish",
|
| 518 |
+
"chinese",
|
| 519 |
+
]
|
| 520 |
+
|
| 521 |
+
# doc_text = [
|
| 522 |
+
# "fast",
|
| 523 |
+
# "slow",
|
| 524 |
+
# ]
|
| 525 |
+
|
| 526 |
+
# doc_text = [
|
| 527 |
+
# "one type",
|
| 528 |
+
# "two types",
|
| 529 |
+
# ]
|
| 530 |
+
|
| 531 |
+
# doc_text = [
|
| 532 |
+
# "statement",
|
| 533 |
+
# "question",
|
| 534 |
+
# ]
|
| 535 |
+
|
| 536 |
+
# doc_text = [
|
| 537 |
+
# "one speaker",
|
| 538 |
+
# "two speakers",
|
| 539 |
+
# ]
|
| 540 |
+
|
| 541 |
+
# doc_text = [
|
| 542 |
+
# "high",
|
| 543 |
+
# "low",
|
| 544 |
+
# ]
|
| 545 |
+
|
| 546 |
+
# doc_text = [
|
| 547 |
+
# "outdoor",
|
| 548 |
+
# "indoor",
|
| 549 |
+
# ]
|
| 550 |
+
|
| 551 |
+
# doc_text = [
|
| 552 |
+
# "happy",
|
| 553 |
+
# "sad",
|
| 554 |
+
# ]
|
| 555 |
+
|
| 556 |
+
# doc_text = [
|
| 557 |
+
# "child",
|
| 558 |
+
# "adult",
|
| 559 |
+
# ]
|
| 560 |
+
|
| 561 |
+
# doc_text = [
|
| 562 |
+
# "American accent",
|
| 563 |
+
# "British accent",
|
| 564 |
+
# ]
|
| 565 |
+
|
| 566 |
+
# doc_text = [
|
| 567 |
+
# "helicopter engine",
|
| 568 |
+
# "car engine",
|
| 569 |
+
# ]
|
| 570 |
+
|
| 571 |
+
# doc_text = [
|
| 572 |
+
# "rain",
|
| 573 |
+
# "wind",
|
| 574 |
+
# ]
|
| 575 |
+
|
| 576 |
+
# doc_text = [
|
| 577 |
+
# "hiphop",
|
| 578 |
+
# "classical",
|
| 579 |
+
# ]
|
| 580 |
+
|
| 581 |
+
# doc_text = [
|
| 582 |
+
# "three persons",
|
| 583 |
+
# "four persons",
|
| 584 |
+
# ]
|
| 585 |
+
|
| 586 |
+
# doc_text = [
|
| 587 |
+
# "piano",
|
| 588 |
+
# "guitar",
|
| 589 |
+
# ]
|
| 590 |
+
|
| 591 |
+
# doc_text = [
|
| 592 |
+
# "one",
|
| 593 |
+
# "three",
|
| 594 |
+
# ]
|
| 595 |
+
|
| 596 |
+
# doc_text = [
|
| 597 |
+
# "two",
|
| 598 |
+
# "six",
|
| 599 |
+
# ]
|
| 600 |
+
|
| 601 |
+
query_embeddings = model.encode(
|
| 602 |
+
text=query_text,
|
| 603 |
+
audio=query_audio,
|
| 604 |
+
task="query",
|
| 605 |
+
instruction=QUERY_INSTRUCTION,
|
| 606 |
+
normalize=True,
|
| 607 |
+
device=device,
|
| 608 |
+
)
|
| 609 |
+
doc_embeddings = model.encode(
|
| 610 |
+
text=doc_text,
|
| 611 |
+
# text=[None, None],
|
| 612 |
+
# audio=doc_audio,
|
| 613 |
+
task="document",
|
| 614 |
+
instruction=DOC_INSTRUCTION,
|
| 615 |
+
normalize=True,
|
| 616 |
+
device=device,
|
| 617 |
+
)
|
| 618 |
+
similarity = query_embeddings @ doc_embeddings.T
|
| 619 |
+
print(similarity)
|
| 620 |
+
|
| 621 |
+
similarity = query_embeddings @ query_embeddings.T
|
| 622 |
+
print(similarity)
|