LauraPanizo commited on
Commit
1bc2e94
1 Parent(s): 12f5a90

First version from tutorial

Browse files
Files changed (2) hide show
  1. embedding_test.py +40 -0
  2. embeddings.csv +0 -0
embedding_test.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from retry import retry
3
+ import pandas as pd
4
+
5
+ model_id = "sentence-transformers/all-MiniLM-L6-v2"
6
+ hf_token = "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"
7
+
8
+ api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
9
+ headers = {"Authorization": f"Bearer {hf_token}"}
10
+
11
+ @retry(tries=3, delay=10)
12
+ def query(texts):
13
+ response = requests.post(api_url, headers=headers, json={"inputs": texts})
14
+ result = response.json()
15
+ if isinstance(result, list):
16
+ return result
17
+ elif list(result.keys())[0] == "error":
18
+ raise RuntimeError("The model is currently loading, please re-run the query")
19
+
20
+
21
+ texts = ["How do I get a replacement Medicare card?",
22
+ "What is the monthly premium for Medicare Part B?",
23
+ "How do I terminate my Medicare Part B (medical insurance)?",
24
+ "How do I sign up for Medicare?",
25
+ "Can I sign up for Medicare Part B if I am working and have health insurance through an employer?",
26
+ "How do I sign up for Medicare Part B if I already have Part A?",
27
+ "What are Medicare late enrollment penalties?",
28
+ "What is Medicare and who can get it?",
29
+ "How can I get help with my Medicare Part A and Part B premiums?",
30
+ "What are the different parts of Medicare?",
31
+ "Will my Medicare premiums be higher because of my higher income?",
32
+ "What is TRICARE ?",
33
+ "Should I sign up for Medicare Part B if I have Veterans' Benefits?"]
34
+ def main():
35
+ output = query(texts)
36
+ embeddings = pd.DataFrame(output)
37
+ embeddings.to_csv("embeddings.csv", index=False)
38
+
39
+ if __name__ == '__main__':
40
+ main()
embeddings.csv ADDED
The diff for this file is too large to render. See raw diff