Model reference · open weights

LENS-d4000

Available as managed deployment Embeddings yibinlei · community Embeddings 1 variants 532 dl/mo

LENS-d4000 is an open-weight embedding model from yibinlei. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.

Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.

What it is

Released byyibinlei
TypeEmbedding models
TaskEmbeddings
Parameters (lead)7.1B
Context32k tokens
Runs withtransformers
Released2024-12-30
Popularity532 downloads / month
LicenceOpen weights

About

What LENS-d4000 is

LENS is a model that produces Lexicon-based EmbeddiNgS (LENS) leveraging large language models. Each dimension of the embeddings is designed to correspond to a token cluster where semantically similar tokens are grouped together. These embeddings have a similar feature size as dense embeddings, with LENS-d4000 offering 4000-dimensional representations.

The technical report of LENS is available in Enhancing Lexicon-Based Text Embeddings with Large Language Models.

Read the full model card

Usage

git clone https://huggingface.co/yibinlei/LENS-d4000
cd LENS-d4000
import torch
from torch import Tensor
import torch.nn.functional as F
from transformers import AutoTokenizer
from bidirectional_mistral import MistralBiForCausalLM

def get_detailed_instruct(task_instruction: str, query: str) -> str:
    return f'{task_instruction}\n{query}'

def pooling_func(vecs: Tensor, pooling_mask: Tensor) -> Tensor:
    # We use max-pooling for LENS.
    return torch.max(torch.log(1 + torch.relu(vecs)) * pooling_mask.unsqueeze(-1), dim=1).values

# Prepare the data
instruction = "Given a web search query, retrieve relevant passages that answer the query."
queries = ["what is rba",
           "what is oilskin fabric"]
instructed_queries = [get_detailed_instruct(instruction, query) for query in queries]
docs = ["Since 2007, the RBA's outstanding reputation has been affected by the 'Securency' or NPA scandal.",
        "Today's oilskins (or oilies) typically come in two parts, jackets and trousers. Oilskin jackets are generally similar to common rubberized waterproofs."]

# Load the model and tokenizer
model = MistralBiForCausalLM.from_pretrained("yibinlei/LENS-d4000", ignore_mismatched_sizes=True)
model.lm_head = torch.load('lm_head.pth')
tokenizer = AutoTokenizer.from_pretrained("yibinlei/LENS-d4000")

# Preprocess the data
query_max_len, doc_max_len = 512, 512
instructed_query_inputs = tokenizer(
                instructed_queries,
                padding=True,
                truncation=True,
                return_tensors='pt',
                max_length=query_max_len,
                add_special_tokens=True
            )
doc_inputs = tokenizer(
                docs,
                padding=True,
                truncation=True,
                return_tensors='pt',
                max_length=doc_max_len,
                add_special_tokens=True
            )
# We perform pooling exclusively on the outputs of the query tokens, excluding outputs from the instruction.
query_only_mask = torch.zeros_like(instructed_query_inputs['input_ids'], dtype=instructed_query_inputs['attention_mask'].dtype)
special_token_id = tokenizer.convert_tokens_to_ids('')
for idx, seq in enumerate(instructed_query_inputs['input_ids']):
    special_pos = (seq == special_token_id).nonzero()
    if len(special_pos) > 0:
        query_start_pos = special_pos[-1].item()
        query_only_mask[idx, query_start_pos:-2] = 1
    else:
        raise ValueError("No special token found")

# Obtain the embeddings
with torch.no_grad():
    instructed_query_outputs = model(**instructed_query_inputs)
    query_embeddings = pooling_func(instructed_query_outputs, query_only_mask)
    doc_outputs = model(**doc_inputs)
    # As the output of each token is used for predicting the next token, the pooling mask is shifted left by 1. The output of the final token EOS token is also excluded.
    doc_inputs['attention_mask'][:, -2:] = 0
    doc_embeddings = pooling_func(doc_outputs, doc_inputs['attention_mask'])

# Normalize the embeddings
query_embeddings = F.normalize(query_embeddings, p=2, dim=1)
doc_embeddings = F.normalize(doc_embeddings, p=2, dim=1)

# Compute the similarity
similarity = torch.matmul(query_embeddings, doc_embeddings.T)

From the published model card. Full card on the HuggingFace links in the sidebar.

Benchmarks

Reported results

As published on the model card — the maker's own numbers, not measured by AxForge.

TaskDatasetMetricScore
ClassificationMTEB AmazonCounterfactualClassification (en)accuracy93.612
ClassificationMTEB AmazonCounterfactualClassification (en)ap73.894
ClassificationMTEB AmazonCounterfactualClassification (en)ap_weighted73.894
ClassificationMTEB AmazonCounterfactualClassification (en)f190.317
ClassificationMTEB AmazonCounterfactualClassification (en)f1_weighted93.756
ClassificationMTEB AmazonCounterfactualClassification (en)main_score93.612
ClassificationMTEB AmazonPolarityClassification (default)accuracy97.055
ClassificationMTEB AmazonPolarityClassification (default)ap95.531
ClassificationMTEB AmazonPolarityClassification (default)ap_weighted95.531
ClassificationMTEB AmazonPolarityClassification (default)f197.054
ClassificationMTEB AmazonPolarityClassification (default)f1_weighted97.054
ClassificationMTEB AmazonPolarityClassification (default)main_score97.055
ClassificationMTEB AmazonReviewsClassification (en)accuracy62.834
ClassificationMTEB AmazonReviewsClassification (en)f161.459
ClassificationMTEB AmazonReviewsClassification (en)f1_weighted61.459
ClassificationMTEB AmazonReviewsClassification (en)main_score62.834
RetrievalMTEB ArguAna (default)main_score77.317
RetrievalMTEB ArguAna (default)map_at_156.757
RetrievalMTEB ArguAna (default)map_at_1071.136
RetrievalMTEB ArguAna (default)map_at_10071.339
RetrievalMTEB ArguAna (default)map_at_100071.340
RetrievalMTEB ArguAna (default)map_at_2071.314
RetrievalMTEB ArguAna (default)map_at_368.670
RetrievalMTEB ArguAna (default)map_at_570.274

Using it via the API

Call it like any OpenAI endpoint

Once AxForge deploys lens-d4000 for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (lens-d4000 below is illustrative; you get the exact model name on deployment.)

$ curl -sS https://api.axforge.ai/v1/embeddings \
  -H "Authorization: Bearer $AXFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"lens-d4000","input":"text to embed"}'

Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.

© 2026 AxForge · EU-hosted AI infrastructure Pricing Docs Trust Privacy Terms