Ponimash commited on
Commit
104c80a
1 Parent(s): 860a8fc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -1
README.md CHANGED
@@ -13,4 +13,48 @@ tags:
13
  - .net
14
  - sbert
15
  - C#
16
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  - .net
14
  - sbert
15
  - C#
16
+ ---
17
+
18
+ ### Porting [this model](https://huggingface.co/FractalGPT/SbertDistil) for use in C#
19
+
20
+
21
+ * Example of use in C#:
22
+
23
+ ```csharp
24
+ using AI.DataPrepaire.DataLoader.NNWBlockLoader;
25
+ using AI.DataStructs.Algebraic;
26
+ using AI.ONNX.NLP.Bert;
27
+
28
+
29
+ string path = "SbertDistilAIFr";
30
+ // Загрузка модели Bert
31
+ BertEmbedder embedder = BertEmbedder.FromPretrained(path);
32
+ // Добавление последнего(линейного) слоя
33
+ LinearLayerLoader linearLayer = LinearLayerLoader.LoadFromBinary(@$"{path}\1_Linear\model.aifr");
34
+ embedder.V2VBlocks.Add(linearLayer);
35
+
36
+ // Векторизация предложений
37
+ Vector vects1 = embedder.ForwardSBert("Kittens love milk");
38
+ Vector vects2 = embedder.ForwardSBert("Visual Studio Code (VS Code) — текстовый редактор, разработанный Microsoft для Windows, Linux и macOS.");
39
+ Vector vects3 = embedder.ForwardSBert("Visual Studio Code, also commonly referred to as VS Code,[12] is a source-code editor developed by Microsoft for Windows, Linux and macOS.");
40
+ Vector vects1_rus = embedder.ForwardSBert("Котята любят молоко");
41
+
42
+ // Рассчет близости между текстами
43
+ Console.WriteLine(vects1.Cos(vects1_rus));
44
+ Console.WriteLine(vects1.Cos(vects2));
45
+ Console.WriteLine(vects2.Cos(vects3));
46
+ Console.WriteLine(vects1.Cos(vects3));
47
+ Console.ReadKey();
48
+ ```
49
+
50
+ * Network output
51
+
52
+ ```
53
+ 0.8312274467817271
54
+ 0.18402859300814606
55
+ 0.9556528309990797
56
+ 0.14738954582438052
57
+ ```
58
+
59
+
60
+ * [GitHub](https://github.com/AIFramework/AIFrameworkOpen)