Askio commited on
Commit
43ade6a
Β·
verified Β·
1 Parent(s): 9229617

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md CHANGED
@@ -68,6 +68,66 @@ This file is a list of chunks used for document retrieval, which contains the fo
68
  - **Example**: `A molecule editor is a computer program for creating and modifying representations of chemical structures.`
69
 
70
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  ## πŸ“„ License
73
 
 
68
  - **Example**: `A molecule editor is a computer program for creating and modifying representations of chemical structures.`
69
 
70
  ---
71
+ ## πŸ›  How to Use with Python
72
+
73
+ You can load and work with the mmRAG dataset using standard Python libraries like `json`. Below is a simple example of how to load and interact with the data files.
74
+
75
+ ### βœ… Step 1: Load the Dataset
76
+
77
+ ```python
78
+ import json
79
+
80
+ # Load query datasets
81
+ with open("mmrag_train.json", "r", encoding="utf-8") as f:
82
+ train_data = json.load(f)
83
+
84
+ with open("mmrag_dev.json", "r", encoding="utf-8") as f:
85
+ dev_data = json.load(f)
86
+
87
+ with open("mmrag_test.json", "r", encoding="utf-8") as f:
88
+ test_data = json.load(f)
89
+
90
+ # Load document chunks
91
+ with open("processed_documents.json", "r", encoding="utf-8") as f:
92
+ documents = json.load(f)
93
+ # Load as dict if needed
94
+ documents = {doc["id"]: doc["text"] for doc in documents}
95
+ ```
96
+ ### βœ… Step 2: Access Query and Document Examples
97
+
98
+ ```python
99
+ # Example query
100
+ query_example = train_data[0]
101
+ print("Query:", query_example["query"])
102
+ print("Answer:", query_example["answer"])
103
+ print("Relevant Chunks:", query_example["relevant_chunks"])
104
+
105
+ # Get the text of a relevant chunk
106
+ for chunk_id, relevance in query_example["relevant_chunks"].items():
107
+ if relevance > 0:
108
+ print(f"Chunk ID: {chunk_id}, Relevance label: {relevance}\nText: {documents[chunk_id]}")
109
+ ```
110
+ ### πŸ“Š Example: Get Sorted Routing Scores
111
+ The following example shows how to extract and sort the `dataset_score` field of a query to understand which dataset is most relevant to the query.
112
+
113
+ ```python
114
+ # Choose a query from the dataset
115
+ query_example = train_data[0]
116
+
117
+ print("Query:", query_example["query"])
118
+ print("Answer:", query_example["answer"])
119
+
120
+ # Get dataset routing scores
121
+ routing_scores = query_example["dataset_score"]
122
+
123
+ # Sort datasets by relevance score (descending)
124
+ sorted_routing = sorted(routing_scores.items(), key=lambda x: x[1], reverse=True)
125
+
126
+ print("\nRouting Results (sorted):")
127
+ for dataset, score in sorted_routing:
128
+ print(f"{dataset}: {score}")
129
+ ```
130
+
131
 
132
  ## πŸ“„ License
133