shibing624 commited on
Commit
01c2dee
1 Parent(s): 59e85aa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -3
README.md CHANGED
@@ -9,22 +9,36 @@ tags:
9
  ---
10
  # shibing624/text2vec
11
  This is a CoSENT(Cosine Sentence) model: It maps sentences to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
 
12
  ## Usage (text2vec)
13
  Using this model becomes easy when you have [text2vec](https://github.com/shibing624/text2vec) installed:
 
14
  ```
15
  pip install -U text2vec
16
  ```
 
17
  Then you can use the model like this:
 
18
  ```python
19
- from text2vec import SBert
20
  sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
21
 
22
- model = SBert('shibing624/text2vec-base-chinese')
23
  embeddings = model.encode(sentences)
24
  print(embeddings)
25
  ```
 
26
  ## Usage (HuggingFace Transformers)
27
- Without [text2vec](https://github.com/shibing624/text2vec), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
 
 
 
 
 
 
 
 
 
28
  ```python
29
  from transformers import BertTokenizer, BertModel
30
  import torch
@@ -50,6 +64,28 @@ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask']
50
  print("Sentence embeddings:")
51
  print(sentence_embeddings)
52
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  ## Evaluation Results
54
  For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [text2vec](https://github.com/shibing624/text2vec)
55
 
 
9
  ---
10
  # shibing624/text2vec
11
  This is a CoSENT(Cosine Sentence) model: It maps sentences to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
12
+
13
  ## Usage (text2vec)
14
  Using this model becomes easy when you have [text2vec](https://github.com/shibing624/text2vec) installed:
15
+
16
  ```
17
  pip install -U text2vec
18
  ```
19
+
20
  Then you can use the model like this:
21
+
22
  ```python
23
+ from text2vec import SentenceModel
24
  sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
25
 
26
+ model = SentenceModel('shibing624/text2vec-base-chinese')
27
  embeddings = model.encode(sentences)
28
  print(embeddings)
29
  ```
30
+
31
  ## Usage (HuggingFace Transformers)
32
+ Without [text2vec](https://github.com/shibing624/text2vec), you can use the model like this:
33
+
34
+ First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
35
+
36
+ Install transformers:
37
+ ```
38
+ pip install transformers
39
+ ```
40
+
41
+ Then load model and predict:
42
  ```python
43
  from transformers import BertTokenizer, BertModel
44
  import torch
 
64
  print("Sentence embeddings:")
65
  print(sentence_embeddings)
66
  ```
67
+
68
+ ## Usage (sentence-transformers)
69
+ [sentence-transformers](https://github.com/UKPLab/sentence-transformers) is a popular library to compute dense vector representations for sentences.
70
+
71
+ Install sentence-transformers:
72
+ ```
73
+ pip install -U sentence-transformers
74
+ ```
75
+
76
+ Then load model and predict:
77
+
78
+ ```python
79
+ from sentence_transformers import SentenceTransformer
80
+
81
+ m = SentenceTransformer("shibing624/text2vec-base-chinese")
82
+ sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
83
+
84
+ sentence_embeddings = m.encode(sentences)
85
+ print("Sentence embeddings:")
86
+ print(sentence_embeddings)
87
+ ```
88
+
89
  ## Evaluation Results
90
  For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [text2vec](https://github.com/shibing624/text2vec)
91