-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathyoutu_models.py
More file actions
154 lines (141 loc) · 6.08 KB
/
youtu_models.py
File metadata and controls
154 lines (141 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from __future__ import annotations
import logging
from functools import partial
from mteb.encoder_interface import PromptType
from mteb.model_meta import ModelMeta
from mteb.models.instruct_wrapper import InstructSentenceTransformerWrapper
logger = logging.getLogger(__name__)
youtu_instruction = {
"CmedqaRetrieval": {
"query": "Given a Chinese community medical question, retrieve replies that best answer the question",
"document": "",
},
"CovidRetrieval": {
"query": "Given a question on COVID-19, retrieve news articles that answer the question",
"document": "",
},
"DuRetrieval": {
"query": "Given a Chinese search query, retrieve web passages that answer the question",
"document": "",
},
"EcomRetrieval": {
"query": "Given a user query from an e-commerce website, retrieve description sentences of relevant products",
"document": "",
},
"MedicalRetrieval": {
"query": "Given a medical question, retrieve user replies that best answer the question",
"document": "",
},
"MMarcoRetrieval": {
"query": "Given a web search query, retrieve relevant passages that answer the query",
"document": "",
},
"T2Retrieval": {
"query": "Given a Chinese search query, retrieve web passages that answer the question",
"document": "",
},
"VideoRetrieval": {
"query": "Given a video search query, retrieve the titles of relevant videos",
"document": "",
},
"AFQMC": "Represent the text in conversations between users and financial customer service, retrieve semantically similar text",
"ATEC": "Represent the text in conversations between users and financial customer service, retrieve semantically similar text",
"BQ": "Represent the user problem descriptions when handling bank credit business, retrieve semantically similar text",
"LCQMC": "Represent the user question descriptions on general question-answering platforms, retrieve semantically similar text",
"PAWSX": "Represent the Chinese Translations of English Encyclopedias, retrieve semantically similar text",
"QBQTC": "Represent the web search query, retrieve semantically similar text",
"STSB": "Represent the short general domain sentences, retrieve semantically similar text",
"T2Reranking": {
"query": "Given a Chinese search query, retrieve web passages that answer the question",
"document": "",
},
"MMarcoReranking": {
"query": "Given a web search query, retrieve relevant passages that answer the query",
"document": "",
},
"CMedQAv1-reranking": {
"query": "Given a Chinese community medical question, retrieve replies that best answer the question",
"document": "",
},
"CMedQAv2-reranking": {
"query": "Given a Chinese community medical question, retrieve replies that best answer the question",
"document": "",
},
"Ocnli": "Retrieve semantically similar text",
"Cmnli": "Retrieve semantically similar text",
"TNews": "Classify the fine-grained category of the given news title",
"IFlyTek": "Given an App description text, find the appropriate fine-grained category",
"Waimai": "Classify the customer review from a food takeaway platform into positive or negative",
"OnlineShopping": "Classify the customer review for online shopping into positive or negative",
"JDReview": "Classify the customer review for iPhone on e-commerce platform into positive or negative",
"MultilingualSentiment": "Classify sentiment of the customer review into positive, neutral, or negative",
"CLSClusteringS2S": "Given the papers, find the appropriate fine-grained topic or theme based on the titles",
"CLSClusteringP2P": "Given the papers, find the appropriate fine-grained topic or theme based on the titles and abstracts",
"ThuNewsClusteringS2S": "Identify the topic or theme of the given news articles based on the titles",
"ThuNewsClusteringP2P": "Identify the topic or theme of the given news articles based on the titles and contents",
}
def instruction_template(
instruction: str, prompt_type: PromptType | None = None
) -> str:
if not instruction or prompt_type == PromptType.passage:
return ""
if isinstance(instruction, dict):
if prompt_type is None:
instruction = list(instruction.values())[0]
else:
instruction = instruction[prompt_type]
return f"Instruction: {instruction} \nQuery: "
training_data = {
"T2Retrieval": ["train"],
"DuRetrieval": ["train"],
"T2Reranking": ["train"],
"MMarcoReranking": ["train"],
"CMedQAv2-reranking": ["train"],
"BQ": ["train"],
"LCQMC": ["train"],
"PAWSX": ["train"],
"STS-B": ["train"],
"AFQMC": ["train"],
"Cmnli": ["train"],
"Ocnli": ["train"],
}
def youtu_models_loader(model_name_or_path, **kwargs):
return InstructSentenceTransformerWrapper(
model_name_or_path,
revision=kwargs.pop("revision", None),
instruction_template=instruction_template,
apply_instruction_to_passages=False,
prompts_dict=youtu_instruction,
trust_remote_code=True,
**kwargs,
)
model_name_or_path = "tencent/Youtu-Embedding"
Youtu_Embedding_V1 = ModelMeta(
name="tencent/Youtu-Embedding",
languages=["zho-Hans"],
revision=None,
release_date="2025-09-28",
loader=partial(
InstructSentenceTransformerWrapper,
model_name_or_path,
revision=None,
instruction_template=instruction_template,
apply_instruction_to_passages=True,
prompts_dict=youtu_instruction,
trust_remote_code=True,
max_seq_length=8192,
),
open_weights=True,
n_parameters=2672957440,
memory_usage_mb=None,
embed_dim=2048,
license="apache-2.0",
max_tokens=8192,
reference="https://huggingface.co/tencent/Youtu-Embedding",
similarity_fn_name="cosine",
framework=["Sentence Transformers", "PyTorch"],
use_instructions=True,
public_training_code=None,
public_training_data=None,
training_datasets=training_data,
)