我正在尝试从huggingface下载并保存以下模型以供以后使用。这是片段。
from transformers import AutoModelForSequenceClassification,
AutoTokenizer,AutoModelForCausalLM
model_name='jinaai/jina-reranker-v2-base-multilingual'
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer.save_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
model.save_pretrained(f"model/{model_name}")
出现此错误
ValueError: Unrecognized configuration class <class 'transformers_modules.jina-
reranker-v2-base-multilingual.configuration_xlm_roberta.XLMRobertaFlashConfig'> for
this kind of AutoModel: AutoModelForCausalLM.
Model type should be one of BartConfig, BertConfig, BertGenerationConfig,
BigBirdConfig, BigBirdPegasusConfig.......
项目的文件夹结构
root/aimodel.py (where the code snippet is written)
root/jinai/jina-reranker-v2-base-multilingual/ < all files from this url - [https://huggingface.co/jinaai/jina-reranker-v2-base-multilingual/tree/main][1] >
该模型是一个句子对分类模型,针对多语言句子相似性/检索进行了微调。它不是通用文本生成模型,因此您不能这样加载它。因此,您应该使用
AutoModelForSequenceClassification
而不是 AutoModelForCausalLM
,请参阅 文档。
以下是如何使用它的示例:
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(
'jinaai/jina-reranker-v2-base-multilingual',
torch_dtype="auto",
trust_remote_code=True,
).to('cuda').eval()
candidates = ["the car goes fast", "the car goes slow", "the bicycle goes slow"]
sentence_pairs = [["the car drives fast", doc] for doc in candidates]
scores = model.compute_score(sentence_pairs, max_length=1024)
print(scores)
> [0.7217432260513306, 0.14128141105175018, 0.0384661927819252]
如果您想使用
AutoModelForCausalLM
来使用/微调模型,请查看huggingface上的文本生成模型列表:https://huggingface.co/models?pipeline_tag=text- Generation&sort=downloads