FlagEmbedding icon indicating copy to clipboard operation
FlagEmbedding copied to clipboard

微调后bge-m3每次测试结果都不相同

Open May-Sunshine opened this issue 2 months ago • 0 comments

微调脚本

torchrun --nproc_per_node 2
-m FlagEmbedding.finetune.embedder.encoder_only.m3
--model_name_or_path models/bge-m3
--cache_dir ./cache/model
--train_data ./data/bge-emb.jsonl
--cache_path ./cache/data
--train_group_size 8
--query_max_len 512
--passage_max_len 512
--pad_to_multiple_of 8
--knowledge_distillation True
--same_dataset_within_batch True
--small_threshold 0
--drop_threshold 0
--output_dir ./test_encoder_only_m3_bge-m3_sd
--overwrite_output_dir
--learning_rate 1e-5
--fp16
--num_train_epochs 2
--per_device_train_batch_size 2
--dataloader_drop_last True
--warmup_ratio 0.1
--gradient_checkpointing
--logging_steps 1
--save_steps 100
--negatives_cross_device
--temperature 0.02
--sentence_pooling_method cls
--normalize_embeddings True
--kd_loss_type m3_kd_loss
--unified_finetuning True
--use_self_distill True
--fix_encoder False
--self_distill_start_step 0

测试脚本

from FlagEmbedding import FlagReranker, BGEM3FlagModel

model_path = 'test_encoder_only_m3_bge-m3_sd' model = BGEM3FlagModel(model_path, use_fp16=True)

sentences_1 = ["上海宾筵资产管理有限公司"] sentences_2 = ['北京宾筵资产管理有限公司', '上海宾筵资产管理中心(有限合伙)', '北京春秋永乐文化传播股份有限公司', '北京春秋永乐文化传播有限公司', '福清泳贸塑胶有限公司']

sentence_pairs = [[i, j] for i in sentences_1 for j in sentences_2] score = model.compute_score(sentence_pairs, batch_size=8, max_passage_length=50, weights_for_different_modes=[0.7, 0.3, 0]) print('sparse+dense:', score['sparse+dense']) print('dense:', score['dense'])

测试结果

Image

May-Sunshine avatar Nov 03 '25 08:11 May-Sunshine