Run this model with HF Jobs
Run openbmb/MiniCPM-Reranker on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/openbmb/MiniCPM-Reranker. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/openbmb/MiniCPM-Reranker on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use openbmb/MiniCPM-Reranker with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-Reranker with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="openbmb/MiniCPM-Reranker", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("openbmb/MiniCPM-Reranker", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files88 unmodified lines8990919292939495969798991001011021031049610510610710810911011111211311411511611711811997981229910010112510210310410510610710825 unmodified lines13413513615713713816016116216316416516616716816917017117217317417517617717817918018118218318413914018618714114214314414514614788 unmodified lines#### Huggingface Transformers
```pythonfrom transformers import AutoModel, LlamaTokenizer, AutoModelForSequenceClassificationfrom transformers import AutoModelForSequenceClassification, AutoTokenizerimport torchimport numpy as np
# from https://github.com/huggingface/transformers/blob/v4.44.2/src/transformers/models/xlm_roberta/tokenization_xlm_roberta.pyclass MiniCPMRerankerLLamaTokenizer(LlamaTokenizer): def build_inputs_with_special_tokens( self, token_ids_0, token_ids_1 = None ): """ - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s> B`
Args: token_ids_0 (`List[int]`): List of IDs to which the special tokens will be added. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs.
Returns: `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens. """
if token_ids_1 is None: return super().build_inputs_with_special_tokens(token_ids_0) bos = [self.bos_token_id] sep = [self.eos_token_id] return bos + token_ids_0 + sep + token_ids_1
model_name = "openbmb/MiniCPM-Reranker"tokenizer = MiniCPMRerankerLLamaTokenizer.from_pretrained(model_name, trust_remote_code=True)tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)tokenizer.padding_side = "right"
model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True,attn_implementation="flash_attention_2", torch_dtype=torch.float16).to("cuda")model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).to("cuda")# You can also use the following code to use flash_attention_2# model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True,attn_implementation="flash_attention_2", torch_dtype=torch.float16).to("cuda")
model.eval()
@torch.no_grad()25 unmodified lines
```pythonfrom sentence_transformers import CrossEncoderfrom transformers import LlamaTokenizerimport torch
# from https://github.com/huggingface/transformers/blob/v4.44.2/src/transformers/models/xlm_roberta/tokenization_xlm_roberta.pyclass MiniCPMRerankerLLamaTokenizer(LlamaTokenizer): def build_inputs_with_special_tokens( self, token_ids_0, token_ids_1 = None ): """ - single sequence: `<s> X </s>` - pair of sequences: `<s> A </s> B`
Args: token_ids_0 (`List[int]`): List of IDs to which the special tokens will be added. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs.
Returns: `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens. """
if token_ids_1 is None: return super().build_inputs_with_special_tokens(token_ids_0) bos = [self.bos_token_id] sep = [self.eos_token_id] return bos + token_ids_0 + sep + token_ids_1
#model_name = "openbmb/MiniCPM-Reranker"model = CrossEncoder(model_name,max_length=1024,trust_remote_code=True, automodel_args={"attn_implementation":"flash_attention_2","torch_dtype": torch.float16})model.tokenizer = MiniCPMRerankerLLamaTokenizer.from_pretrained(model_name, trust_remote_code=True)model = CrossEncoder(model_name,max_length=1024,trust_remote_code=True, automodel_args={"torch_dtype": torch.float16})# You can also use the following code to use flash_attention_2#model = CrossEncoder(model_name,max_length=1024,trust_remote_code=True, automodel_args={"attn_implementation":"flash_attention_2","torch_dtype": torch.float16})
model.tokenizer.padding_side = "right"
query = "中国的首都是哪里?"README.md+12-55