wangyuxinwhy / uniem Goto Github PK
View Code? Open in Web Editor NEWunified embedding model
License: Apache License 2.0
unified embedding model
License: Apache License 2.0
辛苦问个问题,使用 sentence-transformers 进行 encode 时最后会加上一个 mean pooling 操作,然后将池化后的特征作为最终的特征,model 定义时候我看可选cls, last_mean, first_last_mean,embedding_last_mean, last_weighted 几种不同的方式,这个的选择对最终embedding 效果有影响吗?
由于一些原因无法使用py3.10进行微调,想重构一下源码,请问一下,fintuner或者说uniem库中有哪些组件是必须使用py3.10的,您方还有印象吗?
None
cMedQA
https://github.com/zhangsheng93/cMedQA
None
作者您好
我这边想试试 m3e 的微调效果,因此想问下这个数据集,您是否加进去训练了?
如果没有的,我先拿下来训练,看效果是否可以的
看上去目前的finetune和train脚本都是基于单卡的脚本。
Do M3E support multilingual?
想问下,检索排序的三个指标MAP, MRR, NDCG 分别是检索的还是排序的指标,如果三个指标是对同一份推理结果的指标,那么MAP@1是不是应该和MRR@1相等
None
是否可以仿照英文的MTEB-leaderboard: https://huggingface.co/spaces/mteb/leaderboard。
在huggingface上建立一个中文相关数据集的在线榜单。
这样应该也能有助于提高您工作的一些影响力。
我直接调huggingface上面的m3e模型
class HuggingfaceModel:
def __init__(
self,
model_name: str = 'moka-ai/m3e-small',
device: str | None = None,
) -> None:
from transformers import AutoModel, AutoTokenizer # type: ignore
if device is None:
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
else:
self.device = device
self.model = AutoModel.from_pretrained(model_name)
self.model.to(self.device)
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
self.model.eval()
def encode(self, sentences: list[str], batch_size: int = 32, **kwargs) -> list[np.ndarray]:
all_embeddings: list[np.ndarray] = []
for batch_texts in tqdm(
generate_batch(sentences, batch_size),
total=len(sentences) // batch_size,
):
inputs = self.tokenizer(
batch_texts,
padding=True,
truncation=True,
return_tensors='pt',
max_length=512,
)
inputs = inputs.to(self.device)
with torch.no_grad():
outputs = self.model(**inputs, output_hidden_states=True)
embeddings = outputs.hidden_states[-1][:, 0, :].squeeze()
embeddings = cast(torch.Tensor, embeddings)
all_embeddings.extend(embeddings.cpu().numpy())
return all_embeddings
观察到这样的调用和编码方式跟用sentenceTransformer上面调用有千分之二左右的性能差距,想问一下SentenceTransformer具体相对这样编码有什么改进,自己看没看出什么门道!感谢
你好,没有找到hfl/chinese-roberta-wwm-ext的small版,只找到了base和large,请问train_m3e.py是在这个roberta-wwm基础上训练得到的吗?
None
目前负样本的数量还是受限于单卡的显存,即最多为batch size per gpu。
是否有这种操作:把GPU2的样本作为GPU1样本的负样本呢?
在 PyPI 中这个包的名字是 sentence-transformers
. 所以需要改成 pip install sentence-transformers
~
@wangyuxinwhy 大佬,非常感谢开源贡献的这个项目。
小白有一个疑问。
请问m3e模型如何微调?
您好,照着官网的教程,使用了自己的数据集,finetune时报错 argument after ** must be a mapping, not NoneType
感谢大佬们看看
代码如下:
import pandas as pd
from uniem.finetuner import FineTuner
df3_raw = """{"sentence1":"金霉素", "sentence2":"红霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"妥布霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"硫酸新霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"灰黄霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"曲霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"复方新霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"庆大霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"克林霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"黄曲霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"青霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"土霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"阿奇霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"林可霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"氯霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"螺旋霉素", "label":"0.0"}"""
df3 = pd.read_json(df3_raw, lines=True)
finetuner = FineTuner('moka-ai3/m3e-base/', dataset=df3.to_dict('records'))
finetuner.run(epochs=1)
None
感谢非常棒的工作!
请问下用在交互式模型上怎么样?
1.比如,输入query[sep]title 来通过模型,来判断是否相关。
2.如果不行的话,我加载m3e模型,继续把数据组织成交互式的方法来微调,是否比原生的bert好点呢?
None
很棒的工作!我目前正在做检索任务,问下怎么切换s2s、s2p,目前貌似只有一个encode方法,我直接embe_q=model.encode(问题) 和 embe_p=model.encode(文档),embe_q和embe_p做相似度对比吗。
首先感谢大佬开源如此优秀的工具!
版本:0.2.2
函数:uniem.data_structures.get_record_type
描述:该函数的逻辑似乎会导致程序将 TripletRecord 类型识别为 PairRecord
实验:
from uniem.data_structures import RecordType, get_record_type
sample = {
'text': 'hello',
'text_pos': 'hi',
'text_neg': 'no',
}
ret = get_record_type(sample)
print(ret.__class__)
print(ret)
返回:期望返回类型名称是 TripletRecord
<enum 'RecordType'>
RecordType.PAIR
3.10
batch size 小的时候使用 SigmoidContrastLoss
会好一点,大的时候 SoftmaxContrastLoss
好一点。请问这个是做实验了还是有理论分析呢?理论上,第一个loss是一个query,对于一个正例,做batch_size-1个二分类任务(batch_size-1)个负例。
而SoftmaxContrastLoss,一个query,对于一个正例,做一个多分类任务(也是见到batch_size-1个负例)。从负例的角度没差别呀?
None
您好,很棒的工作!请问M3E系列支持的最长token数量是多少?超过最长的文本会被截断吗?
谢谢!
None
您好,照着官网的教程,使用了自己的数据集,finetune时报错 argument after ** must be a mapping, not NoneType
感谢大佬们看看,前一个issue不小心关闭了
代码如下:
import pandas as pd
from uniem.finetuner import FineTuner
df3_raw = """{"sentence1":"金霉素", "sentence2":"红霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"妥布霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"硫酸新霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"灰黄霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"曲霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"复方新霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"庆大霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"克林霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"黄曲霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"青霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"土霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"阿奇霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"林可霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"氯霉素", "label":"0.0"}
{"sentence1":"金霉素", "sentence2":"螺旋霉素", "label":"0.0"}"""
df3 = pd.read_json(df3_raw, lines=True)
finetuner = FineTuner('moka-ai3/m3e-base/', dataset=df3.to_dict('records'))
finetuner.run(epochs=1)
3.10
很棒的工作👍🎉 在HuggingFace的模型页面看到为了保证 in-batch 负采样的效果,我们使用 A100 80G 来最大化 batch-size
。想请问一下:训练的batch-size是多大呢?除了使用大显存GPU外,是否还使用其他增大batch-size的技巧?
非常棒的工作,请教一下复现instructor的实验的超参。请问是batch size=32, epoch=3吗,那就是训练10万多步。
rt
使用该脚本,执行 python test.py,一段时间后就会占光显存,然后 OOM
安装的uniem 版本为 0.2.4post1
import pandas as pd
from uniem.finetuner import FineTuner
# 读取 jsonl 文件
df = pd.read_json('/paddle/data/embedding/m3e.train_data.jsonl', lines=True)
# 指定训练的模型为 m3e-small
finetuner = FineTuner('/paddle/data/suke/model_hub/m3e-base', dataset=df.to_dict('records'))
finetuner.run(batch_size=50, epochs=3, save_on_epoch_end=True,output_dir='/paddle/data/suke/test_sft/finetuned-model-m3e')
3.10
Start with seed: 42
Output dir: /paddle/data/suke/test_sft/finetuned-model-m3e
Start training for 3 epochs
Epoch 1/3 - loss: 1.2525: 0%| | 27/42092 [00:59<26:17:28, 2.25s/it]╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /paddle/code/suke/uniem/scripts/test_m3e_sample.py:9 in <module> │
│ │
│ 6 df = pd.read_json('/paddle/data/embedding/m3e.train_data.jsonl', lines= │
│ 7 # 指定训练的模型为 m3e-small │
│ 8 finetuner = FineTuner('/paddle/data/suke/model_hub/m3e-base', datase │
│ ❱ 9 finetuner.run(batch_size=50, epochs=3, save_on_epoch_end=True,output_di │
│ 10 │
│ │
│ /usr/local/lib/python3.10/site-packages/uniem/utils.py:113 in decorator │
│ │
│ 110 │ │ is_manually_passed_batch_size = 'batch_size' in kwargs │
│ 111 │ │ │
│ 112 │ │ if is_manually_passed_batch_size: │
│ ❱ 113 │ │ │ return function(*args, **kwargs) │
│ 114 │ │ else: │
│ 115 │ │ │ while True: │
│ 116 │ │ │ │ if batch_size == 0: │
│ │
│ /usr/local/lib/python3.10/site-packages/uniem/finetuner.py:239 in run │
│ │
│ 236 │ │ │ save_on_epoch_end=save_on_epoch_end, │
│ 237 │ │ ) │
│ 238 │ │ accelerator.print(f'Start training for {epochs} epochs') │
│ ❱ 239 │ │ trainer.train() │
│ 240 │ │ │
│ 241 │ │ accelerator.wait_for_everyone() │
│ 242 │ │ accelerator.print('Training finished') │
│ │
│ /usr/local/lib/python3.10/site-packages/uniem/trainer.py:52 in train │
│ │
│ 49 │ │ │ for batch_index, batch in enumerate(self.train_dataloader) │
│ 50 │ │ │ │ with self.accelerator.accumulate(self.model): │
│ 51 │ │ │ │ │ self.optimizer.zero_grad() │
│ ❱ 52 │ │ │ │ │ batch_output = self.model(**batch) │
│ 53 │ │ │ │ │ loss = batch_output['loss'] │
│ 54 │ │ │ │ │ self.accelerator.backward(loss) │
│ 55 │ │ │ │ │ self.optimizer.step() │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/uniem/model.py:254 in forward │
│ │
│ 251 │ ) -> dict[str, torch.Tensor]: │
│ 252 │ │ text_embeddings = self.embedder(text_ids) │
│ 253 │ │ text_pos_embeddings = self.embedder(text_pos_ids) │
│ ❱ 254 │ │ text_neg_embeddings = self.embedder(text_neg_ids) │
│ 255 │ │ loss = self.criterion(text_embeddings, text_pos_embeddings, te │
│ 256 │ │ return {'loss': loss} │
│ 257 │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/uniem/model.py:109 in forward │
│ │
│ 106 │ def forward(self, input_ids: torch.Tensor, attention_mask: torch.T │
│ 107 │ │ if attention_mask is None: │
│ 108 │ │ │ attention_mask = creat_attention_mask_from_input_ids(input │
│ ❱ 109 │ │ embeddings = self.encoder(input_ids, attention_mask=attention_ │
│ 110 │ │ embeddings = mean_pooling(embeddings, attention_mask) │
│ 111 │ │ return embeddings │
│ 112 │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/transformers/models/bert/modeling_be │
│ rt.py:1020 in forward │
│ │
│ 1017 │ │ │ inputs_embeds=inputs_embeds, │
│ 1018 │ │ │ past_key_values_length=past_key_values_length, │
│ 1019 │ │ ) │
│ ❱ 1020 │ │ encoder_outputs = self.encoder( │
│ 1021 │ │ │ embedding_output, │
│ 1022 │ │ │ attention_mask=extended_attention_mask, │
│ 1023 │ │ │ head_mask=head_mask, │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/transformers/models/bert/modeling_be │
│ rt.py:610 in forward │
│ │
│ 607 │ │ │ │ │ encoder_attention_mask, │
│ 608 │ │ │ │ ) │
│ 609 │ │ │ else: │
│ ❱ 610 │ │ │ │ layer_outputs = layer_module( │
│ 611 │ │ │ │ │ hidden_states, │
│ 612 │ │ │ │ │ attention_mask, │
│ 613 │ │ │ │ │ layer_head_mask, │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/transformers/models/bert/modeling_be │
│ rt.py:495 in forward │
│ │
│ 492 │ ) -> Tuple[torch.Tensor]: │
│ 493 │ │ # decoder uni-directional self-attention cached key/values tu │
│ 494 │ │ self_attn_past_key_value = past_key_value[:2] if past_key_val │
│ ❱ 495 │ │ self_attention_outputs = self.attention( │
│ 496 │ │ │ hidden_states, │
│ 497 │ │ │ attention_mask, │
│ 498 │ │ │ head_mask, │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/transformers/models/bert/modeling_be │
│ rt.py:425 in forward │
│ │
│ 422 │ │ past_key_value: Optional[Tuple[Tuple[torch.FloatTensor]]] = N │
│ 423 │ │ output_attentions: Optional[bool] = False, │
│ 424 │ ) -> Tuple[torch.Tensor]: │
│ ❱ 425 │ │ self_outputs = self.self( │
│ 426 │ │ │ hidden_states, │
│ 427 │ │ │ attention_mask, │
│ 428 │ │ │ head_mask, │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/transformers/models/bert/modeling_be │
│ rt.py:306 in forward │
│ │
│ 303 │ │ │ key_layer = torch.cat([past_key_value[0], key_layer], dim │
│ 304 │ │ │ value_layer = torch.cat([past_key_value[1], value_layer], │
│ 305 │ │ else: │
│ ❱ 306 │ │ │ key_layer = self.transpose_for_scores(self.key(hidden_sta │
│ 307 │ │ │ value_layer = self.transpose_for_scores(self.value(hidden │
│ 308 │ │ │
│ 309 │ │ query_layer = self.transpose_for_scores(mixed_query_layer) │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py:1501 in │
│ _call_impl │
│ │
│ 1498 │ │ if not (self._backward_hooks or self._backward_pre_hooks or s │
│ 1499 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hoo │
│ 1500 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks │
│ ❱ 1501 │ │ │ return forward_call(*args, **kwargs) │
│ 1502 │ │ # Do not call functions when jit is used │
│ 1503 │ │ full_backward_hooks, non_full_backward_hooks = [], [] │
│ 1504 │ │ backward_pre_hooks = [] │
│ │
│ /usr/local/lib/python3.10/site-packages/torch/nn/modules/linear.py:114 in │
│ forward │
│ │
│ 111 │ │ │ init.uniform_(self.bias, -bound, bound) │
│ 112 │ │
│ 113 │ def forward(self, input: Tensor) -> Tensor: │
│ ❱ 114 │ │ return F.linear(input, self.weight, self.bias) │
│ 115 │ │
│ 116 │ def extra_repr(self) -> str: │
│ 117 │ │ return 'in_features={}, out_features={}, bias={}'.format( │
╰──────────────────────────────────────────────────────────────────────────────╯
OutOfMemoryError: CUDA out of memory. Tried to allocate 76.00 MiB (GPU 0; 79.35
GiB total capacity; 73.60 GiB already allocated; 22.12 MiB free; 78.13 GiB
reserved in total by PyTorch) If reserved memory is >> allocated memory try
setting max_split_size_mb to avoid fragmentation. See documentation for Memory
Management and PYTORCH_CUDA_ALLOC_CONF
temperature: 0.01
add_swap_loss: True
batch_size: 80
max_length: 512
lr: 3e-5
epochs: 3
我们自己训练的模型跑了 MTEB ,也传到了 leaderboard 上面,名字叫 exp-base-softmax-last_mean。Classification Average (12 datasets) 跑到了 71.08,低于 instructor-base 的 72.36。不过 instructor 自己的评测是添加了手工调整的指令,我们评测的时候是不添加任何指令的。
Originally posted by @wangyuxinwhy in #1 (comment)
背景:之前基于text2vec的代码,使用in-batch的loss方式,在自己的数据集上进行finetune。对比了和uniem的训练脚本,逻辑基本一致,且保证参数一致,比如lr、weight_decay、num_warmup_steps、temperature等
问题:finetune发现,(1)使用text2vec的效果稍微优于uniem。这里指的是训练脚本,其中pretrain model均为m3e-model(2)相同batch size的情况下,uniem占用显存更少
猜测:之前以为是混合精度的原因导致的,但后来发现这个设置默认是"no"。
所以想要请教下,导致这个差异的原因可能是什么呢?期待大佬的答复。
embedder 引入了 新的参数 model_class,但没有正确的在Finetuner中传递。
None
能否在华为npu 910a上微调和推理
能否支持onnx
我用指令启动您给的实例脚本 accelerate launch finetune_jsonl.py
然后发现程序报错
RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not
used in producing loss. You can enable unused parameter detection by passing the keyword argument find_unused_parameters=True
to
torch.nn.parallel.DistributedDataParallel
, and by
making sure all forward
function outputs participate in calculating loss.
If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's forward
function. Please include the loss function and the structure of the return value of forward
of your module when reporting this issue (e.g. list, dict, iterable).
Parameter indices which did not receive grad for rank 1: 197 198
In addition, you can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print out information about which particular parameters did not
receive gradient on this rank as part of this error
请教一下您这要怎么解决呀
None
Hi @wangyuxinwhy ,
请问mteb-zh评测测试集为什么跟text2vec测试集不同?是因为m3e训练数据大部分都是qa形式吗,短q长a,而相似度数据偏向于较短的qq pair吗
比如这几个测试集 https://github.com/bojone/BERT-whitening/tree/main/chn
我在用您提供的代码和模型进行再训练,进行的是句子对的训练,我的数据集比较大,可能有100w条。
我训练的时候发现基本上训练一轮以后,损失函数可能就会突然变大,然后维持一个稳定的数值不变,判断应该是模型跑飞了。
想请教一下作者有遇到过这种情况么,有没有训练经验可以分享一下的。
None
如果想要复现M3E-Base的结果,不知道作者方便透露下具体的参数或者相应的config file吗,
还是说train_m3e.py里的默认参数已经是最优参数了?
感谢!
目前我看代码train/eval,都是没有显式加入instruction,而是自动mergeinstruction和input部分用来作为一个text样本。
这样对于所有pair类型同质的数据,例如STS,NLI, QQpair等,相当于没有instruction?
而对于那种自带instruction的数据,相当于instruction+input融合了,有了instcution,这样需要模型自动辨识是否为一个symmetric/asymmetric任务?
the output of encoder is N*d states for each text input;
Your default is the same as mean pooling?
不同于T2ranking自身的评测, 您的文中有引入了 map、MRR、NDCG等指标。方便发一下这个评估的代码,我们这边是防止自己评估的代码与评测代码有微小差异导致评测不准确的问题。
None
感谢作者的分享,非常棒的项目!
目前看起来Finetuner的接口只支持单个数据集作为输入:
RawDataset = Sequence[dict] | dict[str, Sequence[dict]] | HFDatasetDict | HFDataset
是这样吗?
m3e模型如何微调无监督文本呢?就是一条样本不是一对相似句子或不相似句子,只是一条领域文本
命令:accelerate launch python scripts/train_m3e.py /path/to/model_base/ /path/to/dataset/
Root Cause (first observed failure):
[0]:
time : 2023-07-25_13:27:50
host : SH-IDC1-10-198-6-78
rank : 0 (local_rank: 0)
exitcode : 1 (pid: 132975)
error_file: <N/A>
traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
请问这种问题怎么解决呢?如果需要什么更加详细的信息可以和我留言,这个问题确实困扰我很久了。。
3.10
load_wiki_atomic_edits的原始process函数如下
def _process(example):
return {
'base_sentence': concat_words(example['base_sentence'].split(' ')),
'edited_sentence': concat_words(example['edited_sentence'].split(' ')),
}
return 的key应该是'text'和'text_pos',而不是'base_sentence'和'edited_sentence'
这里应该写错了。
None
uniem/mteb-zh/mteb_zh/tasks.py
Line 266 in 9acd3eb
是不是就是不丢弃T2ranking dev的那些query和doc pair,获取前1个万个doc之后,然后再将dev里边的doc放进去,然后进行评测是吧?
None
Hi @wangyuxinwhy ,
感谢分享,主要是有个问题想讨论一下。虽然m3e在几个开源测试集上指标有提升,但是相比openai-ada-002,抗干扰能力明显变弱
比如在自己构造的一份检索的测试集上,m3e-base几乎不能正确召回,luotuo为开源的在openai向量上蒸馏出来的向量模型,虽然效果远不如openai的结果,但是对比m3e也是优势比较大
测试代码如下:
每个docs是3条数据,docs[0]为问题q, docs[1]为m3e检索回来的相似度最高的doc片段, docs[2]为正确的doc片段
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
model_path = 'moka-ai/m3e-base'
model = SentenceTransformer(model_path)
docs = ["富森美公司的主要收入模式是什么",
"""公司多年来深耕装饰建材
家居业务,合理设置卖场定位,拥有大量优质代理商、经销商客户资源, 同时,公司在集
合式营销、市场管理、资源整合、产品促销等方面不断创新, 相继被中宣部等八部委联合
授予“全国百城万店无假货示范市场” ,被 国家工商总局授予“全国诚信示范市场” ,被
国家质检总局授予 “全国购物放心市场” ,被 四川省人民政府授予“四川省服务名牌企业”
等荣誉称号, 逐渐树立起品牌规范性专业市场形象 。“富森美”品牌已成为成都及四川地
区具有广泛影响力的装饰建材流通类品牌,在消费者心��中享有较高的品牌认知度和美誉
度,有力地支持了公司渠道扩张和商业模式的实行。
“服务 +产品”策略, 全业态定位满足消费者需求 。在区域专业市场中, 公司通过 合理的
定位、 高度的便利性和全面的 “服务 +产品” 策略 有效地吸引商户入驻和消费者体验、 消费。""",
"""公司目前
自持卖场物业建筑面积超过 110 万平方米, 2019 年底加盟及委托管理卖场经营规模达到
51.6 万平方米, 公司自有和委管卖场均使用的 “富森美” 品牌, 近三年获评 2018 年和 2019
年的**家居品牌大会“**十大家居连锁卖场”以及“ 2019 -2020 十大优选**家居消
费平台” 。公司当前主要收入模式来自卖场招商收租金, 毛利率、 净利率和成本费用率均处
于行业前列,富森美主要优点在于: 1)自持物业成本低; 2)精细化运营能力强,布局多
层次业态,差异化招商、服务; 3)产业链整合创新能力突出,平台资源丰富。
数字化整合升 级, 加速新零售布局。公司紧跟家居行业个性化等需求增长的趋势, 围绕 “引
流和赋能” ,通过微信小程序、网上直播、联合营销、专场活动以及优化品牌结构等多种方
式巩固公司的区域优势,重点对卖场数字化升级,实现线上流量的精准转化,同时提升运
营效率。"""]
embeddings = model.encode(docs)
print(cosine_similarity(embeddings))
docs = ["富森美公司的风险提示有哪些",
"""公司报告
请务必仔细阅读正文之后的各项信息披露与声明 第21页 共28页 简单金融 成就梦想
2019 年富森美在 **上市公司口碑榜 当中荣获 “最具成长性新零售产业上市公司” ,
公司发展新零售模式主要优势在于: 1)创始人 多年从事装饰建材家居行业工作, 始终以
用户思维、产品思维而非商业地产思维发展业务 ,创新打造或孵化出多层次新业态 ;2)
品牌与销售方面, 公司 始终深耕产品,协助商户完成各类产品的市场营销活动, 为厂家和
商户提供了全产业链服务, 具备良好的销售经验和基础; 3)公司的供应链体系完整,资
源丰富,平台优势突出; 4)新零售项目运营团队年轻化,由 90后担纲运营,能够准确地
把握当代消费者的需求 。""",
"""我们对
公司 2020~2022 年EPS 预测分别为 0.89 元/1.09 元/1.26 元,对应 PE分别为
18X/15X/13X ,首次覆盖,给予“买入”评级。
风险提示: 地产景气周期下滑,市场竞争加剧,公司新零售业务发展进度不及预期。
市场数据: 2020 年12月08日
收盘价(元 ) 16.15
一年内最高 /最低(元) 16.85 /10.47
市净率 2.3
息率(分红 /股价) 2.17
流通 A股 市 值 ( 百 万 元 ) 4819
上证指数 /深证成指 3410.18 /13973.89
注:“息率 ” 以 最 近 一 年 已 公 布 分 红 计 算
基础数据 : 2020 年09月30日
每股净资产 ( 元 ) 7.02
资产负债率 % 14."""]
embeddings = model.encode(docs)
print(cosine_similarity(embeddings))
"""
[[1. 0.8282594 0.79422724]
[0.8282594 1. 0.89455336]
[0.79422724 0.89455336 0.9999997 ]]
[[1. 0.8106332 0.6698204]
[0.8106332 1. 0.8019115]
[0.6698204 0.8019115 0.9999999]]
"""
None
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.