CindyDelage commited on
Commit
95bea38
·
verified ·
1 Parent(s): c9c557d

Update retriever.py

Browse files
Files changed (1) hide show
  1. retriever.py +22 -43
retriever.py CHANGED
@@ -4,50 +4,29 @@ from langchain.docstore.document import Document
4
  import datasets
5
 
6
 
7
- class GuestInfoRetrieverTool(Tool):
8
- name = "guest_info_retriever"
9
- description = "Retrieves detailed information about gala guests based on their name or relation, in order to lauch the conversation."
10
- inputs = {
11
- "query": {
12
- "type": "string",
13
- "description": "The name or relation of the guest you want information about."
14
- }
15
- }
16
  output_type = "string"
17
 
18
- def __init__(self, docs):
19
- self.is_initialized = False
20
- self.retriever = BM25Retriever.from_documents(docs)
21
-
22
-
23
- def forward(self, query: str):
24
- results = self.retriever.invoke("Description")#get_relevant_documents(query)
25
- if results:
26
- return "\n\n" .join([doc.page_content for doc in results[:3]])
27
- else:
28
- return "No matching guest information found."
29
-
30
-
31
- def load_guest_dataset():
32
- # Load the dataset
33
- guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
34
-
35
- # Convert dataset entries into Document objects
36
- docs = [
37
- Document(
38
- page_content="\n".join([
39
- f"Name: {guest['name']}",
40
- f"Relation: {guest['relation']}",
41
- f"Description: {guest['description']}",
42
- f"Email: {guest['email']}"
43
- ]),
44
- metadata={"name": guest["name"]}
45
  )
46
- for guest in guest_dataset
47
- ]
48
-
49
- # Return the tool
50
- return GuestInfoRetrieverTool(docs)
51
-
52
-
53
 
 
 
 
 
 
 
 
 
 
4
  import datasets
5
 
6
 
7
+ class FrugalAI_methods(Tool):
8
+ name = "Frugal_AI_methods_retriever"
9
+ description = "Retrieves methods for model frugalization."
 
 
 
 
 
 
10
  output_type = "string"
11
 
12
+ def pruning(self):
13
+ """
14
+ Optimizes models by removing unnecessary components, such as certain weights in a neural network.
15
+ This function demonstrates how to apply pruning.
16
+ """
17
+ model = apply_pruning(model, amount=0.3)
18
+ code = "model = apply_pruning(model, amount=0.3)"
19
+ return (
20
+ f"To apply pruning to a model, use the following code snippet: {code}. "
21
+ f"You should adapt it to your actual implementation. In particular, the 'amount' parameter "
22
+ f"can be increased or decreased depending on the initial number of weights and the complexity of your use case (minimu value: 0, maximum value: 1)."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  )
 
 
 
 
 
 
 
24
 
25
+ def quantization(self):
26
+ """
27
+ Converts high-precision weights into lower-precision one to reduce cost.
28
+ """
29
+ code = "model = torch.quantization.quantize_dynamic(model, dtype=torch.qint8)"
30
+ return (
31
+ f"To apply quantization to a model, use the following code snippet: {code}."
32
+ )