CyberTea commited on
Commit
6491233
·
1 Parent(s): c03ef79

model and files

Browse files
Files changed (2) hide show
  1. convert.py +24 -0
  2. sbert_large_nlu_ru.onnx +3 -0
convert.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!pip install uv
2
+ #!uv pip install transformers torch onnx
3
+ # Импорты
4
+ from transformers import AutoTokenizer, AutoModel
5
+ import torch
6
+ import onnx
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained("ai-forever/sbert_large_nlu_ru")
9
+ model = AutoModel.from_pretrained("ai-forever/sbert_large_nlu_ru")
10
+
11
+ # Экспорт в ONNX
12
+ dummy_input = tokenizer("Тест", return_tensors="pt", padding=True, truncation=True)
13
+ torch.onnx.export(model,
14
+ (dummy_input['input_ids'], dummy_input['attention_mask']),
15
+ "sbert_large_nlu_ru.onnx",
16
+ input_names=["input_ids", "attention_mask"],
17
+ output_names=["last_hidden_state"],
18
+ dynamic_axes={
19
+ "input_ids": {0: "batch", 1: "sequence"},
20
+ "attention_mask": {0: "batch", 1: "sequence"},
21
+ "last_hidden_state": {0: "batch", 1: "sequence", 2: "features"}
22
+ })
23
+ # from google.colab import files
24
+ # files.download("/content/sbert_large_nlu_ru.onnx")
sbert_large_nlu_ru.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d91ca1f8d72b61c3f41914b8076fd695b00b05fc93182ab87f5d1dff59ebf670
3
+ size 1708105085