olgab42 commited on
Commit
e5c18c0
·
verified ·
1 Parent(s): 0735a83

Delete README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -57
README.md DELETED
@@ -1,57 +0,0 @@
1
- ---
2
- base_model:
3
- - Alibaba-NLP/gte-multilingual-base
4
- pipeline_tag: text-generation
5
- license: apache-2.0
6
- ---
7
-
8
- This is the ONNX version of the [gte-multilingual-base](https://huggingface.co/Alibaba-NLP/gte-multilingual-base) model.
9
-
10
- This example is adapted from the original model repository for the ONNX version.
11
- ```python
12
- # Requires transformers>=4.36.0
13
- import onnxruntime as ort
14
- import numpy as np
15
- from transformers import AutoTokenizer
16
-
17
- input_texts = [
18
- "what is the capital of China?",
19
- "how to implement quick sort in python?",
20
- "北京",
21
- "快排算法介绍"
22
- ]
23
-
24
- # Load the tokenizer (using the original model for tokenizer)
25
- tokenizer = AutoTokenizer.from_pretrained('Alibaba-NLP/gte-multilingual-base')
26
-
27
- # Load the ONNX model
28
- session = ort.InferenceSession("model.onnx")
29
-
30
- # Tokenize the input texts
31
- batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='np')
32
-
33
- # Run inference
34
- outputs = session.run(None, {
35
- "input_ids": batch_dict["input_ids"],
36
- "attention_mask": batch_dict["attention_mask"]
37
- })
38
-
39
- # Get embeddings from the second output (last hidden states)
40
- # Extract the [CLS] token embedding (first token) for each sequence
41
- last_hidden_states = outputs[1] # Shape: (batch_size, seq_len, hidden_size)
42
- dimension = 768 # The output dimension of the output embedding, should be in [128, 768]
43
- embeddings = last_hidden_states[:, 0, :dimension] # Shape: (batch_size, dimension)
44
-
45
- # Debug: Check embeddings
46
- print(f"Embeddings shape: {embeddings.shape}")
47
- print(f"First few values of first embedding: {embeddings[0][:5]}")
48
- print(f"First few values of second embedding: {embeddings[1][:5]}")
49
-
50
- # Normalize embeddings
51
- embeddings = embeddings / np.linalg.norm(embeddings, axis=1, keepdims=True)
52
-
53
- # Calculate similarity scores
54
- scores = (embeddings[:1] @ embeddings[1:].T) * 100
55
- print(scores.tolist())
56
- # [[0.3016996383666992, 0.7503870129585266, 0.3203084468841553]]
57
- ```