Run this model with HF Jobs
Run ronig/protein_biencoder 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/ronig/protein_biencoder. 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/ronig/protein_biencoder 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 ronig/protein_biencoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ronig/protein_biencoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="ronig/protein_biencoder", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("ronig/protein_biencoder", trust_remote_code=True) model = AutoModel.from_pretrained("ronig/protein_biencoder", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
updating model peptriever_2023-06-23T16:07:24.508460
Browse filesFiles changed (2)
- bi_encoder.pyAdded+64
- config.json+4
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364from transformers import PreTrainedModelfrom transformers.models.bert.modeling_bert import BertOnlyMLMHead
from peptriever.model.bert_embedding import BertEmbeddingConfig, BertForEmbedding
class BiEncoderConfig(BertEmbeddingConfig): max_length1: int max_length2: int
class BiEncoder(PreTrainedModel): config_class = BiEncoderConfig
def __init__(self, config: BiEncoderConfig): super().__init__(config) config1 = _replace_max_length(config, "max_length1") self.bert1 = BertForEmbedding(config1) config2 = _replace_max_length(config, "max_length2") self.bert2 = BertForEmbedding(config2) self.post_init()
def forward(self, x1, x2): y1 = self.forward1(x1) y2 = self.forward2(x2) return {"y1": y1, "y2": y2}
def forward2(self, x2): y2 = self.bert2(input_ids=x2["input_ids"]) return y2
def forward1(self, x1): y1 = self.bert1(input_ids=x1["input_ids"]) return y1
class BiEncoderWithMaskedLM(PreTrainedModel): config_class = BiEncoderConfig
def __init__(self, config: BiEncoderConfig): super().__init__(config=config) config1 = _replace_max_length(config, "max_length1") self.bert1 = BertForEmbedding(config1) self.lm_head1 = BertOnlyMLMHead(config=config1)
config2 = _replace_max_length(config, "max_length2") self.bert2 = BertForEmbedding(config2) self.lm_head2 = BertOnlyMLMHead(config=config2) self.post_init()
def forward(self, x1, x2): y1, state1 = self.bert1.forward_with_state(input_ids=x1["input_ids"]) y2, state2 = self.bert2.forward_with_state(input_ids=x2["input_ids"]) scores1 = self.lm_head1(state1) scores2 = self.lm_head2(state2) outputs = {"y1": y1, "y2": y2, "scores1": scores1, "scores2": scores2} return outputs
def _replace_max_length(config, length_key): c1 = config.__dict__.copy() c1["max_position_embeddings"] = c1.pop(length_key) config1 = BertEmbeddingConfig(**c1) return config13 unmodified lines4567893 unmodified lines"BiEncoder"],"attention_probs_dropout_prob": 0.1,"classifier_dropout": null,"distance_func": "euclidean","hidden_act": "gelu",3 unmodified lines456789101112133 unmodified lines"BiEncoder"],"attention_probs_dropout_prob": 0.1,"auto_map": {"AutoConfig": "bi_encoder.BiEncoderConfig","AutoModel": "bi_encoder.BiEncoder"},"classifier_dropout": null,"distance_func": "euclidean","hidden_act": "gelu",
bi_encoder.pyAdded+64
config.json+4