CoolFace
Modelpublic

codefuse-ai/F2LLM-v2-0.6B

sourceHugging Faceapache-2.0updated 22d agoView on Hugging Face
16likes8.5kdownloads
README.md241 linesDownload Raw Back to root
1---2license: apache-2.03language:4- en5- zh6- ru7- es8- fr9- de10- ar11- nl12- vi13- hi14- ko15- ja16- it17- id18- pt19- pl20- tr21- da22- th23- sv24- fa25- uk26- cs27- 'no'28- el29- ca30- ro31- fi32- bg33- tl34- gl35- my36- hy37- km38- ne39- hu40- eu41- he42- lo43- sw44- az45- lv46- si47- sk48- tg49- et50- lt51- ms52- hr53- is54- sl55- sr56- ur57- bn58- af59- ta60- ka61- te62- ml63- mn64- nn65- kk66- cy67- mr68- sq69- nb70- mk71- jv72- kn73- eo74- la75- gu76- uz77- am78- oc79- be80- mg81- vo82- pa83- lb84- ht85- br86- ga87- xh88- tt89- bs90- yo91base_model:92- codefuse-ai/F2LLM-v2-0.6B-Preview93pipeline_tag: feature-extraction94library_name: transformers95tags:96- sentence-transformers97datasets:98- codefuse-ai/F2LLM-v299---100 101# F2LLM-v2-0.6B102 103F2LLM-v2 is a family of general-purpose, multilingual embedding models in 8 distinct sizes ranging from 80M to 14B. Trained on a curated composite of 60 million publicly available high-quality data, F2LLM-v2 supports more than 200 languages, with a particular emphasis on previously underserved mid- and low-resource languages.104 105F2LLM-v2 is fully open. We release base models in 5 sizes, instruct models in 8 sizes, the training data, the training code, and intermediate checkpoints. The three smallest instruct models are pruned and trained from the 0.6B base model.106 107| Model | Base                                                                                | Instruct                                                            |108| ----- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------- |109| 80M   |                                                                                     | [🤗F2LLM-v2-80M](https://huggingface.co/codefuse-ai/F2LLM-v2-80M)   |110| 160M  |                                                                                     | [🤗F2LLM-v2-160M](https://huggingface.co/codefuse-ai/F2LLM-v2-160M) |111| 330M  |                                                                                     | [🤗F2LLM-v2-330M](https://huggingface.co/codefuse-ai/F2LLM-v2-330M) |112| 0.6B  | [🤗F2LLM-v2-0.6B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B-Preview) | [🤗F2LLM-v2-0.6B](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B) |113| 1.7B  | [🤗F2LLM-v2-1.7B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-1.7B-Preview) | [🤗F2LLM-v2-1.7B](https://huggingface.co/codefuse-ai/F2LLM-v2-1.7B) |114| 4B    | [🤗F2LLM-v2-4B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-4B-Preview)     | [🤗F2LLM-v2-4B](https://huggingface.co/codefuse-ai/F2LLM-v2-4B)     |115| 8B    | [🤗F2LLM-v2-8B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-8B-Preview)     | [🤗F2LLM-v2-8B](https://huggingface.co/codefuse-ai/F2LLM-v2-8B)     |116| 14B   | [🤗F2LLM-v2-14B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-14B-Preview)   | [🤗F2LLM-v2-14B](https://huggingface.co/codefuse-ai/F2LLM-v2-14B)   |117 118## Performance119 120The F2LLM-v2 family set a new state-of-the-art on a wide range of MTEB benchmarks, including Code, European, Scandinavian, German, French, Spanish, Polish, Dutch, Japanese, Vietnamese, Thai, Indic, Persian, among others.121 122<img src="img/performance.png" width="100%" alt="Performance">123 124For details, refer to the [MTEB leaderboard](https://huggingface.co/spaces/mteb/leaderboard).125 126## Usage127 128### With Sentence Transformers129 130To encode text with the [Sentence Transformers](https://www.sbert.net/) library:131 132```python133from sentence_transformers import SentenceTransformer134model = SentenceTransformer("codefuse-ai/F2LLM-v2-0.6B", device="cuda:0", model_kwargs={"torch_dtype": "bfloat16"})135# Some sample query and documents136query = "What is F2LLM used for?"137documents = [138    'We present F2LLM, a family of fully open embedding LLMs that achieve a strong balance between model size, training data, and embedding performance.',139    'F2LLM is a model for computing text embeddings that can be used for various NLP tasks such as information retrieval, semantic search, and text classification.',140    'F2LLM 是 CodeFuse 开源的系列嵌入模型。',141    'F2LLM — это модель вычисления встраивания текста, которую можно использовать для различных задач НЛП, таких как поиск информации, семантический поиск и классификация текста.'142]143# Encode the query and documents separately. The encode_query method uses the query prompt144query_embedding = model.encode_query(query)145document_embeddings = model.encode_document(documents)146print(query_embedding.shape, document_embeddings.shape)147# (1024,) (4, 1024)148# Compute cosine similarity between the query and documents149similarity = model.similarity(query_embedding, document_embeddings)150print(similarity)151# tensor([[0.5978, 0.8532, 0.7953, 0.8431]])152```153 154### With Transformers155 156Or directly with the [Transformers](https://huggingface.co/docs/transformers/index) library:157 158```python159from transformers import AutoModel, AutoTokenizer160import torch161import torch.nn.functional as F162model_path = "codefuse-ai/F2LLM-v2-0.6B"163tokenizer = AutoTokenizer.from_pretrained(model_path)164model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map={'': 0})165query = "What is F2LLM used for?"166query_prompt = "Instruct: Given a question, retrieve passages that can help answer the question.\nQuery: "167documents = [168    'We present F2LLM, a family of fully open embedding LLMs that achieve a strong balance between model size, training data, and embedding performance.',169    'F2LLM is a model for computing text embeddings that can be used for various NLP tasks such as information retrieval, semantic search, and text classification.',170    'F2LLM 是 CodeFuse 开源的系列嵌入模型。',171    'F2LLM — это модель вычисления встраивания текста, которую можно использовать для различных задач НЛП, таких как поиск информации, семантический поиск и классификация текста.'172]173def encode(sentences):174    batch_size = len(sentences)175    # the tokenizer will automatically add eos token176    tokenized_inputs = tokenizer(sentences, padding=True, return_tensors='pt').to(model.device)177    last_hidden_state = model(**tokenized_inputs).last_hidden_state178    eos_positions = tokenized_inputs.attention_mask.sum(dim=1) - 1179    embeddings = last_hidden_state[torch.arange(batch_size, device=model.device), eos_positions]180    embeddings = F.normalize(embeddings, p=2, dim=1)181    return embeddings182# Encode the query and documents183query_embedding = encode([query_prompt + query])184document_embeddings = encode(documents)185print(query_embedding.shape, document_embeddings.shape)186# torch.Size([1, 1024]) torch.Size([4, 1024])187# Compute cosine similarity between the query and documents188similarity = query_embedding @ document_embeddings.T189print(similarity)190# tensor([[0.5938, 0.8555, 0.7969, 0.8438]], device='cuda:0',191#        dtype=torch.bfloat16, grad_fn=<MmBackward0>)192```193 194### Prompts195 196The model supports custom instructions in the following format:197 198```text199Instruct: your_instruction200Query:201```202 203In general, for retrieval and reranking tasks:204 205- use the prompt for queries206- do not prepend the prompt to documents/passages207 208For symmetric tasks such as STS, clustering, and bitext mining, you can encode the documents either with or without prompts. The model is trained to support both scenarios.209 210### MRL Support211 212This model is trained with Matryoshka Representation Learning (MRL), allowing for a superior tradeoff between performance and embedding size. You can truncate the embeddings to keep only the first `d` dimensions to reduce storage and speed up vector search in downstream systems. The model is trained with a smallest Matryoshka dimension of 8.213 214<img src="img/mrl.png" width="80%" alt="MRL results">215 216Example:217```python218embedding = embedding[..., :128]219embedding = torch.nn.functional.normalize(embedding, p=2, dim=-1)220```221> Note: you need to apply normalization **after** trucation, not the other way around.222 223If you are using sentence transformer, you can also simply pass `truncate_dim=128` to the encode interface.224 225## Intermediate Checkpoints226 227To facilitate future research, we release intermediate checkpoints in the `intermediate_checkpoints` branch.228 229## Citation230 231```232@misc{f2llm-v2,233      title={F2LLM-v2: Inclusive, Performant, and Efficient Embeddings for a Multilingual World}, 234      author={Ziyin Zhang and Zihan Liao and Hang Yu and Peng Di and Rui Wang},235      year={2026},236      eprint={2603.19223},237      archivePrefix={arXiv},238      primaryClass={cs.CL},239      url={https://arxiv.org/abs/2603.19223}, 240}241```