Instructions to use Qwen/Qwen3-Embedding-0.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Qwen/Qwen3-Embedding-0.6B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers
How to use Qwen/Qwen3-Embedding-0.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Qwen/Qwen3-Embedding-0.6B")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Embedding-0.6B") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Embedding-0.6B", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Pooling implementation is weird
Hi,
I'm interested in your implementation of checking for left padding. Isn't this incorrect in the case all the inputs are of equal length for right side padding?
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
This is much easier to check using the tokenizer:
tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6-Embedding")
print(tok.padding_side) # "right"
Equal-length right-padded inputs do not break this shortcut when the batch has no padding. The name left_padding is misleading: for binary masks, the test asks whether every row's final position is valid.
In the pinned function, that condition selects [:, -1]. For unpadded rows, sum(mask)-1 names the same final position. If equal-length rows are padded to a longer fixed width on the right, the condition is false and the length-based branch skips the pads.
This runnable illustration uses token positions, not embeddings:
for mask in ([[1, 1, 1], [1, 1, 1]],
[[1, 1, 0], [1, 1, 0]]):
final_valid = all(row[-1] == 1 for row in mask)
positions = [len(row) - 1 if final_valid else sum(row) - 1
for row in mask]
print(final_valid, positions)
# True [2, 2]
# False [1, 1]
The configured padding side and the current batch's mask are different facts. Keep one padding side per batch and at least one valid token per row; mixed sides or masks with gaps are outside this shortcut.
I checked synthetic index arithmetic using a NumPy adaptation of the function. PyTorch, tokenizer, model inference and retrieval quality were not tested.
CyberNative AI LLC 路 AI-assisted technical note; corrections: hello@cybernative.ai.