-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: peft training for llm embed finetuning
- Loading branch information
1 parent
cc5f5fa
commit fb6f376
Showing
18 changed files
with
274 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 评测 | ||
|
||
|
||
```python | ||
from typing import List, Union, Dict | ||
import numpy as np | ||
from retrievals import AutoModelForEmbedding | ||
|
||
|
||
class AutoModelForEmbeddingEval(AutoModelForEmbedding): | ||
def __init__(self, **kwargs): | ||
super(AutoModelForEmbeddingEval, self).__init__() | ||
|
||
def encode_queries(self, queries: List[str], **kwargs) -> np.ndarray: | ||
"""For MTEB eval | ||
This function will be used for retrieval task | ||
if there is an instruction for queries, we will add it to the query text | ||
""" | ||
if self.query_instruction is not None: | ||
input_texts = ['{}{}'.format(self.query_instruction, q) for q in queries] | ||
else: | ||
input_texts = queries | ||
return self.encode_from_text(input_texts, batch_size=4) | ||
|
||
def encode_corpus(self, corpus: List[Union[Dict[str, str], str]], **kwargs) -> np.ndarray: | ||
"""For MTEB eval | ||
This function will be used for retrieval task | ||
encode corpus for retrieval task | ||
""" | ||
if isinstance(corpus[0], dict): | ||
input_texts = ['{} {}'.format(doc.get('title', ''), doc['text']).strip() for doc in corpus] | ||
else: | ||
input_texts = corpus | ||
return self.encode_from_text(input_texts, batch_size=4) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
numpy | ||
numpy<=1.26.0 | ||
torch | ||
transformers | ||
accelerator | ||
peft | ||
datasets | ||
faiss-cpu==1.8.0 | ||
faiss-cpu | ||
scikit-learn | ||
tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from .data.collator import ( | ||
ColBertCollator, | ||
LLMRerankCollator, | ||
PairCollator, | ||
RerankCollator, | ||
TripletCollator, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.