dejanseo / gemma-embed

huggingface.co
Total runs: 0
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: June 28 2025
feature-extraction

Introduction of gemma-embed

Model Details of gemma-embed

Training Gemma-3-1B Embedding Model with LoRA

In our previous post, Training a Query Fan-Out Model , we demonstrated how to generate millions of high-quality query reformulations without human labelling, by navigating the embedding space between a seed query and its target document and then decoding each intermediate vector back into text using a trained query decoder.

That decoder's success critically depends on having an embedding encoder whose latent geometry is fully under our control: off-the-shelf models (e.g. mxbai embed large) optimize for general semantic similarity, not for invertibility, so their embeddings cannot reliably be mapped back into meaningful queries.

To bridge that gap, this article introduces Gemma-Embed , a bespoke 256-dim embedding model built by fine-tuning google/gemma-3-1b-pt with LoRA adapters and contrastive objectives. By training our own encoder, we lock in a consistent, L2-normalized latent space that the subsequent query decoder can invert with high fidelity.

Quick Recap of the Query Fan-Out Mission
  • Query Decoder : Train a T5-based model to invert a fixed retrieval encoder (e.g. GTR) so that any embedding vector produces the original query. Achieved ~96% cosine similarity on reconstruction.
  • Latent Space Traversal : For each (query, document) pair, interpolate in the embedding space, decode each point, and retain reformulations that improve retrieval metrics—yielding hundreds of thousands of synthetic examples.
  • Production Model (qsT5) : Fine-tune T5 on that synthetic dataset (with and without pseudo-relevance feedback) to internalize traversal patterns—so at inference time it generates diverse, effective reformulations without any explicit vector arithmetic.

Together, these steps automate query fan-out, boost retrieval performance, and open the door to interpretable, language-agnostic search suggestions.

To power a query fan‑out decoder that inverts embeddings back to natural language queries, we need an embedding encoder whose latent geometry we control. Since no off‑the‑shelf Gemma‑3 embedding model exists, we fine‑tune google/gemma‑3‑1b‑pt with LoRA and contrastive objectives to produce high‑quality, L2‑normalized 256‑dim embeddings.

Model Architecture
Base Encoder
  • google/gemma-3-1b-pt (1 B params)
LoRA Adapters
  • Target modules : q_proj , v_proj
  • Rank (r) : 8
  • Alpha (α) : 16
  • Dropout : 0.05
Projection Head
  • Input : hidden_size (1024)
  • MLP : Linear(1024→512) → ReLU → Linear(512→256)
  • L2 normalization
Data and Format
Phase 1 – Unsupervised SimCSE
  • Source : text.txt (wiki sentences or plain text logs)
  • Size : 579,719 sentences
  • Format : UTF‑8 plain text, one sequence per line
  • Sample lines :
    Breaking news: stock markets rally as central bank hints at rate cut.
    How do I fine‑tune a large language model for embeddings?
    The Northern Lights are visible tonight in high‑latitude regions.
    
Phase 2 – Supervised Paraphrase Contrastive
  • Source : triplets.csv
  • Columns : a_ids,a_mask,p_ids,p_mask,n_ids,n_mask (token IDs & masks)
  • Size : user‑provided paraphrase pairs (e.g., ParaNMT ~3.6 M, QuoraQP ~400 k, PAWS ~60 k)
  • Format : CSV with header. Each row:
    a_ids,a_mask,p_ids,p_mask,n_ids,n_mask
    102 345 ... ,1 1 ... ,203 456 ... ,1 1 ... ,307 523 ... ,1 1 ...
    
  • Original text pairs stored in scripts folder for reference.
Phase 3 – In‑Domain Self‑Contrast
  • Source : queries.db
    CREATE TABLE queries (
        query_id INTEGER PRIMARY KEY AUTOINCREMENT,
        query TEXT UNIQUE NOT NULL
    );
    
  • Size : 7,129,444 unique queries
  • Pretokenized : pretokenized_queries.pt
  • Tensors : input_ids (7,129,444 × 128), attention_mask (7,129,444 × 128)
  • File size : ~13.5 GB
  • Sample queries :
    SELECT query FROM queries LIMIT 5;
    How to bake sourdough at home?
    Weather tomorrow in Sydney
    Best restaurants near me open now
    convert 1 mile to kilometers
    streamlit file uploader example
    
Training Pipeline
Phase Objective Loss Batch Epochs LR Data Size
1 Unsupervised SimCSE InfoNCE (τ=0.05) 12 1 1e‑5 579,719 sentences
2 Supervised Triplet Contrastive TripletMarginLoss(0.2) 12 3 1e‑5 ~4 M triplets
3 In‑Domain Self‑Contrast InfoNCE (τ=0.05) 64 1 1e‑5 7,129,444 queries
File Layout
train-gemma/
├── text.txt
├── triplets.csv
├── queries.db
├── pretokenized_queries.pt
├── scripts/
│   ├── train_stage_1.py
│   ├── train_stage_2.py
│   ├── pretokenize_queries.py
│   └── train_stage_3.py
├── stage1_simcse/final/
├── phase2_triplet_amp/final/
└── phase3_self_contrast/final/
Sample Data Sizes
  • text.txt : 579,719 lines (~50 MB)
  • triplets.csv : depends on sources (~500 MB for 4 M rows)
  • queries.db : ~200 MB SQLite file
  • pretokenized_queries.pt : 13.5 GB
Inference Test

Inference Test Results

Runs of dejanseo gemma-embed on huggingface.co

0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About gemma-embed huggingface.co Model

gemma-embed huggingface.co

gemma-embed huggingface.co is an AI model on huggingface.co that provides gemma-embed's model effect (), which can be used instantly with this dejanseo gemma-embed model. huggingface.co supports a free trial of the gemma-embed model, and also provides paid use of the gemma-embed. Support call gemma-embed model through api, including Node.js, Python, http.

gemma-embed huggingface.co Url

https://huggingface.co/dejanseo/gemma-embed

dejanseo gemma-embed online free

gemma-embed huggingface.co is an online trial and call api platform, which integrates gemma-embed's modeling effects, including api services, and provides a free online trial of gemma-embed, you can try gemma-embed online for free by clicking the link below.

dejanseo gemma-embed online free url in huggingface.co:

https://huggingface.co/dejanseo/gemma-embed

gemma-embed install

gemma-embed is an open source model from GitHub that offers a free installation service, and any user can find gemma-embed on GitHub to install. At the same time, huggingface.co provides the effect of gemma-embed install, users can directly use gemma-embed installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

gemma-embed install url in huggingface.co:

https://huggingface.co/dejanseo/gemma-embed

Url of gemma-embed

gemma-embed huggingface.co Url

Provider of gemma-embed huggingface.co

dejanseo
ORGANIZATIONS

Other API from dejanseo

huggingface.co

Total runs: 423
Run Growth: 128
Growth Rate: 30.26%
Updated:November 20 2025
huggingface.co

Total runs: 60
Run Growth: 0
Growth Rate: 0.00%
Updated:August 15 2024
huggingface.co

Total runs: 46
Run Growth: 34
Growth Rate: 73.91%
Updated:August 15 2024
huggingface.co

Total runs: 36
Run Growth: 0
Growth Rate: 0.00%
Updated:July 10 2024
huggingface.co

Total runs: 32
Run Growth: -17
Growth Rate: -53.13%
Updated:November 20 2025
huggingface.co

Total runs: 30
Run Growth: 0
Growth Rate: 0.00%
Updated:July 09 2024
huggingface.co

Total runs: 27
Run Growth: 10
Growth Rate: 37.04%
Updated:April 25 2025
huggingface.co

Total runs: 26
Run Growth: 16
Growth Rate: 61.54%
Updated:September 04 2024
huggingface.co

Total runs: 24
Run Growth: 0
Growth Rate: 0.00%
Updated:July 17 2024
huggingface.co

Total runs: 20
Run Growth: 2
Growth Rate: 10.00%
Updated:April 22 2025
huggingface.co

Total runs: 17
Run Growth: 3
Growth Rate: 15.79%
Updated:July 05 2026
huggingface.co

Total runs: 12
Run Growth: -5
Growth Rate: -41.67%
Updated:August 15 2024
huggingface.co

Total runs: 12
Run Growth: 0
Growth Rate: 0.00%
Updated:July 26 2024
huggingface.co

Total runs: 10
Run Growth: 3
Growth Rate: 30.00%
Updated:April 17 2025
huggingface.co

Total runs: 10
Run Growth: 5
Growth Rate: 50.00%
Updated:June 14 2025
huggingface.co

Total runs: 10
Run Growth: 4
Growth Rate: 40.00%
Updated:April 09 2025
huggingface.co

Total runs: 6
Run Growth: 2
Growth Rate: 33.33%
Updated:April 17 2025
huggingface.co

Total runs: 5
Run Growth: 0
Growth Rate: 0.00%
Updated:May 10 2024
huggingface.co

Total runs: 3
Run Growth: 0
Growth Rate: 0.00%
Updated:June 29 2024
huggingface.co

Total runs: 3
Run Growth: -2
Growth Rate: -66.67%
Updated:September 17 2025
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:March 17 2025
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:May 17 2026