Views
No views yet
1from transformers import AutoModel, AutoTokenizer
2
3model_name = "sayed0am/arabic-english-bge-m3"
4model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
5tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=True)1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("sayed0am/arabic-english-bge-m3")1#!/bin/bash
2
3port=8000
4model=sayed0am/arabic-english-bge-m3
5volume=$PWD/data
6
7docker run -it \
8 -v $volume:/app/.cache \
9 -p $port:$port \
10 michaelf34/infinity:latest-cpu \
11 v2 \
12 --engine optimum \
13 --model-id $model \
14 --port $port \
15 --url-prefix v1 \
16 --api-key sk-1231# pip install huggingface-hub
2
3from huggingface_hub import snapshot_download
4
5snapshot_download(repo_id="sayed0am/arabic-english-bge-m3",local_dir="arabic-english-bge-m3")1from optimum.onnxruntime import ORTModelForFeatureExtraction
2from transformers import AutoTokenizer
3import torch
4
5# Make sure that you download the model weights locally to `bge-m3-onnx`
6model = ORTModelForFeatureExtraction.from_pretrained("arabic-english-bge-m3", subfolder="onnx", provider="CUDAExecutionProvider") # omit provider for CPU usage.
7tokenizer = AutoTokenizer.from_pretrained("arabic-english-bge-m3")
8sentences = [
9 "English: The quick brown fox jumps over the lazy dog.",
10 "Arabic: الثعلب البني السريع يقفز فوق الكلب الكسول."
11]
12encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to("cuda") # For CPU remove .to("cuda")
13
14# Get the embeddings
15out=model(**encoded_input,return_dict=True).last_hidden_state
16
17# normalize the embeddings
18dense_vecs = torch.nn.functional.normalize(out[:, 0], dim=-1)
19