SeanLee97 commited on
Commit
a639ecf
·
verified ·
1 Parent(s): 19be5f2

add sentence-transformer usage

Browse files
Files changed (1) hide show
  1. README.md +27 -1
README.md CHANGED
@@ -9,6 +9,7 @@ datasets:
9
  - WhereIsAI/pubmedqa-test-angle-format-a
10
  language:
11
  - en
 
12
  ---
13
 
14
  # WhereIsAI/pubmed-angle-base-en
@@ -51,6 +52,7 @@ Example:
51
  from angle_emb import AnglE
52
  from angle_emb.utils import cosine_similarity
53
 
 
54
  angle = AnglE.from_pretrained('WhereIsAI/pubmed-angle-base-en', pooling_strategy='cls').cuda()
55
 
56
  query = 'How to treat childhood obesity and overweight?'
@@ -60,6 +62,7 @@ docs = [
60
  'If you want to treat tonsillitis better, you can choose some anti-inflammatory drugs under the guidance of a doctor, or use local drugs, such as washing the tonsil crypts, injecting drugs into the tonsils, etc. If your child has a sore throat, you can also give him or her some pain relievers. If your child has a fever, you can give him or her antipyretics. If the condition is serious, seek medical attention as soon as possible. If the medication does not have a good effect and the symptoms recur, the author suggests surgical treatment. Parents should also make sure to keep their children warm to prevent them from catching a cold and getting tonsillitis again.',
61
  ]
62
 
 
63
  embeddings = angle.encode(docs)
64
  query_emb = embeddings[0]
65
 
@@ -79,10 +82,33 @@ Install sentence-transformers
79
  python -m pip install -U sentence-transformers
80
  ```
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  ## Citation
84
 
85
- If you use this model for academic papers, please cite angle's paper, as follows:
86
 
87
  ```bibtext
88
  @article{li2023angle,
 
9
  - WhereIsAI/pubmedqa-test-angle-format-a
10
  language:
11
  - en
12
+ library_name: sentence-transformers
13
  ---
14
 
15
  # WhereIsAI/pubmed-angle-base-en
 
52
  from angle_emb import AnglE
53
  from angle_emb.utils import cosine_similarity
54
 
55
+ # 1. load
56
  angle = AnglE.from_pretrained('WhereIsAI/pubmed-angle-base-en', pooling_strategy='cls').cuda()
57
 
58
  query = 'How to treat childhood obesity and overweight?'
 
62
  'If you want to treat tonsillitis better, you can choose some anti-inflammatory drugs under the guidance of a doctor, or use local drugs, such as washing the tonsil crypts, injecting drugs into the tonsils, etc. If your child has a sore throat, you can also give him or her some pain relievers. If your child has a fever, you can give him or her antipyretics. If the condition is serious, seek medical attention as soon as possible. If the medication does not have a good effect and the symptoms recur, the author suggests surgical treatment. Parents should also make sure to keep their children warm to prevent them from catching a cold and getting tonsillitis again.',
63
  ]
64
 
65
+ # 2. encode
66
  embeddings = angle.encode(docs)
67
  query_emb = embeddings[0]
68
 
 
82
  python -m pip install -U sentence-transformers
83
  ```
84
 
85
+ ```python
86
+ from sentence_transformers import SentenceTransformer
87
+ from sentence_transformers.util import cos_sim
88
+
89
+
90
+ # 1. load model
91
+ model = SentenceTransformer("WhereIsAI/pubmed-angle-base-en")
92
+
93
+ query = 'How to treat childhood obesity and overweight?'
94
+ docs = [
95
+ query,
96
+ 'The child is overweight. Parents should relieve their children\'s symptoms through physical activity and healthy eating. First, they can let them do some aerobic exercise, such as jogging, climbing, swimming, etc. In terms of diet, children should eat more cucumbers, carrots, spinach, etc. Parents should also discourage their children from eating fried foods and dried fruits, which are high in calories and fat. Parents should not let their children lie in bed without moving after eating. If their children\'s condition is serious during the treatment of childhood obesity, parents should go to the hospital for treatment under the guidance of a doctor in a timely manner.',
97
+ 'If you want to treat tonsillitis better, you can choose some anti-inflammatory drugs under the guidance of a doctor, or use local drugs, such as washing the tonsil crypts, injecting drugs into the tonsils, etc. If your child has a sore throat, you can also give him or her some pain relievers. If your child has a fever, you can give him or her antipyretics. If the condition is serious, seek medical attention as soon as possible. If the medication does not have a good effect and the symptoms recur, the author suggests surgical treatment. Parents should also make sure to keep their children warm to prevent them from catching a cold and getting tonsillitis again.',
98
+ ]
99
+
100
+
101
+ # 2. encode
102
+ embeddings = model.encode(docs)
103
+
104
+ similarities = cos_sim(embeddings[0], embeddings[1:])
105
+ print('similarities:', similarities)
106
+ ```
107
+
108
 
109
  ## Citation
110
 
111
+ If you use this model for academic purpose, please cite AnglE's paper, as follows:
112
 
113
  ```bibtext
114
  @article{li2023angle,