CoolFace
Modelpublic

Alibaba-NLP/LaSER-Qwen3-8B

sourceHugging Facemitupdated 6mo agoView on Hugging Face
6likes150downloads
Model Card

LaSER-Qwen3-8B

LaSER (Latent Space Explicit Reasoning) is a self-distillation framework that internalizes explicit Chain-of-Thought reasoning into the latent space of dense retrievers, enabling the model to "think silently" through continuous latent tokens.

LaSER-Qwen3-8B is the flagship 8B-parameter dense retriever built on Qwen/Qwen3-8B, achieving state-of-the-art performance on reasoning-intensive retrieval benchmarks.

๐Ÿ“„ Paper: LaSER: Internalizing Explicit Reasoning into Latent Space for Dense Retrieval ๐Ÿ’ป Code: https://github.com/ignorejjj/LaSER

Model Summary

AttributeDetail
Model TypeDense Retriever with Latent Thinking
Base ModelQwen/Qwen3-8B
Parameters8B
Embedding Dimension4096
Max Sequence Length8192 (training: 512)
Similarity FunctionCosine Similarity
Latent Thinking Steps (K)3 (default)
Training Data81K examples from ReasonEmb
LicenseMIT

Highlights

  • โ€”29.3 nDCG@10 on BRIGHT โ€” surpasses computationally expensive rewrite-then-retrieve pipelines (28.1) while being ~300ร— faster
  • โ€”State-of-the-art across BRIGHT, FollowIR, and BrowseComp-Plus benchmarks
  • โ€”Only ~1.7ร— latency overhead compared to standard single-pass dense retrievers

How It Works

Unlike standard dense retrievers that encode queries in a single forward pass, LaSER generates K continuous latent thinking tokens autoregressively in the embedding space:

  1. 1.Encode the input text into embeddings
  2. 2.At each thinking step, project the last hidden state through the LM head โ†’ softmax โ†’ compute a probability-weighted soft token from the embedding table
  3. 3.Append the soft token and repeat for K steps (using KV caching for efficiency)
  4. 4.Mean-pool the hidden states from all K thinking steps โ†’ L2 normalize

This enables complex reasoning while maintaining the inference efficiency of standard dense retrievers (~1.7ร— latency overhead, only ~0.3% of rewrite-then-retrieve pipelines).

Usage

Direct Usage with Transformers

python
import torch
import torch.nn.functional as F
from transformers import AutoModelForCausalLM, AutoTokenizer


def laser_encode(model, tokenizer, texts, max_length=512, num_thinking_steps=3):
    """Encode texts using LaSER's latent thinking mechanism."""
    device = next(model.parameters()).device
    batch = tokenizer(texts, padding=True, truncation=True, max_length=max_length, return_tensors="pt").to(device)
    input_ids, attention_mask = batch["input_ids"], batch["attention_mask"]

    batch_size = input_ids.size(0)
    thinking_slots = num_thinking_steps - 1
    eos_id = tokenizer.eos_token_id

    if thinking_slots > 0:
        eos_padding = torch.full((batch_size, thinking_slots), eos_id, dtype=input_ids.dtype, device=device)
        mask_padding = torch.ones((batch_size, thinking_slots), dtype=attention_mask.dtype, device=device)
        input_ids = torch.cat([input_ids, eos_padding], dim=1)
        attention_mask = torch.cat([attention_mask, mask_padding], dim=1)

    input_embeds = model.get_input_embeddings()(input_ids)
    embedding_table = model.get_input_embeddings().weight
    base_seq_len = input_embeds.size(1) - thinking_slots

    past_key_values = None
    hidden_steps = []

    for step_idx in range(thinking_slots):
        pos = base_seq_len + step_idx
        step_embeds = input_embeds[:, :pos, :] if past_key_values is None else input_embeds[:, pos-1:pos, :]
        step_mask = attention_mask[:, :pos]

        outputs = model(inputs_embeds=step_embeds, attention_mask=step_mask,
                       output_hidden_states=True, past_key_values=past_key_values,
                       use_cache=True, return_dict=True)
        hidden_steps.append(outputs.hidden_states[-1][:, -1, :])
        token_probs = torch.softmax(outputs.logits[:, -1, :], dim=-1)
        new_embed = token_probs @ embedding_table
        past_key_values = outputs.past_key_values
        pre = input_embeds[:, :pos, :]
        post = input_embeds[:, pos+1:, :]
        input_embeds = torch.cat([pre, new_embed.unsqueeze(1), post], dim=1)

    final_embeds = input_embeds[:, -1:, :] if past_key_values else input_embeds
    outputs = model(inputs_embeds=final_embeds, attention_mask=attention_mask,
                   output_hidden_states=True, past_key_values=past_key_values,
                   use_cache=True, return_dict=True)
    hidden_steps.append(outputs.hidden_states[-1][:, -1, :])

    embeddings = torch.stack(hidden_steps, dim=1).mean(dim=1)
    return F.normalize(embeddings, p=2, dim=-1)


