MoD-Embedding
231
license:apache-2.0
by
bflhc
Embedding Model
OTHER
New
231 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
Unknown
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Code Examples
Compute similaritypythontransformers
from transformers import AutoModel, AutoTokenizer
import torch
import torch.nn.functional as F
tokenizer = AutoTokenizer.from_pretrained("bflhc/MoD-Embedding", padding_side='left')
model = AutoModel.from_pretrained("bflhc/MoD-Embedding")
model.eval()
def encode(texts):
inputs = tokenizer(texts, padding=True, truncation=True,
max_length=8192, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
# Use last token embedding
embeddings = outputs.last_hidden_state[:, -1, :]
# Normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
return embeddings
# Example usage
texts = ["Hello world", "你好世界"]
embeddings = encode(texts)
similarity = torch.matmul(embeddings[0], embeddings[1])
print(f"Similarity: {similarity.item():.4f}")Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.