Spaces:
Runtime error
Runtime error
Update retriever.py
Browse files- retriever.py +22 -43
retriever.py
CHANGED
|
@@ -4,50 +4,29 @@ from langchain.docstore.document import Document
|
|
| 4 |
import datasets
|
| 5 |
|
| 6 |
|
| 7 |
-
class
|
| 8 |
-
name = "
|
| 9 |
-
description = "Retrieves
|
| 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
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 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 |
+
)
|