# Load model
model_name = "Alibaba-NLP/LaSER-Qwen3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.padding_side = "left"
if tokenizer.pad_token_id is None:
    tokenizer.pad_token = tokenizer.eos_token

model = AutoModelForCausalLM.from_pretrained(
    model_name, torch_dtype=torch.float16, trust_remote_code=True
).cuda().eval()

# Encode queries and documents
with torch.inference_mode():
    query_emb = laser_encode(model, tokenizer, ["why is the sky blue"], num_thinking_steps=3)
    doc_emb = laser_encode(model, tokenizer, ["Rayleigh scattering makes short wavelengths scatter more strongly"], num_thinking_steps=3)

# Compute similarity
similarity = (query_emb @ doc_emb.T).item()
print(f"Cosine similarity: {similarity:.4f}")

Batch Encoding

python
queries = [
    "What causes tides in the ocean?",
    "How does photosynthesis convert light to energy?",
    "Why do metals conduct electricity?",
]

with torch.inference_mode():
    query_embeddings = laser_encode(model, tokenizer, queries, num_thinking_steps=3)
    print(f"Batch embeddings shape: {query_embeddings.shape}")  # (3, 4096)

Evaluation Results

BRIGHT Benchmark (nDCG@10) โ€” In-Domain

ModelSizeBio.Earth.Econ.Psy.Rob.Stack.Sus.Leet.PonyAoPSTheoQ.TheoT.**Avg.**
Qwen3-Embedding-8B8B14.717.915.519.99.112.916.517.40.82.516.824.514.0
Fair Baseline (Qwen3-8B)8B49.751.226.937.423.428.034.13.73.22.816.831.825.7
Rewrite-then-Retrieve (Qwen3-8B) โ€ 8B53.154.332.134.820.531.132.23.215.24.117.438.828.1
GIRCSE (Qwen3-8B)8B59.056.527.240.319.028.531.43.23.61.714.027.226.0
LaSER-Qwen3-8B (Ours)8B58.448.128.040.917.029.928.31.75.91.514.619.229.3

FollowIR Benchmark โ€” Out-of-Domain

ModelSizeRobust04 MAP@5News21 nDCG@5Core17 MAP@5Scorep-MRR
Fair Baseline (Qwen3-8B)8B2.818.911.211.01.7
GIRCSE (Qwen3-8B)8B3.022.68.511.42.0
LaSER-Qwen3-8B (Ours)8B4.121.811.411.41.3

BrowseComp-Plus Benchmark โ€” Out-of-Domain

ModelSizeR@5R@100R@1000
Fair Baseline (Qwen3-8B)8B11.337.463.2
GIRCSE (Qwen3-8B)8B13.040.868.1
LaSER-Qwen3-8B (Ours)8B6.826.854.9

Latency Analysis (Single A100, Batch Size 8)

MethodLatency (ms)BRIGHT nDCG@10
Basic Retriever (8B)~30 ms25.7
Rewrite-then-Retrieve (8B)~4000 ms28.1
LaSER (8B)~50 ms29.3
LaSER achieves the best performance while incurring only ~1.7ร— latency over the basic retriever, compared to ~130ร— for rewrite-then-retrieve pipelines.

Training Details

  • โ€”Training Data: 81K query-document pairs from ReasonEmb, each with a CoT reasoning path generated by GPT-4o-mini
  • โ€”Method: LoRA fine-tuning (r=64, ฮฑ=32) for 1 epoch on 4ร—A100 GPUs
  • โ€”Loss: Contrastive learning + Output-level KL distillation (ฮปโ‚‚=10) + Process-level trajectory alignment (ฮปโ‚ƒ=0.1)
  • โ€”Temperature: ฯ„=0.02
  • โ€”Thinking Steps: K=3

Model Family

ModelParametersBRIGHT Avg.Link
LaSER-Qwen3-0.6B0.6B23.1๐Ÿค— Link
LaSER-Qwen3-4B4B28.0๐Ÿค— Link
LaSER-Qwen3-8B8B29.3๐Ÿค— This model

Citation

bibtex
@article{jin2026laser,
  title={LaSER: Internalizing Explicit Reasoning into Latent Space for Dense Retrieval},
  author={Jin, Jiajie and Zhang, Yanzhao and Li, Mingxin and Long, Dingkun and Xie, Pengjun and Zhu, Yutao and Dou, Zhicheng},
  year={2026},
  journal={arXiv preprint},
  url={https://arxiv.org/abs/2603.01425},
}