QagentS commited on
Commit
354cfe9
1 Parent(s): ebceec6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +88 -87
README.md CHANGED
@@ -103,12 +103,23 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
103
  device = "cuda"
104
  model = AutoModelForCausalLM.from_pretrained("PipableAI/pip-code-to-doc-1.3b").to(device)
105
  tokenizer = AutoTokenizer.from_pretrained("PipableAI/pip-code-to-doc-1.3b")
106
- prompt = f"""
 
 
 
 
 
 
 
 
 
 
 
107
  <function_code>
108
  def example_function(x):
109
  return x * 2
110
  </function_code>
111
- <question>Give one line description of the python code above in natural language.</question>
112
  <doc>"""
113
  inputs = tokenizer(prompt, return_tensors="pt")
114
  outputs = model.generate(**inputs, max_new_tokens=300)
@@ -121,95 +132,85 @@ tokenizer.decode(outputs[0], skip_special_tokens=True).split('<doc>')[-1].split(
121
 
122
  ### prompt
123
  ```python
124
- <function_code>
125
- ###########################
126
- # Generate Analytical Model
127
- ###########################
128
- ##################################################
129
- # func: get_np_array_transition_probability_matrix
130
- ##################################################
131
- def get_np_array_transition_probability_matrix(int_num_states, np_array_A_matrix):
132
- print('np_array_A_matrix:')
133
- print(np_array_A_matrix)
134
- #####################################################
135
- # Perturb the adjacency matrix to avoid singularities
136
- #####################################################
137
- np_array_A_matrix += (np.full((int_num_states, int_num_states), float_eps) - (np.identity(int_num_states) * float_eps))
138
- print('np_array_A_matrix:')
139
- print(np_array_A_matrix)
140
- print('np_array_D_matrix:')
141
- np_array_D_matrix = np.diag(np.sum(np_array_A_matrix, axis=1))
142
- print(np_array_D_matrix)
143
- print('np_array_D_matrix_inv:')
144
- np_array_D_matrix_inv = np.linalg.inv(np_array_D_matrix)
145
- print(np_array_D_matrix_inv)
146
- print('\n\n')
147
- print('np_array_P_matrix:')
148
- np_array_P_matrix = np.dot(np_array_D_matrix_inv, np_array_A_matrix)
149
- print(np_array_P_matrix)
150
- print('np.sum(np_array_P_matrix, axis=1):')
151
- print(np.sum(np_array_P_matrix, axis=1))
152
- print('\n\n')
153
- return np_array_P_matrix
154
- ##################################################
155
- # func: get_np_array_perron_frobenius_eigen_vector
156
- ##################################################
157
- def get_np_array_perron_frobenius_matrix(int_num_states, np_array_P_matrix):
158
- np_array_perron_frobenius_matrix = np.linalg.matrix_power(np_array_P_matrix,1000)
159
- np_array_perron_frobenius_vector = np_array_perron_frobenius_matrix[0,:]
160
- print('np_array_perron_frobenius_matrix:')
161
- print(np_array_perron_frobenius_matrix)
162
- print('np.sum(np_array_perron_frobenius_matrix, axis=1):')
163
- print(np.sum(np_array_perron_frobenius_matrix, axis=1))
164
- print('np.sum(np_array_perron_frobenius_matrix, axis=0):')
165
- print(np.sum(np_array_perron_frobenius_matrix, axis=0))
166
- print('np.sum(np_array_perron_frobenius_matrix, axis=0)/int_num_states:')
167
- print(np.sum(np_array_perron_frobenius_matrix, axis=0)/int_num_states)
168
- print('np.dot(np_array_perron_frobenius_vector, np_array_P_matrix):')
169
- print(np.dot(np_array_perron_frobenius_vector, np_array_P_matrix))
170
- print('np_array_perron_frobenius_vector:')
171
- print(np_array_perron_frobenius_vector)
172
- print('\n\n')
173
- return np_array_perron_frobenius_vector, np_array_perron_frobenius_matrix
174
- #############################
175
- # func: get_np_array_Z_matrix
176
- #############################
177
- def get_np_array_Z_matrix(int_num_states, np_array_P_matrix, np_array_perron_frobenius_matrix):
178
- np_array_Z_matrix = np.linalg.inv(np.identity(int_num_states) - np_array_P_matrix + np_array_perron_frobenius_matrix)
179
- print('np_array_Z_matrix:')
180
- print(np_array_Z_matrix)
181
- print('\n\n')
182
- return(np_array_Z_matrix)
183
- #############################
184
- # func: get_np_array_H_matrix
185
- #############################
186
- def get_np_array_H_matrix(int_num_states, np_array_Z_matrix, np_array_perron_frobenius_vector):
187
- np_array_H_matrix = np.zeros([int_num_states, int_num_states])
188
- for i in range(int_num_states):
189
- for j in range(int_num_states):
190
- np_array_H_matrix[i][j] = (np_array_Z_matrix[j][j] - np_array_Z_matrix[i][j])/np_array_perron_frobenius_vector[j]
191
- print('np_array_H_matrix:')
192
- print(np_array_H_matrix)
193
- print('\n\n')
194
- return np_array_H_matrix
195
- ###########
196
- # func: run
197
- ###########
198
- def run(np_array_A_matrix):
199
- int_num_states = len(np_array_A_matrix)
200
- np_array_P_matrix = get_np_array_transition_probability_matrix(int_num_states, np_array_A_matrix)
201
- np_array_perron_frobenius_vector, np_array_perron_frobenius_matrix = get_np_array_perron_frobenius_matrix(int_num_states, np_array_P_matrix)
202
- np_array_Z_matrix = get_np_array_Z_matrix(int_num_states, np_array_P_matrix, np_array_perron_frobenius_matrix)
203
- np_array_H_matrix = get_np_array_H_matrix(int_num_states, np_array_Z_matrix, np_array_perron_frobenius_vector)
204
- return(np_array_H_matrix)
205
- </function_code>
206
- <question>Give one line description of the python code above in natural language.</question>
207
- <doc>
208
  ```
209
 
210
  ### Response
211
  ```txt
212
- The given python code is a function that calculates the transition probability matrix, P, for a given adjacency matrix A, and then uses these matrices to calculate the Perron-Frobenius eigenvector and its inverse matrix Z, and finally, the H matrix which is the inverse of the Z matrix. The H matrix is then returned as the output of the function. The adjacency matrix A is a square matrix where each element at position (i, j) represents the probability of transitioning from state i to state j. The function first perturbs the adjacency matrix to avoid singularities, then calculates the transition probability matrix P, the Perron-Frobenius eigenvector and its inverse matrix Z, and finally, the H matrix. The H matrix is then returned as the output of the function.
 
 
 
 
 
 
 
 
213
  ```
214
 
215
  ### Team
 
103
  device = "cuda"
104
  model = AutoModelForCausalLM.from_pretrained("PipableAI/pip-code-to-doc-1.3b").to(device)
105
  tokenizer = AutoTokenizer.from_pretrained("PipableAI/pip-code-to-doc-1.3b")
106
+ prompt = f"""<example_response>
107
+ --code:def function_2(x): return x / 2
108
+ --question:Document the code
109
+ --doc:
110
+ Description:This function takes a number and divides it by 2.
111
+ Parameters:
112
+ - x (numeric): The input value to be divided by 2.
113
+ Returns:
114
+ - float: The result of x divided by 2
115
+ Example:
116
+ To call the function, use the following code:
117
+ function2(1.0)</example_response>
118
  <function_code>
119
  def example_function(x):
120
  return x * 2
121
  </function_code>
122
+ <question>Document the python code above giving function description ,parameters and return type and example how to call the function.</question>
123
  <doc>"""
124
  inputs = tokenizer(prompt, return_tensors="pt")
125
  outputs = model.generate(**inputs, max_new_tokens=300)
 
132
 
133
  ### prompt
134
  ```python
135
+ text=''' <example_response>
136
+ --code:def function_2(x): return x / 2
137
+ --question:Document the code
138
+ --doc:
139
+ Description:This function takes a number and divides it by 2.
140
+ Parameters:
141
+ - x (numeric): The input value to be divided by 2.
142
+ Returns:
143
+ - float: The result of x divided by 2
144
+ Example:
145
+ To call the function, use the following code:
146
+ function2(1.0)</example_response>
147
+ <function_code>def _plot_bounding_polygon(
148
+ polygons_coordinates, output_html_path="bounding_polygon_map.html"
149
+ ):
150
+ # Create a Folium map centered at the average coordinates of all bounding boxes
151
+ map_center = [
152
+ sum(
153
+ [
154
+ coord[0]
155
+ for polygon_coords in polygons_coordinates
156
+ for coord in polygon_coords
157
+ ]
158
+ )
159
+ / sum([len(polygon_coords) for polygon_coords in polygons_coordinates]),
160
+ sum(
161
+ [
162
+ coord[1]
163
+ for polygon_coords in polygons_coordinates
164
+ for coord in polygon_coords
165
+ ]
166
+ )
167
+ / sum([len(polygon_coords) for polygon_coords in polygons_coordinates]),
168
+ ]
169
+
170
+ my_map = folium.Map(location=map_center, zoom_start=12)
171
+
172
+ # Add each bounding polygon to the map
173
+ for polygon_coords in polygons_coordinates:
174
+ folium.Polygon(
175
+ locations=polygon_coords,
176
+ color="blue",
177
+ fill=True,
178
+ fill_color="blue",
179
+ fill_opacity=0.2,
180
+ ).add_to(my_map)
181
+
182
+ # Add bounding boxes as markers to the map
183
+ marker_cluster = MarkerCluster().add_to(my_map)
184
+
185
+ for polygon_coords in polygons_coordinates:
186
+ for coord in polygon_coords:
187
+ folium.Marker(
188
+ location=[coord[0], coord[1]], popup=f"Coordinates: {coord}"
189
+ ).add_to(marker_cluster)
190
+
191
+ # Add draw control to allow users to draw additional polygons
192
+ draw = Draw(export=True)
193
+ draw.add_to(my_map)
194
+
195
+ # Save the map as an HTML file
196
+ my_map.save(output_html_path)
197
+
198
+ return output_html_path
199
+ </function_code>
200
+ <question>Document the python code above giving function description ,parameters and return type and example how to call the function</question><doc>'''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  ```
202
 
203
  ### Response
204
  ```txt
205
+ Description:This function generates a map of the bounding polygons and saves it as an HTML file.
206
+ Parameters:
207
+ - polygons_coordinates (list of lists of tuples): A list of lists of tuples representing the coordinates of the polygons. Each polygon is a list of coordinates.
208
+ - output_html_path (str, optional): The path where the HTML file should be saved. Defaults to "bounding_polygon_map.html".
209
+ Returns:
210
+ - str: The path to the saved HTML file.
211
+ Example:
212
+ To call the function, use the following code:
213
+ plot_bounding_polygon([[(0, 0), (1, 0), (1, 1), (0, 1)], [(2, 2), (3, 2), (3, 3), (2, 3)]], "my_map.html").
214
  ```
215
 
216
  ### Team