我正在尝试使用自己的数据集从预先训练的wav2vec2模型(例如,来自jonatasgrosman/wav2vec2-large-xlsr-53-german)中获取嵌入
我的目标是将这些功能用于下游任务(不特别是语音识别)。也就是说,由于数据集相对较小,我将使用这些嵌入来训练SVM,以进行最终分类
到目前为止,我已经尝试过:
model_name = "facebook/wav2vec2-large-xlsr-53-german"
feature_extractor = Wav2Vec2Processor.from_pretrained(model_name)
model = Wav2Vec2Model.from_pretrained(model_name)
input_values = feature_extractor(train_dataset[:10]["speech"], return_tensors="pt", padding=True,
feature_size=1, sampling_rate=16000 ).input_values
然后,我不确定这里的嵌入是否对应于最后隐藏状态的顺序:
hidden_states = model(input_values).last_hidden_state
或模型最后一个conv层的特征序列:
features_last_cnn_layer = model(input_values).extract_features
此外,这是从预先训练的模型中提取特征的正确方法吗
如何从特定层获得嵌入
PD:在这里发布的HuggingFace论坛似乎不太活跃
只需检查documentation:
contextualized embeddings
(即,每个特征(CNN输出)都有一个向量表示,该向量表示在某种程度上受序列的其他标记的影响)李>输出:
hidden_states
值包含每个注意层的嵌入和上下文化嵌入p.S.:jonatasgrosman/wav2vec2-large-xlsr-53-german模型用
feat_extract_norm
==层进行训练。也就是说,您还应该向模型传递一个注意遮罩:相关问题 更多 >
编程相关推荐