Add a JSON perplexity task if the given task name matches the JSON task specification. See `json.JsonPerplexity`.
(task_name)
| 338 | |
| 339 | |
| 340 | def add_json_task(task_name): |
| 341 | """Add a JSON perplexity task if the given task name matches the |
| 342 | JSON task specification. |
| 343 | |
| 344 | See `json.JsonPerplexity`. |
| 345 | """ |
| 346 | if not task_name.startswith("json"): |
| 347 | return |
| 348 | |
| 349 | def create_json_task(): |
| 350 | splits = task_name.split("=", 1) |
| 351 | if len(splits) != 2 or not splits[1]: |
| 352 | raise ValueError( |
| 353 | "json tasks need a path argument pointing to the local " |
| 354 | "dataset, specified like this: json=" |
| 355 | + _EXAMPLE_JSON_PATH |
| 356 | + ' (if there are no splits, use "train")' |
| 357 | ) |
| 358 | |
| 359 | json_path = splits[1] |
| 360 | if json_path == _EXAMPLE_JSON_PATH: |
| 361 | raise ValueError( |
| 362 | "please do not copy the example path directly, but substitute " |
| 363 | "it with a path to your local dataset" |
| 364 | ) |
| 365 | return lambda: json.JsonPerplexity(json_path) |
| 366 | |
| 367 | TASK_REGISTRY[task_name] = create_json_task() |
| 368 | |
| 369 | |
| 370 | def get_task(task_name): |
no test coverage detected