🚀 Monarch Mixer-BERT
Monarch Mixer-BERT是来自论文Benchmarking and Building Long-Context Retrieval Models with LoCo and M2-BERT的M2-BERT-2k的80M检查点。该模型可用于生成用于检索的嵌入向量,为长上下文检索任务提供支持。
查看我们的 GitHub 以获取有关如何下载和微调该模型的说明!
🚀 快速开始
模型加载
你可以使用Hugging Face的 AutoModel
来加载此模型:
from transformers import AutoModelForMaskedLM, BertConfig
config = BertConfig.from_pretrained("hazyresearch/M2-BERT-2K-Retrieval-Encoder-V1")
model = AutoModelForMaskedLM.from_pretrained("hazyresearch/M2-BERT-2k-Retrieval-Encoder-V1", config=config, trust_remote_code=True)
分词器使用
此模型使用Hugging Face的 bert-base-uncased tokenizer
:
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
生成嵌入向量
该模型用于生成用于检索的嵌入向量,嵌入向量的维度为768:
from transformers import AutoTokenizer, AutoModelForMaskedLM, BertConfig
max_seq_length = 2048
testing_string = "Every morning, I make a cup of coffee to start my day."
config = BertConfig.from_pretrained("hazyresearch/M2-BERT-2K-Retrieval-Encoder-V1")
model = AutoModelForMaskedLM.from_pretrained("hazyresearch/M2-BERT-2k-Retrieval-Encoder-V1", config=config, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased", model_max_length=max_seq_length)
input_ids = tokenizer([testing_string], return_tensors="pt", padding="max_length", return_token_type_ids=False, truncation=True, max_length=max_seq_length)
outputs = model(**input_ids)
embeddings = outputs['sentence_embedding']
远程代码使用
此模型在调用 from_pretrained
方法时需要传入 trust_remote_code=True
。这是因为我们使用了自定义的PyTorch代码(详见我们的GitHub)。你可以考虑传入一个 revision
参数来指定代码的确切git提交版本,例如:
mlm = AutoModelForMaskedLM.from_pretrained(
"hazyresearch/M2-BERT-2k-Retrieval-Encoder-V1",
config=config,
trust_remote_code=True,
)
配置说明
请注意,use_flash_mm
默认值为 false
,目前暂不支持使用FlashMM。
📄 许可证
本项目采用Apache-2.0许可证。