This model is a sample model for the
Chinese blog post and
angle tutorial.
1from angle_emb import AnglE
2from angle_emb.utils import cosine_similarity
3
4# 1. load
5angle = AnglE.from_pretrained('WhereIsAI/pubmed-angle-base-en', pooling_strategy='cls').cuda()
6
7query = 'How to treat childhood obesity and overweight?'
8docs = [
9 query,
10 '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.',
11 '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.',
12]
13
14# 2. encode
15embeddings = angle.encode(docs)
16query_emb = embeddings[0]
17
18for doc, emb in zip(docs[1:], embeddings[1:]):
19 print(cosine_similarity(query_emb, emb))
20
21# 0.8029839020052982
22# 0.4260630076818197
1from sentence_transformers import SentenceTransformer
2from sentence_transformers.util import cos_sim
3
4
5# 1. load model
6model = SentenceTransformer("WhereIsAI/pubmed-angle-base-en")
7
8query = 'How to treat childhood obesity and overweight?'
9docs = [
10 query,
11 '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.',
12 '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.',
13]
14
15
16# 2. encode
17embeddings = model.encode(docs)
18
19similarities = cos_sim(embeddings[0], embeddings[1:])
20print('similarities:', similarities)
If you use this model for academic purpose, please cite AnglE's paper, as follows:
1@article{li2023angle,
2 title={AnglE-optimized Text Embeddings},
3 author={Li, Xianming and Li, Jing},
4 journal={arXiv preprint arXiv:2309.12871},
5 year={2023}
6}