MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / parse_values

Function parse_values

tensorflow/contrib/training/python/training/hparam.py:195–307  ·  view source on GitHub ↗

Parses hyperparameter values from a string into a python map. `values` is a string containing comma-separated `name=value` pairs. For each pair, the value of the hyperparameter named `name` is set to `value`. If a hyperparameter name appears multiple times in `values`, a ValueError is ra

(values, type_map, ignore_unknown=False)

Source from the content-addressed store, hash-verified

193
194
195def parse_values(values, type_map, ignore_unknown=False):
196 """Parses hyperparameter values from a string into a python map.
197
198 `values` is a string containing comma-separated `name=value` pairs.
199 For each pair, the value of the hyperparameter named `name` is set to
200 `value`.
201
202 If a hyperparameter name appears multiple times in `values`, a ValueError
203 is raised (e.g. 'a=1,a=2', 'a[1]=1,a[1]=2').
204
205 If a hyperparameter name in both an index assignment and scalar assignment,
206 a ValueError is raised. (e.g. 'a=[1,2,3],a[0] = 1').
207
208 The hyperparameter name may contain '.' symbols, which will result in an
209 attribute name that is only accessible through the getattr and setattr
210 functions. (And must be first explicit added through add_hparam.)
211
212 WARNING: Use of '.' in your variable names is allowed, but is not well
213 supported and not recommended.
214
215 The `value` in `name=value` must follows the syntax according to the
216 type of the parameter:
217
218 * Scalar integer: A Python-parsable integer point value. E.g.: 1,
219 100, -12.
220 * Scalar float: A Python-parsable floating point value. E.g.: 1.0,
221 -.54e89.
222 * Boolean: Either true or false.
223 * Scalar string: A non-empty sequence of characters, excluding comma,
224 spaces, and square brackets. E.g.: foo, bar_1.
225 * List: A comma separated list of scalar values of the parameter type
226 enclosed in square brackets. E.g.: [1,2,3], [1.0,1e-12], [high,low].
227
228 When index assignment is used, the corresponding type_map key should be the
229 list name. E.g. for "arr[1]=0" the type_map must have the key "arr" (not
230 "arr[1]").
231
232 Args:
233 values: String. Comma separated list of `name=value` pairs where
234 'value' must follow the syntax described above.
235 type_map: A dictionary mapping hyperparameter names to types. Note every
236 parameter name in values must be a key in type_map. The values must
237 conform to the types indicated, where a value V is said to conform to a
238 type T if either V has type T, or V is a list of elements of type T.
239 Hence, for a multidimensional parameter 'x' taking float values,
240 'x=[0.1,0.2]' will parse successfully if type_map['x'] = float.
241 ignore_unknown: Bool. Whether values that are missing a type in type_map
242 should be ignored. If set to True, a ValueError will not be raised for
243 unknown hyperparameter type.
244
245 Returns:
246 A python map mapping each name to either:
247 * A scalar value.
248 * A list of scalar values.
249 * A dictionary mapping index numbers to scalar values.
250 (e.g. "x=5,L=[1,2],arr[1]=3" results in {'x':5,'L':[1,2],'arr':{1:3}}")
251
252 Raises:

Callers 1

parseMethod · 0.85

Calls 5

_process_scalar_valueFunction · 0.85
_process_list_valueFunction · 0.85
_parse_failFunction · 0.85
matchMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected