Instructions to use Elvis-t9/CGE-test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Elvis-t9/CGE-test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Elvis-t9/CGE-test", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Elvis-t9/CGE-test", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update modeling_cge2.py
Browse files- modeling_cge2.py +6 -1
modeling_cge2.py
CHANGED
|
@@ -493,7 +493,12 @@ class CgeForEmbedding(CGEModel):
|
|
| 493 |
all_embeddings = all_embeddings[0]
|
| 494 |
return all_embeddings
|
| 495 |
|
| 496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
def encode(self, sentences, batch_size=16, convert_to_numpy=False,
|
| 498 |
convert_to_tensor=True, show_progress_bar=True, max_seq_length=None, **kwargs):
|
| 499 |
if max_seq_length is None:
|
|
|
|
| 493 |
all_embeddings = all_embeddings[0]
|
| 494 |
return all_embeddings
|
| 495 |
|
| 496 |
+
def forward(self, input_ids: torch.Tensor, attention_mask: torch.Tensor):
|
| 497 |
+
outputs = self.plm_model(input_ids, attention_mask, output_hidden_states=True)
|
| 498 |
+
hidden_states = outputs.hidden_states[self.keep_max_layer]
|
| 499 |
+
embeddings = self.get_sentence_embedding(self.embedding_method, hidden_states, 'disc', attention_mask)
|
| 500 |
+
return {"sentence_embeddings": embeddings}
|
| 501 |
+
|
| 502 |
def encode(self, sentences, batch_size=16, convert_to_numpy=False,
|
| 503 |
convert_to_tensor=True, show_progress_bar=True, max_seq_length=None, **kwargs):
|
| 504 |
if max_seq_length is None:
|